Skip to content

Commit

Permalink
Do not ignore alias names of transient attributes. (Fixes #311)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijcd committed Mar 14, 2012
1 parent 07d2834 commit 0d7520e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/factory_girl/attribute_assigner.rb
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions spec/acceptance/transient_attributes_spec.rb
Expand Up @@ -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.