Skip to content

Commit

Permalink
Support id method in Factory.
Browse files Browse the repository at this point in the history
  • Loading branch information
flori authored and tristandunn committed Jun 7, 2010
1 parent 61b25fa commit 16feec0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/factory_girl/factory.rb
@@ -1,4 +1,5 @@
class Factory
undef :id
undef :type

# Raised when a factory is defined that attempts to instantiate itself.
Expand Down
15 changes: 15 additions & 0 deletions spec/factory_girl/factory_spec.rb
Expand Up @@ -77,6 +77,21 @@
attributes.first.name.should == :type
end

it "should return static attribute when asked for the id" do
result = @factory.id
result.should be_kind_of(Array)
result.first.should be_kind_of(Factory::Attribute::Static)
result.first.name.should == :id
end

it "should define id as an attribute" do
@factory.id { "it's an id" }
attributes = @factory.attributes
attributes.should be_kind_of(Array)
attributes.size.should == 1
attributes.first.name.should == :id
end

it "should not allow the same attribute to be added twice" do
lambda {
2.times { @factory.add_attribute :first_name }
Expand Down

0 comments on commit 16feec0

Please sign in to comment.