factory_boy 1.0.4 → 1.0.5
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/README.rdoc +9 -1
- data/lib/setup.rb +19 -19
- data/test/help_test.rb +1 -1
- data/test/plant_tests.rb +115 -0
- data/test/test_plant.rb +3 -114
- data/test/test_plant_with_active_support.rb +8 -0
- metadata +8 -4
data/README.rdoc
CHANGED
@@ -105,12 +105,20 @@ As with factory_girl you are able to use sequences, like that :
|
|
105
105
|
== Dependencies
|
106
106
|
|
107
107
|
No dependency.
|
108
|
-
|
108
|
+
Doesn't work, for now, with Active Support 3.0 (In development)
|
109
109
|
|
110
|
+
== In Development
|
111
|
+
|
112
|
+
- Stubs only find of Plant class so we can use both AR find on klasses that are not 'planted'
|
113
|
+
- Plant(:xx).clear
|
114
|
+
- Provide an id to each Plant
|
115
|
+
- When assign instance to an association(ie profile of user), set foreign_key id (ie profile_id of user)
|
116
|
+
- To work with Rails 3 (Active Support 3)
|
110
117
|
|
111
118
|
== Change Log
|
112
119
|
|
113
120
|
FIX : Push new object in pool of a class doesn't override objects in pool. Safe push.
|
121
|
+
FIX : Use #clone instead of #dup. Not same behavior with and without rails(may be overriden by active support)
|
114
122
|
|
115
123
|
== Notes
|
116
124
|
|
data/lib/setup.rb
CHANGED
@@ -3,30 +3,30 @@ begin
|
|
3
3
|
rescue LoadError
|
4
4
|
end
|
5
5
|
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
Plant.destroy
|
13
|
-
original_run(result,&block)
|
14
|
-
Plant.unstub_find_for_each_class
|
15
|
-
end
|
16
|
-
end
|
6
|
+
module Plant
|
7
|
+
module Run
|
8
|
+
def run(result,&block)
|
9
|
+
Plant.destroy
|
10
|
+
original_run(result,&block)
|
11
|
+
Plant.unstub_find_for_each_class
|
17
12
|
end
|
13
|
+
end
|
18
14
|
end
|
19
15
|
|
20
16
|
if defined?(ActiveSupport::TestCase)
|
21
17
|
module ActiveSupport
|
22
|
-
class TestCase
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
class TestCase < ::Test::Unit::TestCase
|
19
|
+
alias_method :original_run, :run
|
20
|
+
include Plant::Run
|
21
|
+
end
|
22
|
+
end
|
23
|
+
else
|
24
|
+
module Test
|
25
|
+
module Unit
|
26
|
+
class TestCase
|
27
|
+
alias_method :original_run, :run
|
28
|
+
include Plant::Run
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
|
-
end
|
32
|
+
end
|
data/test/help_test.rb
CHANGED
data/test/plant_tests.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
module PlantTests
|
2
|
+
def setup
|
3
|
+
assert_find_is_unstubbed_for_each_class
|
4
|
+
Plant(:customer)
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_define_simple_definition
|
8
|
+
assert customer = Plant(:customer)
|
9
|
+
assert_nil customer.name
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_define_assign_attributes
|
13
|
+
user = Plant(:user)
|
14
|
+
assert_equal "Zorro", user.name
|
15
|
+
assert_equal 800, user.age
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_define_stubs_find_without_parameter
|
19
|
+
user = Plant(:user)
|
20
|
+
assert_equal user, User.find
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_define_stubs_find_with_array_result
|
24
|
+
2.times { Plant(:user) }
|
25
|
+
assert_equal 2, User.find(:all).size
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_define_with_association_has_one
|
29
|
+
user = Plant(:user)
|
30
|
+
profile = Profile.find
|
31
|
+
assert_equal profile, user.profile
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_define_with_association_has_many
|
35
|
+
user = Plant(:user)
|
36
|
+
assert adresses = user.adresses
|
37
|
+
adress = Adress.find
|
38
|
+
assert_equal adress, user.adresses.first
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_stubs_find_with_option_all
|
42
|
+
user = Plant(:user)
|
43
|
+
users = User.find(:all)
|
44
|
+
assert_equal [user], users
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_find_all_must_return_an_empty_array_if_no_object
|
48
|
+
users = User.find(:all)
|
49
|
+
assert_equal [], users
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_stubs_find_with_option_first
|
53
|
+
users = 3.times.map { Plant(:user) }
|
54
|
+
assert_equal users.first, User.find(:first)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_stubs_find_with_option_last
|
58
|
+
users = 3.times.map { Plant(:user) }
|
59
|
+
assert_equal users.last, User.find(:last)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_mocha_is_not_overidden_with_plant_setup
|
63
|
+
Plant.expects(:pool).once
|
64
|
+
Plant(:user)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_create_plant_with_hash_for_values
|
68
|
+
adress = Plant(:adress)
|
69
|
+
user = Plant(:user, :name => "Marie", :adresses => [adress])
|
70
|
+
assert_equal "Marie", user.name
|
71
|
+
assert_equal adress, user.adresses.first
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_define_with_class_option
|
75
|
+
Plant.define :marie, :class => User do |peter|
|
76
|
+
peter.name = "Marie"
|
77
|
+
peter.adresses = [Adress.new(:street => "Rue de Brest")]
|
78
|
+
end
|
79
|
+
marie = Plant(:marie)
|
80
|
+
assert_equal "Marie", marie.name
|
81
|
+
assert_equal "Rue de Brest", marie.adresses.first.street
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_plants_are_reloaded_and_4_plants_are_defined
|
85
|
+
assert_equal 4, Plant.plants.size
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_define_with_dependent_attribute
|
89
|
+
Plant.define :user do |user|
|
90
|
+
user.name = "Marie"
|
91
|
+
user.adresses = [Adress.new(:street => "Rue de #{user.name}")]
|
92
|
+
end
|
93
|
+
assert_equal "Rue de Marie", Plant(:user).adresses.first.street
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_plant_sequences
|
97
|
+
assert_equal "incognito1@kantena.com", Plant.next(:email)
|
98
|
+
assert_equal "incognito2@kantena.com", Plant.next(:email)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_creation_of_two_plants_of_same_class_should_keep_each_object_safe
|
102
|
+
user_1 = Plant(:user, :name => "Elise")
|
103
|
+
user_2 = Plant(:user, :name => "Vincent")
|
104
|
+
|
105
|
+
assert_equal "Elise", user_1.name
|
106
|
+
assert_equal "Vincent", user_2.name
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def assert_find_is_unstubbed_for_each_class
|
112
|
+
[Adress, Customer, Profile, User].each {|klass| assert_equal "original_find", klass.find }
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
data/test/test_plant.rb
CHANGED
@@ -1,118 +1,7 @@
|
|
1
1
|
require 'help_test'
|
2
|
+
require 'plant'
|
3
|
+
require 'plant_tests'
|
2
4
|
|
3
5
|
class PlantTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
assert_find_is_unstubbed_for_each_class
|
7
|
-
Plant(:customer)
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_define_simple_definition
|
11
|
-
assert customer = Plant(:customer)
|
12
|
-
assert_nil customer.name
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_define_assign_attributes
|
16
|
-
user = Plant(:user)
|
17
|
-
assert_equal "Zorro", user.name
|
18
|
-
assert_equal 800, user.age
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_define_stubs_find_without_parameter
|
22
|
-
user = Plant(:user)
|
23
|
-
assert_equal user, User.find
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_define_stubs_find_with_array_result
|
27
|
-
2.times { Plant(:user) }
|
28
|
-
assert_equal 2, User.find(:all).size
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_define_with_association_has_one
|
32
|
-
user = Plant(:user)
|
33
|
-
profile = Profile.find
|
34
|
-
assert_equal profile, user.profile
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_define_with_association_has_many
|
38
|
-
user = Plant(:user)
|
39
|
-
assert adresses = user.adresses
|
40
|
-
adress = Adress.find
|
41
|
-
assert_equal adress, user.adresses.first
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_stubs_find_with_option_all
|
45
|
-
user = Plant(:user)
|
46
|
-
users = User.find(:all)
|
47
|
-
assert_equal [user], users
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_find_all_must_return_an_empty_array_if_no_object
|
51
|
-
users = User.find(:all)
|
52
|
-
assert_equal [], users
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_stubs_find_with_option_first
|
56
|
-
users = 3.times.map { Plant(:user) }
|
57
|
-
assert_equal users.first, User.find(:first)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_stubs_find_with_option_last
|
61
|
-
users = 3.times.map { Plant(:user) }
|
62
|
-
assert_equal users.last, User.find(:last)
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_mocha_is_not_overidden_with_plant_setup
|
66
|
-
Plant.expects(:pool).once
|
67
|
-
Plant(:user)
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_create_plant_with_hash_for_values
|
71
|
-
adress = Plant(:adress)
|
72
|
-
user = Plant(:user, :name => "Marie", :adresses => [adress])
|
73
|
-
assert_equal "Marie", user.name
|
74
|
-
assert_equal adress, user.adresses.first
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_define_with_class_option
|
78
|
-
Plant.define :marie, :class => User do |peter|
|
79
|
-
peter.name = "Marie"
|
80
|
-
peter.adresses = [Adress.new(:street => "Rue de Brest")]
|
81
|
-
end
|
82
|
-
marie = Plant(:marie)
|
83
|
-
assert_equal "Marie", marie.name
|
84
|
-
assert_equal "Rue de Brest", marie.adresses.first.street
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_plants_are_reloaded_and_4_plants_are_defined
|
88
|
-
assert_equal 4, Plant.plants.size
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_define_with_dependent_attribute
|
92
|
-
Plant.define :user do |user|
|
93
|
-
user.name = "Marie"
|
94
|
-
user.adresses = [Adress.new(:street => "Rue de #{user.name}")]
|
95
|
-
end
|
96
|
-
assert_equal "Rue de Marie", Plant(:user).adresses.first.street
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_plant_sequences
|
100
|
-
assert_equal "incognito1@kantena.com", Plant.next(:email)
|
101
|
-
assert_equal "incognito2@kantena.com", Plant.next(:email)
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_creation_of_two_plants_of_same_class_should_keep_each_object_safe
|
105
|
-
user_1 = Plant(:user, :name => "Elise")
|
106
|
-
user_2 = Plant(:user, :name => "Vincent")
|
107
|
-
|
108
|
-
assert_equal "Elise", user_1.name
|
109
|
-
assert_equal "Vincent", user_2.name
|
110
|
-
end
|
111
|
-
|
112
|
-
private
|
113
|
-
|
114
|
-
def assert_find_is_unstubbed_for_each_class
|
115
|
-
[Adress, Customer, Profile, User].each {|klass| assert_equal "original_find", klass.find }
|
116
|
-
end
|
117
|
-
|
6
|
+
include PlantTests
|
118
7
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_boy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 5
|
10
|
+
version: 1.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Philippe Cantin
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-21 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -38,8 +38,10 @@ files:
|
|
38
38
|
- test/models/customer.rb
|
39
39
|
- test/models/profile.rb
|
40
40
|
- test/models/user.rb
|
41
|
+
- test/plant_tests.rb
|
41
42
|
- test/plants.rb
|
42
43
|
- test/test_plant.rb
|
44
|
+
- test/test_plant_with_active_support.rb
|
43
45
|
has_rdoc: true
|
44
46
|
homepage: http://github.com/anoiaque/factory_boy
|
45
47
|
licenses: []
|
@@ -80,5 +82,7 @@ test_files:
|
|
80
82
|
- test/models/customer.rb
|
81
83
|
- test/models/profile.rb
|
82
84
|
- test/models/user.rb
|
85
|
+
- test/plant_tests.rb
|
83
86
|
- test/plants.rb
|
84
87
|
- test/test_plant.rb
|
88
|
+
- test/test_plant_with_active_support.rb
|