mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Updated docs and examples for new syntax
This commit is contained in:
parent
6c2322a11d
commit
a7f7e85187
12 changed files with 24 additions and 23 deletions
|
@ -127,7 +127,7 @@ module FactoryGirl
|
|||
# # ...
|
||||
# end
|
||||
#
|
||||
# Factory(:author).class
|
||||
# FactoryGirl.create(:author).class
|
||||
# # => User
|
||||
#
|
||||
# Because an attribute defined without a value or block will build an
|
||||
|
@ -142,7 +142,7 @@ module FactoryGirl
|
|||
# author
|
||||
# end
|
||||
#
|
||||
# Factory(:post).author.class
|
||||
# FactoryGirl.create(:post).author.class
|
||||
# # => User
|
||||
def aliases
|
||||
@options[:aliases] || []
|
||||
|
|
|
@ -56,11 +56,11 @@ module FactoryGirl
|
|||
# end
|
||||
#
|
||||
# # Builds (but doesn't save) a Post and a User
|
||||
# Factory.build(:post)
|
||||
# FactoryGirl.build(:post)
|
||||
#
|
||||
# # Builds and saves a User, builds a Post, assigns the User to the
|
||||
# # author association, and saves the User.
|
||||
# Factory.create(:post)
|
||||
# FactoryGirl.create(:post)
|
||||
#
|
||||
def association(name, overrides = {})
|
||||
nil
|
||||
|
|
|
@ -3,8 +3,8 @@ module FactoryGirl
|
|||
# Raised when calling Factory.sequence from a dynamic attribute block
|
||||
class SequenceAbuseError < StandardError; end
|
||||
|
||||
# Sequences are defined using Factory.sequence. Sequence values are generated
|
||||
# using next.
|
||||
# Sequences are defined using sequence within a FactoryGirl.define block.
|
||||
# Sequence values are generated using next.
|
||||
class Sequence
|
||||
|
||||
def initialize(value = 1, &proc) #:nodoc:
|
||||
|
|
|
@ -12,7 +12,7 @@ module FactoryGirlStepHelpers
|
|||
end
|
||||
model_class = factory.build_class
|
||||
model_class.find(:first, :conditions => attributes_find) or
|
||||
Factory(factory_name, attributes)
|
||||
FactoryGirl.create(factory_name, attributes)
|
||||
end
|
||||
|
||||
def convert_human_hash_to_attribute_hash(human_hash, associations = [])
|
||||
|
@ -37,22 +37,22 @@ FactoryGirl.factories.values.each do |factory|
|
|||
end
|
||||
|
||||
Given /^an? #{factory.human_name} exists$/ do
|
||||
Factory(factory.name)
|
||||
FactoryGirl.create(factory.name)
|
||||
end
|
||||
|
||||
Given /^(\d+) #{factory.human_name.pluralize} exist$/ do |count|
|
||||
count.to_i.times { Factory(factory.name) }
|
||||
count.to_i.times { FactoryGirl.create(factory.name) }
|
||||
end
|
||||
|
||||
if factory.build_class.respond_to?(:columns)
|
||||
factory.build_class.columns.each do |column|
|
||||
human_column_name = column.name.downcase.gsub('_', ' ')
|
||||
Given /^an? #{factory.human_name} exists with an? #{human_column_name} of "([^"]*)"$/i do |value|
|
||||
Factory(factory.name, column.name => value)
|
||||
FactoryGirl.create(factory.name, column.name => value)
|
||||
end
|
||||
|
||||
Given /^(\d+) #{factory.human_name.pluralize} exist with an? #{human_column_name} of "([^"]*)"$/i do |count, value|
|
||||
count.to_i.times { Factory(factory.name, column.name => value) }
|
||||
count.to_i.times { FactoryGirl.create(factory.name, column.name => value) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module FactoryGirl
|
|||
# email { 'billy@bob.example.com' }
|
||||
# end
|
||||
#
|
||||
# Factory(:user, :name => 'Johnny')
|
||||
# FactoryGirl.create(:user, :name => 'Johnny')
|
||||
#
|
||||
# This syntax was derived from Pete Yandell's machinist.
|
||||
module Blueprint
|
||||
|
|
|
@ -15,14 +15,14 @@ module FactoryGirl
|
|||
# end
|
||||
#
|
||||
# # Creates a saved instance without raising (same as saving the result
|
||||
# # of Factory.build)
|
||||
# # of FactoryGirl.build)
|
||||
# User.generate(:name => 'Johnny')
|
||||
#
|
||||
# # Creates a saved instance and raises when invalid (same as
|
||||
# # Factory.create)
|
||||
# # FactoryGirl.create)
|
||||
# User.generate!
|
||||
#
|
||||
# # Creates an unsaved instance (same as Factory.build)
|
||||
# # Creates an unsaved instance (same as FactoryGirl.build)
|
||||
# User.spawn
|
||||
#
|
||||
# # Creates an instance and yields it to the passed block
|
||||
|
|
|
@ -2,7 +2,7 @@ module FactoryGirl
|
|||
module Syntax
|
||||
|
||||
# Extends ActiveRecord::Base to provide a make class method, which is a
|
||||
# shortcut for Factory.create.
|
||||
# shortcut for FactoryGirl.create.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
|
|
|
@ -20,6 +20,7 @@ module FactoryGirl
|
|||
# factory will be copied to the current one with an ability to override
|
||||
# them.
|
||||
# * default_strategy: +Symbol+
|
||||
# DEPRECATED.
|
||||
# The strategy that will be used by the Factory shortcut method.
|
||||
# Defaults to :create.
|
||||
#
|
||||
|
|
|
@ -61,7 +61,7 @@ describe "a custom create" do
|
|||
end
|
||||
|
||||
it "uses the custom create block instead of save" do
|
||||
Factory(:user).should be_persisted
|
||||
FactoryGirl.create(:user).should be_persisted
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ describe "a blueprint" do
|
|||
|
||||
describe "after making an instance" do
|
||||
before do
|
||||
@instance = Factory(:user, :last_name => 'Rye')
|
||||
@instance = FactoryGirl.create(:user, :last_name => 'Rye')
|
||||
end
|
||||
|
||||
it "should use attributes from the blueprint" do
|
||||
|
@ -26,7 +26,7 @@ describe "a blueprint" do
|
|||
|
||||
it "should evaluate attribute blocks for each instance" do
|
||||
@instance.email.should =~ /somebody\d+@example.com/
|
||||
Factory(:user).email.should_not == @instance.email
|
||||
FactoryGirl.create(:user).email.should_not == @instance.email
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ describe "a factory using sham syntax" do
|
|||
|
||||
describe "after making an instance" do
|
||||
before do
|
||||
@instance = Factory(:user, :last_name => 'Rye')
|
||||
@instance = FactoryGirl.create(:user, :last_name => 'Rye')
|
||||
end
|
||||
|
||||
it "should support a sham called 'name'" do
|
||||
|
|
|
@ -7,7 +7,7 @@ describe FactoryGirl::Proxy::AttributesFor do
|
|||
|
||||
describe "when asked to associate with another factory" do
|
||||
before do
|
||||
stub(Factory).create
|
||||
stub(FactoryGirl).create
|
||||
@proxy.associate(:owner, :user, {})
|
||||
end
|
||||
|
||||
|
@ -21,9 +21,9 @@ describe FactoryGirl::Proxy::AttributesFor do
|
|||
end
|
||||
|
||||
it "should not call Factory.create when building an association" do
|
||||
stub(Factory).create
|
||||
stub(FactoryGirl).create
|
||||
@proxy.association(:user).should be_nil
|
||||
Factory.should have_received.create.never
|
||||
FactoryGirl.should have_received.create.never
|
||||
end
|
||||
|
||||
it "should always return nil when building an association" do
|
||||
|
|
Loading…
Reference in a new issue