Skip to content

Commit fccaac7

Browse files
authored
Merge pull request #115 from epigenesys/rails-5-generator
Rails 5 generator
2 parents f7463cb + 1acf165 commit fccaac7

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

lib/generators/active_record/session_migration_generator.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ def session_table_name
1919
end
2020
current_table_name
2121
end
22+
23+
def migration_version
24+
"[#{ActiveRecord::Migration.current_version}]" if ActiveRecord::Migration.respond_to?(:current_version)
25+
end
2226
end
2327
end
2428
end

lib/generators/active_record/templates/migration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class <%= migration_class_name %> < ActiveRecord::Migration
1+
class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
22
def change
33
create_table :<%= session_table_name %> do |t|
44
t.string :session_id, :null => false

test/generators/session_migration_generator_test.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,25 @@ class SessionMigrationGeneratorTest < Rails::Generators::TestCase
88
destination 'tmp'
99
setup :prepare_destination
1010

11+
def active_record_version
12+
"\\[#{ActiveRecord::Migration.current_version}\\]" if ActiveRecord::Migration.respond_to?(:current_version)
13+
end
14+
1115
def test_session_migration_with_default_name
1216
run_generator
13-
assert_migration "db/migrate/add_sessions_table.rb", /class AddSessionsTable < ActiveRecord::Migration/
17+
assert_migration "db/migrate/add_sessions_table.rb", /class AddSessionsTable < ActiveRecord::Migration#{active_record_version}/
1418
end
1519

1620
def test_session_migration_with_given_name
1721
run_generator ["create_session_table"]
18-
assert_migration "db/migrate/create_session_table.rb", /class CreateSessionTable < ActiveRecord::Migration/
22+
assert_migration "db/migrate/create_session_table.rb", /class CreateSessionTable < ActiveRecord::Migration#{active_record_version}/
1923
end
2024

2125
def test_session_migration_with_custom_table_name
2226
ActiveRecord::SessionStore::Session.table_name = "custom_table_name"
2327
run_generator
2428
assert_migration "db/migrate/add_sessions_table.rb" do |migration|
25-
assert_match(/class AddSessionsTable < ActiveRecord::Migration/, migration)
29+
assert_match(/class AddSessionsTable < ActiveRecord::Migration#{active_record_version}/, migration)
2630
assert_match(/create_table :custom_table_name/, migration)
2731
end
2832
ensure

0 commit comments

Comments
 (0)