Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Ruby on Rails 5.1, Ruby 2.4 #329

Merged
merged 2 commits into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ rvm:
- 2.1
- 2.2.4
- 2.3.1
- 2.4.1
- ruby-head
env:
- DB=SQLITE
Expand All @@ -16,12 +17,19 @@ gemfile:
- gemfiles/rails41.gemfile
- gemfiles/rails42.gemfile
- gemfiles/rails50.gemfile
- gemfiles/rails51.gemfile
matrix:
allow_failures:
- rvm: ruby-head
exclude:
- rvm: 2.1
gemfile: gemfiles/rails50.gemfile
- rvm: 2.1
gemfile: gemfiles/rails51.gemfile
- rvm: 2.4.1
gemfile: gemfiles/rails40.gemfile
- rvm: 2.4.1
gemfile: gemfiles/rails41.gemfile
fast_finish: true
branches:
only:
Expand Down
4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ end
appraise 'rails50' do
gem 'rails', '~> 5.0.0'
end

appraise 'rails51' do
gem 'rails', '>= 5.1.0.rc1', '< 5.2'
end
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Audited [![Build Status](https://secure.travis-ci.org/collectiveidea/audited.svg

**Audited** (previously acts_as_audited) is an ORM extension that logs all changes to your models. Audited can also record who made those changes, save comments and associate models related to the changes.

Audited currently (4.x) works with Rails 5.0 and 4.2. It may work with 4.1 and 4.0, but this is not guaranteed.
Audited currently (4.x) works with Rails 5.1, 5.0 and 4.2. It may work with 4.1 and 4.0, but this is not guaranteed.

For Rails 3, use gem version 3.0 or see the [3.0-stable branch](https://github.com/collectiveidea/audited/tree/3.0-stable).

Expand All @@ -14,6 +14,7 @@ Audited supports and is [tested against](http://travis-ci.org/collectiveidea/aud
* 2.1.5
* 2.2.4
* 2.3.1
* 2.4.1

Audited may work just fine with a Ruby version not listed above, but we can't guarantee that it will. If you'd like to maintain a Ruby that isn't listed, please let us know with a [pull request](https://github.com/collectiveidea/audited/pulls).

Expand Down
7 changes: 7 additions & 0 deletions gemfiles/rails51.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", ">= 5.1.0.rc1", "< 5.2"

gemspec :name => "audited", :path => "../"
2 changes: 2 additions & 0 deletions lib/generators/audited/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
require 'active_record'
require 'rails/generators/active_record'
require 'generators/audited/migration'
require 'generators/audited/migration_helper'

module Audited
module Generators
class InstallGenerator < Rails::Generators::Base
include Rails::Generators::Migration
include Audited::Generators::MigrationHelper
extend Audited::Generators::Migration

class_option :audited_changes_column_type, type: :string, default: "text", required: false
Expand Down
9 changes: 9 additions & 0 deletions lib/generators/audited/migration_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Audited
module Generators
module MigrationHelper
def migration_parent
Rails::VERSION::MAJOR == 4 ? 'ActiveRecord::Migration' : "ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]"
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class <%= migration_class_name %> < ActiveRecord::Migration
class <%= migration_class_name %> < <%= migration_parent %>
def self.up
add_column :audits, :association_id, :integer
add_column :audits, :association_type, :string
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/audited/templates/add_comment_to_audits.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class <%= migration_class_name %> < ActiveRecord::Migration
class <%= migration_class_name %> < <%= migration_parent %>
def self.up
add_column :audits, :comment, :string
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class <%= migration_class_name %> < ActiveRecord::Migration
class <%= migration_class_name %> < <%= migration_parent %>
def self.up
add_column :audits, :remote_address, :string
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class <%= migration_class_name %> < ActiveRecord::Migration
class <%= migration_class_name %> < <%= migration_parent %>
def self.up
add_column :audits, :request_uuid, :string
add_index :audits, :request_uuid
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/audited/templates/install.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class <%= migration_class_name %> < ActiveRecord::Migration
class <%= migration_class_name %> < <%= migration_parent %>
def self.up
create_table :audits, :force => true do |t|
t.column :auditable_id, :integer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class <%= migration_class_name %> < ActiveRecord::Migration
class <%= migration_class_name %> < <%= migration_parent %>
def self.up
if index_exists? :audits, [:association_id, :association_type], :name => 'association_index'
remove_index :audits, :name => 'association_index'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class <%= migration_class_name %> < ActiveRecord::Migration
class <%= migration_class_name %> < <%= migration_parent %>
def self.up
rename_column :audits, :changes, :audited_changes
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class <%= migration_class_name %> < ActiveRecord::Migration
class <%= migration_class_name %> < <%= migration_parent %>
def self.up
rename_column :audits, :auditable_parent_id, :association_id
rename_column :audits, :auditable_parent_type, :association_type
Expand Down
2 changes: 2 additions & 0 deletions lib/generators/audited/upgrade_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
require 'active_record'
require 'rails/generators/active_record'
require 'generators/audited/migration'
require 'generators/audited/migration_helper'

module Audited
module Generators
class UpgradeGenerator < Rails::Generators::Base
include Rails::Generators::Migration
include Audited::Generators::MigrationHelper
extend Audited::Generators::Migration

source_root File.expand_path("../templates", __FILE__)
Expand Down
2 changes: 1 addition & 1 deletion spec/audited/sweeper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def update
controller.send(:current_user=, user)

expect {
put :update, id: 123
put :update, Rails::VERSION::MAJOR == 4 ? {id: 123} : {params: {id: 123}}
}.to_not change( Audited::Audit, :count )
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/support/active_record/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def name=(val)

class UserOnlyPassword < ::ActiveRecord::Base
self.table_name = :users
attribute :non_column_attr if Rails.version >= '5.1'
audited allow_mass_assignment: true, only: :password
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class ChangeAuditedChangesTypeToJson < ActiveRecord::Migration
parent = Rails::VERSION::MAJOR == 4 ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
class ChangeAuditedChangesTypeToJson < parent
def self.up
remove_column :audits, :audited_changes
add_column :audits, :audited_changes, :json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class ChangeAuditedChangesTypeToJsonb < ActiveRecord::Migration
parent = Rails::VERSION::MAJOR == 4 ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
class ChangeAuditedChangesTypeToJsonb < parent
def self.up
remove_column :audits, :audited_changes
add_column :audits, :audited_changes, :jsonb
Expand Down
9 changes: 9 additions & 0 deletions test/install_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@ class InstallGeneratorTest < Rails::Generators::TestCase
assert_includes(content, 't.column :audited_changes, :json')
end
end

test "generate migration with correct AR migration parent" do
run_generator

assert_migration "db/migrate/install_audited.rb" do |content|
parent = Rails::VERSION::MAJOR == 4 ? 'ActiveRecord::Migration' : "ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]"
assert_includes(content, "class InstallAudited < #{parent}\n")
end
end
end
17 changes: 16 additions & 1 deletion test/upgrade_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
destination File.expand_path('../../tmp', __FILE__)
setup :prepare_destination
tests Audited::Generators::UpgradeGenerator
self.use_transactional_fixtures = false
if Rails::VERSION::MAJOR == 4
self.use_transactional_fixtures = false
else
self.use_transactional_tests = false
end

test "should add 'comment' to audits table" do
load_schema 1
Expand Down Expand Up @@ -74,4 +78,15 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
assert_match(/add_index :audits, :request_uuid/, content)
end
end

test "generate migration with correct AR migration parent" do
load_schema 1

run_generator %w(upgrade)

assert_migration "db/migrate/add_comment_to_audits.rb" do |content|
parent = Rails::VERSION::MAJOR == 4 ? 'ActiveRecord::Migration' : "ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]"
assert_includes(content, "class AddCommentToAudits < #{parent}\n")
end
end
end