Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding attributes and callbacks return the attribute added

  • Loading branch information...
commit 58ec702fa3f328fbf02bb34b75ea80b97a567569 1 parent 854204d
Joshua Clayton joshuaclayton authored
1  lib/factory_girl/attribute_list.rb
View
@@ -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)
10 spec/factory_girl/attribute_list_spec.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.