Skip to content

Commit

Permalink
Adding attributes and callbacks return the attribute added
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Aug 20, 2011
1 parent 854204d commit 58ec702
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/factory_girl/attribute_list.rb
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion spec/factory_girl/attribute_list_spec.rb
Expand Up @@ -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) }
Expand Down Expand Up @@ -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" }

Expand All @@ -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
Expand Down

0 comments on commit 58ec702

Please sign in to comment.