From dc32fd69e84dd667b763dd691943123636efa1bd Mon Sep 17 00:00:00 2001 From: Joshua Clayton Date: Fri, 7 Oct 2011 18:19:27 -0400 Subject: [PATCH] Change syntax for ignoring attributes to use block syntax instead of calling ignore on individual declarations. Old syntax: factory :user do rockstar(true).ignore four { 2 + 2 }.ignore name { "John Doe#{" - Rockstar" if rockstar}" } end New syntax: factory :user do ignore do rockstar true four { 2 + 2 } end name { "John Doe#{" - Rockstar" if rockstar}" } end --- GETTING_STARTED.md | 6 ++- lib/factory_girl/attribute.rb | 8 +--- lib/factory_girl/attribute/association.rb | 2 +- lib/factory_girl/attribute/dynamic.rb | 11 +++-- lib/factory_girl/attribute/sequence.rb | 11 +++-- lib/factory_girl/attribute/static.rb | 10 ++-- lib/factory_girl/declaration.rb | 10 ++-- lib/factory_girl/declaration/association.rb | 2 +- lib/factory_girl/declaration/dynamic.rb | 6 +-- lib/factory_girl/declaration/implicit.rb | 6 +-- lib/factory_girl/declaration/static.rb | 6 +-- lib/factory_girl/definition_proxy.rb | 16 +++++-- lib/factory_girl/factory.rb | 10 +++- lib/factory_girl/proxy.rb | 7 ++- lib/factory_girl/proxy/attributes_for.rb | 8 +--- lib/factory_girl/proxy/build.rb | 9 +--- lib/factory_girl/proxy/stub.rb | 8 +--- spec/acceptance/transient_attributes_spec.rb | 48 ++++++++++++++++++-- spec/factory_girl/attribute/dynamic_spec.rb | 10 ++-- spec/factory_girl/attribute/sequence_spec.rb | 2 +- spec/factory_girl/attribute/static_spec.rb | 6 +-- spec/factory_girl/attribute_list_spec.rb | 18 ++++---- spec/factory_girl/attribute_spec.rb | 6 +-- spec/factory_girl/definition_proxy_spec.rb | 12 ++--- spec/factory_girl/factory_spec.rb | 4 +- spec/support/shared_examples/proxy.rb | 2 +- 26 files changed, 152 insertions(+), 92 deletions(-) diff --git a/GETTING_STARTED.md b/GETTING_STARTED.md index fc979f3dd..624dacfba 100644 --- a/GETTING_STARTED.md +++ b/GETTING_STARTED.md @@ -159,8 +159,10 @@ Transient Attributes There may be times where your code can be DRYed up by passing in transient attributes to factories. factory :user do - rockstar(true).ignore - upcased { false }.ignore + ignore do + rockstar true + upcased { false } + end name { "John Doe#{" - Rockstar" if rockstar}" } email { "#{name.downcase}@example.com" } diff --git a/lib/factory_girl/attribute.rb b/lib/factory_girl/attribute.rb index 8e102ceea..bc8abdb44 100644 --- a/lib/factory_girl/attribute.rb +++ b/lib/factory_girl/attribute.rb @@ -12,16 +12,12 @@ class Attribute #:nodoc: attr_reader :name, :ignored - def initialize(name) + def initialize(name, ignored) @name = name.to_sym - @ignored = false + @ignored = ignored ensure_non_attribute_writer! end - def ignore - @ignored = true - end - def add_to(proxy) end diff --git a/lib/factory_girl/attribute/association.rb b/lib/factory_girl/attribute/association.rb index de9e909a8..d298da2c2 100644 --- a/lib/factory_girl/attribute/association.rb +++ b/lib/factory_girl/attribute/association.rb @@ -4,7 +4,7 @@ class Association < Attribute #:nodoc: attr_reader :factory def initialize(name, factory, overrides) - super(name) + super(name, false) @factory = factory @overrides = overrides end diff --git a/lib/factory_girl/attribute/dynamic.rb b/lib/factory_girl/attribute/dynamic.rb index d421a63b1..3edb009b9 100644 --- a/lib/factory_girl/attribute/dynamic.rb +++ b/lib/factory_girl/attribute/dynamic.rb @@ -1,8 +1,8 @@ module FactoryGirl class Attribute #:nodoc: class Dynamic < Attribute #:nodoc: - def initialize(name, block) - super(name) + def initialize(name, ignored, block) + super(name, ignored) @block = block end @@ -11,7 +11,12 @@ def add_to(proxy) if FactoryGirl::Sequence === value raise SequenceAbuseError end - proxy.set(name, value, @ignored) + + if @ignored + proxy.set_ignored(name, value) + else + proxy.set(name, value) + end end end end diff --git a/lib/factory_girl/attribute/sequence.rb b/lib/factory_girl/attribute/sequence.rb index 0678f3d92..9c73a4bce 100644 --- a/lib/factory_girl/attribute/sequence.rb +++ b/lib/factory_girl/attribute/sequence.rb @@ -2,13 +2,18 @@ module FactoryGirl class Attribute class Sequence < Attribute - def initialize(name, sequence) - super(name) + def initialize(name, sequence, ignored) + super(name, ignored) @sequence = sequence end def add_to(proxy) - proxy.set(name, FactoryGirl.generate(@sequence)) + value = FactoryGirl.generate(@sequence) + if @ignored + proxy.set_ignored(name, value) + else + proxy.set(name, value) + end end end diff --git a/lib/factory_girl/attribute/static.rb b/lib/factory_girl/attribute/static.rb index 5fcd5812f..b30478bab 100644 --- a/lib/factory_girl/attribute/static.rb +++ b/lib/factory_girl/attribute/static.rb @@ -5,13 +5,17 @@ class Static < Attribute #:nodoc: attr_reader :value - def initialize(name, value) - super(name) + def initialize(name, value, ignored) + super(name, ignored) @value = value end def add_to(proxy) - proxy.set(name, @value, @ignored) + if @ignored + proxy.set_ignored(name, @value) + else + proxy.set(name, @value) + end end def priority diff --git a/lib/factory_girl/declaration.rb b/lib/factory_girl/declaration.rb index b6141a744..d756a0238 100644 --- a/lib/factory_girl/declaration.rb +++ b/lib/factory_girl/declaration.rb @@ -2,18 +2,18 @@ module FactoryGirl class Declaration attr_reader :name - def initialize(name) - @name = name + def initialize(name, ignored = false) + @name = name + @ignored = ignored end def ignore + $stderr.puts "DEPRECATION WARNING: Use ignore block syntax instead of calling #ignore" @ignored = true end def to_attributes - build.tap do |attributes| - attributes.each(&:ignore) if @ignored - end + build end end end diff --git a/lib/factory_girl/declaration/association.rb b/lib/factory_girl/declaration/association.rb index dd26f76de..74e42ee2c 100644 --- a/lib/factory_girl/declaration/association.rb +++ b/lib/factory_girl/declaration/association.rb @@ -2,7 +2,7 @@ module FactoryGirl class Declaration class Association < Declaration def initialize(name, options) - super(name) + super(name, false) @options = options end diff --git a/lib/factory_girl/declaration/dynamic.rb b/lib/factory_girl/declaration/dynamic.rb index aabf307ad..59b91bf85 100644 --- a/lib/factory_girl/declaration/dynamic.rb +++ b/lib/factory_girl/declaration/dynamic.rb @@ -1,15 +1,15 @@ module FactoryGirl class Declaration class Dynamic < Declaration - def initialize(name, block) - super(name) + def initialize(name, ignored = false, block) + super(name, ignored) @block = block end private def build - [Attribute::Dynamic.new(name, @block)] + [Attribute::Dynamic.new(name, @ignored, @block)] end end end diff --git a/lib/factory_girl/declaration/implicit.rb b/lib/factory_girl/declaration/implicit.rb index bf7bc8d24..d41665738 100644 --- a/lib/factory_girl/declaration/implicit.rb +++ b/lib/factory_girl/declaration/implicit.rb @@ -1,8 +1,8 @@ module FactoryGirl class Declaration class Implicit < Declaration - def initialize(name, factory = nil) - super(name) + def initialize(name, factory = nil, ignored = false) + super(name, ignored) @factory = factory end @@ -12,7 +12,7 @@ def build if FactoryGirl.factories.registered?(name) [Attribute::Association.new(name, name, {})] elsif FactoryGirl.sequences.registered?(name) - [Attribute::Sequence.new(name, name)] + [Attribute::Sequence.new(name, name, @ignored)] else trait_root = @factory || FactoryGirl trait_root.trait_by_name(name).attributes.to_a diff --git a/lib/factory_girl/declaration/static.rb b/lib/factory_girl/declaration/static.rb index 9d4255c9c..28cb19f5b 100644 --- a/lib/factory_girl/declaration/static.rb +++ b/lib/factory_girl/declaration/static.rb @@ -1,15 +1,15 @@ module FactoryGirl class Declaration class Static < Declaration - def initialize(name, value) - super(name) + def initialize(name, value, ignored = false) + super(name, ignored) @value = value end private def build - [Attribute::Static.new(name, @value)] + [Attribute::Static.new(name, @value, @ignored)] end end end diff --git a/lib/factory_girl/definition_proxy.rb b/lib/factory_girl/definition_proxy.rb index b658c52e5..230225e36 100644 --- a/lib/factory_girl/definition_proxy.rb +++ b/lib/factory_girl/definition_proxy.rb @@ -8,8 +8,9 @@ class DefinitionProxy attr_reader :child_factories - def initialize(factory) - @factory = factory + def initialize(factory, ignore = false) + @factory = factory + @ignore = ignore @child_factories = [] end @@ -36,16 +37,21 @@ def add_attribute(name, value = nil, &block) if value raise AttributeDefinitionError, "Both value and block given" else - declaration = Declaration::Dynamic.new(name, block) + declaration = Declaration::Dynamic.new(name, @ignore, block) end else - declaration = FactoryGirl::Declaration::Static.new(name, value) + declaration = FactoryGirl::Declaration::Static.new(name, value, @ignore) end @factory.declare_attribute(declaration) declaration end + def ignore(&block) + proxy = DefinitionProxy.new(@factory, true) + proxy.instance_eval(&block) + end + # Calls add_attribute using the missing method name as the name of the # attribute, so that: # @@ -79,7 +85,7 @@ def add_attribute(name, value = nil, &block) # are equivalent. def method_missing(name, *args, &block) if args.empty? && block.nil? - @factory.declare_attribute(Declaration::Implicit.new(name, @factory)) + @factory.declare_attribute(Declaration::Implicit.new(name, @factory, @ignore)) elsif args.first.is_a?(Hash) && args.first.has_key?(:factory) association(name, *args) else diff --git a/lib/factory_girl/factory.rb b/lib/factory_girl/factory.rb index 6534d1937..f6fe0c3eb 100644 --- a/lib/factory_girl/factory.rb +++ b/lib/factory_girl/factory.rb @@ -60,7 +60,15 @@ def run(proxy_class, overrides) #:nodoc: if factory_overrides.empty? attribute.add_to(proxy) else - factory_overrides.each { |attr, val| proxy.set(attr, val, attribute.ignored); overrides.delete(attr) } + factory_overrides.each do |attr, val| + if attribute.ignored + proxy.set_ignored(attr, val) + else + proxy.set(attr, val) + end + + overrides.delete(attr) + end end end overrides.each { |attr, val| proxy.set(attr, val) } diff --git a/lib/factory_girl/proxy.rb b/lib/factory_girl/proxy.rb index ab7304838..ada1cd4b7 100644 --- a/lib/factory_girl/proxy.rb +++ b/lib/factory_girl/proxy.rb @@ -5,12 +5,17 @@ class Proxy #:nodoc: def initialize(klass) @callbacks = {} + @ignored_attributes = {} end def get(attribute) end - def set(attribute, value, ignored = false) + def set(attribute, value) + end + + def set_ignored(attribute, value) + @ignored_attributes[attribute] = value end def associate(name, factory, attributes) diff --git a/lib/factory_girl/proxy/attributes_for.rb b/lib/factory_girl/proxy/attributes_for.rb index e2287c69e..89481fbed 100644 --- a/lib/factory_girl/proxy/attributes_for.rb +++ b/lib/factory_girl/proxy/attributes_for.rb @@ -11,12 +11,8 @@ def get(attribute) @ignored_attributes[attribute] || @hash[attribute] end - def set(attribute, value, ignored = false) - if ignored - @ignored_attributes[attribute] = value - else - @hash[attribute] = value - end + def set(attribute, value) + @hash[attribute] = value end def result(to_create) diff --git a/lib/factory_girl/proxy/build.rb b/lib/factory_girl/proxy/build.rb index 4ab9e69d8..3d15142e6 100644 --- a/lib/factory_girl/proxy/build.rb +++ b/lib/factory_girl/proxy/build.rb @@ -4,7 +4,6 @@ class Build < Proxy #:nodoc: def initialize(klass) super(klass) @instance = klass.new - @ignored_attributes = {} end def get(attribute) @@ -15,12 +14,8 @@ def get(attribute) end end - def set(attribute, value, ignored = false) - if ignored - @ignored_attributes[attribute] = value - else - @instance.send(:"#{attribute}=", value) - end + def set(attribute, value) + @instance.send(:"#{attribute}=", value) end def associate(name, factory_name, overrides) diff --git a/lib/factory_girl/proxy/stub.rb b/lib/factory_girl/proxy/stub.rb index 5f4fddc82..eb14403eb 100644 --- a/lib/factory_girl/proxy/stub.rb +++ b/lib/factory_girl/proxy/stub.rb @@ -55,12 +55,8 @@ def get(attribute) end end - def set(attribute, value, ignored = false) - if ignored - @ignored_attributes[attribute] = value - else - @instance.send(:"#{attribute}=", value) - end + def set(attribute, value) + @instance.send(:"#{attribute}=", value) end def associate(name, factory_name, overrides) diff --git a/spec/acceptance/transient_attributes_spec.rb b/spec/acceptance/transient_attributes_spec.rb index 67ac9f645..743c39e39 100644 --- a/spec/acceptance/transient_attributes_spec.rb +++ b/spec/acceptance/transient_attributes_spec.rb @@ -8,9 +8,11 @@ sequence(:name) {|n| "John #{n}" } factory :user do - four { 2 + 2 }.ignore - rockstar(true).ignore - upcased(false).ignore + ignore do + four { 2 + 2 } + rockstar true + upcased false + end name { "#{FactoryGirl.generate(:name)}#{" - Rockstar" if rockstar}" } email { "#{name.downcase}#{four}@example.com" } @@ -66,3 +68,43 @@ end end end + +describe "deprecated way of ignoring attributes" do + before do + define_model("User", :name => :string) + + FactoryGirl.define do + factory :user do + rockstar(false).ignore + + name { "John Doe#{" Rockstar" if rockstar}" } + end + end + end + + it "assigns attributes correctly" do + FactoryGirl.build(:user, :rockstar => true).name.should == "John Doe Rockstar" + FactoryGirl.build(:user).name.should == "John Doe" + end +end + +describe "transient sequences" do + before do + define_model("User", :name => :string) + + FactoryGirl.define do + factory :user do + ignore do + sequence(:counter) + end + + name { "John Doe #{counter}" } + end + end + end + + it "increments sequences correctly" do + FactoryGirl.build(:user).name.should == "John Doe 1" + FactoryGirl.build(:user).name.should == "John Doe 2" + end +end diff --git a/spec/factory_girl/attribute/dynamic_spec.rb b/spec/factory_girl/attribute/dynamic_spec.rb index 2ba78b881..77b9c0be4 100644 --- a/spec/factory_girl/attribute/dynamic_spec.rb +++ b/spec/factory_girl/attribute/dynamic_spec.rb @@ -5,7 +5,7 @@ let(:proxy) { stub("proxy", :set => nil) } let(:block) { lambda { } } - subject { FactoryGirl::Attribute::Dynamic.new(name, block) } + subject { FactoryGirl::Attribute::Dynamic.new(name, false, block) } its(:name) { should == name } @@ -14,7 +14,7 @@ it "calls the block to set a value" do subject.add_to(proxy) - proxy.should have_received(:set).with(name, "value", false) + proxy.should have_received(:set).with(name, "value") end end @@ -23,7 +23,7 @@ it "yields the proxy to the block" do subject.add_to(proxy) - proxy.should have_received(:set).with(name, proxy, false) + proxy.should have_received(:set).with(name, proxy) end end @@ -37,7 +37,7 @@ it "evaluates the attribute from the proxy" do subject.add_to(proxy) - proxy.should have_received(:set).with(name, result, false) + proxy.should have_received(:set).with(name, result) end end @@ -51,6 +51,6 @@ end describe FactoryGirl::Attribute::Dynamic, "with a string name" do - subject { FactoryGirl::Attribute::Dynamic.new("name", nil) } + subject { FactoryGirl::Attribute::Dynamic.new("name", nil, false) } its(:name) { should == :name } end diff --git a/spec/factory_girl/attribute/sequence_spec.rb b/spec/factory_girl/attribute/sequence_spec.rb index 0c1b473c7..b90fe0cb0 100644 --- a/spec/factory_girl/attribute/sequence_spec.rb +++ b/spec/factory_girl/attribute/sequence_spec.rb @@ -6,7 +6,7 @@ let(:sequence) { FactoryGirl::Sequence.new(sequence_name, 5) { |n| "Name #{n}" } } let(:proxy) { stub("proxy") } - subject { FactoryGirl::Attribute::Sequence.new(name, sequence_name) } + subject { FactoryGirl::Attribute::Sequence.new(name, sequence_name, false) } before { FactoryGirl.register_sequence(sequence) } its(:name) { should == name } diff --git a/spec/factory_girl/attribute/static_spec.rb b/spec/factory_girl/attribute/static_spec.rb index cb8f6a131..21d558fe7 100644 --- a/spec/factory_girl/attribute/static_spec.rb +++ b/spec/factory_girl/attribute/static_spec.rb @@ -5,18 +5,18 @@ let(:value) { "John" } let(:proxy) { stub("proxy") } - subject { FactoryGirl::Attribute::Static.new(name, value) } + subject { FactoryGirl::Attribute::Static.new(name, value, false) } its(:name) { should == name } it "sets its static value on a proxy" do proxy.stubs(:set) subject.add_to(proxy) - proxy.should have_received(:set).with(name, value, false) + proxy.should have_received(:set).with(name, value) end end describe FactoryGirl::Attribute::Static, "with a string name" do - subject { FactoryGirl::Attribute::Static.new("name", nil) } + subject { FactoryGirl::Attribute::Static.new("name", nil, false) } its(:name) { should == :name } end diff --git a/spec/factory_girl/attribute_list_spec.rb b/spec/factory_girl/attribute_list_spec.rb index e84d2f955..871b90386 100644 --- a/spec/factory_girl/attribute_list_spec.rb +++ b/spec/factory_girl/attribute_list_spec.rb @@ -10,8 +10,8 @@ end describe FactoryGirl::AttributeList, "#define_attribute" do - let(:static_attribute) { FactoryGirl::Attribute::Static.new(:full_name, "value") } - let(:dynamic_attribute) { FactoryGirl::Attribute::Dynamic.new(:email, lambda {|u| "#{u.full_name}@example.com" }) } + let(:static_attribute) { FactoryGirl::Attribute::Static.new(:full_name, "value", false) } + let(:dynamic_attribute) { FactoryGirl::Attribute::Dynamic.new(:email, false, lambda {|u| "#{u.full_name}@example.com" }) } it "maintains a list of attributes" do subject.define_attribute(static_attribute) @@ -33,7 +33,7 @@ end context "when set as overridable" do - let(:static_attribute_with_same_name) { FactoryGirl::Attribute::Static.new(:full_name, "overridden value") } + let(:static_attribute_with_same_name) { FactoryGirl::Attribute::Static.new(:full_name, "overridden value", false) } before { subject.overridable } it "redefines the attribute if the name already exists" do @@ -58,10 +58,10 @@ end describe FactoryGirl::AttributeList, "#apply_attributes" do - let(:full_name_attribute) { FactoryGirl::Attribute::Static.new(:full_name, "John Adams") } - let(:city_attribute) { FactoryGirl::Attribute::Static.new(:city, "Boston") } - let(:email_attribute) { FactoryGirl::Attribute::Dynamic.new(:email, lambda {|model| "#{model.full_name}@example.com" }) } - let(:login_attribute) { FactoryGirl::Attribute::Dynamic.new(:login, lambda {|model| "username-#{model.full_name}" }) } + let(:full_name_attribute) { FactoryGirl::Attribute::Static.new(:full_name, "John Adams", false) } + let(:city_attribute) { FactoryGirl::Attribute::Static.new(:city, "Boston", false) } + let(:email_attribute) { FactoryGirl::Attribute::Dynamic.new(:email, false, lambda {|model| "#{model.full_name}@example.com" }) } + let(:login_attribute) { FactoryGirl::Attribute::Dynamic.new(:login, false, lambda {|model| "username-#{model.full_name}" }) } def list(*attributes) FactoryGirl::AttributeList.new.tap do |list| @@ -90,7 +90,7 @@ def list(*attributes) it "doesn't overwrite attributes that are already defined" do subject.define_attribute(full_name_attribute) - attribute_with_same_name = FactoryGirl::Attribute::Static.new(:full_name, "Benjamin Franklin") + attribute_with_same_name = FactoryGirl::Attribute::Static.new(:full_name, "Benjamin Franklin", false) subject.apply_attributes(list(attribute_with_same_name)) subject.to_a.should == [full_name_attribute] @@ -120,7 +120,7 @@ def list(*attributes) it "overwrites attributes that are already defined" do subject.define_attribute(full_name_attribute) - attribute_with_same_name = FactoryGirl::Attribute::Static.new(:full_name, "Benjamin Franklin") + attribute_with_same_name = FactoryGirl::Attribute::Static.new(:full_name, "Benjamin Franklin", false) subject.apply_attributes(list(attribute_with_same_name)) subject.to_a.should == [attribute_with_same_name] diff --git a/spec/factory_girl/attribute_spec.rb b/spec/factory_girl/attribute_spec.rb index 99716f0fc..9b1541e79 100644 --- a/spec/factory_girl/attribute_spec.rb +++ b/spec/factory_girl/attribute_spec.rb @@ -3,7 +3,7 @@ describe FactoryGirl::Attribute do let(:name) { "user" } let(:proxy) { stub("proxy") } - subject { FactoryGirl::Attribute.new(name) } + subject { FactoryGirl::Attribute.new(name, false) } its(:name) { should == name.to_sym } it { should_not be_association } @@ -17,7 +17,7 @@ it "raises an error when defining an attribute writer" do error_message = %{factory_girl uses 'f.test value' syntax rather than 'f.test = value'} expect { - FactoryGirl::Attribute.new('test=') + FactoryGirl::Attribute.new('test=', false) }.to raise_error(FactoryGirl::AttributeDefinitionError, error_message) end @@ -26,7 +26,7 @@ end it "uses priority to perform comparisons" do - second_attribute = FactoryGirl::Attribute.new('name') + second_attribute = FactoryGirl::Attribute.new('name', false) (subject <=> second_attribute).should be_zero end end diff --git a/spec/factory_girl/definition_proxy_spec.rb b/spec/factory_girl/definition_proxy_spec.rb index 891834638..6e7bcb99f 100644 --- a/spec/factory_girl/definition_proxy_spec.rb +++ b/spec/factory_girl/definition_proxy_spec.rb @@ -11,7 +11,7 @@ subject.add_attribute(:name, 'value') factory.ensure_compiled factory.should have_received(:define_attribute).with(attribute) - FactoryGirl::Attribute::Static.should have_received(:new).with(:name, "value") + FactoryGirl::Attribute::Static.should have_received(:new).with(:name, "value", false) end it "should add a dynamic attribute when an attribute is defined with a block" do @@ -21,7 +21,7 @@ factory.stubs(:define_attribute) subject.add_attribute(:name, &block) factory.ensure_compiled - FactoryGirl::Attribute::Dynamic.should have_received(:new).with(:name, block) + FactoryGirl::Attribute::Dynamic.should have_received(:new).with(:name, false, block) factory.should have_received(:define_attribute).with(attribute) end @@ -105,14 +105,14 @@ def to_create(&block) it "creates a dynamic attribute" do subject.add_attribute(attribute_name, &block) factory.ensure_compiled - FactoryGirl::Attribute::Dynamic.should have_received(:new).with(attribute_name, block) + FactoryGirl::Attribute::Dynamic.should have_received(:new).with(attribute_name, false, block) factory.should have_received(:define_attribute).with(attribute) end it "creates a dynamic attribute without the method being defined" do subject.send(attribute_name, &block) factory.ensure_compiled - FactoryGirl::Attribute::Dynamic.should have_received(:new).with(attribute_name, block) + FactoryGirl::Attribute::Dynamic.should have_received(:new).with(attribute_name, false, block) factory.should have_received(:define_attribute).with(attribute) end end @@ -123,14 +123,14 @@ def to_create(&block) it "creates a static attribute" do subject.add_attribute(attribute_name, attribute_value) factory.ensure_compiled - FactoryGirl::Attribute::Static.should have_received(:new).with(attribute_name, attribute_value) + FactoryGirl::Attribute::Static.should have_received(:new).with(attribute_name, attribute_value, false) factory.should have_received(:define_attribute).with(attribute) end it "creates a static attribute without the method being defined" do subject.send(attribute_name, attribute_value) factory.ensure_compiled - FactoryGirl::Attribute::Static.should have_received(:new).with(attribute_name, attribute_value) + FactoryGirl::Attribute::Static.should have_received(:new).with(attribute_name, attribute_value, false) factory.should have_received(:define_attribute).with(attribute) end end diff --git a/spec/factory_girl/factory_spec.rb b/spec/factory_girl/factory_spec.rb index 5b2614415..75bcaa8af 100644 --- a/spec/factory_girl/factory_spec.rb +++ b/spec/factory_girl/factory_spec.rb @@ -246,8 +246,8 @@ describe FactoryGirl::Factory, "running a factory" do subject { FactoryGirl::Factory.new(:user) } - let(:attribute) { FactoryGirl::Attribute::Static.new(:name, "value") } - let(:declaration) { FactoryGirl::Declaration::Static.new(:name, "value") } + let(:attribute) { FactoryGirl::Attribute::Static.new(:name, "value", false) } + let(:declaration) { FactoryGirl::Declaration::Static.new(:name, "value", false) } let(:proxy) { stub("proxy", :result => "result", :set => nil) } let(:attributes) { [attribute] } let(:attribute_list) { stub('attribute-list', :declarations => [declaration], :to_a => attributes) } diff --git a/spec/support/shared_examples/proxy.rb b/spec/support/shared_examples/proxy.rb index a9ae8b083..f51144864 100644 --- a/spec/support/shared_examples/proxy.rb +++ b/spec/support/shared_examples/proxy.rb @@ -94,7 +94,7 @@ describe "when setting an ignored attribute" do before do - subject.set(attribute, value, true) + subject.set_ignored(attribute, value) end it { instance.should have_received(:"#{attribute}=").with(value).never }