factory_girl_kibiz0r 2.0.0.beta2 → 2.0.0.beta3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/factory_girl.rb +0 -1
- data/lib/factory_girl/attribute/dynamic.rb +1 -2
- data/lib/factory_girl/attribute/static.rb +1 -2
- data/lib/factory_girl/factory.rb +14 -2
- data/lib/factory_girl/proxy.rb +25 -4
- data/lib/factory_girl/proxy/attributes_for.rb +2 -2
- data/lib/factory_girl/proxy/build.rb +3 -7
- data/lib/factory_girl/version.rb +1 -1
- data/spec/acceptance/attributes_for_spec.rb +6 -1
- data/spec/acceptance/callbacks_spec.rb +2 -2
- data/spec/factory_girl/factory_spec.rb +8 -0
- data/spec/factory_girl/proxy_spec.rb +25 -7
- metadata +11 -12
- data/lib/factory_girl/attribute/list.rb +0 -19
    
        data/lib/factory_girl.rb
    CHANGED
    
    | @@ -12,7 +12,6 @@ require 'factory_girl/attribute/association' | |
| 12 12 | 
             
            require 'factory_girl/attribute/callback'
         | 
| 13 13 | 
             
            require 'factory_girl/attribute/sequence'
         | 
| 14 14 | 
             
            require 'factory_girl/attribute/implicit'
         | 
| 15 | 
            -
            require 'factory_girl/attribute/list'
         | 
| 16 15 | 
             
            require 'factory_girl/sequence'
         | 
| 17 16 | 
             
            require 'factory_girl/aliases'
         | 
| 18 17 | 
             
            require 'factory_girl/definition_proxy'
         | 
    
        data/lib/factory_girl/factory.rb
    CHANGED
    
    | @@ -36,7 +36,7 @@ module FactoryGirl | |
| 36 36 | 
             
                  assert_valid_options(options)
         | 
| 37 37 | 
             
                  @name       = factory_name_for(name)
         | 
| 38 38 | 
             
                  @options    = options
         | 
| 39 | 
            -
                  @attributes   =  | 
| 39 | 
            +
                  @attributes   = []
         | 
| 40 40 | 
             
                end
         | 
| 41 41 |  | 
| 42 42 | 
             
                def inherit_from(parent) #:nodoc:
         | 
| @@ -62,17 +62,21 @@ module FactoryGirl | |
| 62 62 | 
             
                    raise AssociationDefinitionError, "Self-referencing association '#{name}' in factory '#{self.name}'"
         | 
| 63 63 | 
             
                  end
         | 
| 64 64 | 
             
                  @attributes << attribute
         | 
| 65 | 
            +
                  attribute
         | 
| 65 66 | 
             
                end
         | 
| 66 67 |  | 
| 67 68 | 
             
                def add_callback(name, &block)
         | 
| 68 69 | 
             
                  unless [:after_build, :after_create, :after_stub].include?(name.to_sym)
         | 
| 69 70 | 
             
                    raise InvalidCallbackNameError, "#{name} is not a valid callback name. Valid callback names are :after_build, :after_create, and :after_stub"
         | 
| 70 71 | 
             
                  end
         | 
| 71 | 
            -
                   | 
| 72 | 
            +
                  attribute = Attribute::Callback.new(name.to_sym, block)
         | 
| 73 | 
            +
                  @attributes << attribute
         | 
| 74 | 
            +
                  attribute
         | 
| 72 75 | 
             
                end
         | 
| 73 76 |  | 
| 74 77 | 
             
                def run(proxy_class, overrides) #:nodoc:
         | 
| 75 78 | 
             
                  proxy = proxy_class.new(build_class)
         | 
| 79 | 
            +
                  proxy.ignored_attributes = ignored_attributes
         | 
| 76 80 | 
             
                  overrides = symbolize_keys(overrides)
         | 
| 77 81 | 
             
                  overrides.each {|attr, val| proxy.set(attr, val) }
         | 
| 78 82 | 
             
                  passed_keys = overrides.keys.collect {|k| FactoryGirl.aliases_for(k) }.flatten
         | 
| @@ -127,6 +131,14 @@ module FactoryGirl | |
| 127 131 |  | 
| 128 132 | 
             
                private
         | 
| 129 133 |  | 
| 134 | 
            +
                def ignored_attributes
         | 
| 135 | 
            +
                  Hash[@attributes.select do |attribute|
         | 
| 136 | 
            +
                    attribute.ignored?
         | 
| 137 | 
            +
                  end.map do |attribute|
         | 
| 138 | 
            +
                    [attribute.name, nil]
         | 
| 139 | 
            +
                  end]
         | 
| 140 | 
            +
                end
         | 
| 141 | 
            +
             | 
| 130 142 | 
             
                def class_for (class_or_to_s)
         | 
| 131 143 | 
             
                  if class_or_to_s.respond_to?(:to_sym)
         | 
| 132 144 | 
             
                    class_name = variable_name_to_class_name(class_or_to_s)
         | 
    
        data/lib/factory_girl/proxy.rb
    CHANGED
    
    | @@ -2,20 +2,31 @@ module FactoryGirl | |
| 2 2 | 
             
              class Proxy #:nodoc:
         | 
| 3 3 |  | 
| 4 4 | 
             
                attr_reader :callbacks
         | 
| 5 | 
            +
                attr_writer :ignored_attributes
         | 
| 5 6 |  | 
| 6 7 | 
             
                def initialize(klass)
         | 
| 7 8 | 
             
                end
         | 
| 8 9 |  | 
| 9 10 | 
             
                def get(attribute)
         | 
| 10 | 
            -
                   | 
| 11 | 
            +
                  if ignored? attribute
         | 
| 12 | 
            +
                    ignored_attributes[attribute]
         | 
| 13 | 
            +
                  else
         | 
| 14 | 
            +
                    get_attr attribute
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def get_attr(attribute)
         | 
| 11 19 | 
             
                end
         | 
| 12 20 |  | 
| 13 21 | 
             
                def set(attribute, value)
         | 
| 22 | 
            +
                  if ignored? attribute
         | 
| 23 | 
            +
                    ignored_attributes[attribute] = value
         | 
| 24 | 
            +
                  else
         | 
| 25 | 
            +
                    set_attr attribute, value
         | 
| 26 | 
            +
                  end
         | 
| 14 27 | 
             
                end
         | 
| 15 28 |  | 
| 16 | 
            -
                def  | 
| 17 | 
            -
                  @ignored = {}
         | 
| 18 | 
            -
                  @ignored[attribute] = value
         | 
| 29 | 
            +
                def set_attr(attribute, value)
         | 
| 19 30 | 
             
                end
         | 
| 20 31 |  | 
| 21 32 | 
             
                def associate(name, factory, attributes)
         | 
| @@ -83,5 +94,15 @@ module FactoryGirl | |
| 83 94 | 
             
                def result(to_create)
         | 
| 84 95 | 
             
                  raise NotImplementedError, "Strategies must return a result"
         | 
| 85 96 | 
             
                end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                private
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                def ignored?(attribute)
         | 
| 101 | 
            +
                  ignored_attributes.has_key? attribute
         | 
| 102 | 
            +
                end
         | 
| 103 | 
            +
             | 
| 104 | 
            +
                def ignored_attributes
         | 
| 105 | 
            +
                  @ignored_attributes ||= {}
         | 
| 106 | 
            +
                end
         | 
| 86 107 | 
             
              end
         | 
| 87 108 | 
             
            end
         | 
| @@ -5,15 +5,11 @@ module FactoryGirl | |
| 5 5 | 
             
                    @instance = klass.new
         | 
| 6 6 | 
             
                  end
         | 
| 7 7 |  | 
| 8 | 
            -
                  def  | 
| 9 | 
            -
                     | 
| 10 | 
            -
                      @instance.send(attribute)
         | 
| 11 | 
            -
                    else
         | 
| 12 | 
            -
                      super
         | 
| 13 | 
            -
                    end
         | 
| 8 | 
            +
                  def get_attr(attribute)
         | 
| 9 | 
            +
                    @instance.send(attribute)
         | 
| 14 10 | 
             
                  end
         | 
| 15 11 |  | 
| 16 | 
            -
                  def  | 
| 12 | 
            +
                  def set_attr(attribute, value)
         | 
| 17 13 | 
             
                    @instance.send(:"#{attribute}=", value)
         | 
| 18 14 | 
             
                  end
         | 
| 19 15 |  | 
    
        data/lib/factory_girl/version.rb
    CHANGED
    
    
| @@ -23,11 +23,12 @@ describe "a generated attributes hash" do | |
| 23 23 | 
             
                    body { "default body" }
         | 
| 24 24 | 
             
                    summary { title }
         | 
| 25 25 | 
             
                    user
         | 
| 26 | 
            +
                    uploaded_image(nil).ignore
         | 
| 26 27 | 
             
                  end
         | 
| 27 28 | 
             
                end
         | 
| 28 29 | 
             
              end
         | 
| 29 30 |  | 
| 30 | 
            -
              subject { attributes_for(:post, :title => 'overridden title') }
         | 
| 31 | 
            +
              subject { attributes_for(:post, :title => 'overridden title', :uploaded_image => "foo") }
         | 
| 31 32 |  | 
| 32 33 | 
             
              it "assigns an overridden value" do
         | 
| 33 34 | 
             
                subject[:title].should == "overridden title"
         | 
| @@ -44,5 +45,9 @@ describe "a generated attributes hash" do | |
| 44 45 | 
             
              it "doesn't assign associations" do
         | 
| 45 46 | 
             
                subject[:user_id].should be_nil
         | 
| 46 47 | 
             
              end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
              it "doesn't assign ignored attributes" do
         | 
| 50 | 
            +
                subject[:uploaded_image].should be_nil
         | 
| 51 | 
            +
              end
         | 
| 47 52 | 
             
            end
         | 
| 48 53 |  | 
| @@ -17,7 +17,7 @@ describe "callbacks" do | |
| 17 17 | 
             
                  end
         | 
| 18 18 |  | 
| 19 19 | 
             
                  factory :user_with_proxied_callbacks, :parent => :user_with_callbacks do |u|
         | 
| 20 | 
            -
                    u.proxified?( | 
| 20 | 
            +
                    u.proxified?(false).ignore
         | 
| 21 21 | 
             
                    after_create { |user, proxy| user.last_name << ', Proxified' if proxy.proxified? }
         | 
| 22 22 | 
             
                  end
         | 
| 23 23 | 
             
                end
         | 
| @@ -46,7 +46,7 @@ describe "callbacks" do | |
| 46 46 | 
             
              end
         | 
| 47 47 |  | 
| 48 48 | 
             
              it "provides the proxy to callbacks that want it" do
         | 
| 49 | 
            -
                user = FactoryGirl.create(:user_with_proxied_callbacks)
         | 
| 49 | 
            +
                user = FactoryGirl.create(:user_with_proxied_callbacks, :proxified? => true)
         | 
| 50 50 | 
             
                user.first_name.should == 'Buildy'
         | 
| 51 51 | 
             
                user.last_name.should == 'Createy, Proxified'
         | 
| 52 52 | 
             
              end
         | 
| @@ -53,6 +53,7 @@ describe FactoryGirl::Factory do | |
| 53 53 | 
             
                  stub(@attribute).add_to
         | 
| 54 54 | 
             
                  stub(@proxy).set
         | 
| 55 55 | 
             
                  stub(@proxy).result { 'result' }
         | 
| 56 | 
            +
                  stub(@proxy).ignored_attributes = anything
         | 
| 56 57 | 
             
                  stub(FactoryGirl::Attribute::Static).new { @attribute }
         | 
| 57 58 | 
             
                  stub(FactoryGirl::Proxy::Build).new { @proxy }
         | 
| 58 59 |  | 
| @@ -69,6 +70,12 @@ describe FactoryGirl::Factory do | |
| 69 70 | 
             
                  @factory.run(FactoryGirl::Proxy::Build, {})
         | 
| 70 71 | 
             
                end
         | 
| 71 72 |  | 
| 73 | 
            +
                it "should add the ignored attributes to the proxy by name when running" do
         | 
| 74 | 
            +
                  stub(@attribute).ignored? { true }
         | 
| 75 | 
            +
                  mock(@proxy).ignored_attributes = { :name => nil }
         | 
| 76 | 
            +
                  @factory.run(FactoryGirl::Proxy::Build, {})
         | 
| 77 | 
            +
                end
         | 
| 78 | 
            +
             | 
| 72 79 | 
             
                it "should return the result from the proxy when running" do
         | 
| 73 80 | 
             
                  mock(@proxy).result(nil) { 'result' }
         | 
| 74 81 | 
             
                  @factory.run(FactoryGirl::Proxy::Build, {}).should == 'result'
         | 
| @@ -79,6 +86,7 @@ describe FactoryGirl::Factory do | |
| 79 86 | 
             
                proxy = 'proxy'
         | 
| 80 87 | 
             
                stub(FactoryGirl::Proxy::Build).new { proxy }
         | 
| 81 88 | 
             
                stub(proxy).result {}
         | 
| 89 | 
            +
                stub(proxy).ignored_attributes = anything
         | 
| 82 90 | 
             
                block = lambda {}
         | 
| 83 91 | 
             
                factory = FactoryGirl::Factory.new(:object)
         | 
| 84 92 | 
             
                factory.to_create(&block)
         | 
| @@ -10,7 +10,7 @@ describe FactoryGirl::Proxy do | |
| 10 10 | 
             
              end
         | 
| 11 11 |  | 
| 12 12 | 
             
              it "should return nil when asked for an attribute" do
         | 
| 13 | 
            -
                @proxy. | 
| 13 | 
            +
                @proxy.get_attr(:name).should be_nil
         | 
| 14 14 | 
             
              end
         | 
| 15 15 |  | 
| 16 16 | 
             
              it "should call get for a missing method" do
         | 
| @@ -18,13 +18,31 @@ describe FactoryGirl::Proxy do | |
| 18 18 | 
             
                @proxy.name.should == "it's a name"
         | 
| 19 19 | 
             
              end
         | 
| 20 20 |  | 
| 21 | 
            -
               | 
| 22 | 
            -
                 | 
| 23 | 
            -
             | 
| 21 | 
            +
              describe "with ignored attributes" do
         | 
| 22 | 
            +
                before do
         | 
| 23 | 
            +
                  @proxy.ignored_attributes = {
         | 
| 24 | 
            +
                    :foo => "bar",
         | 
| 25 | 
            +
                    :baz => 8,
         | 
| 26 | 
            +
                    :nil_attr => nil
         | 
| 27 | 
            +
                  }
         | 
| 28 | 
            +
                  dont_allow(@proxy).get_attr
         | 
| 29 | 
            +
                  dont_allow(@proxy).set_attr
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                it "#set stores the value rather than calling #set_attr" do
         | 
| 33 | 
            +
                  @proxy.set(:baz, 5)
         | 
| 34 | 
            +
                  @proxy.get(:baz).should == 5
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                it "#get returns the stored value of the ignored attribute without calling #get_attr" do
         | 
| 38 | 
            +
                  @proxy.get(:foo).should == "bar"
         | 
| 39 | 
            +
                end
         | 
| 24 40 |  | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 41 | 
            +
                it "recognizes nil as a valid value for an ignored attribute" do
         | 
| 42 | 
            +
                  @proxy.get(:nil_attr).should be_nil
         | 
| 43 | 
            +
                  @proxy.set(:baz, nil)
         | 
| 44 | 
            +
                  @proxy.get(:baz).should be_nil
         | 
| 45 | 
            +
                end
         | 
| 28 46 | 
             
              end
         | 
| 29 47 |  | 
| 30 48 | 
             
              it "should do nothing when asked to associate with another factory" do
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,15 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: factory_girl_kibiz0r
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 5 | 
            -
              prerelease:  | 
| 4 | 
            +
              hash: 62196453
         | 
| 5 | 
            +
              prerelease: 6
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 2
         | 
| 8 8 | 
             
              - 0
         | 
| 9 9 | 
             
              - 0
         | 
| 10 | 
            -
              -  | 
| 11 | 
            -
               | 
| 10 | 
            +
              - beta
         | 
| 11 | 
            +
              - 3
         | 
| 12 | 
            +
              version: 2.0.0.beta3
         | 
| 12 13 | 
             
            platform: ruby
         | 
| 13 14 | 
             
            authors: 
         | 
| 14 15 | 
             
            - Joe Ferris
         | 
| @@ -16,8 +17,7 @@ autorequire: | |
| 16 17 | 
             
            bindir: bin
         | 
| 17 18 | 
             
            cert_chain: []
         | 
| 18 19 |  | 
| 19 | 
            -
            date: 2011-05- | 
| 20 | 
            -
            default_executable: 
         | 
| 20 | 
            +
            date: 2011-05-26 00:00:00 Z
         | 
| 21 21 | 
             
            dependencies: 
         | 
| 22 22 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 23 23 | 
             
              name: rcov
         | 
| @@ -85,12 +85,13 @@ dependencies: | |
| 85 85 | 
             
                requirements: 
         | 
| 86 86 | 
             
                - - ~>
         | 
| 87 87 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 88 | 
            -
                    hash:  | 
| 88 | 
            +
                    hash: 62196421
         | 
| 89 89 | 
             
                    segments: 
         | 
| 90 90 | 
             
                    - 3
         | 
| 91 91 | 
             
                    - 0
         | 
| 92 92 | 
             
                    - 0
         | 
| 93 | 
            -
                    -  | 
| 93 | 
            +
                    - beta
         | 
| 94 | 
            +
                    - 3
         | 
| 94 95 | 
             
                    version: 3.0.0.beta3
         | 
| 95 96 | 
             
              type: :development
         | 
| 96 97 | 
             
              version_requirements: *id005
         | 
| @@ -148,7 +149,6 @@ files: | |
| 148 149 | 
             
            - lib/factory_girl/attribute/callback.rb
         | 
| 149 150 | 
             
            - lib/factory_girl/attribute/dynamic.rb
         | 
| 150 151 | 
             
            - lib/factory_girl/attribute/implicit.rb
         | 
| 151 | 
            -
            - lib/factory_girl/attribute/list.rb
         | 
| 152 152 | 
             
            - lib/factory_girl/attribute/sequence.rb
         | 
| 153 153 | 
             
            - lib/factory_girl/attribute/static.rb
         | 
| 154 154 | 
             
            - lib/factory_girl/attribute.rb
         | 
| @@ -216,7 +216,6 @@ files: | |
| 216 216 | 
             
            - features/step_definitions/database_steps.rb
         | 
| 217 217 | 
             
            - features/support/env.rb
         | 
| 218 218 | 
             
            - features/support/factories.rb
         | 
| 219 | 
            -
            has_rdoc: true
         | 
| 220 219 | 
             
            homepage: http://thoughtbot.com/projects/factory_girl
         | 
| 221 220 | 
             
            licenses: []
         | 
| 222 221 |  | 
| @@ -248,10 +247,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 248 247 | 
             
            requirements: []
         | 
| 249 248 |  | 
| 250 249 | 
             
            rubyforge_project: 
         | 
| 251 | 
            -
            rubygems_version: 1. | 
| 250 | 
            +
            rubygems_version: 1.8.4
         | 
| 252 251 | 
             
            signing_key: 
         | 
| 253 252 | 
             
            specification_version: 3
         | 
| 254 | 
            -
            summary: factory_girl provides a framework and DSL for defining and using model instance factories. | 
| 253 | 
            +
            summary: factory_girl provides a framework and DSL for defining and using model instance factories.
         | 
| 255 254 | 
             
            test_files: 
         | 
| 256 255 | 
             
            - spec/acceptance/attribute_aliases_spec.rb
         | 
| 257 256 | 
             
            - spec/acceptance/attributes_for_spec.rb
         |