factory_girl_library 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.document +5 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +24 -0
- data/Gemfile.lock +231 -0
- data/Guardfile +6 -0
- data/LICENSE.txt +20 -0
- data/README.md +136 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/db/test_db +0 -0
- data/factory_girl_library.gemspec +103 -0
- data/lib/factory_girl_library.rb +35 -0
- data/lib/factory_girl_library/factory_girl/factory_decorator.rb +27 -0
- data/lib/factory_girl_library/factory_girl/factory_girl_class_decorator.rb +13 -0
- data/lib/factory_girl_library/factory_girl/strategy/library.rb +22 -0
- data/lib/factory_girl_library/factory_girl/syntax/methods_decorator.rb +11 -0
- data/lib/factory_girl_library/library.rb +55 -0
- data/lib/factory_girl_library/railtie.rb +11 -0
- data/spec/factory_girl_library/factory_girl/factory_decorator_spec.rb +22 -0
- data/spec/factory_girl_library/factory_girl/factory_girl_class_decorator_spec.rb +21 -0
- data/spec/factory_girl_library/factory_girl/strategy/library_spec.rb +39 -0
- data/spec/factory_girl_library/library_spec.rb +70 -0
- data/spec/factory_girl_library_spec.rb +24 -0
- data/spec/spec_helper.rb +50 -0
- data/spec/support/db.rb +5 -0
- data/spec/support/factories/comment.rb +6 -0
- data/spec/support/factories/post.rb +5 -0
- metadata +242 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 18209e345fa11020f21454ae958733f05cfe33e6
|
4
|
+
data.tar.gz: 77001282d943fcab35b2f259b22edfaed4233349
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b0414657bfd89a95d22826c3517f0243b71447dbaa01a2c9e6d9311afc43d46369364aab636bd0655e26ed2f693ef3deaac8bd55211894edb21919e562302049
|
7
|
+
data.tar.gz: 5efc8c5684f1dd6de520002809d136220d438e222ee3c187b21695c76bde7a47237321f0fa35983448edea9e2fbaad843584bc507549014a396691eef5efdfaf
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: QFxqBBA8KtQlfVTcv0w6r4sFzR6UR83xj
|
data/.document
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "rspec-rails", ">= 3.0"
|
4
|
+
gem "factory_girl", ">= 4.0"
|
5
|
+
gem "rails", ">= 3.2"
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
gem 'mysql2'
|
9
|
+
gem "rdoc", "~> 3.12"
|
10
|
+
gem "bundler", "~> 1.0"
|
11
|
+
gem "jeweler", "~> 2.0.1"
|
12
|
+
gem "simplecov", "~> 0"
|
13
|
+
gem 'sqlite3', '~> 1.3'
|
14
|
+
gem 'rspec-its', '~> 1.1'
|
15
|
+
gem 'coveralls', '~> 0.7', require: false
|
16
|
+
gem 'guard-rspec', '~> 4.5', require: false
|
17
|
+
end
|
18
|
+
|
19
|
+
group :test do
|
20
|
+
gem 'pry-byebug'
|
21
|
+
gem 'rb-fsevent'
|
22
|
+
gem 'terminal-notifier-guard'
|
23
|
+
end
|
24
|
+
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,231 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionmailer (4.1.9)
|
5
|
+
actionpack (= 4.1.9)
|
6
|
+
actionview (= 4.1.9)
|
7
|
+
mail (~> 2.5, >= 2.5.4)
|
8
|
+
actionpack (4.1.9)
|
9
|
+
actionview (= 4.1.9)
|
10
|
+
activesupport (= 4.1.9)
|
11
|
+
rack (~> 1.5.2)
|
12
|
+
rack-test (~> 0.6.2)
|
13
|
+
actionview (4.1.9)
|
14
|
+
activesupport (= 4.1.9)
|
15
|
+
builder (~> 3.1)
|
16
|
+
erubis (~> 2.7.0)
|
17
|
+
activemodel (4.1.9)
|
18
|
+
activesupport (= 4.1.9)
|
19
|
+
builder (~> 3.1)
|
20
|
+
activerecord (4.1.9)
|
21
|
+
activemodel (= 4.1.9)
|
22
|
+
activesupport (= 4.1.9)
|
23
|
+
arel (~> 5.0.0)
|
24
|
+
activesupport (4.1.9)
|
25
|
+
i18n (~> 0.6, >= 0.6.9)
|
26
|
+
json (~> 1.7, >= 1.7.7)
|
27
|
+
minitest (~> 5.1)
|
28
|
+
thread_safe (~> 0.1)
|
29
|
+
tzinfo (~> 1.1)
|
30
|
+
addressable (2.3.7)
|
31
|
+
arel (5.0.1.20140414130214)
|
32
|
+
builder (3.2.2)
|
33
|
+
byebug (3.5.1)
|
34
|
+
columnize (~> 0.8)
|
35
|
+
debugger-linecache (~> 1.2)
|
36
|
+
slop (~> 3.6)
|
37
|
+
celluloid (0.16.0)
|
38
|
+
timers (~> 4.0.0)
|
39
|
+
coderay (1.1.0)
|
40
|
+
columnize (0.9.0)
|
41
|
+
coveralls (0.7.11)
|
42
|
+
multi_json (~> 1.10)
|
43
|
+
rest-client (>= 1.6.8, < 2)
|
44
|
+
simplecov (~> 0.9.1)
|
45
|
+
term-ansicolor (~> 1.3)
|
46
|
+
thor (~> 0.19.1)
|
47
|
+
debugger-linecache (1.2.0)
|
48
|
+
descendants_tracker (0.0.4)
|
49
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
50
|
+
diff-lcs (1.2.5)
|
51
|
+
docile (1.1.5)
|
52
|
+
erubis (2.7.0)
|
53
|
+
factory_girl (4.5.0)
|
54
|
+
activesupport (>= 3.0.0)
|
55
|
+
faraday (0.9.1)
|
56
|
+
multipart-post (>= 1.2, < 3)
|
57
|
+
ffi (1.9.6)
|
58
|
+
formatador (0.2.5)
|
59
|
+
git (1.2.9.1)
|
60
|
+
github_api (0.12.3)
|
61
|
+
addressable (~> 2.3)
|
62
|
+
descendants_tracker (~> 0.0.4)
|
63
|
+
faraday (~> 0.8, < 0.10)
|
64
|
+
hashie (>= 3.3)
|
65
|
+
multi_json (>= 1.7.5, < 2.0)
|
66
|
+
nokogiri (~> 1.6.3)
|
67
|
+
oauth2
|
68
|
+
guard (2.12.4)
|
69
|
+
formatador (>= 0.2.4)
|
70
|
+
listen (~> 2.7)
|
71
|
+
lumberjack (~> 1.0)
|
72
|
+
nenv (~> 0.1)
|
73
|
+
notiffany (~> 0.0)
|
74
|
+
pry (>= 0.9.12)
|
75
|
+
shellany (~> 0.0)
|
76
|
+
thor (>= 0.18.1)
|
77
|
+
guard-compat (1.2.1)
|
78
|
+
guard-rspec (4.5.0)
|
79
|
+
guard (~> 2.1)
|
80
|
+
guard-compat (~> 1.1)
|
81
|
+
rspec (>= 2.99.0, < 4.0)
|
82
|
+
hashie (3.4.0)
|
83
|
+
highline (1.7.1)
|
84
|
+
hike (1.2.3)
|
85
|
+
hitimes (1.2.2)
|
86
|
+
i18n (0.7.0)
|
87
|
+
jeweler (2.0.1)
|
88
|
+
builder
|
89
|
+
bundler (>= 1.0)
|
90
|
+
git (>= 1.2.5)
|
91
|
+
github_api
|
92
|
+
highline (>= 1.6.15)
|
93
|
+
nokogiri (>= 1.5.10)
|
94
|
+
rake
|
95
|
+
rdoc
|
96
|
+
json (1.8.2)
|
97
|
+
jwt (1.3.0)
|
98
|
+
listen (2.8.5)
|
99
|
+
celluloid (>= 0.15.2)
|
100
|
+
rb-fsevent (>= 0.9.3)
|
101
|
+
rb-inotify (>= 0.9)
|
102
|
+
lumberjack (1.0.9)
|
103
|
+
mail (2.6.3)
|
104
|
+
mime-types (>= 1.16, < 3)
|
105
|
+
method_source (0.8.2)
|
106
|
+
mime-types (2.4.3)
|
107
|
+
mini_portile (0.6.2)
|
108
|
+
minitest (5.5.1)
|
109
|
+
multi_json (1.10.1)
|
110
|
+
multi_xml (0.5.5)
|
111
|
+
multipart-post (2.0.0)
|
112
|
+
mysql2 (0.3.18)
|
113
|
+
nenv (0.2.0)
|
114
|
+
netrc (0.10.3)
|
115
|
+
nokogiri (1.6.6.2)
|
116
|
+
mini_portile (~> 0.6.0)
|
117
|
+
notiffany (0.0.6)
|
118
|
+
nenv (~> 0.1)
|
119
|
+
shellany (~> 0.0)
|
120
|
+
oauth2 (1.0.0)
|
121
|
+
faraday (>= 0.8, < 0.10)
|
122
|
+
jwt (~> 1.0)
|
123
|
+
multi_json (~> 1.3)
|
124
|
+
multi_xml (~> 0.5)
|
125
|
+
rack (~> 1.2)
|
126
|
+
pry (0.10.1)
|
127
|
+
coderay (~> 1.1.0)
|
128
|
+
method_source (~> 0.8.1)
|
129
|
+
slop (~> 3.4)
|
130
|
+
pry-byebug (3.0.1)
|
131
|
+
byebug (~> 3.4)
|
132
|
+
pry (~> 0.10)
|
133
|
+
rack (1.5.2)
|
134
|
+
rack-test (0.6.3)
|
135
|
+
rack (>= 1.0)
|
136
|
+
rails (4.1.9)
|
137
|
+
actionmailer (= 4.1.9)
|
138
|
+
actionpack (= 4.1.9)
|
139
|
+
actionview (= 4.1.9)
|
140
|
+
activemodel (= 4.1.9)
|
141
|
+
activerecord (= 4.1.9)
|
142
|
+
activesupport (= 4.1.9)
|
143
|
+
bundler (>= 1.3.0, < 2.0)
|
144
|
+
railties (= 4.1.9)
|
145
|
+
sprockets-rails (~> 2.0)
|
146
|
+
railties (4.1.9)
|
147
|
+
actionpack (= 4.1.9)
|
148
|
+
activesupport (= 4.1.9)
|
149
|
+
rake (>= 0.8.7)
|
150
|
+
thor (>= 0.18.1, < 2.0)
|
151
|
+
rake (10.4.2)
|
152
|
+
rb-fsevent (0.9.4)
|
153
|
+
rb-inotify (0.9.5)
|
154
|
+
ffi (>= 0.5.0)
|
155
|
+
rdoc (3.12.2)
|
156
|
+
json (~> 1.4)
|
157
|
+
rest-client (1.7.3)
|
158
|
+
mime-types (>= 1.16, < 3.0)
|
159
|
+
netrc (~> 0.7)
|
160
|
+
rspec (3.2.0)
|
161
|
+
rspec-core (~> 3.2.0)
|
162
|
+
rspec-expectations (~> 3.2.0)
|
163
|
+
rspec-mocks (~> 3.2.0)
|
164
|
+
rspec-core (3.2.1)
|
165
|
+
rspec-support (~> 3.2.0)
|
166
|
+
rspec-expectations (3.2.0)
|
167
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
168
|
+
rspec-support (~> 3.2.0)
|
169
|
+
rspec-its (1.2.0)
|
170
|
+
rspec-core (>= 3.0.0)
|
171
|
+
rspec-expectations (>= 3.0.0)
|
172
|
+
rspec-mocks (3.2.1)
|
173
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
174
|
+
rspec-support (~> 3.2.0)
|
175
|
+
rspec-rails (3.2.1)
|
176
|
+
actionpack (>= 3.0, < 4.3)
|
177
|
+
activesupport (>= 3.0, < 4.3)
|
178
|
+
railties (>= 3.0, < 4.3)
|
179
|
+
rspec-core (~> 3.2.0)
|
180
|
+
rspec-expectations (~> 3.2.0)
|
181
|
+
rspec-mocks (~> 3.2.0)
|
182
|
+
rspec-support (~> 3.2.0)
|
183
|
+
rspec-support (3.2.2)
|
184
|
+
shellany (0.0.1)
|
185
|
+
simplecov (0.9.2)
|
186
|
+
docile (~> 1.1.0)
|
187
|
+
multi_json (~> 1.0)
|
188
|
+
simplecov-html (~> 0.9.0)
|
189
|
+
simplecov-html (0.9.0)
|
190
|
+
slop (3.6.0)
|
191
|
+
sprockets (2.12.3)
|
192
|
+
hike (~> 1.2)
|
193
|
+
multi_json (~> 1.0)
|
194
|
+
rack (~> 1.0)
|
195
|
+
tilt (~> 1.1, != 1.3.0)
|
196
|
+
sprockets-rails (2.2.4)
|
197
|
+
actionpack (>= 3.0)
|
198
|
+
activesupport (>= 3.0)
|
199
|
+
sprockets (>= 2.8, < 4.0)
|
200
|
+
sqlite3 (1.3.10)
|
201
|
+
term-ansicolor (1.3.0)
|
202
|
+
tins (~> 1.0)
|
203
|
+
terminal-notifier-guard (1.6.4)
|
204
|
+
thor (0.19.1)
|
205
|
+
thread_safe (0.3.4)
|
206
|
+
tilt (1.4.1)
|
207
|
+
timers (4.0.1)
|
208
|
+
hitimes
|
209
|
+
tins (1.3.4)
|
210
|
+
tzinfo (1.2.2)
|
211
|
+
thread_safe (~> 0.1)
|
212
|
+
|
213
|
+
PLATFORMS
|
214
|
+
ruby
|
215
|
+
|
216
|
+
DEPENDENCIES
|
217
|
+
bundler (~> 1.0)
|
218
|
+
coveralls (~> 0.7)
|
219
|
+
factory_girl (>= 4.0)
|
220
|
+
guard-rspec (~> 4.5)
|
221
|
+
jeweler (~> 2.0.1)
|
222
|
+
mysql2
|
223
|
+
pry-byebug
|
224
|
+
rails (>= 3.2)
|
225
|
+
rb-fsevent
|
226
|
+
rdoc (~> 3.12)
|
227
|
+
rspec-its (~> 1.1)
|
228
|
+
rspec-rails (>= 3.0)
|
229
|
+
simplecov (~> 0)
|
230
|
+
sqlite3 (~> 1.3)
|
231
|
+
terminal-notifier-guard
|
data/Guardfile
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
guard :rspec, cmd: 'bundle exec rspec', all_after_pass: true, failed_mode: :focus do
|
2
|
+
watch(%r{^spec/factory_girl_library/.+_spec\.rb$})
|
3
|
+
watch(%r{^lib/factory_girl_library/(.+)\.rb$}) { |m| "spec/factory_girl_library/#{m[1]}_spec.rb" }
|
4
|
+
watch('spec/spec_helper.rb') { "spec" }
|
5
|
+
watch('spec/factory_girl_library_spec.rb') { "spec" }
|
6
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 Valeriy Prokopchuk
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/vprokopchuk256/factory_girl_library.svg?branch=development)](https://travis-ci.org/vprokopchuk256/factory_girl_library)
|
2
|
+
[![Coverage Status](https://coveralls.io/repos/vprokopchuk256/factory_girl_library/badge.svg?branch=development)](https://coveralls.io/r/vprokopchuk256/factory_girl_library?branch=development)
|
3
|
+
|
4
|
+
# Factories can be fast
|
5
|
+
|
6
|
+
Personally I love [Rspec](https://github.com/rspec/rspec) and [FactoryGirl](https://github.com/thoughtbot/factory_girl). Both libraries are very eloquent and very comfortable to use. Especially when one writes tests following [best practices](http://betterspecs.org/).
|
7
|
+
|
8
|
+
But there is a problem there. Single expectation tests means a lot of tests. Huge suite sometimes. And many tests need some data that should be created. That takes a lot of time and makes suite unbearable long.
|
9
|
+
|
10
|
+
```factory_girl_library``` is a library based on top of [FactoryGirl](https://github.com/thoughtbot/factory_girl) that allows to load frequently used instances into the memory and then reuse that from there without recreating each time data is required.
|
11
|
+
|
12
|
+
That makes your tests faster. That is especially significant when complex objects with many assosiations are created.
|
13
|
+
|
14
|
+
# How it works
|
15
|
+
|
16
|
+
```factory_girl_library``` defines [FactoryGirl](https://github.com/thoughtbot/factory_girl) custom strategy ```library``` that in turn creates & memorize requested instance first time, and then access cached version.
|
17
|
+
|
18
|
+
Example:
|
19
|
+
|
20
|
+
Let's assume that we have ```Post``` factory defined:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
FactoryGirl.define do
|
24
|
+
factory :post do
|
25
|
+
is_interesting true
|
26
|
+
is_usefull true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
then ```post``` instance will be created once only below:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
|
35
|
+
describe 'interesting Post instance behavior' do
|
36
|
+
let(:post) { FactoryGirl.library(:post) }
|
37
|
+
|
38
|
+
it 'is interesting' do
|
39
|
+
expect(post).to be_interesting
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'is usefull' do
|
43
|
+
expect(post).to be_usefull
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
```factory_girl_library``` allows developer to modify instance attributes for the test being. All such changes will be reverted after each test:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
describe 'not interesting Post instance behavior' do
|
53
|
+
let(:post) { FactoryGirl.library(:post, is_interesting: false) }
|
54
|
+
|
55
|
+
it 'is NOT interesting' do
|
56
|
+
expect(post).not_to be_interesting
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'is usefull' do
|
60
|
+
expect(post).to be_usefull
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'once more interesting Post instance behavior' do
|
65
|
+
let(:post) { FactoryGirl.library(:post) }
|
66
|
+
|
67
|
+
it 'is interesting' do
|
68
|
+
expect(post).to be_interesting
|
69
|
+
end
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
That is important to understand that library internally stores original object instance without additional parameters are applied and only after that applies custom attributes to already cached object version
|
74
|
+
|
75
|
+
After each test object is reverted back in the database ( db transaction is responsible for that ) and reloaded into the memory after that. So ```factory_girl_library``` takes care of db and memory object synchronization.
|
76
|
+
|
77
|
+
Also ```after :all``` hook is defined internally. It destroys all objects that were created by the tests.
|
78
|
+
|
79
|
+
# Installation
|
80
|
+
|
81
|
+
In Gemfile:
|
82
|
+
|
83
|
+
```
|
84
|
+
gem 'factory_firl_library'
|
85
|
+
```
|
86
|
+
|
87
|
+
# When you should use it
|
88
|
+
|
89
|
+
* You have bunch of simple tests that creates data examples internally
|
90
|
+
* You are trying to make test as atomic as possible.
|
91
|
+
So one object instance is described / used in the most of your test cases.
|
92
|
+
|
93
|
+
# When you should NOT use it
|
94
|
+
|
95
|
+
* ```SQLite``` is NOT supported.
|
96
|
+
```MySQL``` and ```PostgreSQL``` ARE supported.
|
97
|
+
|
98
|
+
* Integration tests
|
99
|
+
Internally ```factory_girl_library``` requires transaction to rollback to the original data that is not a case for integration tests where dedicated connection is used usually. You still can use it for non integration tests.
|
100
|
+
|
101
|
+
* Test that requires transactions with the isolation level other than :read_committed
|
102
|
+
The reason for that is simple. Internally ```factory_girl_library``` runs tests in the transaction with isolation_level == :read_committed and internal transactions with different isolation level are not allowed.
|
103
|
+
|
104
|
+
# Known issues
|
105
|
+
|
106
|
+
If you are using Rails 4 you could see warning message like this:
|
107
|
+
|
108
|
+
```
|
109
|
+
DEPRECATION WARNING: Currently, Active Record suppresses errors raised within `after_rollback`/`after_commit` callbacks and only print them to the logs. In the next version, these errors will no longer be suppressed. Instead, the errors will propagate normally just like in other Active Record callbacks.
|
110
|
+
|
111
|
+
You can opt into the new behavior and remove this warning by setting:
|
112
|
+
|
113
|
+
config.active_record.raise_in_transactional_callbacks = true
|
114
|
+
```
|
115
|
+
|
116
|
+
You could see that message because ```factory_girl_library``` uses ```after_rollback``` hook for data synchronization.
|
117
|
+
|
118
|
+
That warning message could be easily suppressed as described [here](http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#error-handling-in-transaction-callbacks).
|
119
|
+
|
120
|
+
## Version History
|
121
|
+
|
122
|
+
**(1.0.0)** (27 Feb, 2015)
|
123
|
+
|
124
|
+
* First version
|
125
|
+
|
126
|
+
## Contributing
|
127
|
+
|
128
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
129
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
130
|
+
* Fork the project
|
131
|
+
* Start a feature/bugfix branch
|
132
|
+
* Commit and push until you are happy with your contribution
|
133
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
134
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
135
|
+
|
136
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
require 'jeweler'
|
14
|
+
Jeweler::Tasks.new do |gem|
|
15
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
16
|
+
gem.name = "factory_girl_library"
|
17
|
+
gem.homepage = "http://github.com/vprokopchuk256/factory_girl_library"
|
18
|
+
gem.license = "MIT"
|
19
|
+
gem.summary = "Fast FactoryGirl factories"
|
20
|
+
gem.description = "Fast FactoryGirl factories"
|
21
|
+
gem.email = "vprokopchuk@gmail.com"
|
22
|
+
gem.authors = ["Valeriy Prokopchuk"]
|
23
|
+
gem.required_ruby_version = '>= 2.0'
|
24
|
+
end
|
25
|
+
Jeweler::RubygemsDotOrgTasks.new
|
26
|
+
|
27
|
+
require 'rspec/core'
|
28
|
+
require 'rspec/core/rake_task'
|
29
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
30
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Code coverage detail"
|
34
|
+
task :simplecov do
|
35
|
+
ENV['COVERAGE'] = "true"
|
36
|
+
Rake::Task['spec'].execute
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "factory_girl_library #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/db/test_db
ADDED
Binary file
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: factory_girl_library 1.0.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "factory_girl_library"
|
9
|
+
s.version = "1.0.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Valeriy Prokopchuk"]
|
14
|
+
s.date = "2015-02-28"
|
15
|
+
s.description = "Fast FactoryGirl factories"
|
16
|
+
s.email = "vprokopchuk@gmail.com"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.md"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".coveralls.yml",
|
23
|
+
".document",
|
24
|
+
".rspec",
|
25
|
+
".travis.yml",
|
26
|
+
"Gemfile",
|
27
|
+
"Gemfile.lock",
|
28
|
+
"Guardfile",
|
29
|
+
"LICENSE.txt",
|
30
|
+
"README.md",
|
31
|
+
"Rakefile",
|
32
|
+
"VERSION",
|
33
|
+
"db/test_db",
|
34
|
+
"factory_girl_library.gemspec",
|
35
|
+
"lib/factory_girl_library.rb",
|
36
|
+
"lib/factory_girl_library/factory_girl/factory_decorator.rb",
|
37
|
+
"lib/factory_girl_library/factory_girl/factory_girl_class_decorator.rb",
|
38
|
+
"lib/factory_girl_library/factory_girl/strategy/library.rb",
|
39
|
+
"lib/factory_girl_library/factory_girl/syntax/methods_decorator.rb",
|
40
|
+
"lib/factory_girl_library/library.rb",
|
41
|
+
"lib/factory_girl_library/railtie.rb",
|
42
|
+
"spec/factory_girl_library/factory_girl/factory_decorator_spec.rb",
|
43
|
+
"spec/factory_girl_library/factory_girl/factory_girl_class_decorator_spec.rb",
|
44
|
+
"spec/factory_girl_library/factory_girl/strategy/library_spec.rb",
|
45
|
+
"spec/factory_girl_library/library_spec.rb",
|
46
|
+
"spec/factory_girl_library_spec.rb",
|
47
|
+
"spec/spec_helper.rb",
|
48
|
+
"spec/support/db.rb",
|
49
|
+
"spec/support/factories/comment.rb",
|
50
|
+
"spec/support/factories/post.rb"
|
51
|
+
]
|
52
|
+
s.homepage = "http://github.com/vprokopchuk256/factory_girl_library"
|
53
|
+
s.licenses = ["MIT"]
|
54
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.0")
|
55
|
+
s.rubygems_version = "2.4.4"
|
56
|
+
s.summary = "Fast FactoryGirl factories"
|
57
|
+
|
58
|
+
if s.respond_to? :specification_version then
|
59
|
+
s.specification_version = 4
|
60
|
+
|
61
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
62
|
+
s.add_runtime_dependency(%q<rspec-rails>, [">= 3.0"])
|
63
|
+
s.add_runtime_dependency(%q<factory_girl>, [">= 4.0"])
|
64
|
+
s.add_runtime_dependency(%q<rails>, [">= 3.2"])
|
65
|
+
s.add_development_dependency(%q<mysql2>, [">= 0"])
|
66
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
67
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
68
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
69
|
+
s.add_development_dependency(%q<simplecov>, ["~> 0"])
|
70
|
+
s.add_development_dependency(%q<sqlite3>, ["~> 1.3"])
|
71
|
+
s.add_development_dependency(%q<rspec-its>, ["~> 1.1"])
|
72
|
+
s.add_development_dependency(%q<coveralls>, ["~> 0.7"])
|
73
|
+
s.add_development_dependency(%q<guard-rspec>, ["~> 4.5"])
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<rspec-rails>, [">= 3.0"])
|
76
|
+
s.add_dependency(%q<factory_girl>, [">= 4.0"])
|
77
|
+
s.add_dependency(%q<rails>, [">= 3.2"])
|
78
|
+
s.add_dependency(%q<mysql2>, [">= 0"])
|
79
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
80
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
81
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
82
|
+
s.add_dependency(%q<simplecov>, ["~> 0"])
|
83
|
+
s.add_dependency(%q<sqlite3>, ["~> 1.3"])
|
84
|
+
s.add_dependency(%q<rspec-its>, ["~> 1.1"])
|
85
|
+
s.add_dependency(%q<coveralls>, ["~> 0.7"])
|
86
|
+
s.add_dependency(%q<guard-rspec>, ["~> 4.5"])
|
87
|
+
end
|
88
|
+
else
|
89
|
+
s.add_dependency(%q<rspec-rails>, [">= 3.0"])
|
90
|
+
s.add_dependency(%q<factory_girl>, [">= 4.0"])
|
91
|
+
s.add_dependency(%q<rails>, [">= 3.2"])
|
92
|
+
s.add_dependency(%q<mysql2>, [">= 0"])
|
93
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
94
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
95
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
96
|
+
s.add_dependency(%q<simplecov>, ["~> 0"])
|
97
|
+
s.add_dependency(%q<sqlite3>, ["~> 1.3"])
|
98
|
+
s.add_dependency(%q<rspec-its>, ["~> 1.1"])
|
99
|
+
s.add_dependency(%q<coveralls>, ["~> 0.7"])
|
100
|
+
s.add_dependency(%q<guard-rspec>, ["~> 4.5"])
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rspec/core'
|
2
|
+
require 'factory_girl'
|
3
|
+
|
4
|
+
require 'factory_girl_library/railtie'
|
5
|
+
require 'factory_girl_library/factory_girl/factory_decorator'
|
6
|
+
require 'factory_girl_library/factory_girl/syntax/methods_decorator'
|
7
|
+
require 'factory_girl_library/factory_girl/factory_girl_class_decorator'
|
8
|
+
require 'factory_girl_library/factory_girl/strategy/library'
|
9
|
+
require 'factory_girl_library/library'
|
10
|
+
|
11
|
+
FactoryGirl::Factory.send(:prepend, FactoryGirlLibrary::FactoryGirl::FactoryDecorator)
|
12
|
+
FactoryGirl.register_strategy(:library, FactoryGirlLibrary::FactoryGirl::Strategy::Library)
|
13
|
+
FactoryGirl.send(:extend, FactoryGirlLibrary::FactoryGirl::FactoryGirlClassDecorator)
|
14
|
+
FactoryGirl::Syntax::Methods.send(:prepend, FactoryGirlLibrary::FactoryGirl::Syntax::MethodsDecorator)
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.around :each do |test|
|
18
|
+
if use_transactional_fixtures != false
|
19
|
+
self.use_transactional_fixtures = false
|
20
|
+
|
21
|
+
::ActiveRecord::Base.connection.transaction(isolation: :read_committed) do
|
22
|
+
test.run
|
23
|
+
raise ::ActiveRecord::Rollback
|
24
|
+
end
|
25
|
+
|
26
|
+
self.use_transactional_fixtures = true
|
27
|
+
else
|
28
|
+
test.run
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
config.after :all do
|
33
|
+
FactoryGirlLibrary::Library.clear
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module FactoryGirlLibrary
|
2
|
+
module FactoryGirl
|
3
|
+
module FactoryDecorator
|
4
|
+
@@last_run_factory = nil
|
5
|
+
|
6
|
+
def self.prepended(mod)
|
7
|
+
mod.send(:extend, ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
def run *args
|
11
|
+
self.class.last_run_factory = name
|
12
|
+
super(*args)
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
def last_run_factory= factory_name
|
17
|
+
@last_run_factory = factory_name
|
18
|
+
end
|
19
|
+
|
20
|
+
def last_run_factory
|
21
|
+
@last_run_factory
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module FactoryGirlLibrary
|
2
|
+
module FactoryGirl
|
3
|
+
module Strategy
|
4
|
+
class Library < ::FactoryGirl::Strategy::Create
|
5
|
+
def association runner
|
6
|
+
runner.run(:library)
|
7
|
+
end
|
8
|
+
|
9
|
+
def result(evaluation)
|
10
|
+
factory_name = ::FactoryGirl::Factory.last_run_factory
|
11
|
+
|
12
|
+
unless FactoryGirlLibrary::Library.registered?(factory_name)
|
13
|
+
Thread.new{ FactoryGirlLibrary::Library.register(factory_name, super(evaluation)) }.join
|
14
|
+
end
|
15
|
+
|
16
|
+
FactoryGirlLibrary::Library.get(factory_name)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module FactoryGirlLibrary
|
2
|
+
class Library
|
3
|
+
include Singleton
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@library = {}.with_indifferent_access
|
7
|
+
@registration_queue = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def register name, object
|
11
|
+
@library[name] = object
|
12
|
+
@registration_queue.push(object)
|
13
|
+
end
|
14
|
+
|
15
|
+
def registered? name
|
16
|
+
@library.has_key?(name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get name, opts = {}
|
20
|
+
@library[name].tap do |object|
|
21
|
+
update(object, opts)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def reload object
|
26
|
+
object.reload if @library.value?(object) and object.respond_to?(:reload)
|
27
|
+
end
|
28
|
+
|
29
|
+
def clear
|
30
|
+
@library.clear
|
31
|
+
|
32
|
+
while object = @registration_queue.pop
|
33
|
+
object.destroy
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def update obj, opts
|
40
|
+
if obj && opts.present?
|
41
|
+
opts.each do |key, value|
|
42
|
+
obj.send("#{key}=", value)
|
43
|
+
end
|
44
|
+
|
45
|
+
obj.save!
|
46
|
+
end
|
47
|
+
|
48
|
+
obj
|
49
|
+
end
|
50
|
+
|
51
|
+
class << self
|
52
|
+
delegate :register, :registered?, :reload, :get, :clear, to: :instance
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Mv
|
2
|
+
module Core
|
3
|
+
class Railtie < ::Rails::Railtie
|
4
|
+
initializer "factory_girl_library.initialize", after: '"active_record.set_configs"' do
|
5
|
+
class ::ActiveRecord::Base
|
6
|
+
after_rollback { |record| FactoryGirlLibrary::Library.reload(record) }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FactoryGirlLibrary::FactoryGirl::FactoryDecorator do
|
4
|
+
before do
|
5
|
+
FactoryGirlLibrary::Library.clear
|
6
|
+
Comment.delete_all
|
7
|
+
Post.delete_all
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#last_run_factory' do
|
11
|
+
subject do
|
12
|
+
create(:post)
|
13
|
+
::FactoryGirl::Factory.last_run_factory
|
14
|
+
end
|
15
|
+
|
16
|
+
it { is_expected.to eq(:post) }
|
17
|
+
|
18
|
+
it 'still created post object' do
|
19
|
+
expect{ subject }.to change(Post, :count).by(1)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FactoryGirlLibrary::FactoryGirl::FactoryGirlClassDecorator do
|
4
|
+
before do
|
5
|
+
FactoryGirlLibrary::Library.clear
|
6
|
+
Comment.delete_all
|
7
|
+
Post.delete_all
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { library(:post, title: :title) }
|
11
|
+
|
12
|
+
it 'calls original method and create post' do
|
13
|
+
expect{ subject }.to change(Post, :count).by(1)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'calls get on library' do
|
17
|
+
expect(FactoryGirlLibrary::Library).to receive(:get).ordered
|
18
|
+
expect(FactoryGirlLibrary::Library).to receive(:get).ordered.with(:post, title: :title)
|
19
|
+
subject
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FactoryGirlLibrary::FactoryGirl::Strategy::Library do
|
4
|
+
self.use_transactional_fixtures = false
|
5
|
+
|
6
|
+
subject{ library(:comment, title: :title) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
FactoryGirlLibrary::Library.clear
|
10
|
+
Comment.delete_all
|
11
|
+
Post.delete_all
|
12
|
+
|
13
|
+
expect(FactoryGirlLibrary::Library).to receive(:register)
|
14
|
+
.ordered
|
15
|
+
.with(:post, instance_of(Post))
|
16
|
+
.once
|
17
|
+
.and_call_original
|
18
|
+
expect(FactoryGirlLibrary::Library).to receive(:register)
|
19
|
+
.ordered
|
20
|
+
.with(:comment, instance_of(Comment))
|
21
|
+
.once
|
22
|
+
.and_call_original
|
23
|
+
end
|
24
|
+
|
25
|
+
its(:title) { is_expected.to eq(:title) }
|
26
|
+
|
27
|
+
it 'is available inside transaction and stays outside' do
|
28
|
+
ActiveRecord::Base.connection.transaction(isolation: :read_committed) do
|
29
|
+
expect{ subject }.to change(Comment, :count).by(1)
|
30
|
+
expect(Comment.first.title).to eq("title")
|
31
|
+
|
32
|
+
raise ActiveRecord::Rollback
|
33
|
+
end
|
34
|
+
|
35
|
+
expect(Comment.first).not_to be_blank
|
36
|
+
expect(Comment.first.title).to eq('Some Interesting title')
|
37
|
+
expect(library(:comment).title).to eq('Some Interesting title')
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'factory_girl_library/library'
|
4
|
+
|
5
|
+
describe FactoryGirlLibrary::Library do
|
6
|
+
self.use_transactional_fixtures = false
|
7
|
+
|
8
|
+
before do
|
9
|
+
FactoryGirlLibrary::Library.clear
|
10
|
+
Comment.delete_all
|
11
|
+
Post.delete_all
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#get' do
|
15
|
+
subject { described_class.get(:post, title: :new_title) }
|
16
|
+
|
17
|
+
describe "when object is registered" do
|
18
|
+
before { described_class.register(:post, create(:post)) }
|
19
|
+
|
20
|
+
it { is_expected.not_to be_blank }
|
21
|
+
its(:title) { is_expected.to eq(:new_title) }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "when object is not registered" do
|
25
|
+
it { is_expected.to be_blank }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#reload' do
|
30
|
+
let(:post) { create(:post) }
|
31
|
+
|
32
|
+
before { described_class.register(:post, post) }
|
33
|
+
|
34
|
+
it 'reloads registered object' do
|
35
|
+
expect(post).to receive(:reload)
|
36
|
+
described_class.reload(post)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#registered?' do
|
41
|
+
subject { described_class.registered?(:post) }
|
42
|
+
|
43
|
+
describe "when object is registered" do
|
44
|
+
before { described_class.register(:post, create(:post)) }
|
45
|
+
|
46
|
+
it { is_expected.to be_truthy }
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "when object is not registered" do
|
50
|
+
it { is_expected.to be_falsey }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#clear' do
|
55
|
+
let(:post) { create(:post) }
|
56
|
+
let(:post_1) { create(:post) }
|
57
|
+
|
58
|
+
before do
|
59
|
+
described_class.register(:post, post)
|
60
|
+
described_class.register(:post_1, post_1)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'destroys registered object in reverse to registration order' do
|
64
|
+
expect(post_1).to receive(:destroy).ordered
|
65
|
+
expect(post).to receive(:destroy).ordered
|
66
|
+
|
67
|
+
described_class.clear
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "FactoryGirlLibrary" do
|
4
|
+
before :all do
|
5
|
+
FactoryGirlLibrary::Library.clear
|
6
|
+
Comment.delete_all
|
7
|
+
Post.delete_all
|
8
|
+
end
|
9
|
+
|
10
|
+
before do
|
11
|
+
library(:comment, title: :title)
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { Comment.first }
|
15
|
+
|
16
|
+
its(:title) { is_expected.to eq('title') }
|
17
|
+
its(:post) { is_expected.to be_present }
|
18
|
+
|
19
|
+
after :all do
|
20
|
+
expect(Comment.count).to eq(1)
|
21
|
+
expect(Post.count).to eq(1)
|
22
|
+
expect(Comment.first.title).to eq('Some Interesting title')
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rails/all'
|
2
|
+
require 'rspec/rails'
|
3
|
+
require 'rspec/its'
|
4
|
+
require 'active_record'
|
5
|
+
require 'factory_girl_library'
|
6
|
+
require 'pry-byebug'
|
7
|
+
|
8
|
+
require 'coveralls'
|
9
|
+
Coveralls.wear!
|
10
|
+
|
11
|
+
# Requires supporting files with custom matchers and macros, etc,
|
12
|
+
# in ./support/ and its subdirectories.
|
13
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
14
|
+
|
15
|
+
if ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks)
|
16
|
+
ActiveRecord::Base.raise_in_transactional_callbacks = true
|
17
|
+
end
|
18
|
+
|
19
|
+
ActiveRecord::Base.after_rollback { |record| FactoryGirlLibrary::Library.reload(record) }
|
20
|
+
|
21
|
+
Post = Class.new(ActiveRecord::Base)
|
22
|
+
|
23
|
+
Comment = Class.new(ActiveRecord::Base) do
|
24
|
+
belongs_to :post
|
25
|
+
end
|
26
|
+
|
27
|
+
RSpec.configure do |config|
|
28
|
+
config.include FactoryGirl::Syntax::Methods
|
29
|
+
config.include DB
|
30
|
+
|
31
|
+
config.before :all do
|
32
|
+
::ActiveRecord::Base.remove_connection if ::ActiveRecord::Base.connected?
|
33
|
+
|
34
|
+
ActiveRecord::Base.establish_connection(adapter: "mysql2",
|
35
|
+
database: "library_test_db",
|
36
|
+
username: "root")
|
37
|
+
end
|
38
|
+
|
39
|
+
config.before :all do
|
40
|
+
db.create_table(:posts) do |t|
|
41
|
+
t.string :title
|
42
|
+
end unless db.table_exists?(:posts)
|
43
|
+
|
44
|
+
db.create_table(:comments) do |t|
|
45
|
+
t.string :title
|
46
|
+
t.integer :post_id
|
47
|
+
end unless db.table_exists?(:comments)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/spec/support/db.rb
ADDED
metadata
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: factory_girl_library
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Valeriy Prokopchuk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec-rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: factory_girl
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mysql2
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rdoc
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.12'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.12'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: jeweler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.0.1
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.0.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: sqlite3
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.3'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.3'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec-its
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '1.1'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ~>
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '1.1'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: coveralls
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ~>
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0.7'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ~>
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0.7'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: guard-rspec
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '4.5'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ~>
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '4.5'
|
181
|
+
description: Fast FactoryGirl factories
|
182
|
+
email: vprokopchuk@gmail.com
|
183
|
+
executables: []
|
184
|
+
extensions: []
|
185
|
+
extra_rdoc_files:
|
186
|
+
- LICENSE.txt
|
187
|
+
- README.md
|
188
|
+
files:
|
189
|
+
- .coveralls.yml
|
190
|
+
- .document
|
191
|
+
- .rspec
|
192
|
+
- .travis.yml
|
193
|
+
- Gemfile
|
194
|
+
- Gemfile.lock
|
195
|
+
- Guardfile
|
196
|
+
- LICENSE.txt
|
197
|
+
- README.md
|
198
|
+
- Rakefile
|
199
|
+
- VERSION
|
200
|
+
- db/test_db
|
201
|
+
- factory_girl_library.gemspec
|
202
|
+
- lib/factory_girl_library.rb
|
203
|
+
- lib/factory_girl_library/factory_girl/factory_decorator.rb
|
204
|
+
- lib/factory_girl_library/factory_girl/factory_girl_class_decorator.rb
|
205
|
+
- lib/factory_girl_library/factory_girl/strategy/library.rb
|
206
|
+
- lib/factory_girl_library/factory_girl/syntax/methods_decorator.rb
|
207
|
+
- lib/factory_girl_library/library.rb
|
208
|
+
- lib/factory_girl_library/railtie.rb
|
209
|
+
- spec/factory_girl_library/factory_girl/factory_decorator_spec.rb
|
210
|
+
- spec/factory_girl_library/factory_girl/factory_girl_class_decorator_spec.rb
|
211
|
+
- spec/factory_girl_library/factory_girl/strategy/library_spec.rb
|
212
|
+
- spec/factory_girl_library/library_spec.rb
|
213
|
+
- spec/factory_girl_library_spec.rb
|
214
|
+
- spec/spec_helper.rb
|
215
|
+
- spec/support/db.rb
|
216
|
+
- spec/support/factories/comment.rb
|
217
|
+
- spec/support/factories/post.rb
|
218
|
+
homepage: http://github.com/vprokopchuk256/factory_girl_library
|
219
|
+
licenses:
|
220
|
+
- MIT
|
221
|
+
metadata: {}
|
222
|
+
post_install_message:
|
223
|
+
rdoc_options: []
|
224
|
+
require_paths:
|
225
|
+
- lib
|
226
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
227
|
+
requirements:
|
228
|
+
- - '>='
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: '2.0'
|
231
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
|
+
requirements:
|
233
|
+
- - '>='
|
234
|
+
- !ruby/object:Gem::Version
|
235
|
+
version: '0'
|
236
|
+
requirements: []
|
237
|
+
rubyforge_project:
|
238
|
+
rubygems_version: 2.4.4
|
239
|
+
signing_key:
|
240
|
+
specification_version: 4
|
241
|
+
summary: Fast FactoryGirl factories
|
242
|
+
test_files: []
|