Permalink
Browse files

Merge pull request #1 from leonL/master

handling field insertions for has_many association
  • Loading branch information...
2 parents 67fdfb7 + 62da4e2 commit bee7d0814a4699279f98e9612672f502320de770 Ryan Brunner committed May 11, 2012
Showing with 5 additions and 1 deletion.
  1. +2 −0 lib/seedomatic/seeder.rb
  2. +1 −0 spec/lib/seeder_spec.rb
  3. +2 −1 spec/support/my_model.rb
View
@@ -36,6 +36,8 @@ def import
def process_lookups(attrs)
attrs.select{|k| k.ends_with? "_lookup"}.each do |key, value|
+ attrs.delete(key)
+
association = key.gsub("_lookup", "")
lookup_class = model_class.reflect_on_association(association).klass
View
@@ -50,6 +50,7 @@
MyCategory.should_receive(:where).with(hash_including('code' => 'bar')).and_return(OpenStruct.new(:first => category))
subject
MyModel[0].category.should == category
+ MyModel[0].category_lookup.should be_nil
}
end
end
View
@@ -3,7 +3,7 @@ class MyCategory
end
class MyModel
- attr_accessor :name, :new_record, :category
+ attr_accessor :name, :new_record, :category, :category_lookup
@@models = []
@@ -26,6 +26,7 @@ def self.create(params = {})
def attributes=(attr)
self.name = attr['name']
self.category = attr['category']
+ self.category_lookup = attr['category_lookup']
end
def save!

0 comments on commit bee7d08

Please sign in to comment.