factory_girl 2.3.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +9 -0
- data/Gemfile.lock +1 -1
- data/gemfiles/2.1.gemfile.lock +1 -1
- data/gemfiles/2.3.gemfile.lock +1 -1
- data/gemfiles/3.0.gemfile.lock +1 -1
- data/gemfiles/3.1.gemfile.lock +1 -1
- data/lib/factory_girl.rb +10 -15
- data/lib/factory_girl/attribute.rb +7 -9
- data/lib/factory_girl/attribute/association.rb +1 -1
- data/lib/factory_girl/attribute_list.rb +18 -16
- data/lib/factory_girl/declaration.rb +5 -0
- data/lib/factory_girl/factory.rb +4 -4
- data/lib/factory_girl/proxy.rb +5 -4
- data/lib/factory_girl/proxy/attributes_for.rb +3 -1
- data/lib/factory_girl/proxy/build.rb +1 -5
- data/lib/factory_girl/proxy/create.rb +5 -6
- data/lib/factory_girl/proxy/stub.rb +7 -9
- data/lib/factory_girl/sequence.rb +0 -3
- data/lib/factory_girl/syntax.rb +4 -0
- data/lib/factory_girl/version.rb +1 -1
- data/spec/acceptance/traits_spec.rb +9 -0
- data/spec/factory_girl/attribute/association_spec.rb +5 -3
- data/spec/factory_girl/attribute/dynamic_spec.rb +3 -3
- data/spec/factory_girl/attribute/sequence_spec.rb +1 -1
- data/spec/factory_girl/attribute/static_spec.rb +1 -1
- data/spec/factory_girl/declaration/implicit_spec.rb +5 -3
- data/spec/factory_girl/proxy/attributes_for_spec.rb +3 -17
- data/spec/factory_girl/proxy/create_spec.rb +3 -2
- data/spec/support/shared_examples/proxy.rb +35 -50
- metadata +115 -174
data/Changelog
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
2.3.1 (November 23, 2011)
|
2
|
+
Remove internally-used associate method from all the FactoryGirl::Proxy subclasses
|
3
|
+
Move around requiring of files
|
4
|
+
Consolidate errors into factory_girl.rb
|
5
|
+
Refactor AttributeList to deal with priority only when iterating over
|
6
|
+
attributes
|
7
|
+
Refactor internals of some of the Proxy subclasses
|
8
|
+
Ensure callbacks on traits are executed in the correct order
|
9
|
+
|
1
10
|
2.3.0 (November 18, 2011)
|
2
11
|
Registries are named, resulting in better messages when factories, traits,
|
3
12
|
or sequences cannot be found
|
data/Gemfile.lock
CHANGED
data/gemfiles/2.1.gemfile.lock
CHANGED
data/gemfiles/2.3.gemfile.lock
CHANGED
data/gemfiles/3.0.gemfile.lock
CHANGED
data/gemfiles/3.1.gemfile.lock
CHANGED
data/lib/factory_girl.rb
CHANGED
@@ -1,34 +1,20 @@
|
|
1
1
|
require "active_support/core_ext/module/delegation"
|
2
2
|
|
3
3
|
require 'factory_girl/proxy'
|
4
|
-
require 'factory_girl/proxy/build'
|
5
|
-
require 'factory_girl/proxy/create'
|
6
|
-
require 'factory_girl/proxy/attributes_for'
|
7
|
-
require 'factory_girl/proxy/stub'
|
8
4
|
require 'factory_girl/registry'
|
9
5
|
require 'factory_girl/null_factory'
|
10
6
|
require 'factory_girl/factory'
|
11
7
|
require 'factory_girl/attribute'
|
12
|
-
require 'factory_girl/attribute/static'
|
13
|
-
require 'factory_girl/attribute/dynamic'
|
14
|
-
require 'factory_girl/attribute/association'
|
15
|
-
require 'factory_girl/attribute/sequence'
|
16
8
|
require 'factory_girl/callback'
|
17
9
|
require 'factory_girl/declaration_list'
|
18
10
|
require 'factory_girl/declaration'
|
19
|
-
require 'factory_girl/declaration/static'
|
20
|
-
require 'factory_girl/declaration/dynamic'
|
21
|
-
require 'factory_girl/declaration/association'
|
22
|
-
require 'factory_girl/declaration/implicit'
|
23
11
|
require 'factory_girl/sequence'
|
24
12
|
require 'factory_girl/attribute_list'
|
25
13
|
require 'factory_girl/trait'
|
26
14
|
require 'factory_girl/aliases'
|
27
15
|
require 'factory_girl/definition'
|
28
16
|
require 'factory_girl/definition_proxy'
|
29
|
-
require 'factory_girl/syntax
|
30
|
-
require 'factory_girl/syntax/default'
|
31
|
-
require 'factory_girl/syntax/vintage'
|
17
|
+
require 'factory_girl/syntax'
|
32
18
|
require 'factory_girl/find_definitions'
|
33
19
|
require 'factory_girl/reload'
|
34
20
|
require 'factory_girl/deprecated'
|
@@ -48,6 +34,15 @@ module FactoryGirl
|
|
48
34
|
# Raised when a factory is defined with the same name as a previously-defined factory.
|
49
35
|
class DuplicateDefinitionError < RuntimeError; end
|
50
36
|
|
37
|
+
# Raised when calling Factory.sequence from a dynamic attribute block
|
38
|
+
class SequenceAbuseError < RuntimeError; end
|
39
|
+
|
40
|
+
# Raised when defining an invalid attribute:
|
41
|
+
# * Defining an attribute which has a name ending in "="
|
42
|
+
# * Defining an attribute with both a static and lazy value
|
43
|
+
# * Defining an attribute twice in the same factory
|
44
|
+
class AttributeDefinitionError < RuntimeError; end
|
45
|
+
|
51
46
|
def self.factories
|
52
47
|
@factories ||= Registry.new("Factory")
|
53
48
|
end
|
@@ -1,11 +1,9 @@
|
|
1
|
-
|
1
|
+
require "factory_girl/attribute/static"
|
2
|
+
require "factory_girl/attribute/dynamic"
|
3
|
+
require "factory_girl/attribute/association"
|
4
|
+
require "factory_girl/attribute/sequence"
|
2
5
|
|
3
|
-
|
4
|
-
# * Defining an attribute which has a name ending in "="
|
5
|
-
# * Defining an attribute with both a static and lazy value
|
6
|
-
# * Defining an attribute twice in the same factory
|
7
|
-
class AttributeDefinitionError < RuntimeError
|
8
|
-
end
|
6
|
+
module FactoryGirl
|
9
7
|
|
10
8
|
class Attribute #:nodoc:
|
11
9
|
include Comparable
|
@@ -55,9 +53,9 @@ module FactoryGirl
|
|
55
53
|
|
56
54
|
def set_proxy_value(proxy, value)
|
57
55
|
if @ignored
|
58
|
-
proxy.set_ignored(
|
56
|
+
proxy.set_ignored(self, value)
|
59
57
|
else
|
60
|
-
proxy.set(
|
58
|
+
proxy.set(self, value)
|
61
59
|
end
|
62
60
|
end
|
63
61
|
end
|
@@ -4,7 +4,7 @@ module FactoryGirl
|
|
4
4
|
|
5
5
|
def initialize(name = nil)
|
6
6
|
@name = name
|
7
|
-
@attributes =
|
7
|
+
@attributes = []
|
8
8
|
end
|
9
9
|
|
10
10
|
def define_attribute(attribute)
|
@@ -15,7 +15,7 @@ module FactoryGirl
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def each(&block)
|
18
|
-
|
18
|
+
sorted_attributes.each(&block)
|
19
19
|
end
|
20
20
|
|
21
21
|
def apply_attributes(attributes_to_apply)
|
@@ -33,21 +33,19 @@ module FactoryGirl
|
|
33
33
|
private
|
34
34
|
|
35
35
|
def add_attribute(attribute)
|
36
|
-
@attributes
|
37
|
-
@attributes[attribute.priority] << attribute
|
36
|
+
@attributes << attribute
|
38
37
|
attribute
|
39
38
|
end
|
40
39
|
|
41
40
|
def prepend_attributes(new_attributes)
|
42
|
-
|
43
|
-
@attributes[priority] ||= []
|
44
|
-
@attributes[priority].unshift *attributes
|
45
|
-
end
|
41
|
+
@attributes.unshift *new_attributes
|
46
42
|
end
|
47
43
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
44
|
+
def sorted_attributes
|
45
|
+
attributes_hash = attributes_hash_by_priority
|
46
|
+
|
47
|
+
attributes_hash.keys.sort.inject([]) do |result, key|
|
48
|
+
result << attributes_hash[key]
|
51
49
|
result
|
52
50
|
end.flatten
|
53
51
|
end
|
@@ -69,16 +67,20 @@ module FactoryGirl
|
|
69
67
|
end
|
70
68
|
|
71
69
|
def find_attribute(attribute_name)
|
72
|
-
@attributes.
|
70
|
+
@attributes.detect do |attribute|
|
73
71
|
attribute.name == attribute_name
|
74
72
|
end
|
75
73
|
end
|
76
74
|
|
77
75
|
def delete_attribute(attribute_name)
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
76
|
+
@attributes.delete_if {|attrib| attrib.name == attribute_name }
|
77
|
+
end
|
78
|
+
|
79
|
+
def attributes_hash_by_priority
|
80
|
+
@attributes.inject({}) do |result, attribute|
|
81
|
+
result[attribute.priority] ||= []
|
82
|
+
result[attribute.priority] << attribute
|
83
|
+
result
|
82
84
|
end
|
83
85
|
end
|
84
86
|
end
|
data/lib/factory_girl/factory.rb
CHANGED
@@ -34,6 +34,8 @@ module FactoryGirl
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def run(proxy_class, overrides, &block) #:nodoc:
|
37
|
+
block ||= lambda {|result| result }
|
38
|
+
|
37
39
|
runner_options = {
|
38
40
|
:attributes => attributes,
|
39
41
|
:callbacks => callbacks,
|
@@ -42,9 +44,7 @@ module FactoryGirl
|
|
42
44
|
:proxy_class => proxy_class
|
43
45
|
}
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
block ? block.call(result) : result
|
47
|
+
block[Runner.new(runner_options).run(overrides)]
|
48
48
|
end
|
49
49
|
|
50
50
|
def human_names
|
@@ -115,7 +115,7 @@ module FactoryGirl
|
|
115
115
|
end
|
116
116
|
|
117
117
|
def callbacks
|
118
|
-
[parent.callbacks, traits.map(&:callbacks), @definition.callbacks].flatten
|
118
|
+
[parent.callbacks, traits.map(&:callbacks).reverse, @definition.callbacks].flatten
|
119
119
|
end
|
120
120
|
|
121
121
|
private
|
data/lib/factory_girl/proxy.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
require "active_support/core_ext/hash/except"
|
2
|
+
require "factory_girl/proxy/build"
|
3
|
+
require "factory_girl/proxy/create"
|
4
|
+
require "factory_girl/proxy/attributes_for"
|
5
|
+
require "factory_girl/proxy/stub"
|
2
6
|
|
3
7
|
module FactoryGirl
|
4
8
|
class Proxy #:nodoc:
|
@@ -19,10 +23,7 @@ module FactoryGirl
|
|
19
23
|
end
|
20
24
|
|
21
25
|
def set_ignored(attribute, value)
|
22
|
-
@ignored_attributes[attribute] = value
|
23
|
-
end
|
24
|
-
|
25
|
-
def associate(name, factory, attributes)
|
26
|
+
@ignored_attributes[attribute.name] = value
|
26
27
|
end
|
27
28
|
|
28
29
|
def run_callbacks(name)
|
@@ -15,11 +15,7 @@ module FactoryGirl
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def set(attribute, value)
|
18
|
-
@instance.send(:"#{attribute}=", value)
|
19
|
-
end
|
20
|
-
|
21
|
-
def associate(name, factory_name, overrides)
|
22
|
-
set(name, association(factory_name, overrides))
|
18
|
+
@instance.send(:"#{attribute.name}=", value)
|
23
19
|
end
|
24
20
|
|
25
21
|
def association(factory_name, overrides = {})
|
@@ -2,12 +2,11 @@ module FactoryGirl
|
|
2
2
|
class Proxy #:nodoc:
|
3
3
|
class Create < Build #:nodoc:
|
4
4
|
def result(to_create)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
5
|
+
super
|
6
|
+
|
7
|
+
to_create ||= lambda {|instance| instance.save! }
|
8
|
+
to_create[@instance]
|
9
|
+
|
11
10
|
run_callbacks(:after_create)
|
12
11
|
@instance
|
13
12
|
end
|
@@ -42,10 +42,6 @@ module FactoryGirl
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def next_id
|
46
|
-
@@next_id += 1
|
47
|
-
end
|
48
|
-
|
49
45
|
def get(attribute)
|
50
46
|
if @ignored_attributes.has_key?(attribute)
|
51
47
|
@ignored_attributes[attribute]
|
@@ -55,11 +51,7 @@ module FactoryGirl
|
|
55
51
|
end
|
56
52
|
|
57
53
|
def set(attribute, value)
|
58
|
-
@instance.send(:"#{attribute}=", value)
|
59
|
-
end
|
60
|
-
|
61
|
-
def associate(name, factory_name, overrides)
|
62
|
-
set(name, association(factory_name, overrides))
|
54
|
+
@instance.send(:"#{attribute.name}=", value)
|
63
55
|
end
|
64
56
|
|
65
57
|
def association(factory_name, overrides = {})
|
@@ -71,6 +63,12 @@ module FactoryGirl
|
|
71
63
|
run_callbacks(:after_stub)
|
72
64
|
@instance
|
73
65
|
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def next_id
|
70
|
+
@@next_id += 1
|
71
|
+
end
|
74
72
|
end
|
75
73
|
end
|
76
74
|
end
|
@@ -1,8 +1,5 @@
|
|
1
1
|
module FactoryGirl
|
2
2
|
|
3
|
-
# Raised when calling Factory.sequence from a dynamic attribute block
|
4
|
-
class SequenceAbuseError < StandardError; end
|
5
|
-
|
6
3
|
# Sequences are defined using sequence within a FactoryGirl.define block.
|
7
4
|
# Sequence values are generated using next.
|
8
5
|
class Sequence
|
data/lib/factory_girl/syntax.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require "factory_girl/syntax/methods"
|
2
|
+
require "factory_girl/syntax/default"
|
3
|
+
require "factory_girl/syntax/vintage"
|
4
|
+
|
1
5
|
module FactoryGirl
|
2
6
|
# Provides alternate syntaxes for factory_girl. If you don't like the default
|
3
7
|
# syntax for defining or using factories, look at one of the
|
data/lib/factory_girl/version.rb
CHANGED
@@ -181,7 +181,12 @@ describe "traits with callbacks" do
|
|
181
181
|
after_create {|user| user.name.upcase! }
|
182
182
|
end
|
183
183
|
|
184
|
+
trait :awesome do
|
185
|
+
after_create {|user| user.name = "awesome" }
|
186
|
+
end
|
187
|
+
|
184
188
|
factory :caps_user, :traits => [:great]
|
189
|
+
factory :awesome_user, :traits => [:great, :awesome]
|
185
190
|
|
186
191
|
factory :caps_user_implicit_trait do
|
187
192
|
great
|
@@ -199,6 +204,10 @@ describe "traits with callbacks" do
|
|
199
204
|
subject { FactoryGirl.create(:caps_user_implicit_trait) }
|
200
205
|
its(:name) { should == "JOHN" }
|
201
206
|
end
|
207
|
+
|
208
|
+
it "executes callbacks in the order assigned" do
|
209
|
+
FactoryGirl.create(:awesome_user).name.should == "awesome"
|
210
|
+
end
|
202
211
|
end
|
203
212
|
|
204
213
|
describe "traits added via proxy" do
|
@@ -12,10 +12,12 @@ describe FactoryGirl::Attribute::Association do
|
|
12
12
|
its(:name) { should == name }
|
13
13
|
its(:factory) { should == factory }
|
14
14
|
|
15
|
-
it "tells the proxy to
|
16
|
-
|
15
|
+
it "tells the proxy to set the association when being added" do
|
16
|
+
association = stub("association")
|
17
|
+
proxy.stubs(:set => nil, :association => association)
|
17
18
|
subject.add_to(proxy)
|
18
|
-
proxy.should have_received(:
|
19
|
+
proxy.should have_received(:set).with(subject, association)
|
20
|
+
proxy.should have_received(:association).with(factory, overrides)
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -14,7 +14,7 @@ describe FactoryGirl::Attribute::Dynamic do
|
|
14
14
|
|
15
15
|
it "calls the block to set a value" do
|
16
16
|
subject.add_to(proxy)
|
17
|
-
proxy.should have_received(:set).with(
|
17
|
+
proxy.should have_received(:set).with(subject, "value")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -23,7 +23,7 @@ describe FactoryGirl::Attribute::Dynamic do
|
|
23
23
|
|
24
24
|
it "yields the proxy to the block" do
|
25
25
|
subject.add_to(proxy)
|
26
|
-
proxy.should have_received(:set).with(
|
26
|
+
proxy.should have_received(:set).with(subject, proxy)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -37,7 +37,7 @@ describe FactoryGirl::Attribute::Dynamic do
|
|
37
37
|
|
38
38
|
it "evaluates the attribute from the proxy" do
|
39
39
|
subject.add_to(proxy)
|
40
|
-
proxy.should have_received(:set).with(
|
40
|
+
proxy.should have_received(:set).with(subject, result)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -14,6 +14,6 @@ describe FactoryGirl::Attribute::Sequence do
|
|
14
14
|
it "assigns the next value in the sequence" do
|
15
15
|
proxy.stubs(:set)
|
16
16
|
subject.add_to(proxy)
|
17
|
-
proxy.should have_received(:set).with(
|
17
|
+
proxy.should have_received(:set).with(subject, "Name 5")
|
18
18
|
end
|
19
19
|
end
|
@@ -12,7 +12,7 @@ describe FactoryGirl::Attribute::Static do
|
|
12
12
|
it "sets its static value on a proxy" do
|
13
13
|
proxy.stubs(:set)
|
14
14
|
subject.add_to(proxy)
|
15
|
-
proxy.should have_received(:set).with(
|
15
|
+
proxy.should have_received(:set).with(subject, value)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -20,9 +20,11 @@ describe FactoryGirl::Declaration::Implicit do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "associates the factory" do
|
23
|
-
|
23
|
+
association = stub("association")
|
24
|
+
proxy.stubs(:set => nil, :association => association)
|
24
25
|
attribute.add_to(proxy)
|
25
|
-
proxy.should have_received(:
|
26
|
+
proxy.should have_received(:set).with(attribute, association)
|
27
|
+
proxy.should have_received(:association).with(name, {})
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
@@ -37,7 +39,7 @@ describe FactoryGirl::Declaration::Implicit do
|
|
37
39
|
it "generates the sequence" do
|
38
40
|
proxy.stubs(:set)
|
39
41
|
attribute.add_to(proxy)
|
40
|
-
proxy.should have_received(:set).with(
|
42
|
+
proxy.should have_received(:set).with(attribute, "magic")
|
41
43
|
end
|
42
44
|
end
|
43
45
|
end
|
@@ -11,32 +11,18 @@ describe FactoryGirl::Proxy::AttributesFor do
|
|
11
11
|
subject.result(nil).should be_kind_of(Hash)
|
12
12
|
end
|
13
13
|
|
14
|
-
context "after associating a factory" do
|
15
|
-
let(:attribute) { :owner }
|
16
|
-
|
17
|
-
before { subject.associate(attribute, :user, {}) }
|
18
|
-
|
19
|
-
it "doesn't set that key in the resulting hash" do
|
20
|
-
subject.result(nil).should_not have_key(attribute)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "returns nil when asked for that attribute" do
|
24
|
-
subject.get(attribute).should be_nil
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
14
|
describe "after setting an attribute" do
|
29
|
-
let(:attribute) { :attribute }
|
15
|
+
let(:attribute) { stub("attribute", :name => :attribute) }
|
30
16
|
let(:value) { "value" }
|
31
17
|
|
32
18
|
before { subject.set(attribute, value) }
|
33
19
|
|
34
20
|
it "sets that value in the resulting hash" do
|
35
|
-
subject.result(nil)[attribute].should == value
|
21
|
+
subject.result(nil)[:attribute].should == value
|
36
22
|
end
|
37
23
|
|
38
24
|
it "returns that value when asked for that attribute" do
|
39
|
-
subject.get(attribute).should == value
|
25
|
+
subject.get(:attribute).should == value
|
40
26
|
end
|
41
27
|
end
|
42
28
|
end
|
@@ -17,10 +17,11 @@ describe FactoryGirl::Proxy::Create do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "runs a custom create block" do
|
20
|
-
|
20
|
+
block_run = false
|
21
|
+
block = lambda {|instance| block_run = true }
|
21
22
|
subject.result(block)
|
22
|
-
block.should have_received(:call).with(instance)
|
23
23
|
instance.should have_received(:save!).never
|
24
|
+
block_run.should be_true
|
24
25
|
end
|
25
26
|
|
26
27
|
end
|
@@ -1,91 +1,76 @@
|
|
1
1
|
shared_examples_for "proxy without association support" do
|
2
|
-
|
3
|
-
expect { subject.associate(:owner, :user, {}) }.to_not raise_error
|
4
|
-
end
|
2
|
+
let(:attribute) { FactoryGirl::Attribute::Association.new(:user, :user, {}) }
|
5
3
|
|
6
4
|
it "does not call FactoryGirl.create when building an association" do
|
7
5
|
FactoryGirl.stubs(:create)
|
8
|
-
subject.
|
6
|
+
subject.set(attribute, "awesome")
|
9
7
|
FactoryGirl.should have_received(:create).never
|
10
8
|
end
|
11
9
|
|
12
|
-
it "returns nil when
|
13
|
-
subject.set(
|
14
|
-
subject.
|
10
|
+
it "returns nil when accessing an association" do
|
11
|
+
subject.set(attribute, "awesome")
|
12
|
+
subject.get(:user).should be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "does not attempt to look up the factory when accessing the association" do
|
16
|
+
FactoryGirl.stubs(:factory_by_name)
|
17
|
+
subject.association(:awesome)
|
18
|
+
FactoryGirl.should have_received(:factory_by_name).never
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
18
22
|
shared_examples_for "proxy with association support" do |factory_girl_proxy_class|
|
19
|
-
let(:
|
20
|
-
let(:
|
21
|
-
let(:
|
22
|
-
let(:overrides) { { :one => 1, :two => 2 } }
|
23
|
+
let(:factory) { stub("associate_factory") }
|
24
|
+
let(:overrides) { { :great => "value" } }
|
25
|
+
let(:factory_name) { :author }
|
23
26
|
|
24
27
|
before do
|
25
28
|
FactoryGirl.stubs(:factory_by_name => factory)
|
26
|
-
|
27
|
-
factory.stubs(:run => factory_name)
|
28
|
-
subject.stubs(:set)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "sets a value for the association" do
|
32
|
-
subject.associate(association_name, factory_name, {})
|
33
|
-
subject.result(nil).send(association_name).should == factory_name
|
34
|
-
end
|
35
|
-
|
36
|
-
it "sets the association attribute as the factory" do
|
37
|
-
subject.associate(association_name, factory_name, {})
|
38
|
-
subject.should have_received(:set).with(association_name, factory_name)
|
29
|
+
factory.stubs(:run)
|
39
30
|
end
|
40
31
|
|
41
|
-
it "runs the factory with the correct
|
42
|
-
subject.
|
43
|
-
factory.should have_received(:run).with(factory_girl_proxy_class,
|
32
|
+
it "runs the factory with the correct overrides" do
|
33
|
+
subject.association(factory_name, overrides)
|
34
|
+
factory.should have_received(:run).with(factory_girl_proxy_class, overrides)
|
44
35
|
end
|
45
36
|
|
46
|
-
it "
|
47
|
-
subject.
|
48
|
-
|
37
|
+
it "finds the factory with the correct factory name" do
|
38
|
+
subject.association(factory_name, overrides)
|
39
|
+
FactoryGirl.should have_received(:factory_by_name).with(factory_name)
|
49
40
|
end
|
50
41
|
end
|
51
42
|
|
52
43
|
shared_examples_for "proxy with :method => :build" do |factory_girl_proxy_class|
|
53
|
-
let(:
|
54
|
-
let(:
|
55
|
-
let(:
|
56
|
-
let(:overrides) { { :method => :build } }
|
44
|
+
let(:factory) { stub("associate_factory") }
|
45
|
+
let(:overrides) { { :method => :build, :great => "value" } }
|
46
|
+
let(:factory_name) { :author }
|
57
47
|
|
58
48
|
before do
|
59
49
|
FactoryGirl.stubs(:factory_by_name => factory)
|
60
|
-
|
61
|
-
factory.stubs(:run => factory_name)
|
62
|
-
subject.stubs(:set)
|
50
|
+
factory.stubs(:run)
|
63
51
|
end
|
64
52
|
|
65
|
-
it "
|
66
|
-
subject.
|
67
|
-
|
53
|
+
it "runs the factory with the correct overrides" do
|
54
|
+
subject.association(factory_name, overrides)
|
55
|
+
factory.should have_received(:run).with(factory_girl_proxy_class, { :great => "value" })
|
68
56
|
end
|
69
57
|
|
70
|
-
it "
|
71
|
-
subject.
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
it "runs the factory with the correct proxy class" do
|
76
|
-
subject.associate(association_name, factory_name, overrides)
|
77
|
-
factory.should have_received(:run).with(factory_girl_proxy_class, {})
|
58
|
+
it "finds the factory with the correct factory name" do
|
59
|
+
subject.association(factory_name, overrides)
|
60
|
+
FactoryGirl.should have_received(:factory_by_name).with(factory_name)
|
78
61
|
end
|
79
62
|
end
|
80
63
|
|
81
64
|
shared_examples_for "proxy with standard getters and setters" do |attribute, value|
|
65
|
+
let(:attribute_instance) { stub("attribute #{attribute}", :name => attribute) }
|
66
|
+
|
82
67
|
before do
|
83
68
|
instance.stubs(:"#{attribute}=" => value, :"#{attribute}" => value)
|
84
69
|
end
|
85
70
|
|
86
71
|
describe "when setting an attribute" do
|
87
72
|
before do
|
88
|
-
subject.set(
|
73
|
+
subject.set(attribute_instance, value)
|
89
74
|
end
|
90
75
|
|
91
76
|
its(attribute) { should == value }
|
@@ -94,7 +79,7 @@ shared_examples_for "proxy with standard getters and setters" do |attribute, val
|
|
94
79
|
|
95
80
|
describe "when setting an ignored attribute" do
|
96
81
|
before do
|
97
|
-
subject.set_ignored(
|
82
|
+
subject.set_ignored(attribute_instance, value)
|
98
83
|
end
|
99
84
|
|
100
85
|
it { instance.should have_received(:"#{attribute}=").with(value).never }
|
metadata
CHANGED
@@ -1,208 +1,157 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_girl
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.3.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 2
|
8
|
-
- 3
|
9
|
-
- 0
|
10
|
-
version: 2.3.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Joe Ferris
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-11-18 00:00:00 -05:00
|
12
|
+
date: 2011-11-23 00:00:00.000000000 -05:00
|
19
13
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
22
16
|
name: activesupport
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirement: &2161610400 !ruby/object:Gem::Requirement
|
25
18
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
33
23
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rspec
|
37
24
|
prerelease: false
|
38
|
-
|
25
|
+
version_requirements: *2161610400
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
requirement: &2161609880 !ruby/object:Gem::Requirement
|
39
29
|
none: false
|
40
|
-
requirements:
|
30
|
+
requirements:
|
41
31
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 2
|
46
|
-
- 0
|
47
|
-
version: "2.0"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
48
34
|
type: :development
|
49
|
-
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: cucumber
|
52
35
|
prerelease: false
|
53
|
-
|
36
|
+
version_requirements: *2161609880
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: cucumber
|
39
|
+
requirement: &2161609340 !ruby/object:Gem::Requirement
|
54
40
|
none: false
|
55
|
-
requirements:
|
41
|
+
requirements:
|
56
42
|
- - ~>
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
hash: 23
|
59
|
-
segments:
|
60
|
-
- 1
|
61
|
-
- 0
|
62
|
-
- 0
|
43
|
+
- !ruby/object:Gem::Version
|
63
44
|
version: 1.0.0
|
64
45
|
type: :development
|
65
|
-
version_requirements: *id003
|
66
|
-
- !ruby/object:Gem::Dependency
|
67
|
-
name: timecop
|
68
46
|
prerelease: false
|
69
|
-
|
47
|
+
version_requirements: *2161609340
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: timecop
|
50
|
+
requirement: &2161608940 !ruby/object:Gem::Requirement
|
70
51
|
none: false
|
71
|
-
requirements:
|
72
|
-
- -
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
version: "0"
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
78
56
|
type: :development
|
79
|
-
version_requirements: *id004
|
80
|
-
- !ruby/object:Gem::Dependency
|
81
|
-
name: rcov
|
82
57
|
prerelease: false
|
83
|
-
|
58
|
+
version_requirements: *2161608940
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rcov
|
61
|
+
requirement: &2161608440 !ruby/object:Gem::Requirement
|
84
62
|
none: false
|
85
|
-
requirements:
|
86
|
-
- -
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
|
89
|
-
segments:
|
90
|
-
- 0
|
91
|
-
version: "0"
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
92
67
|
type: :development
|
93
|
-
version_requirements: *id005
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: aruba
|
96
68
|
prerelease: false
|
97
|
-
|
69
|
+
version_requirements: *2161608440
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: aruba
|
72
|
+
requirement: &2161607980 !ruby/object:Gem::Requirement
|
98
73
|
none: false
|
99
|
-
requirements:
|
100
|
-
- -
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
|
103
|
-
segments:
|
104
|
-
- 0
|
105
|
-
version: "0"
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
106
78
|
type: :development
|
107
|
-
version_requirements: *id006
|
108
|
-
- !ruby/object:Gem::Dependency
|
109
|
-
name: mocha
|
110
79
|
prerelease: false
|
111
|
-
|
80
|
+
version_requirements: *2161607980
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: mocha
|
83
|
+
requirement: &2161607540 !ruby/object:Gem::Requirement
|
112
84
|
none: false
|
113
|
-
requirements:
|
114
|
-
- -
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
|
117
|
-
segments:
|
118
|
-
- 0
|
119
|
-
version: "0"
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
120
89
|
type: :development
|
121
|
-
version_requirements: *id007
|
122
|
-
- !ruby/object:Gem::Dependency
|
123
|
-
name: bourne
|
124
90
|
prerelease: false
|
125
|
-
|
91
|
+
version_requirements: *2161607540
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: bourne
|
94
|
+
requirement: &2161607080 !ruby/object:Gem::Requirement
|
126
95
|
none: false
|
127
|
-
requirements:
|
128
|
-
- -
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
|
131
|
-
segments:
|
132
|
-
- 0
|
133
|
-
version: "0"
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
134
100
|
type: :development
|
135
|
-
version_requirements: *id008
|
136
|
-
- !ruby/object:Gem::Dependency
|
137
|
-
name: appraisal
|
138
101
|
prerelease: false
|
139
|
-
|
102
|
+
version_requirements: *2161607080
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: appraisal
|
105
|
+
requirement: &2161606540 !ruby/object:Gem::Requirement
|
140
106
|
none: false
|
141
|
-
requirements:
|
107
|
+
requirements:
|
142
108
|
- - ~>
|
143
|
-
- !ruby/object:Gem::Version
|
144
|
-
hash: 3
|
145
|
-
segments:
|
146
|
-
- 0
|
147
|
-
- 3
|
148
|
-
- 8
|
109
|
+
- !ruby/object:Gem::Version
|
149
110
|
version: 0.3.8
|
150
111
|
type: :development
|
151
|
-
version_requirements: *id009
|
152
|
-
- !ruby/object:Gem::Dependency
|
153
|
-
name: sqlite3-ruby
|
154
112
|
prerelease: false
|
155
|
-
|
113
|
+
version_requirements: *2161606540
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: sqlite3-ruby
|
116
|
+
requirement: &2161606080 !ruby/object:Gem::Requirement
|
156
117
|
none: false
|
157
|
-
requirements:
|
158
|
-
- -
|
159
|
-
- !ruby/object:Gem::Version
|
160
|
-
|
161
|
-
segments:
|
162
|
-
- 0
|
163
|
-
version: "0"
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
164
122
|
type: :development
|
165
|
-
version_requirements: *id010
|
166
|
-
- !ruby/object:Gem::Dependency
|
167
|
-
name: yard
|
168
123
|
prerelease: false
|
169
|
-
|
124
|
+
version_requirements: *2161606080
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: yard
|
127
|
+
requirement: &2161605540 !ruby/object:Gem::Requirement
|
170
128
|
none: false
|
171
|
-
requirements:
|
172
|
-
- -
|
173
|
-
- !ruby/object:Gem::Version
|
174
|
-
|
175
|
-
segments:
|
176
|
-
- 0
|
177
|
-
version: "0"
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
178
133
|
type: :development
|
179
|
-
version_requirements: *id011
|
180
|
-
- !ruby/object:Gem::Dependency
|
181
|
-
name: bluecloth
|
182
134
|
prerelease: false
|
183
|
-
|
135
|
+
version_requirements: *2161605540
|
136
|
+
- !ruby/object:Gem::Dependency
|
137
|
+
name: bluecloth
|
138
|
+
requirement: &2161604560 !ruby/object:Gem::Requirement
|
184
139
|
none: false
|
185
|
-
requirements:
|
186
|
-
- -
|
187
|
-
- !ruby/object:Gem::Version
|
188
|
-
|
189
|
-
segments:
|
190
|
-
- 0
|
191
|
-
version: "0"
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
192
144
|
type: :development
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: *2161604560
|
147
|
+
description: ! "factory_girl provides a framework and DSL for defining and\n using
|
148
|
+
factories - less error-prone, more explicit, and\n all-around
|
149
|
+
easier to work with than fixtures."
|
198
150
|
email: jferris@thoughtbot.com
|
199
151
|
executables: []
|
200
|
-
|
201
152
|
extensions: []
|
202
|
-
|
203
153
|
extra_rdoc_files: []
|
204
|
-
|
205
|
-
files:
|
154
|
+
files:
|
206
155
|
- .autotest
|
207
156
|
- .gitignore
|
208
157
|
- .rspec
|
@@ -334,38 +283,30 @@ files:
|
|
334
283
|
has_rdoc: true
|
335
284
|
homepage: https://github.com/thoughtbot/factory_girl
|
336
285
|
licenses: []
|
337
|
-
|
338
286
|
post_install_message:
|
339
287
|
rdoc_options: []
|
340
|
-
|
341
|
-
require_paths:
|
288
|
+
require_paths:
|
342
289
|
- lib
|
343
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
290
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
344
291
|
none: false
|
345
|
-
requirements:
|
346
|
-
- -
|
347
|
-
- !ruby/object:Gem::Version
|
348
|
-
|
349
|
-
|
350
|
-
- 0
|
351
|
-
version: "0"
|
352
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
292
|
+
requirements:
|
293
|
+
- - ! '>='
|
294
|
+
- !ruby/object:Gem::Version
|
295
|
+
version: '0'
|
296
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
353
297
|
none: false
|
354
|
-
requirements:
|
355
|
-
- -
|
356
|
-
- !ruby/object:Gem::Version
|
357
|
-
|
358
|
-
segments:
|
359
|
-
- 0
|
360
|
-
version: "0"
|
298
|
+
requirements:
|
299
|
+
- - ! '>='
|
300
|
+
- !ruby/object:Gem::Version
|
301
|
+
version: '0'
|
361
302
|
requirements: []
|
362
|
-
|
363
303
|
rubyforge_project:
|
364
304
|
rubygems_version: 1.6.2
|
365
305
|
signing_key:
|
366
306
|
specification_version: 3
|
367
|
-
summary: factory_girl provides a framework and DSL for defining and using model instance
|
368
|
-
|
307
|
+
summary: factory_girl provides a framework and DSL for defining and using model instance
|
308
|
+
factories.
|
309
|
+
test_files:
|
369
310
|
- Appraisals
|
370
311
|
- cucumber.yml
|
371
312
|
- features/factory_girl_steps.feature
|