factory_boy 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +16 -2
- data/lib/plant.rb +3 -3
- data/lib/reflection.rb +1 -1
- data/lib/selector.rb +2 -1
- data/lib/stubber.rb +3 -3
- data/test/test_plants_ids.rb +1 -0
- metadata +32 -42
data/README.rdoc
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
== Overview
|
2
2
|
|
3
|
+
<b>/!\\Version 2.0.2 is compatible with ActiveRecord < 3.1 </b>
|
4
|
+
|
5
|
+
<b>/!\\Version 2.0.3 is compatible with ActiveRecord >= 3.1 </b>
|
6
|
+
|
3
7
|
Factory Boy aims to avoid slow unit tests due to usage of create/find fixtures in database, with factory_girl for example.
|
4
8
|
|
5
9
|
Factory Boy can be used as factory_girl except that factories are not created in database.
|
@@ -17,12 +21,20 @@ It does not pretend to stub 100% of all queries, but the coverage can be estimat
|
|
17
21
|
<b>After each test everything is unstubbed.</b>
|
18
22
|
That means, if you have a case where a particular(complex) query is executed but not right stubbed with factory boy you can test using fixtures in databases(with factory girl or just model.create ..), skipping factory boy process.
|
19
23
|
|
20
|
-
Tested with
|
24
|
+
Tested with ruby 1.9+, ActiveRecord 3.1(version 2.0.2) and ActiveRecord 3.1+ (version 2.0.3)
|
21
25
|
Tests are suppose to use ActiveSupport::TestCase
|
22
26
|
|
23
27
|
See some examples below.
|
24
28
|
You should see unit tests to inspect tested stubbed queries!
|
25
29
|
|
30
|
+
== Quality Metrics
|
31
|
+
|
32
|
+
{<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/anoiaque/factory_boy]
|
33
|
+
|
34
|
+
== Continuous Integration
|
35
|
+
|
36
|
+
http://travis-ci.org/anoiaque/factory_boy.png
|
37
|
+
|
26
38
|
|
27
39
|
== Queries it supposes to handle
|
28
40
|
|
@@ -157,7 +169,7 @@ As with factory_girl you are able to use sequences, like that :
|
|
157
169
|
|
158
170
|
|
159
171
|
== In Development
|
160
|
-
|
172
|
+
- FIX issues with ruby 1.9.3
|
161
173
|
- Stubs aggregations methods in queries(sum, count ...)
|
162
174
|
- Having - group clauses methods
|
163
175
|
- Select clause method
|
@@ -171,6 +183,8 @@ As with factory_girl you are able to use sequences, like that :
|
|
171
183
|
|
172
184
|
|
173
185
|
== Change Log
|
186
|
+
|
187
|
+
* Compatibility with ActiveRecord >= 3.1
|
174
188
|
* add require 'active_support/test_case' To fix constant not found Test (setup.rb) when ran as gem under rails 3 app
|
175
189
|
* FIX : When : statements incompatibility with ruby 1.9.2
|
176
190
|
== Note
|
data/lib/plant.rb
CHANGED
@@ -10,7 +10,7 @@ module Plant
|
|
10
10
|
@@pool = {}
|
11
11
|
@@map = {}
|
12
12
|
@@sequences = {}
|
13
|
-
|
13
|
+
@@id = 0
|
14
14
|
|
15
15
|
def self.define symbol, args={}
|
16
16
|
klass = args[:class] || symbol.to_s.camelize.constantize
|
@@ -40,7 +40,7 @@ module Plant
|
|
40
40
|
|
41
41
|
def self.pool symbol
|
42
42
|
definition = plants[symbol] || plants[symbol.to_s.camelize.constantize]
|
43
|
-
object = Plant::Reflection.clone(definition
|
43
|
+
object = Plant::Reflection.clone(definition, @@id += 1)
|
44
44
|
yield object if block_given?
|
45
45
|
@@pool[definition.class] ||= []
|
46
46
|
@@pool[definition.class] << object
|
@@ -52,7 +52,7 @@ module Plant
|
|
52
52
|
@@plants = {}
|
53
53
|
@@map = {}
|
54
54
|
@@sequences = {}
|
55
|
-
|
55
|
+
@@id = 0
|
56
56
|
end
|
57
57
|
|
58
58
|
def self.sequence symbol, &proc
|
data/lib/reflection.rb
CHANGED
@@ -16,10 +16,10 @@ module Plant
|
|
16
16
|
cloner = Proc.new {|attribute| clone.send(attribute.to_s + "=", object.send(attribute))}
|
17
17
|
reflection = @@reflections[object.class]
|
18
18
|
|
19
|
-
clone.id = id
|
20
19
|
reflection[:attributes].keys.each(&cloner)
|
21
20
|
[:has_many, :has_one, :belongs_to].each {|relation| reflection[relation].each(&cloner)}
|
22
21
|
|
22
|
+
clone.id = id
|
23
23
|
clone
|
24
24
|
end
|
25
25
|
|
data/lib/selector.rb
CHANGED
data/lib/stubber.rb
CHANGED
@@ -105,8 +105,8 @@ module Plant
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def self.stubs_associations_collections
|
108
|
-
ActiveRecord::Associations::
|
109
|
-
ActiveRecord::Associations::
|
108
|
+
ActiveRecord::Associations::CollectionAssociation.send(:alias_method, :original_method_missing, :method_missing)
|
109
|
+
ActiveRecord::Associations::CollectionAssociation.send(:define_method, :method_missing) do |method, *args, &block|
|
110
110
|
eval("@target.#{method}")
|
111
111
|
end
|
112
112
|
end
|
@@ -116,7 +116,7 @@ module Plant
|
|
116
116
|
end
|
117
117
|
|
118
118
|
def self.unstubs_associations_collections
|
119
|
-
undefine(ActiveRecord::Associations::
|
119
|
+
undefine(ActiveRecord::Associations::CollectionAssociation, :method_missing)
|
120
120
|
end
|
121
121
|
|
122
122
|
def self.unstubs_attribute_methods
|
data/test/test_plants_ids.rb
CHANGED
metadata
CHANGED
@@ -1,33 +1,32 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_boy
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.3
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 2
|
8
|
-
- 0
|
9
|
-
- 2
|
10
|
-
version: 2.0.2
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Philippe Cantin
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-04-29 00:00:00 +02:00
|
19
|
-
default_executable:
|
12
|
+
date: 2012-10-14 00:00:00.000000000 Z
|
20
13
|
dependencies: []
|
21
|
-
|
22
|
-
|
14
|
+
description: ! " Version 2.0.2 is compatible with ActiveRecord < 3.1 \n
|
15
|
+
\ Version 2.0.3+ is compatible with ActiveRecord >= 3.1 \n ------\n
|
16
|
+
\ Factory Girl with database accesses stubbed.\n The versions 2+ only work
|
17
|
+
with Rails 3 (AR 3+) for stubbing queries.\n Now handle Rails 3 (only Rails
|
18
|
+
3) queries stubbing,\n Transform rail3 queries into ruby select on Plants created
|
19
|
+
with factory boy.\n Example\n user = Plant(:user => 'toto', :addresses
|
20
|
+
=> [Plant(:address, :street => 'here')])\n User.where(:name => 'toto').where('addresses.street
|
21
|
+
= 'here').joins(:addresses) will be stubbed into\n a select ruby on plants
|
22
|
+
and return here, user.\n See more on github and in unit tests.\n Compatible
|
23
|
+
ruby 1.9.3.\n"
|
23
24
|
email:
|
24
25
|
executables: []
|
25
|
-
|
26
26
|
extensions: []
|
27
|
-
|
28
|
-
extra_rdoc_files:
|
27
|
+
extra_rdoc_files:
|
29
28
|
- README.rdoc
|
30
|
-
files:
|
29
|
+
files:
|
31
30
|
- lib/blank_slate.rb
|
32
31
|
- lib/factory_boy.rb
|
33
32
|
- lib/plant.rb
|
@@ -64,41 +63,32 @@ files:
|
|
64
63
|
- test/test_queries_with_ranges.rb
|
65
64
|
- test/test_selector_condition.rb
|
66
65
|
- test/test_stubbing.rb
|
67
|
-
has_rdoc: true
|
68
66
|
homepage: http://github.com/anoiaque/factory_boy
|
69
67
|
licenses: []
|
70
|
-
|
71
68
|
post_install_message:
|
72
69
|
rdoc_options: []
|
73
|
-
|
74
|
-
require_paths:
|
70
|
+
require_paths:
|
75
71
|
- lib
|
76
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
73
|
none: false
|
78
|
-
requirements:
|
79
|
-
- -
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
|
82
|
-
|
83
|
-
- 0
|
84
|
-
version: "0"
|
85
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
79
|
none: false
|
87
|
-
requirements:
|
88
|
-
- -
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
|
91
|
-
segments:
|
92
|
-
- 0
|
93
|
-
version: "0"
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
94
84
|
requirements: []
|
95
|
-
|
96
85
|
rubyforge_project:
|
97
|
-
rubygems_version: 1.
|
86
|
+
rubygems_version: 1.8.23
|
98
87
|
signing_key:
|
99
88
|
specification_version: 3
|
100
|
-
summary: Create fixtures for unit testing as in Factory Girl but without database
|
101
|
-
|
89
|
+
summary: Create fixtures for unit testing as in Factory Girl but without database
|
90
|
+
usage.
|
91
|
+
test_files:
|
102
92
|
- test/app/models/address.rb
|
103
93
|
- test/app/models/customer.rb
|
104
94
|
- test/app/models/profile.rb
|