factory_girl 3.2.0 → 3.3.0
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/Appraisals +3 -3
- data/GETTING_STARTED.md +74 -15
- data/Gemfile.lock +38 -44
- data/NEWS +12 -0
- data/gemfiles/3.0.gemfile +1 -1
- data/gemfiles/3.0.gemfile.lock +23 -24
- data/gemfiles/3.1.gemfile +1 -1
- data/gemfiles/3.1.gemfile.lock +19 -19
- data/gemfiles/3.2.gemfile +1 -1
- data/gemfiles/3.2.gemfile.lock +10 -10
- data/lib/factory_girl.rb +39 -37
- data/lib/factory_girl/aliases.rb +3 -4
- data/lib/factory_girl/attribute.rb +33 -11
- data/lib/factory_girl/attribute/association.rb +3 -2
- data/lib/factory_girl/attribute/dynamic.rb +3 -2
- data/lib/factory_girl/attribute/sequence.rb +1 -2
- data/lib/factory_girl/attribute/static.rb +3 -2
- data/lib/factory_girl/attribute_assigner.rb +6 -5
- data/lib/factory_girl/attribute_list.rb +16 -3
- data/lib/factory_girl/callback.rb +7 -3
- data/lib/factory_girl/callbacks_observer.rb +1 -0
- data/lib/factory_girl/configuration.rb +24 -0
- data/lib/factory_girl/declaration.rb +5 -4
- data/lib/factory_girl/declaration/association.rb +1 -0
- data/lib/factory_girl/declaration/dynamic.rb +1 -0
- data/lib/factory_girl/declaration/implicit.rb +1 -0
- data/lib/factory_girl/declaration/static.rb +1 -0
- data/lib/factory_girl/declaration_list.rb +1 -0
- data/lib/factory_girl/definition.rb +22 -3
- data/lib/factory_girl/definition_list.rb +31 -0
- data/lib/factory_girl/definition_proxy.rb +19 -4
- data/lib/factory_girl/evaluation.rb +3 -3
- data/lib/factory_girl/evaluator.rb +24 -14
- data/lib/factory_girl/evaluator_class_definer.rb +2 -13
- data/lib/factory_girl/factory.rb +22 -24
- data/lib/factory_girl/factory_runner.rb +6 -3
- data/lib/factory_girl/find_definitions.rb +2 -2
- data/lib/factory_girl/null_factory.rb +3 -1
- data/lib/factory_girl/null_object.rb +1 -0
- data/lib/factory_girl/reload.rb +4 -6
- data/lib/factory_girl/sequence.rb +3 -2
- data/lib/factory_girl/step_definitions.rb +1 -0
- data/lib/factory_girl/strategy/attributes_for.rb +1 -1
- data/lib/factory_girl/strategy/stub.rb +6 -6
- data/lib/factory_girl/strategy_calculator.rb +1 -0
- data/lib/factory_girl/strategy_syntax_method_registrar.rb +37 -0
- data/lib/factory_girl/syntax.rb +5 -4
- data/lib/factory_girl/syntax/blueprint.rb +5 -8
- data/lib/factory_girl/syntax/default.rb +18 -6
- data/lib/factory_girl/syntax/generate.rb +10 -13
- data/lib/factory_girl/syntax/make.rb +8 -11
- data/lib/factory_girl/syntax/methods.rb +76 -36
- data/lib/factory_girl/syntax/sham.rb +3 -2
- data/lib/factory_girl/syntax/vintage.rb +9 -9
- data/lib/factory_girl/syntax_runner.rb +1 -0
- data/lib/factory_girl/trait.rb +5 -4
- data/lib/factory_girl/version.rb +1 -2
- data/spec/acceptance/activesupport_instrumentation_spec.rb +15 -2
- data/spec/acceptance/callbacks_spec.rb +113 -9
- data/spec/acceptance/create_list_spec.rb +1 -1
- data/spec/acceptance/global_initialize_with_spec.rb +82 -0
- data/spec/acceptance/global_to_create_spec.rb +122 -0
- data/spec/acceptance/modify_factories_spec.rb +2 -2
- data/spec/acceptance/parent_spec.rb +1 -1
- data/spec/acceptance/register_strategies_spec.rb +8 -0
- data/spec/acceptance/syntax/vintage_spec.rb +8 -8
- data/spec/acceptance/traits_spec.rb +145 -3
- data/spec/acceptance/transient_attributes_spec.rb +1 -1
- data/spec/factory_girl/attribute_list_spec.rb +66 -1
- data/spec/factory_girl/attribute_spec.rb +1 -1
- data/spec/factory_girl/definition_proxy_spec.rb +6 -6
- data/spec/factory_girl/definition_spec.rb +22 -16
- data/spec/factory_girl/factory_spec.rb +6 -4
- data/spec/factory_girl/strategy/build_spec.rb +2 -2
- data/spec/factory_girl/strategy/create_spec.rb +1 -1
- data/spec/factory_girl/strategy/stub_spec.rb +2 -2
- data/spec/factory_girl/strategy_calculator_spec.rb +20 -14
- data/spec/support/shared_examples/strategy.rb +8 -9
- metadata +94 -29
- data/gemfiles/2.3.gemfile +0 -7
@@ -12,7 +12,7 @@ describe "modifying factories" do
|
|
12
12
|
factory :user do
|
13
13
|
email
|
14
14
|
|
15
|
-
|
15
|
+
after(:create) do |user|
|
16
16
|
user.login = user.name.upcase if user.name
|
17
17
|
end
|
18
18
|
|
@@ -58,7 +58,7 @@ describe "modifying factories" do
|
|
58
58
|
FactoryGirl.modify do
|
59
59
|
factory :user do
|
60
60
|
name "Great User"
|
61
|
-
|
61
|
+
after(:create) do |user|
|
62
62
|
user.name = user.name.downcase
|
63
63
|
user.login = nil
|
64
64
|
end
|
@@ -41,6 +41,14 @@ describe "register custom strategies" do
|
|
41
41
|
FactoryGirl.build(:named_object).name.should == "Great"
|
42
42
|
FactoryGirl.insert(:named_object).name.should == "Custom strategy"
|
43
43
|
end
|
44
|
+
|
45
|
+
it "allows using the *_list method to build a list using a custom strategy" do
|
46
|
+
FactoryGirl.register_strategy(:insert, custom_strategy)
|
47
|
+
|
48
|
+
inserted_items = FactoryGirl.insert_list(:named_object, 2)
|
49
|
+
inserted_items.length.should == 2
|
50
|
+
inserted_items.map(&:name).should == ["Custom strategy", "Custom strategy"]
|
51
|
+
end
|
44
52
|
end
|
45
53
|
|
46
54
|
describe "including FactoryGirl::Syntax::Methods when custom strategies have been declared" do
|
@@ -89,28 +89,28 @@ describe "after defining a factory" do
|
|
89
89
|
FactoryGirl.register_factory(@factory)
|
90
90
|
end
|
91
91
|
|
92
|
-
it "uses
|
92
|
+
it "uses the attributes_for strategy for Factory.attributes_for" do
|
93
93
|
@factory.stubs(run: "result")
|
94
94
|
Factory.attributes_for(@name, attr: 'value').should == 'result'
|
95
|
-
@factory.should have_received(:run).with(
|
95
|
+
@factory.should have_received(:run).with(:attributes_for, attr: 'value')
|
96
96
|
end
|
97
97
|
|
98
|
-
it "uses
|
98
|
+
it "uses the build strategy for Factory.build" do
|
99
99
|
@factory.stubs(run: "result")
|
100
100
|
Factory.build(@name, attr: 'value').should == 'result'
|
101
|
-
@factory.should have_received(:run).with(
|
101
|
+
@factory.should have_received(:run).with(:build, attr: 'value')
|
102
102
|
end
|
103
103
|
|
104
|
-
it "uses
|
104
|
+
it "uses the create strategy for Factory.create" do
|
105
105
|
@factory.stubs(run: "result")
|
106
106
|
Factory.create(@name, attr: 'value').should == 'result'
|
107
|
-
@factory.should have_received(:run).with(
|
107
|
+
@factory.should have_received(:run).with(:create, attr: 'value')
|
108
108
|
end
|
109
109
|
|
110
|
-
it "uses
|
110
|
+
it "uses the build_stubbed strategy for Factory.stub" do
|
111
111
|
@factory.stubs(run: "result")
|
112
112
|
Factory.stub(@name, attr: 'value').should == 'result'
|
113
|
-
@factory.should have_received(:run).with(
|
113
|
+
@factory.should have_received(:run).with(:build_stubbed, attr: 'value')
|
114
114
|
end
|
115
115
|
|
116
116
|
[:build, :create, :attributes_for, :stub].each do |method|
|
@@ -187,11 +187,11 @@ describe "traits with callbacks" do
|
|
187
187
|
name "John"
|
188
188
|
|
189
189
|
trait :great do
|
190
|
-
|
190
|
+
after(:create) {|user| user.name.upcase! }
|
191
191
|
end
|
192
192
|
|
193
193
|
trait :awesome do
|
194
|
-
|
194
|
+
after(:create) {|user| user.name = "awesome" }
|
195
195
|
end
|
196
196
|
|
197
197
|
factory :caps_user, traits: [:great]
|
@@ -232,7 +232,7 @@ describe "traits added via strategy" do
|
|
232
232
|
end
|
233
233
|
|
234
234
|
trait :great do
|
235
|
-
|
235
|
+
after(:create) {|user| user.name.upcase! }
|
236
236
|
end
|
237
237
|
end
|
238
238
|
end
|
@@ -419,3 +419,145 @@ describe "making sure the factory is properly compiled the first time we want to
|
|
419
419
|
user.role.should == 'admin'
|
420
420
|
end
|
421
421
|
end
|
422
|
+
|
423
|
+
describe "traits with to_create" do
|
424
|
+
before do
|
425
|
+
define_model("User", name: :string)
|
426
|
+
|
427
|
+
FactoryGirl.define do
|
428
|
+
factory :user do
|
429
|
+
trait :with_to_create do
|
430
|
+
to_create {|instance| instance.name = "to_create" }
|
431
|
+
end
|
432
|
+
|
433
|
+
factory :sub_user do
|
434
|
+
to_create {|instance| instance.name = "sub" }
|
435
|
+
|
436
|
+
factory :child_user
|
437
|
+
end
|
438
|
+
|
439
|
+
factory :sub_user_with_trait do
|
440
|
+
with_to_create
|
441
|
+
|
442
|
+
factory :child_user_with_trait
|
443
|
+
end
|
444
|
+
|
445
|
+
factory :sub_user_with_trait_and_override do
|
446
|
+
with_to_create
|
447
|
+
to_create {|instance| instance.name = "sub with trait and override" }
|
448
|
+
|
449
|
+
factory :child_user_with_trait_and_override
|
450
|
+
end
|
451
|
+
end
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
it "can apply to_create from traits" do
|
456
|
+
FactoryGirl.create(:user, :with_to_create).name.should == "to_create"
|
457
|
+
end
|
458
|
+
|
459
|
+
it "can apply to_create from the definition" do
|
460
|
+
FactoryGirl.create(:sub_user).name.should == "sub"
|
461
|
+
FactoryGirl.create(:child_user).name.should == "sub"
|
462
|
+
end
|
463
|
+
|
464
|
+
it "gives additional traits higher priority than to_create from the definition" do
|
465
|
+
FactoryGirl.create(:sub_user, :with_to_create).name.should == "to_create"
|
466
|
+
FactoryGirl.create(:child_user, :with_to_create).name.should == "to_create"
|
467
|
+
end
|
468
|
+
|
469
|
+
it "gives base traits normal priority" do
|
470
|
+
FactoryGirl.create(:sub_user_with_trait).name.should == "to_create"
|
471
|
+
FactoryGirl.create(:child_user_with_trait).name.should == "to_create"
|
472
|
+
end
|
473
|
+
|
474
|
+
it "gives base traits lower priority than overrides" do
|
475
|
+
FactoryGirl.create(:sub_user_with_trait_and_override).name.should == "sub with trait and override"
|
476
|
+
FactoryGirl.create(:child_user_with_trait_and_override).name.should == "sub with trait and override"
|
477
|
+
end
|
478
|
+
|
479
|
+
it "gives additional traits higher priority than base traits and factory definition" do
|
480
|
+
FactoryGirl.define do
|
481
|
+
trait :overridden do
|
482
|
+
to_create {|instance| instance.name = "completely overridden" }
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
486
|
+
FactoryGirl.create(:sub_user_with_trait_and_override, :overridden).name.should == "completely overridden"
|
487
|
+
FactoryGirl.create(:child_user_with_trait_and_override, :overridden).name.should == "completely overridden"
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
describe "traits with initialize_with" do
|
492
|
+
before do
|
493
|
+
define_class("User") do
|
494
|
+
attr_reader :name
|
495
|
+
|
496
|
+
def initialize(name)
|
497
|
+
@name = name
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
501
|
+
FactoryGirl.define do
|
502
|
+
factory :user do
|
503
|
+
trait :with_initialize_with do
|
504
|
+
initialize_with { new("initialize_with") }
|
505
|
+
end
|
506
|
+
|
507
|
+
factory :sub_user do
|
508
|
+
initialize_with { new("sub") }
|
509
|
+
|
510
|
+
factory :child_user
|
511
|
+
end
|
512
|
+
|
513
|
+
factory :sub_user_with_trait do
|
514
|
+
with_initialize_with
|
515
|
+
|
516
|
+
factory :child_user_with_trait
|
517
|
+
end
|
518
|
+
|
519
|
+
factory :sub_user_with_trait_and_override do
|
520
|
+
with_initialize_with
|
521
|
+
initialize_with { new("sub with trait and override") }
|
522
|
+
|
523
|
+
factory :child_user_with_trait_and_override
|
524
|
+
end
|
525
|
+
end
|
526
|
+
end
|
527
|
+
end
|
528
|
+
|
529
|
+
it "can apply initialize_with from traits" do
|
530
|
+
FactoryGirl.build(:user, :with_initialize_with).name.should == "initialize_with"
|
531
|
+
end
|
532
|
+
|
533
|
+
it "can apply initialize_with from the definition" do
|
534
|
+
FactoryGirl.build(:sub_user).name.should == "sub"
|
535
|
+
FactoryGirl.build(:child_user).name.should == "sub"
|
536
|
+
end
|
537
|
+
|
538
|
+
it "gives additional traits higher priority than initialize_with from the definition" do
|
539
|
+
FactoryGirl.build(:sub_user, :with_initialize_with).name.should == "initialize_with"
|
540
|
+
FactoryGirl.build(:child_user, :with_initialize_with).name.should == "initialize_with"
|
541
|
+
end
|
542
|
+
|
543
|
+
it "gives base traits normal priority" do
|
544
|
+
FactoryGirl.build(:sub_user_with_trait).name.should == "initialize_with"
|
545
|
+
FactoryGirl.build(:child_user_with_trait).name.should == "initialize_with"
|
546
|
+
end
|
547
|
+
|
548
|
+
it "gives base traits lower priority than overrides" do
|
549
|
+
FactoryGirl.build(:sub_user_with_trait_and_override).name.should == "sub with trait and override"
|
550
|
+
FactoryGirl.build(:child_user_with_trait_and_override).name.should == "sub with trait and override"
|
551
|
+
end
|
552
|
+
|
553
|
+
it "gives additional traits higher priority than base traits and factory definition" do
|
554
|
+
FactoryGirl.define do
|
555
|
+
trait :overridden do
|
556
|
+
initialize_with { new("completely overridden") }
|
557
|
+
end
|
558
|
+
end
|
559
|
+
|
560
|
+
FactoryGirl.build(:sub_user_with_trait_and_override, :overridden).name.should == "completely overridden"
|
561
|
+
FactoryGirl.build(:child_user_with_trait_and_override, :overridden).name.should == "completely overridden"
|
562
|
+
end
|
563
|
+
end
|
@@ -17,7 +17,7 @@ describe "transient attributes" do
|
|
17
17
|
name { "#{FactoryGirl.generate(:name)}#{" - Rockstar" if rockstar}" }
|
18
18
|
email { "#{name.downcase}#{four}@example.com" }
|
19
19
|
|
20
|
-
|
20
|
+
after(:create) do |user, evaluator|
|
21
21
|
user.name.upcase! if evaluator.upcased
|
22
22
|
end
|
23
23
|
end
|
@@ -73,6 +73,71 @@ describe FactoryGirl::AttributeList, "#associations" do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it "returns associations" do
|
76
|
-
subject.associations.should == [author_attribute, profile_attribute]
|
76
|
+
subject.associations.to_a.should == [author_attribute, profile_attribute]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe FactoryGirl::AttributeList, "filter based on ignored attributes" do
|
81
|
+
def build_ignored_attribute(name)
|
82
|
+
FactoryGirl::Attribute::Static.new(name, "value", true)
|
83
|
+
end
|
84
|
+
|
85
|
+
def build_non_ignored_attribute(name)
|
86
|
+
FactoryGirl::Attribute::Static.new(name, "value", false)
|
87
|
+
end
|
88
|
+
|
89
|
+
before do
|
90
|
+
subject.define_attribute(build_ignored_attribute(:comments_count))
|
91
|
+
subject.define_attribute(build_ignored_attribute(:posts_count))
|
92
|
+
subject.define_attribute(build_non_ignored_attribute(:email))
|
93
|
+
subject.define_attribute(build_non_ignored_attribute(:first_name))
|
94
|
+
subject.define_attribute(build_non_ignored_attribute(:last_name))
|
95
|
+
end
|
96
|
+
|
97
|
+
it "filters #ignored attributes" do
|
98
|
+
subject.ignored.map(&:name).should == [:comments_count, :posts_count]
|
99
|
+
end
|
100
|
+
|
101
|
+
it "filters #non_ignored attributes" do
|
102
|
+
subject.non_ignored.map(&:name).should == [:email, :first_name, :last_name]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe FactoryGirl::AttributeList, "generating names" do
|
107
|
+
def build_ignored_attribute(name)
|
108
|
+
FactoryGirl::Attribute::Static.new(name, "value", true)
|
109
|
+
end
|
110
|
+
|
111
|
+
def build_non_ignored_attribute(name)
|
112
|
+
FactoryGirl::Attribute::Static.new(name, "value", false)
|
113
|
+
end
|
114
|
+
|
115
|
+
def build_association(name)
|
116
|
+
FactoryGirl::Attribute::Association.new(name, :user, {})
|
117
|
+
end
|
118
|
+
|
119
|
+
before do
|
120
|
+
subject.define_attribute(build_ignored_attribute(:comments_count))
|
121
|
+
subject.define_attribute(build_ignored_attribute(:posts_count))
|
122
|
+
subject.define_attribute(build_non_ignored_attribute(:email))
|
123
|
+
subject.define_attribute(build_non_ignored_attribute(:first_name))
|
124
|
+
subject.define_attribute(build_non_ignored_attribute(:last_name))
|
125
|
+
subject.define_attribute(build_association(:avatar))
|
126
|
+
end
|
127
|
+
|
128
|
+
it "knows all its #names" do
|
129
|
+
subject.names.should == [:comments_count, :posts_count, :email, :first_name, :last_name, :avatar]
|
130
|
+
end
|
131
|
+
|
132
|
+
it "knows all its #names for #ignored attributes" do
|
133
|
+
subject.ignored.names.should == [:comments_count, :posts_count]
|
134
|
+
end
|
135
|
+
|
136
|
+
it "knows all its #names for #non_ignored attributes" do
|
137
|
+
subject.non_ignored.names.should == [:email, :first_name, :last_name, :avatar]
|
138
|
+
end
|
139
|
+
|
140
|
+
it "knows all its #names for #associations" do
|
141
|
+
subject.associations.names.should == [:avatar]
|
77
142
|
end
|
78
143
|
end
|
@@ -8,7 +8,7 @@ describe FactoryGirl::Attribute do
|
|
8
8
|
it { should_not be_association }
|
9
9
|
|
10
10
|
it "raises an error when defining an attribute writer" do
|
11
|
-
error_message = %{factory_girl uses '
|
11
|
+
error_message = %{factory_girl uses 'test value' syntax rather than 'test = value'}
|
12
12
|
expect {
|
13
13
|
FactoryGirl::Attribute.new('test=', false)
|
14
14
|
}.to raise_error(FactoryGirl::AttributeDefinitionError, error_message)
|
@@ -126,18 +126,18 @@ describe FactoryGirl::DefinitionProxy, "adding callbacks" do
|
|
126
126
|
let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
|
127
127
|
let(:callback) { -> { "my awesome callback!" } }
|
128
128
|
|
129
|
-
context "#
|
130
|
-
before { proxy.
|
129
|
+
context "#after(:build)" do
|
130
|
+
before { proxy.after(:build, &callback) }
|
131
131
|
it { should have_callback(:after_build).with_block(callback) }
|
132
132
|
end
|
133
133
|
|
134
|
-
context "#
|
135
|
-
before { proxy.
|
134
|
+
context "#after(:create)" do
|
135
|
+
before { proxy.after(:create, &callback) }
|
136
136
|
it { should have_callback(:after_create).with_block(callback) }
|
137
137
|
end
|
138
138
|
|
139
|
-
context "#
|
140
|
-
before { proxy.
|
139
|
+
context "#after(:stub)" do
|
140
|
+
before { proxy.after(:stub, &callback) }
|
141
141
|
it { should have_callback(:after_stub).with_block(callback) }
|
142
142
|
end
|
143
143
|
end
|
@@ -49,13 +49,7 @@ describe FactoryGirl::Definition, "adding callbacks" do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
describe FactoryGirl::Definition, "#to_create" do
|
52
|
-
its(:to_create) { should
|
53
|
-
|
54
|
-
it "calls save! on the object when run" do
|
55
|
-
instance = stub("model instance", :save! => true)
|
56
|
-
subject.to_create[instance]
|
57
|
-
instance.should have_received(:save!).once
|
58
|
-
end
|
52
|
+
its(:to_create) { should be_nil }
|
59
53
|
|
60
54
|
it "returns the assigned value when given a block" do
|
61
55
|
block = proc { nil }
|
@@ -64,9 +58,11 @@ describe FactoryGirl::Definition, "#to_create" do
|
|
64
58
|
end
|
65
59
|
end
|
66
60
|
|
67
|
-
describe FactoryGirl::Definition, "#
|
61
|
+
describe FactoryGirl::Definition, "#definition_list" do
|
68
62
|
let(:female_trait) { FactoryGirl::Trait.new(:female) }
|
69
63
|
let(:admin_trait) { FactoryGirl::Trait.new(:admin) }
|
64
|
+
let(:female_definition) { female_trait.definition }
|
65
|
+
let(:admin_definition) { admin_trait.definition }
|
70
66
|
|
71
67
|
before do
|
72
68
|
subject.define_trait(female_trait)
|
@@ -75,17 +71,22 @@ describe FactoryGirl::Definition, "#processing_order" do
|
|
75
71
|
|
76
72
|
context "without base traits" do
|
77
73
|
it "returns the definition without any traits" do
|
78
|
-
subject.
|
74
|
+
subject.definition_list.should == [subject]
|
75
|
+
end
|
76
|
+
|
77
|
+
it "finds the correct definitions after appending" do
|
78
|
+
subject.append_traits([:female])
|
79
|
+
subject.definition_list.should == [subject, female_definition]
|
79
80
|
end
|
80
81
|
|
81
|
-
it "finds the correct
|
82
|
+
it "finds the correct definitions after inheriting" do
|
82
83
|
subject.inherit_traits([:female])
|
83
|
-
subject.
|
84
|
+
subject.definition_list.should == [female_definition, subject]
|
84
85
|
end
|
85
86
|
|
86
87
|
it "looks for the trait on FactoryGirl" do
|
87
|
-
subject.
|
88
|
-
subject.
|
88
|
+
subject.append_traits([:female, :admin])
|
89
|
+
subject.definition_list.should == [subject, female_definition, admin_definition]
|
89
90
|
end
|
90
91
|
end
|
91
92
|
|
@@ -93,12 +94,17 @@ describe FactoryGirl::Definition, "#processing_order" do
|
|
93
94
|
subject { FactoryGirl::Definition.new("my definition", [:female]) }
|
94
95
|
|
95
96
|
it "returns the base traits and definition" do
|
96
|
-
subject.
|
97
|
+
subject.definition_list.should == [female_definition, subject]
|
98
|
+
end
|
99
|
+
|
100
|
+
it "finds the correct definitions after appending" do
|
101
|
+
subject.append_traits([:admin])
|
102
|
+
subject.definition_list.should == [female_definition, subject, admin_definition]
|
97
103
|
end
|
98
104
|
|
99
|
-
it "finds the correct
|
105
|
+
it "finds the correct definitions after inheriting" do
|
100
106
|
subject.inherit_traits([:admin])
|
101
|
-
subject.
|
107
|
+
subject.definition_list.should == [female_definition, admin_definition, subject]
|
102
108
|
end
|
103
109
|
end
|
104
110
|
end
|
@@ -37,7 +37,7 @@ describe FactoryGirl::Factory do
|
|
37
37
|
factory.associations.each do |association|
|
38
38
|
association.should be_association
|
39
39
|
end
|
40
|
-
factory.associations.
|
40
|
+
factory.associations.to_a.length.should == 3
|
41
41
|
end
|
42
42
|
|
43
43
|
it "includes associations from the parent factory" do
|
@@ -262,18 +262,20 @@ describe FactoryGirl::Factory, "#with_traits" do
|
|
262
262
|
subject { FactoryGirl::Factory.new(:user) }
|
263
263
|
let(:admin_trait) { FactoryGirl::Trait.new(:admin) }
|
264
264
|
let(:female_trait) { FactoryGirl::Trait.new(:female) }
|
265
|
+
let(:admin_definition) { admin_trait.definition }
|
266
|
+
let(:female_definition) { female_trait.definition }
|
265
267
|
|
266
268
|
before do
|
267
269
|
FactoryGirl.register_trait(admin_trait)
|
268
270
|
FactoryGirl.register_trait(female_trait)
|
269
271
|
end
|
270
272
|
|
271
|
-
it "returns a factory with the correct
|
272
|
-
subject.with_traits([:admin, :female]).
|
273
|
+
it "returns a factory with the correct definitions" do
|
274
|
+
subject.with_traits([:admin, :female]).definition_list[1, 2].should == [admin_definition, female_definition]
|
273
275
|
end
|
274
276
|
|
275
277
|
it "doesn't modify the original factory's processing order" do
|
276
278
|
subject.with_traits([:admin, :female])
|
277
|
-
subject.
|
279
|
+
subject.definition_list.should == [subject.definition]
|
278
280
|
end
|
279
281
|
end
|