Skip to content

Commit

Permalink
Fix migrations in tests for rails 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima committed Jan 31, 2018
1 parent 5667847 commit 4c61d32
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gemfiles/rails52.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "rails", ">= 5.2.0.beta2", "< 5.3"
gem "rails", ">= 5.2.0.rc1", "< 5.3"
gem "mysql2", "~> 0.4.4"

gemspec name: "audited", path: "../"
6 changes: 3 additions & 3 deletions spec/audited/auditor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ def non_column_attr=(val)
let(:migrations_path) { SPEC_ROOT.join("support/active_record/postgres") }

after do
ActiveRecord::Migrator.rollback([migrations_path])
run_migrations(:down, migrations_path)
end

it "should work if column type is 'json'" do
ActiveRecord::Migrator.up([migrations_path], 1)
run_migrations(:up, migrations_path, 1)
Audited::Audit.reset_column_information
expect(Audited::Audit.columns_hash["audited_changes"].sql_type).to eq("json")

Expand All @@ -99,7 +99,7 @@ def non_column_attr=(val)
end

it "should work if column type is 'jsonb'" do
ActiveRecord::Migrator.up([migrations_path], 2)
run_migrations(:up, migrations_path, 2)
Audited::Audit.reset_column_information
expect(Audited::Audit.columns_hash["audited_changes"].sql_type).to eq("jsonb")

Expand Down
12 changes: 12 additions & 0 deletions spec/audited_spec_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,16 @@ def create_versions(n = 2)
end
end

def run_migrations(direction, migrations_paths, target_version = nil)
if rails_below?('5.2.0.rc1')
ActiveRecord::Migrator.send(direction, migrations_paths, target_version)
else
ActiveRecord::MigrationContext.new(migrations_paths).send(direction, target_version)
end
end

def rails_below?(rails_version)
Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new(rails_version)
end

end

0 comments on commit 4c61d32

Please sign in to comment.