factory_girl 4.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Appraisals +7 -3
- data/GETTING_STARTED.md +28 -4
- data/Gemfile.lock +28 -32
- data/LICENSE +1 -1
- data/NEWS +11 -0
- data/README.md +2 -2
- data/factory_girl.gemspec +5 -5
- data/features/step_definitions/database_steps.rb +1 -1
- data/gemfiles/3.0.gemfile +1 -1
- data/gemfiles/3.0.gemfile.lock +40 -48
- data/gemfiles/3.1.gemfile +1 -1
- data/gemfiles/3.1.gemfile.lock +41 -49
- data/gemfiles/3.2.gemfile +1 -1
- data/gemfiles/3.2.gemfile.lock +42 -50
- data/gemfiles/4.0.gemfile +7 -0
- data/gemfiles/4.0.gemfile.lock +95 -0
- data/lib/factory_girl/definition_hierarchy.rb +9 -0
- data/lib/factory_girl/definition_proxy.rb +1 -1
- data/lib/factory_girl/evaluator.rb +11 -2
- data/lib/factory_girl/factory.rb +1 -3
- data/lib/factory_girl/sequence.rb +17 -3
- data/lib/factory_girl/strategy/stub.rb +2 -2
- data/lib/factory_girl/strategy_syntax_method_registrar.rb +2 -2
- data/lib/factory_girl/version.rb +1 -1
- data/spec/acceptance/activesupport_instrumentation_spec.rb +3 -3
- data/spec/acceptance/aliases_spec.rb +1 -1
- data/spec/acceptance/attribute_aliases_spec.rb +3 -3
- data/spec/acceptance/attribute_existing_on_object_spec.rb +8 -8
- data/spec/acceptance/attributes_for_spec.rb +11 -9
- data/spec/acceptance/attributes_from_instance_spec.rb +7 -7
- data/spec/acceptance/attributes_ordered_spec.rb +6 -6
- data/spec/acceptance/build_list_spec.rb +20 -5
- data/spec/acceptance/build_spec.rb +10 -13
- data/spec/acceptance/build_stubbed_spec.rb +38 -13
- data/spec/acceptance/callbacks_spec.rb +19 -19
- data/spec/acceptance/create_list_spec.rb +22 -7
- data/spec/acceptance/create_spec.rb +10 -11
- data/spec/acceptance/define_child_before_parent_spec.rb +1 -1
- data/spec/acceptance/definition_spec.rb +2 -7
- data/spec/acceptance/definition_without_block_spec.rb +1 -1
- data/spec/acceptance/global_initialize_with_spec.rb +10 -10
- data/spec/acceptance/global_to_create_spec.rb +18 -18
- data/spec/acceptance/initialize_with_spec.rb +13 -13
- data/spec/acceptance/keyed_by_class_spec.rb +2 -2
- data/spec/acceptance/modify_factories_spec.rb +21 -21
- data/spec/acceptance/modify_inherited_spec.rb +7 -7
- data/spec/acceptance/nested_attributes_spec.rb +2 -2
- data/spec/acceptance/overrides_spec.rb +1 -1
- data/spec/acceptance/parent_spec.rb +9 -9
- data/spec/acceptance/register_strategies_spec.rb +9 -9
- data/spec/acceptance/sequence_context_spec.rb +52 -0
- data/spec/acceptance/sequence_spec.rb +12 -12
- data/spec/acceptance/skip_create_spec.rb +1 -1
- data/spec/acceptance/stub_spec.rb +4 -4
- data/spec/acceptance/syntax_methods_within_dynamic_attributes_spec.rb +5 -5
- data/spec/acceptance/traits_spec.rb +84 -84
- data/spec/acceptance/transient_attributes_spec.rb +13 -13
- data/spec/factory_girl/attribute/association_spec.rb +4 -4
- data/spec/factory_girl/attribute/dynamic_spec.rb +5 -5
- data/spec/factory_girl/attribute/sequence_spec.rb +2 -2
- data/spec/factory_girl/attribute/static_spec.rb +3 -3
- data/spec/factory_girl/attribute_list_spec.rb +12 -12
- data/spec/factory_girl/attribute_spec.rb +1 -1
- data/spec/factory_girl/callback_spec.rb +5 -5
- data/spec/factory_girl/declaration/implicit_spec.rb +1 -1
- data/spec/factory_girl/declaration_list_spec.rb +11 -11
- data/spec/factory_girl/definition_proxy_spec.rb +21 -21
- data/spec/factory_girl/definition_spec.rb +6 -6
- data/spec/factory_girl/disallows_duplicates_registry_spec.rb +1 -1
- data/spec/factory_girl/evaluator_class_definer_spec.rb +54 -21
- data/spec/factory_girl/factory_spec.rb +34 -34
- data/spec/factory_girl/null_factory_spec.rb +1 -1
- data/spec/factory_girl/null_object_spec.rb +3 -3
- data/spec/factory_girl/registry_spec.rb +12 -12
- data/spec/factory_girl/sequence_spec.rb +34 -17
- data/spec/factory_girl/strategy/attributes_for_spec.rb +1 -1
- data/spec/factory_girl/strategy/create_spec.rb +1 -1
- data/spec/factory_girl/strategy/stub_spec.rb +4 -4
- data/spec/factory_girl/strategy_calculator_spec.rb +3 -3
- data/spec/factory_girl_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -1
- data/spec/support/macros/define_constant.rb +2 -2
- data/spec/support/shared_examples/strategy.rb +7 -7
- metadata +17 -11
@@ -5,64 +5,64 @@ describe FactoryGirl::Sequence do
|
|
5
5
|
let(:name) { :test }
|
6
6
|
subject { FactoryGirl::Sequence.new(name) {|n| "=#{n}" } }
|
7
7
|
|
8
|
-
its(:name) { should
|
9
|
-
its(:names) { should
|
10
|
-
its(:next) { should
|
8
|
+
its(:name) { should eq name }
|
9
|
+
its(:names) { should eq [name] }
|
10
|
+
its(:next) { should eq "=1" }
|
11
11
|
|
12
12
|
describe "when incrementing" do
|
13
13
|
before { subject.next }
|
14
|
-
its(:next) { should
|
14
|
+
its(:next) { should eq "=2" }
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "a custom sequence" do
|
19
19
|
subject { FactoryGirl::Sequence.new(:name, "A") {|n| "=#{n}" } }
|
20
|
-
its(:next) { should
|
20
|
+
its(:next) { should eq "=A" }
|
21
21
|
|
22
22
|
describe "when incrementing" do
|
23
23
|
before { subject.next }
|
24
|
-
its(:next) { should
|
24
|
+
its(:next) { should eq "=B" }
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
describe "a sequence with aliases using default value" do
|
29
29
|
subject { FactoryGirl::Sequence.new(:test, aliases: [:alias, :other]) { |n| "=#{n}" } }
|
30
|
-
its(:next) { should
|
31
|
-
its(:names) { should
|
30
|
+
its(:next) { should eq "=1" }
|
31
|
+
its(:names) { should eq [:test, :alias, :other] }
|
32
32
|
|
33
33
|
describe "when incrementing" do
|
34
34
|
before { subject.next }
|
35
|
-
its(:next) { should
|
35
|
+
its(:next) { should eq "=2" }
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
describe "a sequence with custom value and aliases" do
|
40
40
|
subject { FactoryGirl::Sequence.new(:test, 3, aliases: [:alias, :other]) { |n| "=#{n}" } }
|
41
|
-
its(:next) { should
|
41
|
+
its(:next) { should eq "=3" }
|
42
42
|
|
43
43
|
describe "when incrementing" do
|
44
44
|
before { subject.next }
|
45
|
-
its(:next) { should
|
45
|
+
its(:next) { should eq "=4" }
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
describe "a basic sequence without a block" do
|
50
50
|
subject { FactoryGirl::Sequence.new(:name) }
|
51
|
-
its(:next) { should
|
51
|
+
its(:next) { should eq 1 }
|
52
52
|
|
53
53
|
describe "when incrementing" do
|
54
54
|
before { subject.next }
|
55
|
-
its(:next) { should
|
55
|
+
its(:next) { should eq 2 }
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
describe "a custom sequence without a block" do
|
60
60
|
subject { FactoryGirl::Sequence.new(:name, "A") }
|
61
|
-
its(:next) { should
|
61
|
+
its(:next) { should eq "A" }
|
62
62
|
|
63
63
|
describe "when incrementing" do
|
64
64
|
before { subject.next }
|
65
|
-
its(:next) { should
|
65
|
+
its(:next) { should eq "B" }
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -70,9 +70,26 @@ describe FactoryGirl::Sequence do
|
|
70
70
|
subject { FactoryGirl::Sequence.new(:name, %w[foo bar].to_enum) {|n| "=#{n}" } }
|
71
71
|
|
72
72
|
it "navigates to the next items until no items remain" do
|
73
|
-
subject.next.
|
74
|
-
subject.next.
|
73
|
+
expect(subject.next).to eq "=foo"
|
74
|
+
expect(subject.next).to eq "=bar"
|
75
75
|
expect { subject.next }.to raise_error(StopIteration)
|
76
76
|
end
|
77
77
|
end
|
78
|
+
|
79
|
+
describe "a custom sequence and scope" do
|
80
|
+
subject { FactoryGirl::Sequence.new(:name, 'A') {|n| "=#{n}#{foo}" } }
|
81
|
+
let(:scope) { stub('scope', foo: 'attribute') }
|
82
|
+
|
83
|
+
it 'increments within the correct scope' do
|
84
|
+
expect(subject.next(scope)).to eq '=Aattribute'
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'when incrementing' do
|
88
|
+
before { subject.next(scope) }
|
89
|
+
|
90
|
+
it 'increments within the correct scope' do
|
91
|
+
expect(subject.next(scope)).to eq '=Battribute'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
78
95
|
end
|
@@ -7,7 +7,7 @@ describe FactoryGirl::Strategy::AttributesFor do
|
|
7
7
|
it_should_behave_like "strategy without association support"
|
8
8
|
|
9
9
|
it "returns the hash from the evaluation" do
|
10
|
-
subject.result(evaluation).
|
10
|
+
expect(subject.result(evaluation)).to eq result
|
11
11
|
end
|
12
12
|
|
13
13
|
it "does not run the to_create block" do
|
@@ -15,16 +15,16 @@ describe FactoryGirl::Strategy::Stub do
|
|
15
15
|
|
16
16
|
let(:evaluation) { stub("evaluation", object: result_instance, notify: true) }
|
17
17
|
|
18
|
-
it { subject.result(evaluation).
|
19
|
-
it { subject.result(evaluation).
|
18
|
+
it { expect(subject.result(evaluation)).not_to be_new_record }
|
19
|
+
it { expect(subject.result(evaluation)).to be_persisted }
|
20
20
|
|
21
21
|
it "assigns created_at" do
|
22
22
|
created_at = subject.result(evaluation).created_at
|
23
|
-
created_at.
|
23
|
+
expect(created_at).to eq Time.now
|
24
24
|
|
25
25
|
Timecop.travel(150000)
|
26
26
|
|
27
|
-
subject.result(evaluation).created_at.
|
27
|
+
expect(subject.result(evaluation).created_at).to eq created_at
|
28
28
|
end
|
29
29
|
|
30
30
|
[:save, :destroy, :connection, :reload, :update_attribute].each do |database_method|
|
@@ -9,7 +9,7 @@ describe FactoryGirl::StrategyCalculator do
|
|
9
9
|
subject { FactoryGirl::StrategyCalculator.new(strategy).strategy }
|
10
10
|
|
11
11
|
it "returns the class passed" do
|
12
|
-
subject.
|
12
|
+
expect(subject).to eq strategy
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -19,11 +19,11 @@ describe FactoryGirl::StrategyCalculator do
|
|
19
19
|
|
20
20
|
it "finds the strategy by name" do
|
21
21
|
subject
|
22
|
-
FactoryGirl.
|
22
|
+
expect(FactoryGirl).to have_received(:strategy_by_name).with(:build)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "returns the strategy found" do
|
26
|
-
subject.
|
26
|
+
expect(subject).to eq strategy
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
data/spec/factory_girl_spec.rb
CHANGED
@@ -7,16 +7,16 @@ describe FactoryGirl do
|
|
7
7
|
|
8
8
|
it "finds a registered factory" do
|
9
9
|
FactoryGirl.register_factory(factory)
|
10
|
-
FactoryGirl.factory_by_name(factory.name).
|
10
|
+
expect(FactoryGirl.factory_by_name(factory.name)).to eq factory
|
11
11
|
end
|
12
12
|
|
13
13
|
it "finds a registered sequence" do
|
14
14
|
FactoryGirl.register_sequence(sequence)
|
15
|
-
FactoryGirl.sequence_by_name(sequence.name).
|
15
|
+
expect(FactoryGirl.sequence_by_name(sequence.name)).to eq sequence
|
16
16
|
end
|
17
17
|
|
18
18
|
it "finds a registered trait" do
|
19
19
|
FactoryGirl.register_trait(trait)
|
20
|
-
FactoryGirl.trait_by_name(trait.name).
|
20
|
+
expect(FactoryGirl.trait_by_name(trait.name)).to eq trait
|
21
21
|
end
|
22
22
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -13,8 +13,8 @@ module DefineConstantMacros
|
|
13
13
|
def define_model(name, columns = {}, &block)
|
14
14
|
model = define_class(name, ActiveRecord::Base, &block)
|
15
15
|
create_table(model.table_name) do |table|
|
16
|
-
columns.each do |
|
17
|
-
table.column
|
16
|
+
columns.each do |column_name, type|
|
17
|
+
table.column column_name, type
|
18
18
|
end
|
19
19
|
end
|
20
20
|
model
|
@@ -14,7 +14,7 @@ shared_examples_for "strategy without association support" do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "returns nil when accessing an association" do
|
17
|
-
association_named(:user, {}).
|
17
|
+
expect(association_named(:user, {})).to be_nil
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -34,12 +34,12 @@ shared_examples_for "strategy with association support" do |factory_girl_strateg
|
|
34
34
|
|
35
35
|
it "runs the factory with the correct overrides" do
|
36
36
|
association_named(:author, factory_girl_strategy_name, great: "value")
|
37
|
-
factory.
|
37
|
+
expect(factory).to have_received(:run).with(factory_girl_strategy_name, great: "value")
|
38
38
|
end
|
39
39
|
|
40
40
|
it "finds the factory with the correct factory name" do
|
41
41
|
association_named(:author, factory_girl_strategy_name, great: "value")
|
42
|
-
FactoryGirl.
|
42
|
+
expect(FactoryGirl).to have_received(:factory_by_name).with(:author)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -59,12 +59,12 @@ shared_examples_for "strategy with strategy: :build" do |factory_girl_strategy_n
|
|
59
59
|
|
60
60
|
it "runs the factory with the correct overrides" do
|
61
61
|
association_named(:author, strategy: :build, great: "value")
|
62
|
-
factory.
|
62
|
+
expect(factory).to have_received(:run).with(factory_girl_strategy_name, { great: "value" })
|
63
63
|
end
|
64
64
|
|
65
65
|
it "finds the factory with the correct factory name" do
|
66
66
|
association_named(:author, strategy: :build, great: "value")
|
67
|
-
FactoryGirl.
|
67
|
+
expect(FactoryGirl).to have_received(:factory_by_name).with(:author)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -80,11 +80,11 @@ shared_examples_for "strategy with callbacks" do |*callback_names|
|
|
80
80
|
it "runs the callbacks #{callback_names} with the evaluation's object" do
|
81
81
|
subject.result(evaluation)
|
82
82
|
callback_names.each do |name|
|
83
|
-
evaluation.
|
83
|
+
expect(evaluation).to have_received(:notify).with(name, evaluation.object)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
87
|
it "returns the object from the evaluation" do
|
88
|
-
subject.result(evaluation).
|
88
|
+
expect(subject.result(evaluation)).to eq evaluation.object
|
89
89
|
end
|
90
90
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_girl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-01-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -35,7 +35,7 @@ dependencies:
|
|
35
35
|
requirements:
|
36
36
|
- - ~>
|
37
37
|
- !ruby/object:Gem::Version
|
38
|
-
version:
|
38
|
+
version: 2.12.0
|
39
39
|
type: :development
|
40
40
|
prerelease: false
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
requirements:
|
44
44
|
- - ~>
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: 2.12.0
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: cucumber
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -51,7 +51,7 @@ dependencies:
|
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.2.1
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
57
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -59,7 +59,7 @@ dependencies:
|
|
59
59
|
requirements:
|
60
60
|
- - ~>
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
62
|
+
version: 1.2.1
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
64
|
name: timecop
|
65
65
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,7 +115,7 @@ dependencies:
|
|
115
115
|
requirements:
|
116
116
|
- - ! '>='
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
118
|
+
version: 0.12.8
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
requirements:
|
124
124
|
- - ! '>='
|
125
125
|
- !ruby/object:Gem::Version
|
126
|
-
version:
|
126
|
+
version: 0.12.8
|
127
127
|
- !ruby/object:Gem::Dependency
|
128
128
|
name: bourne
|
129
129
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,7 +147,7 @@ dependencies:
|
|
147
147
|
requirements:
|
148
148
|
- - ~>
|
149
149
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
150
|
+
version: 0.5.1
|
151
151
|
type: :development
|
152
152
|
prerelease: false
|
153
153
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -155,9 +155,9 @@ dependencies:
|
|
155
155
|
requirements:
|
156
156
|
- - ~>
|
157
157
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
158
|
+
version: 0.5.1
|
159
159
|
- !ruby/object:Gem::Dependency
|
160
|
-
name: sqlite3
|
160
|
+
name: sqlite3
|
161
161
|
requirement: !ruby/object:Gem::Requirement
|
162
162
|
none: false
|
163
163
|
requirements:
|
@@ -226,6 +226,8 @@ files:
|
|
226
226
|
- gemfiles/3.1.gemfile.lock
|
227
227
|
- gemfiles/3.2.gemfile
|
228
228
|
- gemfiles/3.2.gemfile.lock
|
229
|
+
- gemfiles/4.0.gemfile
|
230
|
+
- gemfiles/4.0.gemfile.lock
|
229
231
|
- lib/factory_girl.rb
|
230
232
|
- lib/factory_girl/aliases.rb
|
231
233
|
- lib/factory_girl/attribute.rb
|
@@ -304,6 +306,7 @@ files:
|
|
304
306
|
- spec/acceptance/overrides_spec.rb
|
305
307
|
- spec/acceptance/parent_spec.rb
|
306
308
|
- spec/acceptance/register_strategies_spec.rb
|
309
|
+
- spec/acceptance/sequence_context_spec.rb
|
307
310
|
- spec/acceptance/sequence_spec.rb
|
308
311
|
- spec/acceptance/skip_create_spec.rb
|
309
312
|
- spec/acceptance/stub_spec.rb
|
@@ -381,6 +384,8 @@ test_files:
|
|
381
384
|
- gemfiles/3.1.gemfile.lock
|
382
385
|
- gemfiles/3.2.gemfile
|
383
386
|
- gemfiles/3.2.gemfile.lock
|
387
|
+
- gemfiles/4.0.gemfile
|
388
|
+
- gemfiles/4.0.gemfile.lock
|
384
389
|
- spec/acceptance/activesupport_instrumentation_spec.rb
|
385
390
|
- spec/acceptance/aliases_spec.rb
|
386
391
|
- spec/acceptance/attribute_aliases_spec.rb
|
@@ -407,6 +412,7 @@ test_files:
|
|
407
412
|
- spec/acceptance/overrides_spec.rb
|
408
413
|
- spec/acceptance/parent_spec.rb
|
409
414
|
- spec/acceptance/register_strategies_spec.rb
|
415
|
+
- spec/acceptance/sequence_context_spec.rb
|
410
416
|
- spec/acceptance/sequence_spec.rb
|
411
417
|
- spec/acceptance/skip_create_spec.rb
|
412
418
|
- spec/acceptance/stub_spec.rb
|