File tree Expand file tree Collapse file tree 2 files changed +20
-14
lines changed Expand file tree Collapse file tree 2 files changed +20
-14
lines changed Original file line number Diff line number Diff line change 11module MigrationTools
22 module MigrationExtension
3+ module ClassMethods
4+ attr_accessor :migration_group
35
4- attr_accessor :migration_group
6+ def group ( arg = nil )
7+ unless MigrationTools ::MIGRATION_GROUPS . member? ( arg . to_s )
8+ raise "Invalid group \" #{ arg . to_s } \" - valid groups are #{ MigrationTools ::MIGRATION_GROUPS . inspect } "
9+ end
510
6- def group ( arg = nil )
7- unless MigrationTools ::MIGRATION_GROUPS . member? ( arg . to_s )
8- raise "Invalid group \" #{ arg . to_s } \" - valid groups are #{ MigrationTools ::MIGRATION_GROUPS . inspect } "
11+ self . migration_group = arg . to_s
912 end
10-
11- self . migration_group = arg . to_s
1213 end
1314
1415 def migrate_with_forced_groups ( direction )
@@ -21,14 +22,15 @@ def migrate_with_forced_groups(direction)
2122end
2223
2324ActiveRecord ::Migration . class_eval do
24- extend MigrationTools ::MigrationExtension
25- class << self
26- alias_method :migrate_without_forced_groups , :migrate
27- alias_method :migrate , :migrate_with_forced_groups
28- end
25+ extend MigrationTools ::MigrationExtension :: ClassMethods
26+ include MigrationTools :: MigrationExtension
27+
28+ alias_method :migrate_without_forced_groups , :migrate
29+ alias_method :migrate , :migrate_with_forced_groups
2930
3031 def migration_group
3132 self . class . migration_group
3233 end
3334end
35+
3436ActiveRecord ::MigrationProxy . delegate :migration_group , :to => :migration
Original file line number Diff line number Diff line change 1616 @task = MigrationTools ::Tasks . new
1717 end
1818
19+ after do
20+ MigrationTools . instance_variable_set ( '@forced' , false )
21+ end
22+
1923 def migrations
2024 [ Alpha , Beta , Delta , Kappa ]
2125 end
@@ -56,15 +60,15 @@ def migration_proxy(m)
5660
5761 it "forcing" do
5862 assert !MigrationTools . forced?
59- Kappa . migrate ( "up" )
63+ Kappa . new . migrate ( "up" )
6064
6165 MigrationTools . forced!
6266 assert MigrationTools . forced?
6367
64- Alpha . migrate ( "up" )
68+ Alpha . new . migrate ( "up" )
6569
6670 begin
67- Kappa . migrate ( "up" )
71+ Kappa . new . migrate ( "up" )
6872 fail "You should not be able to run migrations without groups in forced mode"
6973 rescue RuntimeError => e
7074 assert e . message =~ /Cowardly refusing/
You can’t perform that action at this time.
0 commit comments