Sha256: f21435dfc51188292dda51a6581559318b70cbe62b82ad82b838ab9eccd4468c

Contents?: true

Size: 1.54 KB

Versions: 16

Compression:

Stored size: 1.54 KB

Contents

require 'spec_helper'

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)

    FactoryGirl.define do
      factory :parent_model do
        evaluates_first  { static }
        evaluates_second { evaluates_first }
        evaluates_third  { evaluates_second }

        factory :child_model do
          static 1
        end
      end

      factory :without_parent, class: ParentModel do
        evaluates_first   { static }
        evaluates_second  { evaluates_first }
        evaluates_third   { evaluates_second }
        static 1
      end
    end
  end

  context "factory with a parent" do
    subject { FactoryGirl.build(:child_model) }

    it "assigns attributes in the order they're defined with preference to static attributes" do
      expect(subject[:evaluates_first]).to eq 1
      expect(subject[:evaluates_second]).to eq 1
      expect(subject[:evaluates_third]).to eq 1
    end
  end

  context "factory without a parent" do
    subject { FactoryGirl.build(:without_parent) }

    it "assigns attributes in the order they're defined with preference to static attributes without a parent class" do
      expect(subject[:evaluates_first]).to eq 1
      expect(subject[:evaluates_second]).to eq 1
      expect(subject[:evaluates_third]).to eq 1
    end
  end
end

Version data entries

16 entries across 13 versions & 5 rubygems

Version Path
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/factory_girl-4.5.0/spec/acceptance/attributes_ordered_spec.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/factory_girl-4.5.0/spec/acceptance/attributes_ordered_spec.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/factory_girl-4.5.0/spec/acceptance/attributes_ordered_spec.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/factory_girl-4.5.0/spec/acceptance/attributes_ordered_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/factory_girl-4.4.0/spec/acceptance/attributes_ordered_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/factory_girl-4.4.0/spec/acceptance/attributes_ordered_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/factory_girl-4.4.0/spec/acceptance/attributes_ordered_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/factory_girl-4.4.0/spec/acceptance/attributes_ordered_spec.rb
factory_girl-4.5.0 spec/acceptance/attributes_ordered_spec.rb
factory_girl-4.4.0 spec/acceptance/attributes_ordered_spec.rb
factory_girl-4.3.0 spec/acceptance/attributes_ordered_spec.rb
challah-1.0.0 vendor/bundle/gems/factory_girl-4.2.0/spec/acceptance/attributes_ordered_spec.rb
challah-1.0.0.beta3 vendor/bundle/gems/factory_girl-4.2.0/spec/acceptance/attributes_ordered_spec.rb
challah-1.0.0.beta2 vendor/bundle/gems/factory_girl-4.2.0/spec/acceptance/attributes_ordered_spec.rb
challah-1.0.0.beta vendor/bundle/gems/factory_girl-4.2.0/spec/acceptance/attributes_ordered_spec.rb
factory_girl-4.2.0 spec/acceptance/attributes_ordered_spec.rb