factory_girl 4.5.0 → 4.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +25 -5
- data/Appraisals +11 -7
- data/CONTRIBUTING.md +44 -6
- data/GETTING_STARTED.md +175 -59
- data/Gemfile +5 -0
- data/Gemfile.lock +86 -63
- data/LICENSE +1 -1
- data/NEWS +12 -1
- data/README.md +21 -10
- data/Rakefile +1 -3
- data/factory_girl.gemspec +6 -14
- data/gemfiles/3.2.gemfile +4 -1
- data/gemfiles/3.2.gemfile.lock +84 -52
- data/gemfiles/4.0.gemfile +4 -1
- data/gemfiles/4.0.gemfile.lock +75 -49
- data/gemfiles/4.1.gemfile +4 -1
- data/gemfiles/4.1.gemfile.lock +78 -48
- data/gemfiles/4.2.gemfile +10 -0
- data/gemfiles/4.2.gemfile.lock +123 -0
- data/gemfiles/5.0.gemfile +10 -0
- data/gemfiles/5.0.gemfile.lock +126 -0
- data/lib/factory_girl.rb +13 -4
- data/lib/factory_girl/attribute/dynamic.rb +4 -1
- data/lib/factory_girl/attribute_assigner.rb +2 -2
- data/lib/factory_girl/configuration.rb +4 -0
- data/lib/factory_girl/decorator.rb +2 -2
- data/lib/factory_girl/decorator/class_key_hash.rb +2 -1
- data/lib/factory_girl/definition_proxy.rb +2 -2
- data/lib/factory_girl/evaluator.rb +4 -0
- data/lib/factory_girl/factory_runner.rb +7 -1
- data/lib/factory_girl/find_definitions.rb +1 -1
- data/lib/factory_girl/linter.rb +65 -14
- data/lib/factory_girl/strategy/stub.rb +25 -1
- data/lib/factory_girl/strategy_syntax_method_registrar.rb +4 -0
- data/lib/factory_girl/version.rb +1 -1
- metadata +26 -185
- data/features/find_definitions.feature +0 -75
- data/features/step_definitions/database_steps.rb +0 -9
- data/features/step_definitions/factory_girl_steps.rb +0 -36
- data/features/support/env.rb +0 -10
- data/features/support/factories.rb +0 -16
- data/gemfiles/3.1.gemfile +0 -7
- data/gemfiles/3.1.gemfile.lock +0 -91
- data/spec/acceptance/activesupport_instrumentation_spec.rb +0 -62
- data/spec/acceptance/aliases_spec.rb +0 -19
- data/spec/acceptance/attribute_aliases_spec.rb +0 -45
- data/spec/acceptance/attribute_existing_on_object_spec.rb +0 -68
- data/spec/acceptance/attributes_for_spec.rb +0 -97
- data/spec/acceptance/attributes_from_instance_spec.rb +0 -53
- data/spec/acceptance/attributes_ordered_spec.rb +0 -51
- data/spec/acceptance/build_list_spec.rb +0 -56
- data/spec/acceptance/build_spec.rb +0 -86
- data/spec/acceptance/build_stubbed_spec.rb +0 -161
- data/spec/acceptance/callbacks_spec.rb +0 -253
- data/spec/acceptance/create_list_spec.rb +0 -97
- data/spec/acceptance/create_pair_spec.rb +0 -32
- data/spec/acceptance/create_spec.rb +0 -116
- data/spec/acceptance/define_child_before_parent_spec.rb +0 -21
- data/spec/acceptance/defining_methods_inside_a_factory_spec.rb +0 -17
- data/spec/acceptance/definition_camel_string_spec.rb +0 -15
- data/spec/acceptance/definition_spec.rb +0 -21
- data/spec/acceptance/definition_without_block_spec.rb +0 -15
- data/spec/acceptance/global_initialize_with_spec.rb +0 -82
- data/spec/acceptance/global_to_create_spec.rb +0 -122
- data/spec/acceptance/initialize_with_spec.rb +0 -217
- data/spec/acceptance/keyed_by_class_spec.rb +0 -22
- data/spec/acceptance/lint_spec.rb +0 -65
- data/spec/acceptance/modify_factories_spec.rb +0 -184
- data/spec/acceptance/modify_inherited_spec.rb +0 -52
- data/spec/acceptance/nested_attributes_spec.rb +0 -32
- data/spec/acceptance/overrides_spec.rb +0 -61
- data/spec/acceptance/parent_spec.rb +0 -90
- data/spec/acceptance/private_attributes_spec.rb +0 -20
- data/spec/acceptance/register_strategies_spec.rb +0 -136
- data/spec/acceptance/sequence_context_spec.rb +0 -52
- data/spec/acceptance/sequence_spec.rb +0 -61
- data/spec/acceptance/skip_create_spec.rb +0 -19
- data/spec/acceptance/stub_spec.rb +0 -62
- data/spec/acceptance/syntax_methods_within_dynamic_attributes_spec.rb +0 -51
- data/spec/acceptance/traits_spec.rb +0 -727
- data/spec/acceptance/transient_attributes_spec.rb +0 -151
- data/spec/factory_girl/aliases_spec.rb +0 -31
- data/spec/factory_girl/attribute/association_spec.rb +0 -28
- data/spec/factory_girl/attribute/dynamic_spec.rb +0 -52
- data/spec/factory_girl/attribute/sequence_spec.rb +0 -16
- data/spec/factory_girl/attribute/static_spec.rb +0 -19
- data/spec/factory_girl/attribute_list_spec.rb +0 -143
- data/spec/factory_girl/attribute_spec.rb +0 -16
- data/spec/factory_girl/callback_spec.rb +0 -41
- data/spec/factory_girl/declaration/implicit_spec.rb +0 -25
- data/spec/factory_girl/declaration_list_spec.rb +0 -67
- data/spec/factory_girl/definition_proxy_spec.rb +0 -215
- data/spec/factory_girl/definition_spec.rb +0 -64
- data/spec/factory_girl/disallows_duplicates_registry_spec.rb +0 -19
- data/spec/factory_girl/evaluator_class_definer_spec.rb +0 -77
- data/spec/factory_girl/factory_spec.rb +0 -259
- data/spec/factory_girl/find_definitions_spec.rb +0 -110
- data/spec/factory_girl/null_factory_spec.rb +0 -13
- data/spec/factory_girl/null_object_spec.rb +0 -22
- data/spec/factory_girl/registry_spec.rb +0 -68
- data/spec/factory_girl/sequence_spec.rb +0 -95
- data/spec/factory_girl/strategy/attributes_for_spec.rb +0 -18
- data/spec/factory_girl/strategy/build_spec.rb +0 -7
- data/spec/factory_girl/strategy/create_spec.rb +0 -25
- data/spec/factory_girl/strategy/stub_spec.rb +0 -38
- data/spec/factory_girl/strategy_calculator_spec.rb +0 -29
- data/spec/factory_girl_spec.rb +0 -22
- data/spec/spec_helper.rb +0 -26
- data/spec/support/macros/define_constant.rb +0 -86
- data/spec/support/matchers/callback.rb +0 -9
- data/spec/support/matchers/declaration.rb +0 -83
- data/spec/support/matchers/delegate.rb +0 -44
- data/spec/support/matchers/trait.rb +0 -11
- data/spec/support/shared_examples/strategy.rb +0 -90
@@ -1,151 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "transient attributes" do
|
4
|
-
before do
|
5
|
-
define_model("User", name: :string, email: :string)
|
6
|
-
|
7
|
-
FactoryGirl.define do
|
8
|
-
sequence(:name) { |n| "John #{n}" }
|
9
|
-
|
10
|
-
factory :user do
|
11
|
-
transient do
|
12
|
-
four { 2 + 2 }
|
13
|
-
rockstar true
|
14
|
-
upcased false
|
15
|
-
end
|
16
|
-
|
17
|
-
name { "#{FactoryGirl.generate(:name)}#{" - Rockstar" if rockstar}" }
|
18
|
-
email { "#{name.downcase}#{four}@example.com" }
|
19
|
-
|
20
|
-
after(:create) do |user, evaluator|
|
21
|
-
user.name.upcase! if evaluator.upcased
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "returning attributes for a factory" do
|
28
|
-
subject { FactoryGirl.attributes_for(:user, rockstar: true) }
|
29
|
-
it { should_not have_key(:four) }
|
30
|
-
it { should_not have_key(:rockstar) }
|
31
|
-
it { should_not have_key(:upcased) }
|
32
|
-
it { should have_key(:name) }
|
33
|
-
it { should have_key(:email) }
|
34
|
-
end
|
35
|
-
|
36
|
-
context "with a transient variable assigned" do
|
37
|
-
let(:rockstar) { FactoryGirl.create(:user, rockstar: true, four: "1234") }
|
38
|
-
let(:rockstar_with_name) { FactoryGirl.create(:user, name: "Jane Doe", rockstar: true) }
|
39
|
-
let(:upcased_rockstar) { FactoryGirl.create(:user, rockstar: true, upcased: true) }
|
40
|
-
let(:groupie) { FactoryGirl.create(:user, rockstar: false) }
|
41
|
-
|
42
|
-
it "generates the correct attributes on a rockstar" do
|
43
|
-
expect(rockstar.name).to eq "John 1 - Rockstar"
|
44
|
-
expect(rockstar.email).to eq "john 1 - rockstar1234@example.com"
|
45
|
-
end
|
46
|
-
|
47
|
-
it "generates the correct attributes on an upcased rockstar" do
|
48
|
-
expect(upcased_rockstar.name).to eq "JOHN 1 - ROCKSTAR"
|
49
|
-
expect(upcased_rockstar.email).to eq "john 1 - rockstar4@example.com"
|
50
|
-
end
|
51
|
-
|
52
|
-
it "generates the correct attributes on a groupie" do
|
53
|
-
expect(groupie.name).to eq "John 1"
|
54
|
-
expect(groupie.email).to eq "john 14@example.com"
|
55
|
-
end
|
56
|
-
|
57
|
-
it "generates the correct attributes on a rockstar with a name" do
|
58
|
-
expect(rockstar_with_name.name).to eq "Jane Doe"
|
59
|
-
expect(rockstar_with_name.email).to eq "jane doe4@example.com"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "without transient variables assigned" do
|
64
|
-
let(:rockstar) { FactoryGirl.create(:user) }
|
65
|
-
|
66
|
-
it "uses the default value of the attribute" do
|
67
|
-
expect(rockstar.name).to eq "John 1 - Rockstar"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "using aliased 'ignore' method name" do
|
72
|
-
around do |example|
|
73
|
-
cached_silenced = ActiveSupport::Deprecation.silenced
|
74
|
-
ActiveSupport::Deprecation.silenced = true
|
75
|
-
example.run
|
76
|
-
ActiveSupport::Deprecation.silenced = cached_silenced
|
77
|
-
end
|
78
|
-
|
79
|
-
before do
|
80
|
-
FactoryGirl.define do
|
81
|
-
factory :user_using_ignore, class: User do
|
82
|
-
ignore do
|
83
|
-
honorific "Esteemed"
|
84
|
-
end
|
85
|
-
|
86
|
-
name { "#{honorific} Jane Doe" }
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
let(:esteemed) { FactoryGirl.create(:user_using_ignore) }
|
92
|
-
|
93
|
-
it "uses the default value of the attribute" do
|
94
|
-
expect(esteemed.name).to eq "Esteemed Jane Doe"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "transient sequences" do
|
100
|
-
before do
|
101
|
-
define_model("User", name: :string)
|
102
|
-
|
103
|
-
FactoryGirl.define do
|
104
|
-
factory :user do
|
105
|
-
transient do
|
106
|
-
sequence(:counter)
|
107
|
-
end
|
108
|
-
|
109
|
-
name { "John Doe #{counter}" }
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
it "increments sequences correctly" do
|
115
|
-
expect(FactoryGirl.build(:user).name).to eq "John Doe 1"
|
116
|
-
expect(FactoryGirl.build(:user).name).to eq "John Doe 2"
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe "assigning values from a transient attribute" do
|
121
|
-
before do
|
122
|
-
define_class("User") do
|
123
|
-
attr_accessor :foo_id, :foo_name
|
124
|
-
end
|
125
|
-
|
126
|
-
define_class("Foo") do
|
127
|
-
attr_accessor :id, :name
|
128
|
-
def initialize(id, name)
|
129
|
-
@id = id
|
130
|
-
@name = name
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
FactoryGirl.define do
|
135
|
-
factory :user do
|
136
|
-
transient do
|
137
|
-
foo { Foo.new('id-of-foo', 'name-of-foo')}
|
138
|
-
end
|
139
|
-
|
140
|
-
foo_id { foo.id }
|
141
|
-
foo_name { foo.name }
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
it "does not ignore an _id attribute that is an alias for a transient attribute" do
|
147
|
-
user = FactoryGirl.build(:user, :foo => Foo.new('passed-in-id-of-foo', 'passed-in-name-of-foo'))
|
148
|
-
expect(user.foo_id).to eq 'passed-in-id-of-foo'
|
149
|
-
expect(user.foo_name).to eq 'passed-in-name-of-foo'
|
150
|
-
end
|
151
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe FactoryGirl, "aliases" do
|
4
|
-
context "aliases for an attribute" do
|
5
|
-
subject { FactoryGirl.aliases_for(:test) }
|
6
|
-
it { should include(:test) }
|
7
|
-
it { should include(:test_id) }
|
8
|
-
end
|
9
|
-
|
10
|
-
context "aliases for a foreign key" do
|
11
|
-
subject { FactoryGirl.aliases_for(:test_id) }
|
12
|
-
it { should include(:test) }
|
13
|
-
it { should include(:test_id) }
|
14
|
-
end
|
15
|
-
|
16
|
-
context "aliases for an attribute starting with an underscore" do
|
17
|
-
subject { FactoryGirl.aliases_for(:_id) }
|
18
|
-
it { should_not include(:id) }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe FactoryGirl, "after defining an alias" do
|
23
|
-
before do
|
24
|
-
FactoryGirl.aliases << [/(.*)_suffix/, '\1']
|
25
|
-
end
|
26
|
-
|
27
|
-
subject { FactoryGirl.aliases_for(:test_suffix) }
|
28
|
-
|
29
|
-
it { should include(:test) }
|
30
|
-
it { should include(:test_suffix_id) }
|
31
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe FactoryGirl::Attribute::Association do
|
4
|
-
let(:name) { :author }
|
5
|
-
let(:factory) { :user }
|
6
|
-
let(:overrides) { { first_name: "John" } }
|
7
|
-
let(:association) { stub("association") }
|
8
|
-
|
9
|
-
subject { FactoryGirl::Attribute::Association.new(name, factory, overrides) }
|
10
|
-
before { subject.stubs(association: association) }
|
11
|
-
|
12
|
-
it { should be_association }
|
13
|
-
its(:name) { should eq name }
|
14
|
-
|
15
|
-
it "builds the association when calling the proc" do
|
16
|
-
expect(subject.to_proc.call).to eq association
|
17
|
-
end
|
18
|
-
|
19
|
-
it "builds the association when calling the proc" do
|
20
|
-
subject.to_proc.call
|
21
|
-
expect(subject).to have_received(:association).with(factory, overrides)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe FactoryGirl::Attribute::Association, "with a string name" do
|
26
|
-
subject { FactoryGirl::Attribute::Association.new("name", :user, {}) }
|
27
|
-
its(:name) { should eq :name }
|
28
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe FactoryGirl::Attribute::Dynamic do
|
4
|
-
let(:name) { :first_name }
|
5
|
-
let(:block) { -> { } }
|
6
|
-
|
7
|
-
subject { FactoryGirl::Attribute::Dynamic.new(name, false, block) }
|
8
|
-
|
9
|
-
its(:name) { should eq name }
|
10
|
-
|
11
|
-
context "with a block returning a static value" do
|
12
|
-
let(:block) { -> { "value" } }
|
13
|
-
|
14
|
-
it "returns the value when executing the proc" do
|
15
|
-
expect(subject.to_proc.call).to eq "value"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "with a block returning its block-level variable" do
|
20
|
-
let(:block) { ->(thing) { thing } }
|
21
|
-
|
22
|
-
it "returns self when executing the proc" do
|
23
|
-
expect(subject.to_proc.call).to eq subject
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "with a block referencing an attribute on the attribute" do
|
28
|
-
let(:block) { -> { attribute_defined_on_attribute } }
|
29
|
-
let(:result) { "other attribute value" }
|
30
|
-
|
31
|
-
before do
|
32
|
-
subject.stubs(attribute_defined_on_attribute: result)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "evaluates the attribute from the attribute" do
|
36
|
-
expect(subject.to_proc.call).to eq result
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "with a block returning a sequence" do
|
41
|
-
let(:block) { -> { FactoryGirl.register_sequence(FactoryGirl::Sequence.new(:email, 1) { |n| "foo#{n}" }) } }
|
42
|
-
|
43
|
-
it "raises a sequence abuse error" do
|
44
|
-
expect { subject.to_proc.call }.to raise_error(FactoryGirl::SequenceAbuseError)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe FactoryGirl::Attribute::Dynamic, "with a string name" do
|
50
|
-
subject { FactoryGirl::Attribute::Dynamic.new("name", false, -> { } ) }
|
51
|
-
its(:name) { should eq :name }
|
52
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe FactoryGirl::Attribute::Sequence do
|
4
|
-
let(:sequence_name) { :name }
|
5
|
-
let(:name) { :first_name }
|
6
|
-
let(:sequence) { FactoryGirl::Sequence.new(sequence_name, 5) { |n| "Name #{n}" } }
|
7
|
-
|
8
|
-
subject { FactoryGirl::Attribute::Sequence.new(name, sequence_name, false) }
|
9
|
-
before { FactoryGirl.register_sequence(sequence) }
|
10
|
-
|
11
|
-
its(:name) { should eq name }
|
12
|
-
|
13
|
-
it "assigns the next value in the sequence" do
|
14
|
-
expect(subject.to_proc.call).to eq "Name 5"
|
15
|
-
end
|
16
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe FactoryGirl::Attribute::Static do
|
4
|
-
let(:name) { :first_name }
|
5
|
-
let(:value) { "John" }
|
6
|
-
|
7
|
-
subject { FactoryGirl::Attribute::Static.new(name, value, false) }
|
8
|
-
|
9
|
-
its(:name) { should eq name }
|
10
|
-
|
11
|
-
it "returns the value when executing the proc" do
|
12
|
-
expect(subject.to_proc.call).to eq value
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe FactoryGirl::Attribute::Static, "with a string name" do
|
17
|
-
subject { FactoryGirl::Attribute::Static.new("name", nil, false) }
|
18
|
-
its(:name) { should eq :name }
|
19
|
-
end
|
@@ -1,143 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe FactoryGirl::AttributeList, "#define_attribute" do
|
4
|
-
let(:static_attribute) { FactoryGirl::Attribute::Static.new(:full_name, "value", false) }
|
5
|
-
let(:dynamic_attribute) { FactoryGirl::Attribute::Dynamic.new(:email, false, ->(u) { "#{u.full_name}@example.com" }) }
|
6
|
-
|
7
|
-
it "maintains a list of attributes" do
|
8
|
-
subject.define_attribute(static_attribute)
|
9
|
-
expect(subject.to_a).to eq [static_attribute]
|
10
|
-
|
11
|
-
subject.define_attribute(dynamic_attribute)
|
12
|
-
expect(subject.to_a).to eq [static_attribute, dynamic_attribute]
|
13
|
-
end
|
14
|
-
|
15
|
-
it "returns the attribute" do
|
16
|
-
expect(subject.define_attribute(static_attribute)).to eq static_attribute
|
17
|
-
expect(subject.define_attribute(dynamic_attribute)).to eq dynamic_attribute
|
18
|
-
end
|
19
|
-
|
20
|
-
it "raises if an attribute has already been defined" do
|
21
|
-
expect {
|
22
|
-
2.times { subject.define_attribute(static_attribute) }
|
23
|
-
}.to raise_error(FactoryGirl::AttributeDefinitionError, "Attribute already defined: full_name")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe FactoryGirl::AttributeList, "#define_attribute with a named attribute list" do
|
28
|
-
subject { FactoryGirl::AttributeList.new(:author) }
|
29
|
-
|
30
|
-
let(:association_with_same_name) { FactoryGirl::Attribute::Association.new(:author, :author, {}) }
|
31
|
-
let(:association_with_different_name) { FactoryGirl::Attribute::Association.new(:author, :post, {}) }
|
32
|
-
|
33
|
-
it "raises when the attribute is a self-referencing association" do
|
34
|
-
expect { subject.define_attribute(association_with_same_name) }.to raise_error(FactoryGirl::AssociationDefinitionError, "Self-referencing association 'author' in 'author'")
|
35
|
-
end
|
36
|
-
|
37
|
-
it "does not raise when the attribute is not a self-referencing association" do
|
38
|
-
expect { subject.define_attribute(association_with_different_name) }.to_not raise_error
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe FactoryGirl::AttributeList, "#apply_attributes" do
|
43
|
-
let(:full_name_attribute) { FactoryGirl::Attribute::Static.new(:full_name, "John Adams", false) }
|
44
|
-
let(:city_attribute) { FactoryGirl::Attribute::Static.new(:city, "Boston", false) }
|
45
|
-
let(:email_attribute) { FactoryGirl::Attribute::Dynamic.new(:email, false, ->(model) { "#{model.full_name}@example.com" }) }
|
46
|
-
let(:login_attribute) { FactoryGirl::Attribute::Dynamic.new(:login, false, ->(model) { "username-#{model.full_name}" }) }
|
47
|
-
|
48
|
-
def list(*attributes)
|
49
|
-
FactoryGirl::AttributeList.new.tap do |list|
|
50
|
-
attributes.each { |attribute| list.define_attribute(attribute) }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
it "adds attributes in the order defined regardless of attribute type" do
|
55
|
-
subject.define_attribute(full_name_attribute)
|
56
|
-
subject.define_attribute(login_attribute)
|
57
|
-
subject.apply_attributes(list(city_attribute, email_attribute))
|
58
|
-
expect(subject.to_a).to eq [full_name_attribute, login_attribute, city_attribute, email_attribute]
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe FactoryGirl::AttributeList, "#associations" do
|
63
|
-
let(:full_name_attribute) { FactoryGirl::Attribute::Static.new(:full_name, "value", false) }
|
64
|
-
let(:email_attribute) { FactoryGirl::Attribute::Dynamic.new(:email, false, ->(u) { "#{u.full_name}@example.com" }) }
|
65
|
-
let(:author_attribute) { FactoryGirl::Attribute::Association.new(:author, :user, {}) }
|
66
|
-
let(:profile_attribute) { FactoryGirl::Attribute::Association.new(:profile, :profile, {}) }
|
67
|
-
|
68
|
-
before do
|
69
|
-
subject.define_attribute(full_name_attribute)
|
70
|
-
subject.define_attribute(email_attribute)
|
71
|
-
subject.define_attribute(author_attribute)
|
72
|
-
subject.define_attribute(profile_attribute)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "returns associations" do
|
76
|
-
expect(subject.associations.to_a).to eq [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
|
-
expect(subject.ignored.map(&:name)).to eq [:comments_count, :posts_count]
|
99
|
-
end
|
100
|
-
|
101
|
-
it "filters #non_ignored attributes" do
|
102
|
-
expect(subject.non_ignored.map(&:name)).to eq [: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
|
-
expect(subject.names).to eq [:comments_count, :posts_count, :email, :first_name, :last_name, :avatar]
|
130
|
-
end
|
131
|
-
|
132
|
-
it "knows all its #names for #ignored attributes" do
|
133
|
-
expect(subject.ignored.names).to eq [:comments_count, :posts_count]
|
134
|
-
end
|
135
|
-
|
136
|
-
it "knows all its #names for #non_ignored attributes" do
|
137
|
-
expect(subject.non_ignored.names).to eq [:email, :first_name, :last_name, :avatar]
|
138
|
-
end
|
139
|
-
|
140
|
-
it "knows all its #names for #associations" do
|
141
|
-
expect(subject.associations.names).to eq [:avatar]
|
142
|
-
end
|
143
|
-
end
|