From 58ec702fa3f328fbf02bb34b75ea80b97a567569 Mon Sep 17 00:00:00 2001 From: Joshua Clayton Date: Sat, 20 Aug 2011 16:46:35 -0400 Subject: [PATCH] Adding attributes and callbacks return the attribute added --- lib/factory_girl/attribute_list.rb | 1 + spec/factory_girl/attribute_list_spec.rb | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/factory_girl/attribute_list.rb b/lib/factory_girl/attribute_list.rb index 906d311fa..39eab0605 100644 --- a/lib/factory_girl/attribute_list.rb +++ b/lib/factory_girl/attribute_list.rb @@ -58,6 +58,7 @@ def valid_callback_names def add_attribute(attribute) @attributes[attribute.priority] ||= [] @attributes[attribute.priority] << attribute + attribute end def prepend_attributes(new_attributes) diff --git a/spec/factory_girl/attribute_list_spec.rb b/spec/factory_girl/attribute_list_spec.rb index 7913d7750..879cb7286 100644 --- a/spec/factory_girl/attribute_list_spec.rb +++ b/spec/factory_girl/attribute_list_spec.rb @@ -12,6 +12,11 @@ subject.to_a.should == [static_attribute, dynamic_attribute] end + it "returns the attribute" do + subject.define_attribute(static_attribute).should == static_attribute + subject.define_attribute(dynamic_attribute).should == dynamic_attribute + end + it "raises if an attribute has already been defined" do expect { 2.times { subject.define_attribute(static_attribute) } @@ -49,7 +54,6 @@ let(:valid_callback_names) { [:after_create, :after_build, :after_stub] } let(:invalid_callback_names) { [:before_create, :before_build, :bogus] } - it "allows for defining adding a callback" do subject.add_callback(:after_create) { "Called after_create" } @@ -59,6 +63,10 @@ proxy.callbacks[:after_create].first.call.should == "Called after_create" end + it "returns the callback" do + subject.add_callback(:after_create) { "Called after_create" }.should be_a(FactoryGirl::Attribute::Callback) + end + it "allows valid callback names to be assigned" do valid_callback_names.each do |callback_name| expect do