mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Use 1.9 hash syntax
This commit is contained in:
parent
400c9f193f
commit
6c29b11477
53 changed files with 248 additions and 248 deletions
|
@ -12,7 +12,7 @@ module FactoryGirl
|
|||
@constructor = nil
|
||||
end
|
||||
|
||||
delegate :declare_attribute, :to => :declarations
|
||||
delegate :declare_attribute, to: :declarations
|
||||
|
||||
def attributes
|
||||
@attributes ||= declarations.attribute_list
|
||||
|
|
|
@ -122,7 +122,7 @@ module FactoryGirl
|
|||
# end
|
||||
#
|
||||
# factory :post do
|
||||
# association :author, :factory => :user
|
||||
# association :author, factory: :user
|
||||
# end
|
||||
#
|
||||
# Arguments:
|
||||
|
|
|
@ -16,7 +16,7 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
delegate :add_callback, :declare_attribute, :to_create, :define_trait,
|
||||
:defined_traits, :inherit_traits, :processing_order, :to => :@definition
|
||||
:defined_traits, :inherit_traits, :processing_order, to: :@definition
|
||||
|
||||
def build_class #:nodoc:
|
||||
@build_class ||= if class_name.is_a? Class
|
||||
|
@ -50,7 +50,7 @@ module FactoryGirl
|
|||
#
|
||||
# Example:
|
||||
#
|
||||
# factory :user, :aliases => [:author] do
|
||||
# factory :user, aliases: [:author] do
|
||||
# # ...
|
||||
# end
|
||||
#
|
||||
|
@ -61,7 +61,7 @@ module FactoryGirl
|
|||
# association with the same name, this allows associations to be defined
|
||||
# without factories, such as:
|
||||
#
|
||||
# factory :user, :aliases => [:author] do
|
||||
# factory :user, aliases: [:author] do
|
||||
# # ...
|
||||
# end
|
||||
#
|
||||
|
|
|
@ -6,7 +6,7 @@ module FactoryGirl
|
|||
@definition = Definition.new
|
||||
end
|
||||
|
||||
delegate :defined_traits, :callbacks, :attributes, :constructor, :to => :definition
|
||||
delegate :defined_traits, :callbacks, :attributes, :constructor, to: :definition
|
||||
|
||||
def compile; end
|
||||
def class_name; end
|
||||
|
|
|
@ -40,7 +40,7 @@ module FactoryGirlStepHelpers
|
|||
return unless association
|
||||
|
||||
if attributes_hash = nested_attribute_hash
|
||||
factory.build_class.first(:conditions => attributes_hash.attributes(FindAttributes)) or
|
||||
factory.build_class.first(conditions: attributes_hash.attributes(FindAttributes)) or
|
||||
FactoryGirl.create(association.factory, attributes_hash.attributes)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module FactoryGirl
|
|||
# email { 'billy@bob.example.com' }
|
||||
# end
|
||||
#
|
||||
# FactoryGirl.create(:user, :name => 'Johnny')
|
||||
# FactoryGirl.create(:user, name: 'Johnny')
|
||||
#
|
||||
# This syntax was derived from Pete Yandell's machinist.
|
||||
module Blueprint
|
||||
|
@ -26,7 +26,7 @@ module FactoryGirl
|
|||
module ClassMethods #:nodoc:
|
||||
|
||||
def blueprint(&block)
|
||||
instance = Factory.new(name.underscore, :class => self)
|
||||
instance = Factory.new(name.underscore, class: self)
|
||||
proxy = FactoryGirl::DefinitionProxy.new(instance)
|
||||
proxy.instance_eval(&block)
|
||||
FactoryGirl.register_factory(instance)
|
||||
|
|
|
@ -25,7 +25,7 @@ module FactoryGirl
|
|||
|
||||
proxy.child_factories.each do |(child_name, child_options, child_block)|
|
||||
parent_factory = child_options.delete(:parent) || name
|
||||
factory(child_name, child_options.merge(:parent => parent_factory), &child_block)
|
||||
factory(child_name, child_options.merge(parent: parent_factory), &child_block)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ module FactoryGirl
|
|||
#
|
||||
# # Creates a saved instance without raising (same as saving the result
|
||||
# # of FactoryGirl.build)
|
||||
# User.generate(:name => 'Johnny')
|
||||
# User.generate(name: 'Johnny')
|
||||
#
|
||||
# # Creates a saved instance and raises when invalid (same as
|
||||
# # FactoryGirl.create)
|
||||
|
|
|
@ -15,7 +15,7 @@ module FactoryGirl
|
|||
# end
|
||||
# end
|
||||
#
|
||||
# User.make(:name => 'Johnny')
|
||||
# User.make(name: 'Johnny')
|
||||
#
|
||||
# This syntax was derived from Pete Yandell's machinist.
|
||||
module Make
|
||||
|
|
|
@ -81,7 +81,7 @@ module FactoryGirl
|
|||
#
|
||||
# # The user association will not be built in this example. The user_id
|
||||
# # will be used instead.
|
||||
# Factory(:post, :user_id => 1)
|
||||
# Factory(:post, user_id: 1)
|
||||
def self.alias(pattern, replace)
|
||||
FactoryGirl.aliases << [pattern, replace]
|
||||
end
|
||||
|
@ -110,7 +110,7 @@ module FactoryGirl
|
|||
# Shortcut for Factory.create.
|
||||
#
|
||||
# Example:
|
||||
# Factory(:user, :name => 'Joe')
|
||||
# Factory(:user, name: 'Joe')
|
||||
def Factory(name, attrs = {})
|
||||
::Factory.create(name, attrs)
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
delegate :add_callback, :declare_attribute, :to_create, :define_trait,
|
||||
:callbacks, :attributes, :to => :@definition
|
||||
:callbacks, :attributes, to: :@definition
|
||||
|
||||
def names
|
||||
[@name]
|
||||
|
|
|
@ -4,7 +4,7 @@ describe "aliases and overrides" do
|
|||
before do
|
||||
Factory.alias /one/, "two"
|
||||
|
||||
define_model("User", :two => :string, :one => :string)
|
||||
define_model("User", two: :string, one: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
|
@ -13,7 +13,7 @@ describe "aliases and overrides" do
|
|||
end
|
||||
end
|
||||
|
||||
subject { FactoryGirl.create(:user, :one => "override") }
|
||||
subject { FactoryGirl.create(:user, one: "override") }
|
||||
its(:one) { should == "override" }
|
||||
its(:two) { should be_nil }
|
||||
end
|
||||
|
|
|
@ -2,9 +2,9 @@ require 'spec_helper'
|
|||
|
||||
describe "attribute aliases" do
|
||||
before do
|
||||
define_model('User', :name => :string, :age => :integer)
|
||||
define_model('User', name: :string, age: :integer)
|
||||
|
||||
define_model('Post', :user_id => :integer) do
|
||||
define_model('Post', user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -19,14 +19,14 @@ describe "attribute aliases" do
|
|||
user
|
||||
end
|
||||
|
||||
factory :post_with_named_user, :class => Post do
|
||||
user :factory => :user_with_name, :age => 20
|
||||
factory :post_with_named_user, class: Post do
|
||||
user factory: :user_with_name, age: 20
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "assigning an association by foreign key" do
|
||||
subject { FactoryGirl.build(:post, :user_id => 1) }
|
||||
subject { FactoryGirl.build(:post, user_id: 1) }
|
||||
|
||||
it "doesn't assign both an association and its foreign key" do
|
||||
subject.user_id.should == 1
|
||||
|
|
|
@ -2,7 +2,7 @@ require "spec_helper"
|
|||
|
||||
describe "declaring attributes on a Factory that are private methods on Object" do
|
||||
before do
|
||||
define_model("Website", :system => :boolean, :link => :string, :sleep => :integer)
|
||||
define_model("Website", system: :boolean, link: :string, sleep: :integer)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :website do
|
||||
|
@ -13,7 +13,7 @@ describe "declaring attributes on a Factory that are private methods on Object"
|
|||
end
|
||||
end
|
||||
|
||||
subject { FactoryGirl.build(:website, :sleep => -5) }
|
||||
subject { FactoryGirl.build(:website, sleep: -5) }
|
||||
|
||||
its(:system) { should == false }
|
||||
its(:link) { should == "http://example.com" }
|
||||
|
@ -22,7 +22,7 @@ end
|
|||
|
||||
describe "assigning overrides that are also private methods on object" do
|
||||
before do
|
||||
define_model("Website", :format => :string, :y => :integer, :more_format => :string, :some_funky_method => :string)
|
||||
define_model("Website", format: :string, y: :integer, more_format: :string, some_funky_method: :string)
|
||||
|
||||
Object.class_eval do
|
||||
private
|
||||
|
@ -41,7 +41,7 @@ describe "assigning overrides that are also private methods on object" do
|
|||
Object.send(:undef_method, :some_funky_method)
|
||||
end
|
||||
|
||||
subject { FactoryGirl.build(:website, :format => "Great", :y => 12345, :some_funky_method => "foobar!") }
|
||||
subject { FactoryGirl.build(:website, format: "Great", y: 12345, some_funky_method: "foobar!") }
|
||||
its(:format) { should == "Great" }
|
||||
its(:y) { should == 12345 }
|
||||
its(:more_format) { should == "format: Great" }
|
||||
|
@ -50,7 +50,7 @@ end
|
|||
|
||||
describe "accessing methods from the instance within a dynamic attribute that is also a private method on object" do
|
||||
before do
|
||||
define_model("Website", :more_format => :string) do
|
||||
define_model("Website", more_format: :string) do
|
||||
def format
|
||||
"This is an awesome format"
|
||||
end
|
||||
|
|
|
@ -6,10 +6,10 @@ describe "a generated attributes hash" do
|
|||
before do
|
||||
define_model('User')
|
||||
|
||||
define_model('Post', :title => :string,
|
||||
:body => :string,
|
||||
:summary => :string,
|
||||
:user_id => :integer) do
|
||||
define_model('Post', title: :string,
|
||||
body: :string,
|
||||
summary: :string,
|
||||
user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -25,7 +25,7 @@ describe "a generated attributes hash" do
|
|||
end
|
||||
end
|
||||
|
||||
subject { attributes_for(:post, :title => 'overridden title') }
|
||||
subject { attributes_for(:post, title: 'overridden title') }
|
||||
|
||||
it "assigns an overridden value" do
|
||||
subject[:title].should == "overridden title"
|
||||
|
@ -49,7 +49,7 @@ describe "calling `attributes_for` with a block" do
|
|||
include FactoryGirl::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('Company', :name => :string)
|
||||
define_model('Company', name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :company
|
||||
|
@ -57,7 +57,7 @@ describe "calling `attributes_for` with a block" do
|
|||
end
|
||||
|
||||
it "passes the hash of attributes" do
|
||||
attributes_for(:company, :name => 'thoughtbot') do |attributes|
|
||||
attributes_for(:company, name: 'thoughtbot') do |attributes|
|
||||
attributes[:name].should eq('thoughtbot')
|
||||
end
|
||||
end
|
||||
|
@ -73,7 +73,7 @@ end
|
|||
|
||||
describe "`attributes_for` for a class whose constructor has required params" do
|
||||
before do
|
||||
define_model("User", :name => :string) do
|
||||
define_model("User", name: :string) do
|
||||
def initialize(arg1, arg2); end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ require "spec_helper"
|
|||
|
||||
describe "calling methods on the model instance" do
|
||||
before do
|
||||
define_model('User', :age => :integer, :age_copy => :integer) do
|
||||
define_model('User', age: :integer, age_copy: :integer) do
|
||||
def age
|
||||
read_attribute(:age) || 18
|
||||
end
|
||||
|
@ -33,21 +33,21 @@ describe "calling methods on the model instance" do
|
|||
|
||||
context "with the attribute being overridden" do
|
||||
it "uses the overridden value" do
|
||||
FactoryGirl.build(:user, :age_copy => nil).age_copy.should be_nil
|
||||
FactoryGirl.build(:user, age_copy: nil).age_copy.should be_nil
|
||||
end
|
||||
|
||||
it "uses the overridden value during attributes_for" do
|
||||
FactoryGirl.attributes_for(:user, :age_copy => 25)[:age_copy].should == 25
|
||||
FactoryGirl.attributes_for(:user, age_copy: 25)[:age_copy].should == 25
|
||||
end
|
||||
end
|
||||
|
||||
context "with the referenced attribute being overridden" do
|
||||
it "uses the overridden value" do
|
||||
FactoryGirl.build(:user, :age => nil).age_copy.should be_nil
|
||||
FactoryGirl.build(:user, age: nil).age_copy.should be_nil
|
||||
end
|
||||
|
||||
it "uses the overridden value during attributes_for" do
|
||||
FactoryGirl.attributes_for(:user, :age => 25)[:age_copy].should == 25
|
||||
FactoryGirl.attributes_for(:user, age: 25)[:age_copy].should == 25
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,10 +4,10 @@ describe "a generated attributes hash where order matters" do
|
|||
include FactoryGirl::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('ParentModel', :static => :integer,
|
||||
:evaluates_first => :integer,
|
||||
:evaluates_second => :integer,
|
||||
:evaluates_third => :integer)
|
||||
define_model('ParentModel', static: :integer,
|
||||
evaluates_first: :integer,
|
||||
evaluates_second: :integer,
|
||||
evaluates_third: :integer)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :parent_model do
|
||||
|
@ -20,7 +20,7 @@ describe "a generated attributes hash where order matters" do
|
|||
end
|
||||
end
|
||||
|
||||
factory :without_parent, :class => ParentModel do
|
||||
factory :without_parent, class: ParentModel do
|
||||
evaluates_first { static }
|
||||
evaluates_second { evaluates_first }
|
||||
evaluates_third { evaluates_second }
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe "build multiple instances" do
|
||||
before do
|
||||
define_model('Post', :title => :string)
|
||||
define_model('Post', title: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory(:post) do |post|
|
||||
|
@ -30,7 +30,7 @@ describe "build multiple instances" do
|
|||
end
|
||||
|
||||
context "with default attributes" do
|
||||
subject { FactoryGirl.build_list(:post, 20, :title => "The Hunting of the Snark") }
|
||||
subject { FactoryGirl.build_list(:post, 20, title: "The Hunting of the Snark") }
|
||||
|
||||
it "overrides the default values" do
|
||||
subject.each do |record|
|
||||
|
|
|
@ -6,7 +6,7 @@ describe "a built instance" do
|
|||
before do
|
||||
define_model('User')
|
||||
|
||||
define_model('Post', :user_id => :integer) do
|
||||
define_model('Post', user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -31,13 +31,13 @@ describe "a built instance" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "a built instance with :strategy => :build" do
|
||||
describe "a built instance with strategy: :build" do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User')
|
||||
|
||||
define_model('Post', :user_id => :integer) do
|
||||
define_model('Post', user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -45,7 +45,7 @@ describe "a built instance with :strategy => :build" do
|
|||
factory :user
|
||||
|
||||
factory :post do
|
||||
association(:user, :strategy => :build)
|
||||
association(:user, strategy: :build)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -66,7 +66,7 @@ describe "calling `build` with a block" do
|
|||
include FactoryGirl::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('Company', :name => :string)
|
||||
define_model('Company', name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :company
|
||||
|
@ -74,7 +74,7 @@ describe "calling `build` with a block" do
|
|||
end
|
||||
|
||||
it "passes the built instance" do
|
||||
build(:company, :name => 'thoughtbot') do |company|
|
||||
build(:company, name: 'thoughtbot') do |company|
|
||||
company.name.should eq('thoughtbot')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,10 +6,10 @@ describe "a generated stub instance" do
|
|||
before do
|
||||
define_model('User')
|
||||
|
||||
define_model('Post', :title => :string,
|
||||
:body => :string,
|
||||
:age => :integer,
|
||||
:user_id => :integer) do
|
||||
define_model('Post', title: :string,
|
||||
body: :string,
|
||||
age: :integer,
|
||||
user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -24,7 +24,7 @@ describe "a generated stub instance" do
|
|||
end
|
||||
end
|
||||
|
||||
subject { build_stubbed(:post, :title => 'overridden title') }
|
||||
subject { build_stubbed(:post, title: 'overridden title') }
|
||||
|
||||
it "assigns a default attribute" do
|
||||
subject.body.should == 'default body'
|
||||
|
@ -80,7 +80,7 @@ describe "calling `build_stubbed` with a block" do
|
|||
include FactoryGirl::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('Company', :name => :string)
|
||||
define_model('Company', name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :company
|
||||
|
@ -88,7 +88,7 @@ describe "calling `build_stubbed` with a block" do
|
|||
end
|
||||
|
||||
it "passes the stub instance" do
|
||||
build_stubbed(:company, :name => 'thoughtbot') do |company|
|
||||
build_stubbed(:company, name: 'thoughtbot') do |company|
|
||||
company.name.should eq('thoughtbot')
|
||||
expect { company.save }.to raise_error(RuntimeError)
|
||||
end
|
||||
|
|
|
@ -2,16 +2,16 @@ require 'spec_helper'
|
|||
|
||||
describe "callbacks" do
|
||||
before do
|
||||
define_model("User", :first_name => :string, :last_name => :string)
|
||||
define_model("User", first_name: :string, last_name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user_with_callbacks, :class => :user do
|
||||
factory :user_with_callbacks, class: :user do
|
||||
after_stub { |user| user.first_name = 'Stubby' }
|
||||
after_build { |user| user.first_name = 'Buildy' }
|
||||
after_create { |user| user.last_name = 'Createy' }
|
||||
end
|
||||
|
||||
factory :user_with_inherited_callbacks, :parent => :user_with_callbacks do
|
||||
factory :user_with_inherited_callbacks, parent: :user_with_callbacks do
|
||||
after_stub { |user| user.last_name = 'Double-Stubby' }
|
||||
after_build { |user| user.first_name = 'Child-Buildy' }
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe "create multiple instances" do
|
||||
before do
|
||||
define_model('Post', :title => :string)
|
||||
define_model('Post', title: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory(:post) do |post|
|
||||
|
@ -30,7 +30,7 @@ describe "create multiple instances" do
|
|||
end
|
||||
|
||||
context "with default attributes" do
|
||||
subject { FactoryGirl.create_list(:post, 20, :title => "The Hunting of the Snark") }
|
||||
subject { FactoryGirl.create_list(:post, 20, title: "The Hunting of the Snark") }
|
||||
|
||||
it "overrides the default values" do
|
||||
subject.each do |record|
|
||||
|
@ -42,11 +42,11 @@ end
|
|||
|
||||
describe "multiple creates and ignored attributes to dynamically build attribute lists" do
|
||||
before do
|
||||
define_model('User', :name => :string) do
|
||||
define_model('User', name: :string) do
|
||||
has_many :posts
|
||||
end
|
||||
|
||||
define_model('Post', :title => :string, :user_id => :integer) do
|
||||
define_model('Post', title: :string, user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -65,7 +65,7 @@ describe "multiple creates and ignored attributes to dynamically build attribute
|
|||
end
|
||||
|
||||
after_create do |user, evaluator|
|
||||
FactoryGirl.create_list(:post, evaluator.posts_count, :user => user)
|
||||
FactoryGirl.create_list(:post, evaluator.posts_count, user: user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -77,6 +77,6 @@ describe "multiple creates and ignored attributes to dynamically build attribute
|
|||
end
|
||||
|
||||
it "allows the number of posts to be modified" do
|
||||
FactoryGirl.create(:user_with_posts, :posts_count => 2).posts.length.should == 2
|
||||
FactoryGirl.create(:user_with_posts, posts_count: 2).posts.length.should == 2
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ describe "a created instance" do
|
|||
before do
|
||||
define_model('User')
|
||||
|
||||
define_model('Post', :user_id => :integer) do
|
||||
define_model('Post', user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -31,13 +31,13 @@ describe "a created instance" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "a created instance, specifying :strategy => :build" do
|
||||
describe "a created instance, specifying strategy: :build" do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User')
|
||||
|
||||
define_model('Post', :user_id => :integer) do
|
||||
define_model('Post', user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -45,14 +45,14 @@ describe "a created instance, specifying :strategy => :build" do
|
|||
factory :user
|
||||
|
||||
factory :post do
|
||||
association(:user, :strategy => :build)
|
||||
association(:user, strategy: :build)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
subject { create(:post) }
|
||||
|
||||
it "saves associations (:strategy => :build only affects build, not create)" do
|
||||
it "saves associations (strategy: :build only affects build, not create)" do
|
||||
subject.user.should be_kind_of(User)
|
||||
subject.user.should_not be_new_record
|
||||
end
|
||||
|
@ -94,7 +94,7 @@ describe "calling `create` with a block" do
|
|||
include FactoryGirl::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('Company', :name => :string)
|
||||
define_model('Company', name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :company
|
||||
|
@ -102,7 +102,7 @@ describe "calling `create` with a block" do
|
|||
end
|
||||
|
||||
it "passes the created instance" do
|
||||
create(:company, :name => 'thoughtbot') do |company|
|
||||
create(:company, name: 'thoughtbot') do |company|
|
||||
company.name.should eq('thoughtbot')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,10 +2,10 @@ require "spec_helper"
|
|||
|
||||
describe "defining a child factory before a parent" do
|
||||
before do
|
||||
define_model("User", :name => :string, :admin => :boolean, :email => :string, :upper_email => :string, :login => :string)
|
||||
define_model("User", name: :string, admin: :boolean, email: :string, upper_email: :string, login: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :admin, :parent => :user do
|
||||
factory :admin, parent: :user do
|
||||
admin true
|
||||
end
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@ require 'spec_helper'
|
|||
|
||||
describe "an instance generated by a factory with a custom class name" do
|
||||
before do
|
||||
define_model("User", :admin => :boolean)
|
||||
define_model("User", admin: :boolean)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user
|
||||
|
||||
factory :admin, :class => User do
|
||||
factory :admin, class: User do
|
||||
admin { true }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,9 +4,9 @@ describe "initialize_with with non-FG attributes" do
|
|||
include FactoryGirl::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model("User", :name => :string, :age => :integer) do
|
||||
define_model("User", name: :string, age: :integer) do
|
||||
def self.construct(name, age)
|
||||
new(:name => name, :age => age)
|
||||
new(name: name, age: age)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -26,9 +26,9 @@ describe "initialize_with with FG attributes that are ignored" do
|
|||
include FactoryGirl::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model("User", :name => :string) do
|
||||
define_model("User", name: :string) do
|
||||
def self.construct(name)
|
||||
new(:name => "#{name} from .construct")
|
||||
new(name: "#{name} from .construct")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -51,9 +51,9 @@ describe "initialize_with with FG attributes that are not ignored" do
|
|||
include FactoryGirl::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model("User", :name => :string) do
|
||||
define_model("User", name: :string) do
|
||||
def self.construct(name)
|
||||
new(:name => "#{name} from .construct")
|
||||
new(name: "#{name} from .construct")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -98,7 +98,7 @@ describe "initialize_with non-ORM-backed objects" do
|
|||
end
|
||||
|
||||
it "allows for overrides" do
|
||||
build(:report_generator, :name => "Overridden").name.should == "Overridden"
|
||||
build(:report_generator, name: "Overridden").name.should == "Overridden"
|
||||
end
|
||||
|
||||
it "generates random data" do
|
||||
|
|
|
@ -4,7 +4,7 @@ describe "modifying factories" do
|
|||
include FactoryGirl::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User', :name => :string, :admin => :boolean, :email => :string, :login => :string)
|
||||
define_model('User', name: :string, admin: :boolean, email: :string, login: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
sequence(:email) {|n| "user#{n}@example.com" }
|
||||
|
@ -114,14 +114,14 @@ describe "modifying factories" do
|
|||
end
|
||||
|
||||
context "overriding dynamic attributes" do
|
||||
subject { create(:user, :email => "perfect@example.com") }
|
||||
subject { create(:user, email: "perfect@example.com") }
|
||||
|
||||
its(:name) { should == "Great User" }
|
||||
its(:email) { should == "perfect@example.com" }
|
||||
end
|
||||
|
||||
context "overriding static attributes" do
|
||||
subject { create(:user, :name => "wonderful") }
|
||||
subject { create(:user, name: "wonderful") }
|
||||
|
||||
its(:name) { should == "wonderful" }
|
||||
its(:email) { should == "wonderful-modified@example.com" }
|
||||
|
@ -138,7 +138,7 @@ describe "modifying factories" do
|
|||
end
|
||||
|
||||
context "overriding dynamic attributes" do
|
||||
subject { create(:admin, :email => "perfect@example.com") }
|
||||
subject { create(:admin, email: "perfect@example.com") }
|
||||
|
||||
its(:name) { should == "Great User" }
|
||||
its(:email) { should == "perfect@example.com" }
|
||||
|
@ -146,7 +146,7 @@ describe "modifying factories" do
|
|||
end
|
||||
|
||||
context "overriding static attributes" do
|
||||
subject { create(:admin, :name => "wonderful") }
|
||||
subject { create(:admin, name: "wonderful") }
|
||||
|
||||
its(:name) { should == "wonderful" }
|
||||
its(:email) { should == "wonderful-modified@example.com" }
|
||||
|
|
|
@ -2,7 +2,7 @@ require "spec_helper"
|
|||
|
||||
describe "modifying inherited factories with traits" do
|
||||
before do
|
||||
define_model('User', :gender => :string, :admin => :boolean, :age => :integer)
|
||||
define_model('User', gender: :string, admin: :boolean, age: :integer)
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
trait(:female) { gender "Female" }
|
||||
|
|
|
@ -2,12 +2,12 @@ require "spec_helper"
|
|||
|
||||
describe "association assignment from nested attributes" do
|
||||
before do
|
||||
define_model("Post", :title => :string) do
|
||||
define_model("Post", title: :string) do
|
||||
has_many :comments
|
||||
accepts_nested_attributes_for :comments
|
||||
end
|
||||
|
||||
define_model("Comment", :post_id => :integer, :body => :text) do
|
||||
define_model("Comment", post_id: :integer, body: :text) do
|
||||
belongs_to :post
|
||||
end
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@ require 'spec_helper'
|
|||
|
||||
describe "attribute overrides" do
|
||||
before do
|
||||
define_model('User', :admin => :boolean)
|
||||
define_model('Post', :title => :string,
|
||||
:secure => :boolean,
|
||||
:user_id => :integer) do
|
||||
define_model('User', admin: :boolean)
|
||||
define_model('Post', title: :string,
|
||||
secure: :boolean,
|
||||
user_id: :integer) do
|
||||
belongs_to :user
|
||||
|
||||
def secure=(value)
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe "an instance generated by a factory that inherits from another factory" do
|
||||
before do
|
||||
define_model("User", :name => :string, :admin => :boolean, :email => :string, :upper_email => :string, :login => :string)
|
||||
define_model("User", name: :string, admin: :boolean, email: :string, upper_email: :string, login: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
|
@ -67,7 +67,7 @@ end
|
|||
|
||||
describe "nested factories with different parents" do
|
||||
before do
|
||||
define_model("User", :name => :string)
|
||||
define_model("User", name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
|
@ -77,7 +77,7 @@ describe "nested factories with different parents" do
|
|||
name "John Doe"
|
||||
end
|
||||
|
||||
factory :uppercase_male_user, :parent => :male_user do
|
||||
factory :uppercase_male_user, parent: :male_user do
|
||||
after_build {|user| user.name = user.name.upcase }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ describe "a stubbed instance" do
|
|||
before do
|
||||
define_model('User')
|
||||
|
||||
define_model('Post', :user_id => :integer) do
|
||||
define_model('Post', user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -36,7 +36,7 @@ describe "a stubbed instance overriding strategy" do
|
|||
|
||||
before do
|
||||
define_model('User')
|
||||
define_model('Post', :user_id => :integer) do
|
||||
define_model('Post', user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -44,7 +44,7 @@ describe "a stubbed instance overriding strategy" do
|
|||
factory :user
|
||||
|
||||
factory :post do
|
||||
association(:user, :strategy => :build)
|
||||
association(:user, strategy: :build)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'factory_girl/syntax/blueprint'
|
|||
|
||||
describe "a blueprint" do
|
||||
before do
|
||||
define_model('User', :first_name => :string, :last_name => :string, :email => :string)
|
||||
define_model('User', first_name: :string, last_name: :string, email: :string)
|
||||
|
||||
Factory.sequence(:email) { |n| "somebody#{n}@example.com" }
|
||||
User.blueprint do
|
||||
|
@ -16,7 +16,7 @@ describe "a blueprint" do
|
|||
|
||||
describe "after making an instance" do
|
||||
before do
|
||||
@instance = FactoryGirl.create(:user, :last_name => 'Rye')
|
||||
@instance = FactoryGirl.create(:user, last_name: 'Rye')
|
||||
end
|
||||
|
||||
it "uses attributes from the blueprint" do
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'factory_girl/syntax/generate'
|
|||
|
||||
describe "a factory using generate syntax" do
|
||||
before do
|
||||
define_model('User', :first_name => :string, :last_name => :string, :email => :string) do
|
||||
define_model('User', first_name: :string, last_name: :string, email: :string) do
|
||||
validates_presence_of :first_name
|
||||
end
|
||||
|
||||
|
@ -18,11 +18,11 @@ describe "a factory using generate syntax" do
|
|||
end
|
||||
|
||||
it "does not raise an error when generating an invalid instance" do
|
||||
expect { User.generate(:first_name => nil) }.to_not raise_error
|
||||
expect { User.generate(first_name: nil) }.to_not raise_error
|
||||
end
|
||||
|
||||
it "raises an error when forcefully generating an invalid instance" do
|
||||
expect { User.generate!(:first_name => nil) }.to raise_error(ActiveRecord::RecordInvalid)
|
||||
expect { User.generate!(first_name: nil) }.to raise_error(ActiveRecord::RecordInvalid)
|
||||
end
|
||||
|
||||
%w(generate generate! spawn).each do |method|
|
||||
|
@ -34,7 +34,7 @@ describe "a factory using generate syntax" do
|
|||
|
||||
describe "after generating an instance using #{method}" do
|
||||
before do
|
||||
@instance = User.send(method, :last_name => 'Rye')
|
||||
@instance = User.send(method, last_name: 'Rye')
|
||||
end
|
||||
|
||||
it "uses attributes from the factory" do
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'factory_girl/syntax/make'
|
|||
|
||||
describe "a factory using make syntax" do
|
||||
before do
|
||||
define_model('User', :first_name => :string, :last_name => :string)
|
||||
define_model('User', first_name: :string, last_name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
|
@ -16,7 +16,7 @@ describe "a factory using make syntax" do
|
|||
|
||||
describe "after make" do
|
||||
before do
|
||||
@instance = User.make(:last_name => 'Rye')
|
||||
@instance = User.make(last_name: 'Rye')
|
||||
end
|
||||
|
||||
it "uses attributes from the factory" do
|
||||
|
@ -34,7 +34,7 @@ describe "a factory using make syntax" do
|
|||
|
||||
describe "after make!" do
|
||||
before do
|
||||
@instance = User.make!(:last_name => 'Rye')
|
||||
@instance = User.make!(last_name: 'Rye')
|
||||
end
|
||||
|
||||
it "uses attributes from the factory" do
|
||||
|
|
|
@ -4,10 +4,10 @@ require 'factory_girl/syntax/sham'
|
|||
|
||||
describe "a factory using sham syntax" do
|
||||
before do
|
||||
define_model('User', :first_name => :string,
|
||||
:last_name => :string,
|
||||
:email => :string,
|
||||
:username => :string)
|
||||
define_model('User', first_name: :string,
|
||||
last_name: :string,
|
||||
email: :string,
|
||||
username: :string)
|
||||
|
||||
Sham.name { "Name" }
|
||||
Sham.email { "somebody#{rand(5)}@example.com" }
|
||||
|
@ -25,7 +25,7 @@ describe "a factory using sham syntax" do
|
|||
|
||||
describe "after making an instance" do
|
||||
before do
|
||||
@instance = FactoryGirl.create(:user, :last_name => 'Rye')
|
||||
@instance = FactoryGirl.create(:user, last_name: 'Rye')
|
||||
end
|
||||
|
||||
it "supports a sham called 'name'" do
|
||||
|
|
|
@ -2,9 +2,9 @@ require 'spec_helper'
|
|||
|
||||
describe "vintage syntax" do
|
||||
before do
|
||||
define_model('User', :first_name => :string,
|
||||
:last_name => :string,
|
||||
:email => :string)
|
||||
define_model('User', first_name: :string,
|
||||
last_name: :string,
|
||||
email: :string)
|
||||
|
||||
Factory.sequence(:email) { |n| "somebody#{n}@example.com" }
|
||||
Factory.define :user do |factory|
|
||||
|
@ -16,7 +16,7 @@ describe "vintage syntax" do
|
|||
|
||||
describe "after making an instance" do
|
||||
before do
|
||||
@instance = Factory(:user, :last_name => 'Rye')
|
||||
@instance = Factory(:user, last_name: 'Rye')
|
||||
end
|
||||
|
||||
it "should use attributes from the definition" do
|
||||
|
@ -30,7 +30,7 @@ describe "vintage syntax" do
|
|||
end
|
||||
|
||||
it "raises Factory::SequenceAbuseError" do
|
||||
Factory.define :sequence_abuser, :class => User do |factory|
|
||||
Factory.define :sequence_abuser, class: User do |factory|
|
||||
factory.first_name { Factory.sequence(:name) }
|
||||
end
|
||||
|
||||
|
@ -43,7 +43,7 @@ end
|
|||
describe Factory, "referencing a nonexistent factory as a parent" do
|
||||
it "raises an ArgumentError when trying to use a non-existent factory as parent" do
|
||||
expect {
|
||||
Factory.define(:child, :parent => :nonexsitent) {}
|
||||
Factory.define(:child, parent: :nonexsitent) {}
|
||||
Factory.build(:child)
|
||||
}.to raise_error(ArgumentError)
|
||||
end
|
||||
|
@ -52,15 +52,15 @@ end
|
|||
describe "defining a factory" do
|
||||
before do
|
||||
@name = :user
|
||||
@factory = stub("factory", :names => [@name])
|
||||
@factory = stub("factory", names: [@name])
|
||||
@proxy = "proxy"
|
||||
@options = { :class => 'magic' }
|
||||
FactoryGirl::Factory.stubs(:new => @factory)
|
||||
FactoryGirl::DefinitionProxy.stubs(:new => @proxy)
|
||||
@options = { class: 'magic' }
|
||||
FactoryGirl::Factory.stubs(new: @factory)
|
||||
FactoryGirl::DefinitionProxy.stubs(new: @proxy)
|
||||
end
|
||||
|
||||
it "creates a new factory using the specified name and options" do
|
||||
FactoryGirl::Factory.stubs(:new => @factory)
|
||||
FactoryGirl::Factory.stubs(new: @factory)
|
||||
Factory.define(@name, @options) {|f| }
|
||||
FactoryGirl::Factory.should have_received(:new).with(@name, @options)
|
||||
end
|
||||
|
@ -88,27 +88,27 @@ describe "after defining a factory" do
|
|||
end
|
||||
|
||||
it "uses Strategy::AttributesFor for Factory.attributes_for" do
|
||||
@factory.stubs(:run => "result")
|
||||
Factory.attributes_for(@name, :attr => 'value').should == 'result'
|
||||
@factory.should have_received(:run).with(FactoryGirl::Strategy::AttributesFor, :attr => 'value')
|
||||
@factory.stubs(run: "result")
|
||||
Factory.attributes_for(@name, attr: 'value').should == 'result'
|
||||
@factory.should have_received(:run).with(FactoryGirl::Strategy::AttributesFor, attr: 'value')
|
||||
end
|
||||
|
||||
it "uses Strategy::Build for Factory.build" do
|
||||
@factory.stubs(:run => "result")
|
||||
Factory.build(@name, :attr => 'value').should == 'result'
|
||||
@factory.should have_received(:run).with(FactoryGirl::Strategy::Build, :attr => 'value')
|
||||
@factory.stubs(run: "result")
|
||||
Factory.build(@name, attr: 'value').should == 'result'
|
||||
@factory.should have_received(:run).with(FactoryGirl::Strategy::Build, attr: 'value')
|
||||
end
|
||||
|
||||
it "uses Strategy::Create for Factory.create" do
|
||||
@factory.stubs(:run => "result")
|
||||
Factory.create(@name, :attr => 'value').should == 'result'
|
||||
@factory.should have_received(:run).with(FactoryGirl::Strategy::Create, :attr => 'value')
|
||||
@factory.stubs(run: "result")
|
||||
Factory.create(@name, attr: 'value').should == 'result'
|
||||
@factory.should have_received(:run).with(FactoryGirl::Strategy::Create, attr: 'value')
|
||||
end
|
||||
|
||||
it "uses Strategy::Stub for Factory.stub" do
|
||||
@factory.stubs(:run => "result")
|
||||
Factory.stub(@name, :attr => 'value').should == 'result'
|
||||
@factory.should have_received(:run).with(FactoryGirl::Strategy::Stub, :attr => 'value')
|
||||
@factory.stubs(run: "result")
|
||||
Factory.stub(@name, attr: 'value').should == 'result'
|
||||
@factory.should have_received(:run).with(FactoryGirl::Strategy::Stub, attr: 'value')
|
||||
end
|
||||
|
||||
[:build, :create, :attributes_for, :stub].each do |method|
|
||||
|
@ -151,8 +151,8 @@ describe "after defining a sequence" do
|
|||
@sequence = FactoryGirl::Sequence.new(@name) {}
|
||||
@value = '1 2 5'
|
||||
|
||||
@sequence.stubs(:next => @value)
|
||||
FactoryGirl::Sequence.stubs(:new => @sequence)
|
||||
@sequence.stubs(next: @value)
|
||||
FactoryGirl::Sequence.stubs(new: @sequence)
|
||||
|
||||
Factory.sequence(@name) {}
|
||||
end
|
||||
|
@ -169,7 +169,7 @@ end
|
|||
|
||||
describe "an attribute generated by an in-line sequence" do
|
||||
before do
|
||||
define_model('User', :username => :string)
|
||||
define_model('User', username: :string)
|
||||
|
||||
Factory.define :user do |factory|
|
||||
factory.sequence(:username) { |n| "username#{n}" }
|
||||
|
@ -200,13 +200,13 @@ end
|
|||
|
||||
describe "a factory with a parent" do
|
||||
before do
|
||||
define_model("User", :username => :string)
|
||||
define_model("User", username: :string)
|
||||
|
||||
Factory.define(:user) do |factory|
|
||||
factory.username "awesome_username"
|
||||
end
|
||||
|
||||
Factory.define(:boring_user, :parent => :user) do |factory|
|
||||
Factory.define(:boring_user, parent: :user) do |factory|
|
||||
factory.username "boring_username"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,15 +3,15 @@ require "spec_helper"
|
|||
describe "an instance generated by a factory with multiple traits" do
|
||||
before do
|
||||
define_model("User",
|
||||
:name => :string,
|
||||
:admin => :boolean,
|
||||
:gender => :string,
|
||||
:email => :string,
|
||||
:date_of_birth => :date,
|
||||
:great => :string)
|
||||
name: :string,
|
||||
admin: :boolean,
|
||||
gender: :string,
|
||||
email: :string,
|
||||
date_of_birth: :date,
|
||||
great: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user_without_admin_scoping, :class => User do
|
||||
factory :user_without_admin_scoping, class: User do
|
||||
admin_trait
|
||||
end
|
||||
|
||||
|
@ -44,7 +44,7 @@ describe "an instance generated by a factory with multiple traits" do
|
|||
great
|
||||
end
|
||||
|
||||
factory :admin, :traits => [:admin]
|
||||
factory :admin, traits: [:admin]
|
||||
|
||||
factory :male_user do
|
||||
male
|
||||
|
@ -54,7 +54,7 @@ describe "an instance generated by a factory with multiple traits" do
|
|||
end
|
||||
end
|
||||
|
||||
factory :female, :traits => [:female] do
|
||||
factory :female, traits: [:female] do
|
||||
trait :admin do
|
||||
admin true
|
||||
name "Judy"
|
||||
|
@ -64,19 +64,19 @@ describe "an instance generated by a factory with multiple traits" do
|
|||
great
|
||||
end
|
||||
|
||||
factory :female_admin_judy, :traits => [:admin]
|
||||
factory :female_admin_judy, traits: [:admin]
|
||||
end
|
||||
|
||||
factory :female_admin, :traits => [:female, :admin]
|
||||
factory :female_after_male_admin, :traits => [:male, :female, :admin]
|
||||
factory :male_after_female_admin, :traits => [:female, :male, :admin]
|
||||
factory :female_admin, traits: [:female, :admin]
|
||||
factory :female_after_male_admin, traits: [:male, :female, :admin]
|
||||
factory :male_after_female_admin, traits: [:female, :male, :admin]
|
||||
end
|
||||
|
||||
trait :email do
|
||||
email { "#{name}@example.com" }
|
||||
end
|
||||
|
||||
factory :user_with_email, :class => User, :traits => [:email] do
|
||||
factory :user_with_email, class: User, traits: [:email] do
|
||||
name "Bill"
|
||||
end
|
||||
end
|
||||
|
@ -111,7 +111,7 @@ describe "an instance generated by a factory with multiple traits" do
|
|||
end
|
||||
|
||||
context "the child with multiple traits and overridden attributes" do
|
||||
subject { FactoryGirl.create(:female_admin, :name => "Jill", :gender => nil) }
|
||||
subject { FactoryGirl.create(:female_admin, name: "Jill", gender: nil) }
|
||||
its(:name) { should == "Jill" }
|
||||
its(:gender) { should be_nil }
|
||||
it { should be_admin }
|
||||
|
@ -157,7 +157,7 @@ describe "an instance generated by a factory with multiple traits" do
|
|||
end
|
||||
|
||||
context "factory created with alternate syntax where trait name and attribute are the same and attribute is overridden" do
|
||||
subject { FactoryGirl.create(:great_user, :great => "SORT OF!!!") }
|
||||
subject { FactoryGirl.create(:great_user, great: "SORT OF!!!") }
|
||||
its(:great) { should == "SORT OF!!!" }
|
||||
end
|
||||
|
||||
|
@ -180,7 +180,7 @@ end
|
|||
|
||||
describe "traits with callbacks" do
|
||||
before do
|
||||
define_model("User", :name => :string)
|
||||
define_model("User", name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
|
@ -194,8 +194,8 @@ describe "traits with callbacks" do
|
|||
after_create {|user| user.name = "awesome" }
|
||||
end
|
||||
|
||||
factory :caps_user, :traits => [:great]
|
||||
factory :awesome_user, :traits => [:great, :awesome]
|
||||
factory :caps_user, traits: [:great]
|
||||
factory :awesome_user, traits: [:great, :awesome]
|
||||
|
||||
factory :caps_user_implicit_trait do
|
||||
great
|
||||
|
@ -221,7 +221,7 @@ end
|
|||
|
||||
describe "traits added via strategy" do
|
||||
before do
|
||||
define_model("User", :name => :string, :admin => :boolean)
|
||||
define_model("User", name: :string, admin: :boolean)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
|
@ -239,7 +239,7 @@ describe "traits added via strategy" do
|
|||
end
|
||||
|
||||
context "adding traits in create" do
|
||||
subject { FactoryGirl.create(:user, :admin, :great, :name => "Joe") }
|
||||
subject { FactoryGirl.create(:user, :admin, :great, name: "Joe") }
|
||||
|
||||
its(:admin) { should be_true }
|
||||
its(:name) { should == "JOE" }
|
||||
|
@ -252,7 +252,7 @@ describe "traits added via strategy" do
|
|||
end
|
||||
|
||||
context "adding traits in build" do
|
||||
subject { FactoryGirl.build(:user, :admin, :great, :name => "Joe") }
|
||||
subject { FactoryGirl.build(:user, :admin, :great, name: "Joe") }
|
||||
|
||||
its(:admin) { should be_true }
|
||||
its(:name) { should == "Joe" }
|
||||
|
@ -266,14 +266,14 @@ describe "traits added via strategy" do
|
|||
end
|
||||
|
||||
context "adding traits in build_stubbed" do
|
||||
subject { FactoryGirl.build_stubbed(:user, :admin, :great, :name => "Jack") }
|
||||
subject { FactoryGirl.build_stubbed(:user, :admin, :great, name: "Jack") }
|
||||
|
||||
its(:admin) { should be_true }
|
||||
its(:name) { should == "Jack" }
|
||||
end
|
||||
|
||||
context "adding traits in create_list" do
|
||||
subject { FactoryGirl.create_list(:user, 2, :admin, :great, :name => "Joe") }
|
||||
subject { FactoryGirl.create_list(:user, 2, :admin, :great, name: "Joe") }
|
||||
|
||||
its(:length) { should == 2 }
|
||||
|
||||
|
@ -286,7 +286,7 @@ describe "traits added via strategy" do
|
|||
end
|
||||
|
||||
context "adding traits in build_list" do
|
||||
subject { FactoryGirl.build_list(:user, 2, :admin, :great, :name => "Joe") }
|
||||
subject { FactoryGirl.build_list(:user, 2, :admin, :great, name: "Joe") }
|
||||
|
||||
its(:length) { should == 2 }
|
||||
|
||||
|
@ -301,7 +301,7 @@ end
|
|||
|
||||
describe "traits and dynamic attributes that are applied simultaneously" do
|
||||
before do
|
||||
define_model("User", :name => :string, :email => :string, :combined => :string)
|
||||
define_model("User", name: :string, email: :string, combined: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
trait :email do
|
||||
|
@ -328,7 +328,7 @@ describe "applying inline traits" do
|
|||
has_many :posts
|
||||
end
|
||||
|
||||
define_model("Post", :user_id => :integer) do
|
||||
define_model("Post", user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -350,7 +350,7 @@ end
|
|||
|
||||
describe "inline traits overriding existing attributes" do
|
||||
before do
|
||||
define_model("User", :status => :string)
|
||||
define_model("User", status: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
|
@ -359,8 +359,8 @@ describe "inline traits overriding existing attributes" do
|
|||
trait(:accepted) { status "accepted" }
|
||||
trait(:declined) { status "declined" }
|
||||
|
||||
factory :declined_user, :traits => [:declined]
|
||||
factory :extended_declined_user, :traits => [:declined] do
|
||||
factory :declined_user, traits: [:declined]
|
||||
factory :extended_declined_user, traits: [:declined] do
|
||||
status "extended_declined"
|
||||
end
|
||||
end
|
||||
|
@ -392,13 +392,13 @@ describe "inline traits overriding existing attributes" do
|
|||
end
|
||||
|
||||
it "prefers overridden attributes over attributes from traits, inline traits, or attributes on factories" do
|
||||
FactoryGirl.build(:extended_declined_user, :accepted, :status => "completely overridden").status.should == "completely overridden"
|
||||
FactoryGirl.build(:extended_declined_user, :accepted, status: "completely overridden").status.should == "completely overridden"
|
||||
end
|
||||
end
|
||||
|
||||
describe "making sure the factory is properly compiled the first time we want to instantiate it" do
|
||||
before do
|
||||
define_model("User", :role => :string, :gender => :string, :age => :integer)
|
||||
define_model("User", role: :string, gender: :string, age: :integer)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
|
@ -413,7 +413,7 @@ describe "making sure the factory is properly compiled the first time we want to
|
|||
end
|
||||
|
||||
it "can honor traits on the very first call" do
|
||||
user = FactoryGirl.build(:female_user, :admin, :age => 30)
|
||||
user = FactoryGirl.build(:female_user, :admin, age: 30)
|
||||
user.gender.should == 'female'
|
||||
user.age.should == 30
|
||||
user.role.should == 'admin'
|
||||
|
|
|
@ -2,7 +2,7 @@ require "spec_helper"
|
|||
|
||||
describe "transient attributes" do
|
||||
before do
|
||||
define_model("User", :name => :string, :email => :string)
|
||||
define_model("User", name: :string, email: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
sequence(:name) {|n| "John #{n}" }
|
||||
|
@ -25,7 +25,7 @@ describe "transient attributes" do
|
|||
end
|
||||
|
||||
context "returning attributes for a factory" do
|
||||
subject { FactoryGirl.attributes_for(:user, :rockstar => true) }
|
||||
subject { FactoryGirl.attributes_for(:user, rockstar: true) }
|
||||
it { should_not have_key(:four) }
|
||||
it { should_not have_key(:rockstar) }
|
||||
it { should_not have_key(:upcased) }
|
||||
|
@ -34,10 +34,10 @@ describe "transient attributes" do
|
|||
end
|
||||
|
||||
context "with a transient variable assigned" do
|
||||
let(:rockstar) { FactoryGirl.create(:user, :rockstar => true, :four => "1234") }
|
||||
let(:rockstar_with_name) { FactoryGirl.create(:user, :name => "Jane Doe", :rockstar => true) }
|
||||
let(:upcased_rockstar) { FactoryGirl.create(:user, :rockstar => true, :upcased => true) }
|
||||
let(:groupie) { FactoryGirl.create(:user, :rockstar => false) }
|
||||
let(:rockstar) { FactoryGirl.create(:user, rockstar: true, four: "1234") }
|
||||
let(:rockstar_with_name) { FactoryGirl.create(:user, name: "Jane Doe", rockstar: true) }
|
||||
let(:upcased_rockstar) { FactoryGirl.create(:user, rockstar: true, upcased: true) }
|
||||
let(:groupie) { FactoryGirl.create(:user, rockstar: false) }
|
||||
|
||||
it "generates the correct attributes on a rockstar" do
|
||||
rockstar.name.should == "John 1 - Rockstar"
|
||||
|
@ -71,7 +71,7 @@ end
|
|||
|
||||
describe "transient sequences" do
|
||||
before do
|
||||
define_model("User", :name => :string)
|
||||
define_model("User", name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
|
|
|
@ -3,11 +3,11 @@ require 'spec_helper'
|
|||
describe FactoryGirl::Attribute::Association do
|
||||
let(:name) { :author }
|
||||
let(:factory) { :user }
|
||||
let(:overrides) { { :first_name => "John" } }
|
||||
let(:overrides) { { first_name: "John" } }
|
||||
let(:association) { stub("association") }
|
||||
|
||||
subject { FactoryGirl::Attribute::Association.new(name, factory, overrides) }
|
||||
before { subject.stubs(:association => association) }
|
||||
before { subject.stubs(association: association) }
|
||||
|
||||
it { should be_association }
|
||||
its(:name) { should == name }
|
||||
|
|
|
@ -29,7 +29,7 @@ describe FactoryGirl::Attribute::Dynamic do
|
|||
let(:result) { "other attribute value" }
|
||||
|
||||
before do
|
||||
subject.stubs(:attribute_defined_on_attribute => result)
|
||||
subject.stubs(attribute_defined_on_attribute: result)
|
||||
end
|
||||
|
||||
it "evaluates the attribute from the attribute" do
|
||||
|
|
|
@ -4,17 +4,17 @@ describe FactoryGirl::DeclarationList, "#attribute_list" do
|
|||
let(:static_attribute_1) { stub("static attribute 1") }
|
||||
let(:static_attribute_2) { stub("static attribute 2") }
|
||||
let(:dynamic_attribute_1) { stub("dynamic attribute 1") }
|
||||
let(:static_declaration) { stub("static declaration", :to_attributes => [static_attribute_1, static_attribute_2]) }
|
||||
let(:dynamic_declaration) { stub("static declaration", :to_attributes => [dynamic_attribute_1]) }
|
||||
let(:static_declaration) { stub("static declaration", to_attributes: [static_attribute_1, static_attribute_2]) }
|
||||
let(:dynamic_declaration) { stub("static declaration", to_attributes: [dynamic_attribute_1]) }
|
||||
|
||||
it "returns an AttributeList" do
|
||||
subject.attribute_list.should be_a(FactoryGirl::AttributeList)
|
||||
end
|
||||
|
||||
let(:attribute_list) { stub("attribute list", :define_attribute => true) }
|
||||
let(:attribute_list) { stub("attribute list", define_attribute: true) }
|
||||
|
||||
it "defines each attribute on the attribute list" do
|
||||
FactoryGirl::AttributeList.stubs(:new => attribute_list)
|
||||
FactoryGirl::AttributeList.stubs(new: attribute_list)
|
||||
|
||||
subject.declare_attribute(static_declaration)
|
||||
subject.declare_attribute(dynamic_declaration)
|
||||
|
@ -32,9 +32,9 @@ describe FactoryGirl::DeclarationList, "#attribute_list" do
|
|||
end
|
||||
|
||||
describe FactoryGirl::DeclarationList, "#declare_attribute" do
|
||||
let(:declaration_1) { stub("declaration", :name => "declaration 1") }
|
||||
let(:declaration_2) { stub("declaration", :name => "declaration 2") }
|
||||
let(:declaration_with_same_name) { stub("declaration", :name => "declaration 1") }
|
||||
let(:declaration_1) { stub("declaration", name: "declaration 1") }
|
||||
let(:declaration_2) { stub("declaration", name: "declaration 2") }
|
||||
let(:declaration_with_same_name) { stub("declaration", name: "declaration 1") }
|
||||
|
||||
context "when not overridable" do
|
||||
it "adds the declaration to the list" do
|
||||
|
|
|
@ -67,8 +67,8 @@ describe FactoryGirl::DefinitionProxy, "#method_missing" do
|
|||
end
|
||||
|
||||
it "declares an association when :factory is passed" do
|
||||
proxy.author :factory => :user
|
||||
subject.should have_association_declaration(:author).with_options(:factory => :user)
|
||||
proxy.author factory: :user
|
||||
subject.should have_association_declaration(:author).with_options(factory: :user)
|
||||
end
|
||||
|
||||
it "declares a static attribute" do
|
||||
|
@ -116,8 +116,8 @@ describe FactoryGirl::DefinitionProxy, "#association" do
|
|||
end
|
||||
|
||||
it "declares an association with options" do
|
||||
proxy.association(:association_name, { :name => "Awesome" })
|
||||
subject.should have_association_declaration(:association_name).with_options(:name => "Awesome")
|
||||
proxy.association(:association_name, { name: "Awesome" })
|
||||
subject.should have_association_declaration(:association_name).with_options(name: "Awesome")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -163,8 +163,8 @@ describe FactoryGirl::DefinitionProxy, "#factory" do
|
|||
end
|
||||
|
||||
it "with options" do
|
||||
proxy.factory(:child, { :awesome => true })
|
||||
proxy.child_factories.should include([:child, { :awesome => true }, nil])
|
||||
proxy.factory(:child, { awesome: true })
|
||||
proxy.child_factories.should include([:child, { awesome: true }, nil])
|
||||
end
|
||||
|
||||
it "with a block" do
|
||||
|
|
|
@ -17,8 +17,8 @@ describe FactoryGirl::Definition, "with a name" do
|
|||
end
|
||||
|
||||
describe FactoryGirl::Definition, "#overridable" do
|
||||
let(:list) { stub("declaration list", :overridable => true) }
|
||||
before { FactoryGirl::DeclarationList.stubs(:new => list) }
|
||||
let(:list) { stub("declaration list", overridable: true) }
|
||||
before { FactoryGirl::DeclarationList.stubs(new: list) }
|
||||
|
||||
it "sets the declaration list as overridable" do
|
||||
subject.overridable.should == subject
|
||||
|
@ -70,7 +70,7 @@ describe FactoryGirl::Definition, "#processing_order" do
|
|||
|
||||
before do
|
||||
subject.define_trait(female_trait)
|
||||
FactoryGirl.stubs(:trait_by_name => admin_trait)
|
||||
FactoryGirl.stubs(trait_by_name: admin_trait)
|
||||
end
|
||||
|
||||
context "without base traits" do
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe FactoryGirl::EvaluatorClassDefiner do
|
||||
let(:simple_attribute) { stub("simple attribute", :name => :simple, :to_proc => lambda { 1 }) }
|
||||
let(:relative_attribute) { stub("relative attribute", :name => :relative, :to_proc => lambda { simple + 1 }) }
|
||||
let(:attribute_that_raises_a_second_time) { stub("attribute that would raise without a cache", :name => :raises_without_proper_cache, :to_proc => lambda { raise "failed" if @run; @run = true; nil }) }
|
||||
let(:simple_attribute) { stub("simple attribute", name: :simple, to_proc: lambda { 1 }) }
|
||||
let(:relative_attribute) { stub("relative attribute", name: :relative, to_proc: lambda { simple + 1 }) }
|
||||
let(:attribute_that_raises_a_second_time) { stub("attribute that would raise without a cache", name: :raises_without_proper_cache, to_proc: lambda { raise "failed" if @run; @run = true; nil }) }
|
||||
let(:callbacks) { [stub("callback 1"), stub("callback 2")] }
|
||||
|
||||
let(:attributes) { [simple_attribute, relative_attribute, attribute_that_raises_a_second_time] }
|
||||
let(:class_definer) { FactoryGirl::EvaluatorClassDefiner.new(attributes, callbacks, FactoryGirl::Evaluator) }
|
||||
let(:evaluator) { class_definer.evaluator_class.new(stub("build strategy", :add_observer => true)) }
|
||||
let(:evaluator) { class_definer.evaluator_class.new(stub("build strategy", add_observer: true)) }
|
||||
|
||||
it "returns an evaluator when accessing the evaluator class" do
|
||||
evaluator.should be_a(FactoryGirl::Evaluator)
|
||||
|
@ -38,7 +38,7 @@ describe FactoryGirl::EvaluatorClassDefiner do
|
|||
|
||||
context "with a custom evaluator as a parent class" do
|
||||
let(:child_callbacks) { [stub("child callback 1"), stub("child callback 2")] }
|
||||
let(:child_attributes) { [stub("child attribute", :name => :simple, :to_proc => lambda { 1 })] }
|
||||
let(:child_attributes) { [stub("child attribute", name: :simple, to_proc: lambda { 1 })] }
|
||||
let(:child_definer) { FactoryGirl::EvaluatorClassDefiner.new(child_attributes, child_callbacks, class_definer.evaluator_class) }
|
||||
|
||||
subject { child_definer.evaluator_class }
|
||||
|
|
|
@ -17,8 +17,8 @@ describe FactoryGirl::Factory do
|
|||
end
|
||||
|
||||
it "passes a custom creation block" do
|
||||
strategy = stub("strategy", :result => nil, :add_observer => true)
|
||||
FactoryGirl::Strategy::Build.stubs(:new => strategy)
|
||||
strategy = stub("strategy", result: nil, add_observer: true)
|
||||
FactoryGirl::Strategy::Build.stubs(new: strategy)
|
||||
block = lambda {}
|
||||
factory = FactoryGirl::Factory.new(:object)
|
||||
factory.to_create(&block)
|
||||
|
@ -48,7 +48,7 @@ describe FactoryGirl::Factory do
|
|||
factory.declare_attribute(association_on_parent)
|
||||
FactoryGirl.register_factory(factory)
|
||||
|
||||
child_factory = FactoryGirl::Factory.new(:child_post, :parent => :post)
|
||||
child_factory = FactoryGirl::Factory.new(:child_post, parent: :post)
|
||||
child_factory.declare_attribute(association_on_child)
|
||||
|
||||
child_factory.associations.map(&:name).should == [:association_on_parent, :association_on_child]
|
||||
|
@ -88,7 +88,7 @@ describe FactoryGirl::Factory do
|
|||
@factory.declare_attribute(FactoryGirl::Declaration::Static.new(:test, 'original'))
|
||||
Factory.alias(/(.*)_alias/, '\1')
|
||||
@result = @factory.run(FactoryGirl::Strategy::AttributesFor,
|
||||
:test_alias => 'new')
|
||||
test_alias: 'new')
|
||||
end
|
||||
|
||||
it "uses the passed in value for the alias" do
|
||||
|
@ -105,20 +105,20 @@ describe FactoryGirl::Factory do
|
|||
end
|
||||
|
||||
it "creates a new factory using the class of the parent" do
|
||||
child = FactoryGirl::Factory.new(:child, :parent => @factory.name)
|
||||
child = FactoryGirl::Factory.new(:child, parent: @factory.name)
|
||||
child.compile
|
||||
child.build_class.should == @factory.build_class
|
||||
end
|
||||
|
||||
it "creates a new factory while overriding the parent class" do
|
||||
child = FactoryGirl::Factory.new(:child, :class => String, :parent => @factory.name)
|
||||
child = FactoryGirl::Factory.new(:child, class: String, parent: @factory.name)
|
||||
child.compile
|
||||
child.build_class.should == String
|
||||
end
|
||||
end
|
||||
|
||||
describe FactoryGirl::Factory, "when defined with a custom class" do
|
||||
subject { FactoryGirl::Factory.new(:author, :class => Float) }
|
||||
subject { FactoryGirl::Factory.new(:author, class: Float) }
|
||||
its(:build_class) { should == Float }
|
||||
end
|
||||
|
||||
|
@ -134,7 +134,7 @@ describe FactoryGirl::Factory, "when given a class that overrides #to_s" do
|
|||
end
|
||||
end
|
||||
|
||||
subject { FactoryGirl::Factory.new(:overriding_class, :class => Overriding::Class) }
|
||||
subject { FactoryGirl::Factory.new(:overriding_class, class: Overriding::Class) }
|
||||
|
||||
it "sets build_class correctly" do
|
||||
subject.build_class.should == overriding_class
|
||||
|
@ -152,7 +152,7 @@ describe FactoryGirl::Factory, "when defined with a class instead of a name" do
|
|||
end
|
||||
|
||||
describe FactoryGirl::Factory, "when defined with a custom class name" do
|
||||
subject { FactoryGirl::Factory.new(:author, :class => :argument_error) }
|
||||
subject { FactoryGirl::Factory.new(:author, class: :argument_error) }
|
||||
its(:build_class) { should == ArgumentError }
|
||||
end
|
||||
|
||||
|
@ -183,7 +183,7 @@ describe FactoryGirl::Factory, "for namespaced class" do
|
|||
end
|
||||
|
||||
context "with a namespaced class with Namespace::Class syntax" do
|
||||
subject { FactoryGirl::Factory.new(name, :class => "Admin::Settings") }
|
||||
subject { FactoryGirl::Factory.new(name, class: "Admin::Settings") }
|
||||
|
||||
it "sets build_class correctly" do
|
||||
subject.build_class.should == settings_class
|
||||
|
@ -191,7 +191,7 @@ describe FactoryGirl::Factory, "for namespaced class" do
|
|||
end
|
||||
|
||||
context "with a namespaced class with namespace/class syntax" do
|
||||
subject { FactoryGirl::Factory.new(name, :class => "admin/settings") }
|
||||
subject { FactoryGirl::Factory.new(name, class: "admin/settings") }
|
||||
|
||||
it "sets build_class correctly" do
|
||||
subject.build_class.should == settings_class
|
||||
|
@ -219,7 +219,7 @@ describe FactoryGirl::Factory, "human names" do
|
|||
end
|
||||
|
||||
context "factory name with aliases" do
|
||||
subject { FactoryGirl::Factory.new(:happy_user, :aliases => [:gleeful_user, :person]) }
|
||||
subject { FactoryGirl::Factory.new(:happy_user, aliases: [:gleeful_user, :person]) }
|
||||
its(:names) { should == [:happy_user, :gleeful_user, :person] }
|
||||
its(:human_names) { should == ["happy user", "gleeful user", "person"] }
|
||||
end
|
||||
|
@ -229,15 +229,15 @@ describe FactoryGirl::Factory, "running a factory" do
|
|||
subject { FactoryGirl::Factory.new(:user) }
|
||||
let(:attribute) { FactoryGirl::Attribute::Static.new(:name, "value", false) }
|
||||
let(:declaration) { FactoryGirl::Declaration::Static.new(:name, "value", false) }
|
||||
let(:strategy) { stub("strategy", :result => "result", :add_observer => true) }
|
||||
let(:strategy) { stub("strategy", result: "result", add_observer: true) }
|
||||
let(:attributes) { [attribute] }
|
||||
let(:attribute_list) { stub('attribute-list', :declarations => [declaration], :to_a => attributes) }
|
||||
let(:attribute_list) { stub('attribute-list', declarations: [declaration], to_a: attributes) }
|
||||
|
||||
before do
|
||||
define_model("User", :name => :string)
|
||||
FactoryGirl::Declaration::Static.stubs(:new => declaration)
|
||||
declaration.stubs(:to_attributes => attributes)
|
||||
FactoryGirl::Strategy::Build.stubs(:new => strategy)
|
||||
define_model("User", name: :string)
|
||||
FactoryGirl::Declaration::Static.stubs(new: declaration)
|
||||
declaration.stubs(to_attributes: attributes)
|
||||
FactoryGirl::Strategy::Build.stubs(new: strategy)
|
||||
subject.declare_attribute(declaration)
|
||||
end
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ describe FactoryGirl::Registry do
|
|||
let(:sequence) { FactoryGirl::Sequence.new(:email) { |n| "somebody#{n}@example.com" } }
|
||||
let(:factory) { FactoryGirl::Factory.new(:object) }
|
||||
let(:other_factory) { FactoryGirl::Factory.new(:string) }
|
||||
let(:factory_with_aliases) { FactoryGirl::Factory.new(:string, :aliases => aliases) }
|
||||
let(:factory_with_aliases) { FactoryGirl::Factory.new(:string, aliases: aliases) }
|
||||
let(:registry_name) { "Factory" }
|
||||
|
||||
subject { FactoryGirl::Registry.new(registry_name) }
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe FactoryGirl::Strategy::AttributesFor do
|
||||
let(:result) { { :name => "John Doe", :gender => "Male", :admin => false } }
|
||||
let(:attribute_assigner) { stub("attribute assigner", :hash => result) }
|
||||
let(:result) { { name: "John Doe", gender: "Male", admin: false } }
|
||||
let(:attribute_assigner) { stub("attribute assigner", hash: result) }
|
||||
|
||||
it_should_behave_like "strategy without association support"
|
||||
|
||||
|
|
|
@ -3,5 +3,5 @@ require "spec_helper"
|
|||
describe FactoryGirl::Strategy::Build do
|
||||
it_should_behave_like "strategy with association support", FactoryGirl::Strategy::Create
|
||||
it_should_behave_like "strategy with callbacks", :after_build
|
||||
it_should_behave_like "strategy with :strategy => :build", FactoryGirl::Strategy::Build
|
||||
it_should_behave_like "strategy with strategy: :build", FactoryGirl::Strategy::Build
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ describe FactoryGirl::Strategy::Create do
|
|||
it "runs a custom create block" do
|
||||
block_run = false
|
||||
block = lambda {|instance| block_run = true }
|
||||
subject.result(stub("assigner", :object => stub("result instance")), block)
|
||||
subject.result(stub("assigner", object: stub("result instance")), block)
|
||||
block_run.should be_true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
|||
describe FactoryGirl::Strategy::Stub do
|
||||
it_should_behave_like "strategy with association support", FactoryGirl::Strategy::Stub
|
||||
it_should_behave_like "strategy with callbacks", :after_stub
|
||||
it_should_behave_like "strategy with :strategy => :build", FactoryGirl::Strategy::Stub
|
||||
it_should_behave_like "strategy with strategy: :build", FactoryGirl::Strategy::Stub
|
||||
|
||||
context "asking for a result" do
|
||||
before { Timecop.freeze(Time.now) }
|
||||
|
@ -14,7 +14,7 @@ describe FactoryGirl::Strategy::Stub do
|
|||
end.new
|
||||
end
|
||||
|
||||
let(:assigner) { stub("attribute assigner", :object => result_instance) }
|
||||
let(:assigner) { stub("attribute assigner", object: result_instance) }
|
||||
let(:to_create) { lambda {|instance| instance } }
|
||||
|
||||
it { subject.result(assigner, to_create).should_not be_new_record }
|
||||
|
|
|
@ -70,8 +70,8 @@ RSpec.configure do |config|
|
|||
|
||||
config.before(:all) do
|
||||
ActiveRecord::Base.establish_connection(
|
||||
:adapter => 'sqlite3',
|
||||
:database => File.join(File.dirname(__FILE__), 'test.db')
|
||||
adapter: 'sqlite3',
|
||||
database: File.join(File.dirname(__FILE__), 'test.db')
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -26,23 +26,23 @@ shared_examples_for "strategy with association support" do |factory_girl_strateg
|
|||
end
|
||||
|
||||
before do
|
||||
FactoryGirl.stubs(:factory_by_name => factory)
|
||||
FactoryGirl.stubs(factory_by_name: factory)
|
||||
factory.stubs(:compile)
|
||||
factory.stubs(:run)
|
||||
end
|
||||
|
||||
it "runs the factory with the correct overrides" do
|
||||
association_named(:author, factory_girl_strategy_class, :great => "value")
|
||||
factory.should have_received(:run).with(factory_girl_strategy_class, :great => "value")
|
||||
association_named(:author, factory_girl_strategy_class, great: "value")
|
||||
factory.should have_received(:run).with(factory_girl_strategy_class, great: "value")
|
||||
end
|
||||
|
||||
it "finds the factory with the correct factory name" do
|
||||
association_named(:author, factory_girl_strategy_class, :great => "value")
|
||||
association_named(:author, factory_girl_strategy_class, great: "value")
|
||||
FactoryGirl.should have_received(:factory_by_name).with(:author)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for "strategy with :strategy => :build" do |factory_girl_strategy_class|
|
||||
shared_examples_for "strategy with strategy: :build" do |factory_girl_strategy_class|
|
||||
let(:factory) { stub("associate_factory") }
|
||||
|
||||
def association_named(name, overrides)
|
||||
|
@ -52,18 +52,18 @@ shared_examples_for "strategy with :strategy => :build" do |factory_girl_strateg
|
|||
end
|
||||
|
||||
before do
|
||||
FactoryGirl.stubs(:factory_by_name => factory)
|
||||
FactoryGirl.stubs(factory_by_name: factory)
|
||||
factory.stubs(:compile)
|
||||
factory.stubs(:run)
|
||||
end
|
||||
|
||||
it "runs the factory with the correct overrides" do
|
||||
association_named(:author, :strategy => :build, :great => "value")
|
||||
factory.should have_received(:run).with(factory_girl_strategy_class, { :great => "value" })
|
||||
association_named(:author, strategy: :build, great: "value")
|
||||
factory.should have_received(:run).with(factory_girl_strategy_class, { great: "value" })
|
||||
end
|
||||
|
||||
it "finds the factory with the correct factory name" do
|
||||
association_named(:author, :strategy => :build, :great => "value")
|
||||
association_named(:author, strategy: :build, great: "value")
|
||||
FactoryGirl.should have_received(:factory_by_name).with(:author)
|
||||
end
|
||||
end
|
||||
|
@ -89,7 +89,7 @@ shared_examples_for "strategy with callbacks" do |*callback_names|
|
|||
end.new
|
||||
end
|
||||
|
||||
let(:assigner) { stub("attribute assigner", :object => result_instance) }
|
||||
let(:assigner) { stub("attribute assigner", object: result_instance) }
|
||||
|
||||
before { subject.add_observer(callback_observer) }
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue