gonzales 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +38 -1
- data/lib/gonzales/adapter/registered.rb +37 -0
- data/lib/gonzales/adapter/unregistered.rb +37 -0
- data/lib/gonzales/adapter.rb +49 -0
- data/lib/gonzales/collection.rb +7 -0
- data/lib/gonzales/factories.rb +1 -0
- data/lib/gonzales/factory_girl/definition_proxy.rb +2 -2
- data/lib/gonzales/test_helper.rb +1 -1
- data/lib/gonzales/version.rb +1 -1
- data/lib/gonzales.rb +30 -14
- data/test/dummy/log/test.log +10693 -0
- data/test/dummy/test/unit/outfit_test.rb +63 -25
- data/test/unit/gonzales/adapter/registered_test.rb +34 -0
- data/test/unit/gonzales/adapter/unregistered_test.rb +34 -0
- data/test/unit/gonzales/adapter_test.rb +39 -0
- data/test/unit/gonzales/collection_test.rb +8 -1
- data/test/unit/gonzales/factories_test.rb +2 -0
- data/test/unit/gonzales/factory_girl/definition_proxy_test.rb +4 -4
- data/test/unit/gonzales/test_helper_test.rb +2 -2
- data/test/unit/gonzales_test.rb +23 -0
- metadata +16 -7
@@ -1,36 +1,74 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class OutfitTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
should 'invoke factory for it and not for boot' do
|
9
|
-
Factory.expects(:create).with(:outfit)
|
10
|
-
outfit = speedy(:outfit)
|
4
|
+
|
5
|
+
context 'default use' do
|
6
|
+
setup do
|
7
|
+
Gonzales.initialize!
|
11
8
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
context 'loading outfit' do
|
10
|
+
should 'invoke factory for it and not for boot' do
|
11
|
+
Gonzales::Adapter.expects(:create).with(:outfit)
|
12
|
+
outfit = speedy(:outfit)
|
13
|
+
end
|
14
|
+
should 'invoke factory for hat, but not for shoe' do
|
15
|
+
Hat.expects(:find).never
|
16
|
+
Shoe.expects(:find).once
|
17
|
+
outfit = speedy(:outfit)
|
18
|
+
assert_equal 'Narrow', outfit.hat.brim_type
|
19
|
+
end
|
17
20
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
context 'outfit' do
|
22
|
+
should 'have alternative thats association loaded' do
|
23
|
+
outfit = speedy(:outfit)
|
24
|
+
assert_equal 1, outfit.alternative_hats.size
|
25
|
+
assert_equal 'Cool', outfit.alternative_hats.first.brim_type
|
26
|
+
end
|
27
|
+
end
|
28
|
+
context 'exploring factory_girl' do
|
29
|
+
should 'explore possibilities' do
|
30
|
+
outfit = speedy(:girl_outfit)
|
31
|
+
assert_equal 'Fat', outfit.hat.brim_type
|
32
|
+
assert_equal 'Classy', outfit.shoe.name
|
33
|
+
assert_equal 1, outfit.alternative_hats.size
|
34
|
+
assert_equal 'Narrow', outfit.alternative_hats.first.brim_type
|
35
|
+
end
|
24
36
|
end
|
25
37
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
38
|
+
|
39
|
+
context 'without preload and' do
|
40
|
+
setup do
|
41
|
+
Gonzales.disable_preload = true
|
42
|
+
Gonzales.expects(:load).never
|
43
|
+
Gonzales.initialize!
|
44
|
+
end
|
45
|
+
teardown do
|
46
|
+
Gonzales.disable_preload = false
|
47
|
+
Gonzales.adapter = :unregistered
|
48
|
+
end
|
49
|
+
context 'using registered adapter' do
|
50
|
+
setup do
|
51
|
+
Gonzales.adapter = :registered
|
52
|
+
end
|
53
|
+
should 'instantiate outfit only once' do
|
54
|
+
assert_difference 'Outfit.count', 1 do
|
55
|
+
speedy(:outfit)
|
56
|
+
speedy(:outfit)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
context 'using unregistered adapter' do
|
61
|
+
setup do
|
62
|
+
Gonzales.adapter = :unregistered
|
63
|
+
end
|
64
|
+
should 'instantiate outfit twice' do
|
65
|
+
assert_difference 'Outfit.count', 2 do
|
66
|
+
speedy(:outfit)
|
67
|
+
speedy(:outfit)
|
68
|
+
end
|
69
|
+
end
|
33
70
|
end
|
34
71
|
end
|
72
|
+
|
35
73
|
end
|
36
74
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Copyright (c) 2012 Bingo Entreprenøren AS
|
2
|
+
# Copyright (c) 2012 Teknobingo Scandinavia AS
|
3
|
+
# Copyright (c) 2012 Knut I. Stenmark
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
# a copy of this software and associated documentation files (the
|
7
|
+
# "Software"), to deal in the Software without restriction, including
|
8
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
# the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
require 'test_helper'
|
25
|
+
|
26
|
+
class Gonzales::Adapter::UnregisteredTest < ActiveSupport::TestCase
|
27
|
+
context 'Registered adapter' do
|
28
|
+
should 'call speedy' do
|
29
|
+
Factory.expects(:create).with(:elmer, :fudd)
|
30
|
+
Gonzales::Adapter::Unregistered.create(:elmer, :fudd)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Copyright (c) 2012 Bingo Entreprenøren AS
|
2
|
+
# Copyright (c) 2012 Teknobingo Scandinavia AS
|
3
|
+
# Copyright (c) 2012 Knut I. Stenmark
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
# a copy of this software and associated documentation files (the
|
7
|
+
# "Software"), to deal in the Software without restriction, including
|
8
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
# the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
require 'test_helper'
|
25
|
+
|
26
|
+
class Gonzales::Adapter::RegisteredTest < ActiveSupport::TestCase
|
27
|
+
context 'Registered adapter' do
|
28
|
+
should 'call speedy' do
|
29
|
+
Gonzales::Factories.expects(:speedy).with(:elmer, :fudd)
|
30
|
+
Gonzales::Adapter::Registered.create(:elmer, :fudd)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Copyright (c) 2012 Bingo Entreprenøren AS
|
2
|
+
# Copyright (c) 2012 Teknobingo Scandinavia AS
|
3
|
+
# Copyright (c) 2012 Knut I. Stenmark
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
# a copy of this software and associated documentation files (the
|
7
|
+
# "Software"), to deal in the Software without restriction, including
|
8
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
# the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
require 'test_helper'
|
25
|
+
|
26
|
+
class Gonzales::AdapterTest < ActiveSupport::TestCase
|
27
|
+
context 'creation' do
|
28
|
+
should 'default to unregistered' do
|
29
|
+
Gonzales::Adapter.class_variable_set(:@@adapter, nil)
|
30
|
+
Gonzales::Adapter::Unregistered.expects(:create).with(:cartoon, :elmer)
|
31
|
+
Gonzales::Adapter.create(:cartoon, :elmer)
|
32
|
+
end
|
33
|
+
should 'use the adapter specified' do
|
34
|
+
Gonzales::Adapter.use :registered
|
35
|
+
Gonzales::Adapter::Registered.expects(:create).with(:cartoon, :elmer)
|
36
|
+
Gonzales::Adapter.create(:cartoon, :elmer)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -52,7 +52,7 @@ class Gonzales::CollectionTest < ActiveSupport::TestCase
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
context '
|
55
|
+
context 'public method' do
|
56
56
|
context 'add' do
|
57
57
|
should 'store entity' do
|
58
58
|
class Entity
|
@@ -76,6 +76,13 @@ class Gonzales::CollectionTest < ActiveSupport::TestCase
|
|
76
76
|
assert_nil @coll.entity(:entity)
|
77
77
|
end
|
78
78
|
end
|
79
|
+
context 'cache' do
|
80
|
+
should 'be cleared upon request' do
|
81
|
+
@coll.class_variable_set :@@entities, {:ugh => 1}
|
82
|
+
@coll.clear_cache
|
83
|
+
assert_equal ({}), @coll.class_variable_get( :@@entities)
|
84
|
+
end
|
85
|
+
end
|
79
86
|
end
|
80
87
|
|
81
88
|
end
|
@@ -44,6 +44,8 @@ class Gonzales::FactoriesTest < ActiveSupport::TestCase
|
|
44
44
|
|
45
45
|
context 'load' do
|
46
46
|
should 'yield context' do
|
47
|
+
Gonzales::Collection.expects(:clear_cache).once
|
48
|
+
::FactoryGirl.expects(:reload).once
|
47
49
|
Gonzales::Collection.expects(:save).once
|
48
50
|
Gonzales::Factories.load do |context|
|
49
51
|
assert_equal Gonzales::Factories, context
|
@@ -49,14 +49,14 @@ class Gonzales::FactoryGirl::DefinitionProxyTest < ActiveSupport::TestCase
|
|
49
49
|
should 'instantiate factory with default attribute' do
|
50
50
|
DefinitionProxyTest.expects(:reflect_on_association).with(:sylvester).returns(@reflection)
|
51
51
|
Gonzales::Collection.expects(:entity).with(:sylvester).returns(nil)
|
52
|
-
|
52
|
+
Gonzales::Adapter.expects(:create).with(:sylvester, {}).returns(:cat)
|
53
53
|
@proxy.speedy(:sylvester)
|
54
54
|
assert_equal :cat, @proxy.sylvester
|
55
55
|
end
|
56
56
|
should 'instantiate factory with defined attribute' do
|
57
57
|
DefinitionProxyTest.expects(:reflect_on_association).with(:sylvester).returns(@reflection)
|
58
58
|
Gonzales::Collection.expects(:entity).with(:elmer).returns(nil)
|
59
|
-
|
59
|
+
Gonzales::Adapter.expects(:create).with(:elmer, {}).returns(:cat)
|
60
60
|
@proxy.speedy(:sylvester, :elmer)
|
61
61
|
assert_equal :cat, @proxy.sylvester
|
62
62
|
end
|
@@ -64,14 +64,14 @@ class Gonzales::FactoryGirl::DefinitionProxyTest < ActiveSupport::TestCase
|
|
64
64
|
DefinitionProxyTest.expects(:reflect_on_association).with(:sylvester).returns(@reflection)
|
65
65
|
@proxy.sylvester = :already_set
|
66
66
|
Gonzales::Collection.expects(:entity).never
|
67
|
-
|
67
|
+
Gonzales::Adapter.expects(:create).never
|
68
68
|
@proxy.speedy(:sylvester)
|
69
69
|
assert_equal :already_set, @proxy.sylvester
|
70
70
|
end
|
71
71
|
should 'load entity from cache if it is there' do
|
72
72
|
DefinitionProxyTest.expects(:reflect_on_association).with(:sylvester).returns(@reflection)
|
73
73
|
Gonzales::Collection.expects(:entity).with(:sylvester).returns(:cat)
|
74
|
-
|
74
|
+
Gonzales::Adapter.expects(:create).never
|
75
75
|
@proxy.speedy(:sylvester)
|
76
76
|
assert_equal :cat, @proxy.sylvester
|
77
77
|
end
|
@@ -32,12 +32,12 @@ class Gonzales::TestHelperTest < ActiveSupport::TestCase
|
|
32
32
|
end
|
33
33
|
should 'call factory if not cached' do
|
34
34
|
Gonzales::Collection.expects(:entity).with(:manolo).returns(nil)
|
35
|
-
|
35
|
+
Gonzales::Adapter.expects(:create).with(:manolo).returns(:munoz)
|
36
36
|
assert_equal :munoz, speedy(:manolo)
|
37
37
|
end
|
38
38
|
should 'call factory with parameters if not cached' do
|
39
39
|
Gonzales::Collection.expects(:entity).with(:elmer).returns(nil)
|
40
|
-
|
40
|
+
Gonzales::Adapter.expects(:create).with(:elmer, :fudd).returns(:midd)
|
41
41
|
assert_equal :midd, speedy(:elmer, :fudd)
|
42
42
|
end
|
43
43
|
end
|
data/test/unit/gonzales_test.rb
CHANGED
@@ -8,8 +8,31 @@ class GonzalesTest < ActiveSupport::TestCase
|
|
8
8
|
context 'initializing' do
|
9
9
|
should 'load factory_file' do
|
10
10
|
Gonzales.factory_module = nil
|
11
|
+
Gonzales::Collection.expects(:clear_cache).never
|
11
12
|
Gonzales.expects(:load).with(Rails.root.join('test', 'speedy.rb'))
|
12
13
|
Gonzales.initialize!
|
13
14
|
end
|
15
|
+
should 'not load factory_file if disable_preload' do
|
16
|
+
Gonzales.factory_module = nil
|
17
|
+
Gonzales.disable_preload = true
|
18
|
+
Gonzales::Collection.expects(:clear_cache).once
|
19
|
+
Gonzales.expects(:load).never
|
20
|
+
Gonzales.initialize!
|
21
|
+
Gonzales.disable_preload = false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'customization' do
|
26
|
+
should 'include adapter as config' do
|
27
|
+
Gonzales::Adapter.expects(:use).with(:registered)
|
28
|
+
Gonzales.configure do |config|
|
29
|
+
config.adapter = :registered
|
30
|
+
end
|
31
|
+
end
|
32
|
+
should 'include adapter as accessor' do
|
33
|
+
Gonzales::Adapter.expects(:use).with(:registered)
|
34
|
+
Gonzales.adapter = :registered
|
35
|
+
end
|
14
36
|
end
|
37
|
+
|
15
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gonzales
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -91,15 +91,18 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
|
-
description: ! " Gonzales makes the best out of FactoryGirl, by allowing
|
95
|
-
the factories into the database before the tests starts. \n You just
|
96
|
-
one new keyword - 'speedy'.\n"
|
94
|
+
description: ! " Gonzales makes the best out of factory_girl (FactoryGirl), by allowing
|
95
|
+
you to load the factories into the database before the tests starts. \n You just
|
96
|
+
have to learn one new keyword - 'speedy'.\n"
|
97
97
|
email:
|
98
98
|
- knut.stenmark@gmail.com
|
99
99
|
executables: []
|
100
100
|
extensions: []
|
101
101
|
extra_rdoc_files: []
|
102
102
|
files:
|
103
|
+
- lib/gonzales/adapter/registered.rb
|
104
|
+
- lib/gonzales/adapter/unregistered.rb
|
105
|
+
- lib/gonzales/adapter.rb
|
103
106
|
- lib/gonzales/collection.rb
|
104
107
|
- lib/gonzales/factories.rb
|
105
108
|
- lib/gonzales/factory_girl/definition_proxy.rb
|
@@ -159,6 +162,9 @@ files:
|
|
159
162
|
- test/dummy/test/unit/wardrobe_test.rb
|
160
163
|
- test/dummy/tmp/speedy.yml
|
161
164
|
- test/test_helper.rb
|
165
|
+
- test/unit/gonzales/adapter/registered_test.rb
|
166
|
+
- test/unit/gonzales/adapter/unregistered_test.rb
|
167
|
+
- test/unit/gonzales/adapter_test.rb
|
162
168
|
- test/unit/gonzales/collection_test.rb
|
163
169
|
- test/unit/gonzales/factories_test.rb
|
164
170
|
- test/unit/gonzales/factory_girl/definition_proxy_test.rb
|
@@ -178,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
178
184
|
version: '0'
|
179
185
|
segments:
|
180
186
|
- 0
|
181
|
-
hash:
|
187
|
+
hash: -4539270136119256787
|
182
188
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
189
|
none: false
|
184
190
|
requirements:
|
@@ -187,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
193
|
version: '0'
|
188
194
|
segments:
|
189
195
|
- 0
|
190
|
-
hash:
|
196
|
+
hash: -4539270136119256787
|
191
197
|
requirements: []
|
192
198
|
rubyforge_project:
|
193
199
|
rubygems_version: 1.8.24
|
@@ -244,6 +250,9 @@ test_files:
|
|
244
250
|
- test/dummy/test/unit/wardrobe_test.rb
|
245
251
|
- test/dummy/tmp/speedy.yml
|
246
252
|
- test/test_helper.rb
|
253
|
+
- test/unit/gonzales/adapter/registered_test.rb
|
254
|
+
- test/unit/gonzales/adapter/unregistered_test.rb
|
255
|
+
- test/unit/gonzales/adapter_test.rb
|
247
256
|
- test/unit/gonzales/collection_test.rb
|
248
257
|
- test/unit/gonzales/factories_test.rb
|
249
258
|
- test/unit/gonzales/factory_girl/definition_proxy_test.rb
|