From 7dcb2241c6c93eb739e1a284770f56cb7f1145b1 Mon Sep 17 00:00:00 2001 From: Joe Ferris Date: Wed, 28 May 2008 22:22:48 -0400 Subject: [PATCH] Renamed #attributes to #attributes_for --- lib/factory_girl/factory.rb | 12 ++++++------ test/factory_test.rb | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/factory_girl/factory.rb b/lib/factory_girl/factory.rb index b479e5f..38fb54a 100644 --- a/lib/factory_girl/factory.rb +++ b/lib/factory_girl/factory.rb @@ -98,7 +98,7 @@ class Factory # Returns: # A set of attributes that can be used to build an instance of the class # this factory generates. (Hash) - def attributes (attrs = {}) + def attributes_for (attrs = {}) result = {} @lazy_attributes.each do |name, block| result[name] = block.call unless attrs.key?(name) @@ -112,14 +112,14 @@ class Factory # # Arguments: # attrs: (Hash) - # See attributes + # See attributes_for # # Returns: # An instance of the class this factory generates, with generated # attributes assigned. def build (attrs = {}) instance = build_class.new - attributes(attrs).each do |attr, value| + attributes_for(attrs).each do |attr, value| instance.send(:"#{attr}=", value) end instance @@ -134,7 +134,7 @@ class Factory # # Arguments: # attrs: (Hash) - # See attributes + # See attributes_for # # Returns: # A saved instance of the class this factory generates, with generated @@ -147,8 +147,8 @@ class Factory class << self - def attributes (name, attrs = {}) - factory_by_name(name).attributes(attrs) + def attributes_for (name, attrs = {}) + factory_by_name(name).attributes_for(attrs) end def build (name, attrs = {}) diff --git a/test/factory_test.rb b/test/factory_test.rb index 1d27424..5e91170 100644 --- a/test/factory_test.rb +++ b/test/factory_test.rb @@ -77,7 +77,7 @@ class FactoryTest < Test::Unit::TestCase end should "include that value in the generated attributes hash" do - assert_equal @value, @factory.attributes[@attr] + assert_equal @value, @factory.attributes_for[@attr] end end @@ -97,14 +97,14 @@ class FactoryTest < Test::Unit::TestCase @factory.add_attribute(@attr) do called = true end - @factory.attributes + @factory.attributes_for assert called end should "use the result of the block as the value of the attribute" do value = "Watch out for snakes!" @factory.add_attribute(@attr) { value } - assert_equal value, @factory.attributes[@attr] + assert_equal value, @factory.attributes_for[@attr] end end @@ -113,7 +113,7 @@ class FactoryTest < Test::Unit::TestCase @attr = :first_name @value = 'Sugar' @factory.send(@attr, @value) - assert_equal @value, @factory.attributes[@attr] + assert_equal @value, @factory.attributes_for[@attr] end should "not allow attributes to be added with both a value parameter and a block" do @@ -132,12 +132,12 @@ class FactoryTest < Test::Unit::TestCase should "return the overridden value in the generated attributes" do @factory.add_attribute(@attr, 'The price is wrong, Bob!') - assert_equal @value, @factory.attributes(@hash)[@attr] + assert_equal @value, @factory.attributes_for(@hash)[@attr] end should "not call a lazy attribute block for an overridden attribute" do @factory.add_attribute(@attr) { flunk } - @factory.attributes(@hash) + @factory.attributes_for(@hash) end end @@ -227,7 +227,7 @@ class FactoryTest < Test::Unit::TestCase @factory = Factory.factories[@name] end - [:build, :create, :attributes].each do |method| + [:build, :create, :attributes_for].each do |method| should "delegate the #{method} method to the factory instance" do @factory.expects(method).with(@attrs)