Permalink
Browse files

Issue #18: belongs_to should not cause an assumption that Migrant is …

…being used on a model
  • Loading branch information...
1 parent 1ea1250 commit 4565f0261236bc4cd34f76e3d613546b6abf4bc5 @pascalh1011 committed Mar 6, 2012
@@ -29,7 +29,7 @@ def run
# Rails 3.2+ caches table (non) existence so this needs to be cleared before we start
ActiveRecord::Base.connection.schema_cache.clear! if ActiveRecord::Base.connection.respond_to?(:schema_cache)
- ActiveRecord::Base.descendants.select { |model| model.schema && model.schema.requires_migration? }.each do |model|
+ ActiveRecord::Base.descendants.select { |model| model.structure_defined? && model.schema.requires_migration? }.each do |model|
model.reset_column_information # db:migrate doesn't do this
@table_name = model.table_name
@columns = Hash[[:changed, :added, :deleted, :renamed, :transferred].collect { |a| [a,[]] }]
@@ -21,6 +21,8 @@ def structure(type=nil, &block)
# So, my_field in the structure block actually calls Migrant::Schema.my_field
create_migrant_schema
+ @structure_defined = true
+
if self.superclass == ActiveRecord::Base
@schema.define_structure(type, &block)
@schema.validations.each do |field, validation_options|
@@ -41,6 +43,10 @@ def structure(type=nil, &block)
end
end
+ def structure_defined?
+ @schema && @structure_defined || false
+ end
+
# Same as defining a structure block, but with no attributes besides
# relationships (such as in a many-to-many)
def no_structure
@@ -0,0 +1,3 @@
+class NonMigrantModel < ActiveRecord::Base
+ belongs_to :business
+end
View
@@ -99,4 +99,8 @@ class TestDataSchema < Test::Unit::TestCase
end
end
+ should "still indicate a structure is not defined if a belongs_to association is added" do
+ assert_equal(false, NonMigrantModel.structure_defined?)
+ assert_equal(true, Business.structure_defined?)
+ end
end

0 comments on commit 4565f02

Please sign in to comment.