Permalink
Browse files

Do not ignore alias names of transient attributes. (Fixes #311)

  • Loading branch information...
1 parent 07d2834 commit 0d7520e825670aa31556645ce8a8bb3d9a762bb1 @ijcd ijcd committed Mar 14, 2012
Showing with 34 additions and 1 deletion.
  1. +1 −1 lib/factory_girl/attribute_assigner.rb
  2. +33 −0 spec/acceptance/transient_attributes_spec.rb
@@ -66,7 +66,7 @@ def override_names
def alias_names_to_ignore
@attribute_list.reject(&:ignored).map do |attribute|
- override_names.map {|override| attribute.name if attribute.alias_for?(override) && attribute.name != override }
+ override_names.map {|override| attribute.name if attribute.alias_for?(override) && attribute.name != override && !ignored_attribute_names.include?(override) }
end.flatten.compact
end
end
@@ -108,3 +108,36 @@
FactoryGirl.build(:user).name.should == "John Doe 2"
end
end
+
+describe "assigning values from a transient attribute" do
+ before do
+ define_class("User") do
+ attr_accessor :foo_id, :foo_name
+ end
+
+ define_class("Foo") do
+ attr_accessor :id, :name
+ def initialize(id, name)
+ @id = id
+ @name = name
+ end
+ end
+
+ FactoryGirl.define do
+ factory :user do
+ ignore do
+ foo { Foo.new('id-of-foo', 'name-of-foo')}
+ end
+
+ foo_id { foo.id }
+ foo_name { foo.name }
+ end
+ end
+ end
+
+ it "does not ignore an _id attribute that is an alias for a transient attribute" do
+ user = FactoryGirl.build(:user, :foo => Foo.new('passed-in-id-of-foo', 'passed-in-name-of-foo'))
+ user.foo_id.should == 'passed-in-id-of-foo'
+ user.foo_name.should == 'passed-in-name-of-foo'
+ end
+end

0 comments on commit 0d7520e

Please sign in to comment.