Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

2 participants

@ijcd

Here is a failing test, a simple fix, the result being a passing test. Other specs still pass.

#311

@joshuaclayton

Thanks for committing this! I'll take a look at this on Friday!

@joshuaclayton joshuaclayton merged commit 0d7520e into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  lib/factory_girl/attribute_assigner.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
View
33 spec/acceptance/transient_attributes_spec.rb
@@ -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
Something went wrong with that request. Please try again.