factory_girl 2.5.2 → 2.6.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/.travis.yml +0 -1
- data/Changelog +6 -0
- data/GETTING_STARTED.md +52 -7
- data/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/gemfiles/3.2.gemfile.lock +1 -1
- data/lib/factory_girl.rb +2 -1
- data/lib/factory_girl/association_runner.rb +50 -0
- data/lib/factory_girl/definition_proxy.rb +1 -1
- data/lib/factory_girl/evaluator.rb +12 -1
- data/lib/factory_girl/factory.rb +5 -5
- data/lib/factory_girl/strategy.rb +32 -0
- data/lib/factory_girl/{proxy → strategy}/attributes_for.rb +5 -2
- data/lib/factory_girl/strategy/build.rb +15 -0
- data/lib/factory_girl/{proxy → strategy}/create.rb +6 -2
- data/lib/factory_girl/{proxy → strategy}/stub.rb +4 -5
- data/lib/factory_girl/syntax/generate.rb +3 -3
- data/lib/factory_girl/syntax/make.rb +2 -2
- data/lib/factory_girl/syntax/methods.rb +6 -6
- data/lib/factory_girl/version.rb +1 -1
- data/spec/acceptance/build_spec.rb +2 -2
- data/spec/acceptance/create_list_spec.rb +41 -0
- data/spec/acceptance/create_spec.rb +39 -10
- data/spec/acceptance/stub_spec.rb +40 -13
- data/spec/acceptance/syntax/vintage_spec.rb +10 -10
- data/spec/acceptance/traits_spec.rb +1 -1
- data/spec/acceptance/transient_attributes_spec.rb +2 -2
- data/spec/factory_girl/association_runner_spec.rb +31 -0
- data/spec/factory_girl/attribute/association_spec.rb +0 -1
- data/spec/factory_girl/attribute_spec.rb +0 -1
- data/spec/factory_girl/declaration/implicit_spec.rb +0 -1
- data/spec/factory_girl/factory_spec.rb +16 -16
- data/spec/factory_girl/{proxy → strategy}/attributes_for_spec.rb +2 -2
- data/spec/factory_girl/strategy/build_spec.rb +7 -0
- data/spec/factory_girl/{proxy → strategy}/create_spec.rb +3 -3
- data/spec/factory_girl/{proxy → strategy}/stub_spec.rb +4 -4
- data/spec/factory_girl/strategy_spec.rb +21 -0
- data/spec/support/shared_examples/strategy.rb +112 -0
- metadata +47 -48
- data/gemfiles/2.1.gemfile +0 -8
- data/gemfiles/2.1.gemfile.lock +0 -74
- data/lib/factory_girl/proxy.rb +0 -64
- data/lib/factory_girl/proxy/build.rb +0 -27
- data/spec/factory_girl/proxy/build_spec.rb +0 -7
- data/spec/factory_girl/proxy_spec.rb +0 -19
- data/spec/support/shared_examples/proxy.rb +0 -90
data/gemfiles/2.1.gemfile
DELETED
data/gemfiles/2.1.gemfile.lock
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: /Users/joshuaclayton/dev/gems/factory_girl
|
3
|
-
specs:
|
4
|
-
factory_girl (2.5.1)
|
5
|
-
activesupport (>= 2.3.9)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: http://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activerecord (2.3.12)
|
11
|
-
activesupport (= 2.3.12)
|
12
|
-
activesupport (2.3.12)
|
13
|
-
appraisal (0.3.8)
|
14
|
-
bundler
|
15
|
-
rake
|
16
|
-
aruba (0.3.7)
|
17
|
-
childprocess (>= 0.1.9)
|
18
|
-
cucumber (>= 0.10.5)
|
19
|
-
rspec (>= 2.6.0)
|
20
|
-
bluecloth (2.1.0)
|
21
|
-
bourne (1.0)
|
22
|
-
mocha (= 0.9.8)
|
23
|
-
builder (3.0.0)
|
24
|
-
childprocess (0.1.9)
|
25
|
-
ffi (~> 1.0.6)
|
26
|
-
cucumber (1.0.0)
|
27
|
-
builder (>= 2.1.2)
|
28
|
-
diff-lcs (>= 1.1.2)
|
29
|
-
gherkin (~> 2.4.1)
|
30
|
-
json (>= 1.4.6)
|
31
|
-
term-ansicolor (>= 1.0.5)
|
32
|
-
diff-lcs (1.1.2)
|
33
|
-
ffi (1.0.9)
|
34
|
-
gherkin (2.4.1)
|
35
|
-
json (>= 1.4.6)
|
36
|
-
json (1.5.3)
|
37
|
-
mocha (0.9.8)
|
38
|
-
rake
|
39
|
-
rake (0.9.2)
|
40
|
-
rcov (0.9.9)
|
41
|
-
rspec (2.6.0)
|
42
|
-
rspec-core (~> 2.6.0)
|
43
|
-
rspec-expectations (~> 2.6.0)
|
44
|
-
rspec-mocks (~> 2.6.0)
|
45
|
-
rspec-core (2.6.4)
|
46
|
-
rspec-expectations (2.6.0)
|
47
|
-
diff-lcs (~> 1.1.2)
|
48
|
-
rspec-mocks (2.6.0)
|
49
|
-
sqlite3 (1.3.3)
|
50
|
-
sqlite3-ruby (1.3.3)
|
51
|
-
sqlite3 (>= 1.3.3)
|
52
|
-
term-ansicolor (1.0.5)
|
53
|
-
test-unit (2.3.0)
|
54
|
-
timecop (0.3.5)
|
55
|
-
yard (0.7.2)
|
56
|
-
|
57
|
-
PLATFORMS
|
58
|
-
ruby
|
59
|
-
|
60
|
-
DEPENDENCIES
|
61
|
-
activerecord (~> 2.1)
|
62
|
-
appraisal (~> 0.3.8)
|
63
|
-
aruba
|
64
|
-
bluecloth
|
65
|
-
bourne
|
66
|
-
cucumber (~> 1.0.0)
|
67
|
-
factory_girl!
|
68
|
-
mocha
|
69
|
-
rcov
|
70
|
-
rspec (~> 2.0)
|
71
|
-
sqlite3-ruby
|
72
|
-
test-unit (~> 2.3.0)
|
73
|
-
timecop
|
74
|
-
yard
|
data/lib/factory_girl/proxy.rb
DELETED
@@ -1,64 +0,0 @@
|
|
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"
|
6
|
-
require "observer"
|
7
|
-
|
8
|
-
module FactoryGirl
|
9
|
-
class Proxy #:nodoc:
|
10
|
-
include Observable
|
11
|
-
|
12
|
-
# Generates an association using the current build strategy.
|
13
|
-
#
|
14
|
-
# Arguments:
|
15
|
-
# name: (Symbol)
|
16
|
-
# The name of the factory that should be used to generate this
|
17
|
-
# association.
|
18
|
-
# attributes: (Hash)
|
19
|
-
# A hash of attributes that should be overridden for this association.
|
20
|
-
#
|
21
|
-
# Returns:
|
22
|
-
# The generated association for the current build strategy. Note that
|
23
|
-
# associations are not generated for the attributes_for strategy. Returns
|
24
|
-
# nil in this case.
|
25
|
-
#
|
26
|
-
# Example:
|
27
|
-
#
|
28
|
-
# factory :user do
|
29
|
-
# # ...
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# factory :post do
|
33
|
-
# # ...
|
34
|
-
# author { |post| post.association(:user, :name => 'Joe') }
|
35
|
-
# end
|
36
|
-
#
|
37
|
-
# # Builds (but doesn't save) a Post and a User
|
38
|
-
# FactoryGirl.build(:post)
|
39
|
-
#
|
40
|
-
# # Builds and saves a User, builds a Post, assigns the User to the
|
41
|
-
# # author association, and saves the Post.
|
42
|
-
# FactoryGirl.create(:post)
|
43
|
-
#
|
44
|
-
def association(name, overrides = {})
|
45
|
-
end
|
46
|
-
|
47
|
-
def result(attribute_assigner, to_create)
|
48
|
-
raise NotImplementedError, "Strategies must return a result"
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.ensure_strategy_exists!(strategy)
|
52
|
-
unless Proxy.const_defined? strategy.to_s.camelize
|
53
|
-
raise ArgumentError, "Unknown strategy: #{strategy}"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
def run_callbacks(name, result_instance)
|
60
|
-
changed
|
61
|
-
notify_observers(name, result_instance)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module FactoryGirl
|
2
|
-
class Proxy #:nodoc:
|
3
|
-
class Build < Proxy #:nodoc:
|
4
|
-
def association(factory_name, overrides = {})
|
5
|
-
factory = FactoryGirl.factory_by_name(factory_name)
|
6
|
-
factory.run(get_method(overrides[:method]), overrides.except(:method))
|
7
|
-
end
|
8
|
-
|
9
|
-
def result(attribute_assigner, to_create)
|
10
|
-
attribute_assigner.object.tap do |result_instance|
|
11
|
-
run_callbacks(:after_build, result_instance)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def get_method(method)
|
18
|
-
case method
|
19
|
-
when :build then Proxy::Build
|
20
|
-
when :create then Proxy::Create
|
21
|
-
when nil then Proxy::Create
|
22
|
-
else raise "unrecognized method #{method}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,7 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe FactoryGirl::Proxy::Build do
|
4
|
-
it_should_behave_like "proxy with association support", FactoryGirl::Proxy::Create
|
5
|
-
it_should_behave_like "proxy with callbacks", :after_build
|
6
|
-
it_should_behave_like "proxy with :method => :build", FactoryGirl::Proxy::Build
|
7
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe FactoryGirl::Proxy do
|
4
|
-
it_should_behave_like "proxy without association support"
|
5
|
-
|
6
|
-
it "raises an error when asking for the result" do
|
7
|
-
expect { subject.result(stub("assigner"), lambda {|instance| instance }) }.to raise_error(NotImplementedError)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe FactoryGirl::Proxy, ".ensure_strategy_exists!" do
|
12
|
-
it "raises when passed a nonexistent strategy" do
|
13
|
-
expect { FactoryGirl::Proxy.ensure_strategy_exists!(:nonexistent) }.to raise_error(ArgumentError, "Unknown strategy: nonexistent")
|
14
|
-
end
|
15
|
-
|
16
|
-
it "doesn't raise when passed a valid strategy" do
|
17
|
-
expect { FactoryGirl::Proxy.ensure_strategy_exists!(:create) }.to_not raise_error
|
18
|
-
end
|
19
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
shared_examples_for "proxy without association support" do
|
2
|
-
let(:attribute) { FactoryGirl::Attribute::Association.new(:user, :user, {}) }
|
3
|
-
|
4
|
-
it "returns nil when accessing an association" do
|
5
|
-
subject.association(:user, {}).should be_nil
|
6
|
-
end
|
7
|
-
|
8
|
-
it "does not attempt to look up the factory when accessing the association" do
|
9
|
-
FactoryGirl.stubs(:factory_by_name)
|
10
|
-
subject.association(:awesome)
|
11
|
-
FactoryGirl.should have_received(:factory_by_name).never
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
shared_examples_for "proxy with association support" do |factory_girl_proxy_class|
|
16
|
-
let(:factory) { stub("associate_factory") }
|
17
|
-
let(:overrides) { { :great => "value" } }
|
18
|
-
let(:factory_name) { :author }
|
19
|
-
|
20
|
-
before do
|
21
|
-
FactoryGirl.stubs(:factory_by_name => factory)
|
22
|
-
factory.stubs(:run)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "runs the factory with the correct overrides" do
|
26
|
-
subject.association(factory_name, overrides)
|
27
|
-
factory.should have_received(:run).with(factory_girl_proxy_class, overrides)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "finds the factory with the correct factory name" do
|
31
|
-
subject.association(factory_name, overrides)
|
32
|
-
FactoryGirl.should have_received(:factory_by_name).with(factory_name)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
shared_examples_for "proxy with :method => :build" do |factory_girl_proxy_class|
|
37
|
-
let(:factory) { stub("associate_factory") }
|
38
|
-
let(:overrides) { { :method => :build, :great => "value" } }
|
39
|
-
let(:factory_name) { :author }
|
40
|
-
|
41
|
-
before do
|
42
|
-
FactoryGirl.stubs(:factory_by_name => factory)
|
43
|
-
factory.stubs(:run)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "runs the factory with the correct overrides" do
|
47
|
-
subject.association(factory_name, overrides)
|
48
|
-
factory.should have_received(:run).with(factory_girl_proxy_class, { :great => "value" })
|
49
|
-
end
|
50
|
-
|
51
|
-
it "finds the factory with the correct factory name" do
|
52
|
-
subject.association(factory_name, overrides)
|
53
|
-
FactoryGirl.should have_received(:factory_by_name).with(factory_name)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
shared_examples_for "proxy with callbacks" do |*callback_names|
|
58
|
-
let(:callback_observer) do
|
59
|
-
define_class("CallbackObserver") do
|
60
|
-
attr_reader :callbacks_called
|
61
|
-
|
62
|
-
def initialize
|
63
|
-
@callbacks_called = []
|
64
|
-
end
|
65
|
-
|
66
|
-
def update(callback_name, assigner)
|
67
|
-
@callbacks_called << [callback_name, assigner]
|
68
|
-
end
|
69
|
-
end.new
|
70
|
-
end
|
71
|
-
|
72
|
-
let(:result_instance) do
|
73
|
-
define_class("ResultInstance") do
|
74
|
-
attr_accessor :id
|
75
|
-
end.new
|
76
|
-
end
|
77
|
-
|
78
|
-
let(:assigner) { stub("attribute assigner", :object => result_instance) }
|
79
|
-
|
80
|
-
before { subject.add_observer(callback_observer) }
|
81
|
-
|
82
|
-
it "runs the callbacks #{callback_names} with the assigner's object" do
|
83
|
-
subject.result(assigner, lambda {|instance| instance })
|
84
|
-
callback_observer.callbacks_called.should == callback_names.map {|name| [name, assigner.object] }
|
85
|
-
end
|
86
|
-
|
87
|
-
it "returns the object from the assigner" do
|
88
|
-
subject.result(assigner, lambda {|instance| instance }).should == assigner.object
|
89
|
-
end
|
90
|
-
end
|