Method 'blueprint'
Case 1
Defining new blueprint in blueprints file.
blueprint :person do
Person.create! :name => 'Namey'
end
You can also define blueprint with regexp name.
# In blueprints file
blueprint /user_(\w+)/ do
User.blueprint :name => options[:arg0]
end
# In spec
build :user_john
@john.name.should == 'john'
You can even take this one step further in ruby 1.9 with named groups.
# In blueprints file
blueprint /user_(?<name>\w+)/ do
User.blueprint options
end
# In spec
build :user_john
@john.name.should == 'john'
Case 2
On active record class instead of create!, to create new object bypassing attr_protected and attr_accessible.
blueprint :person do
Person.blueprint :name => 'Namey', :protected_attribute => 1
end
Case 3
On active record object instead of update_attributes!, to update object bypassing attr_protected and attr_accessible.
blueprint :person do
@person = Person.create! :name => 'Namey'
@person.blueprint(:protected_attribute => 1)
end
Case 4
In blueprints file outside blueprint block, as a convenience method to define new blueprint that creates one active record object.
Person.blueprint :person, :name => 'Namey'