Skip to content

Commit

Permalink
Check migrations properly work in tests
Browse files Browse the repository at this point in the history
Fixed GeneratorHelpers::migration_class_name because a migration file name
and its migration class name must match each other
  • Loading branch information
kymmt90 committed May 12, 2018
1 parent b820a33 commit 1e81f29
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/generators/statesman/generator_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def model_file_name
end

def migration_class_name
klass.gsub(/::/, "").pluralize
klass.demodulize.pluralize
end

def next_migration_number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
it "includes the metadata default value when other than MySQL", unless: mysql? do
expect(subject).to contain(/default: "{}"/)
end

it 'properly migrates the schema' do
require file("db/migrate/#{time}_create_bacon_transitions.rb")
expect { CreateBaconTransitions.new.up }.not_to raise_error
end
end

describe "properly adds class names" do
Expand Down
5 changes: 5 additions & 0 deletions spec/generators/statesman/migration_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@
expect(subject).
to contain("name: \"index_bacon_transitions_parent_most_recent\"")
end

it 'properly migrates the schema' do
require file("db/migrate/#{migration_number}_add_statesman_to_bacon_transitions.rb")
expect { AddStatesmanToBaconTransitions.new.up }.not_to raise_error
end
end
end

0 comments on commit 1e81f29

Please sign in to comment.