fluent_fixtures 0.4.0 → 0.5.0.pre.20170515170202
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/History.md +8 -1
- data/lib/fluent_fixtures/collection.rb +1 -0
- data/lib/fluent_fixtures/dsl.rb +7 -2
- data/lib/fluent_fixtures/factory.rb +24 -13
- data/lib/fluent_fixtures.rb +2 -2
- data/spec/fluent_fixtures/collection_spec.rb +1 -0
- data/spec/fluent_fixtures/dsl_spec.rb +11 -0
- data/spec/fluent_fixtures/factory_spec.rb +44 -1
- metadata +10 -36
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ebb817e0b2fc99aa884784742e8bb0deb77befcdaecf5683a08e8d696edb5192
|
4
|
+
data.tar.gz: 30eafd70938cfe9d9677b4f7a7847e8b00d8666eafdbbe9927dac1a568a1c120
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87590528c3dfefb068c667397e9edf77df914789147a7e52bd162b0622637c0968d28ec70f43ee0b3a3fdd5baffd197e2d071383c68874197ba9cf1a6a420de1
|
7
|
+
data.tar.gz: 5704dc5782a7a78da0c17c1d35e86d24fc1b0ce0010a28f8771a743ba54c2ae8fda1a7428dca6ef2814afecef929faf99953d1fe36cc6a8195769b02b32613b0
|
data/History.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
+
## v0.5.0 [2017-05-12] Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
Enhancements:
|
4
|
+
|
5
|
+
- Add a `presave` option for decorators that need a saved instance.
|
6
|
+
|
7
|
+
|
1
8
|
## v0.4.0 [2016-12-13] Michael Granger <ged@FaerieMUD.org>
|
2
9
|
|
3
|
-
|
10
|
+
Enhancements:
|
4
11
|
|
5
12
|
- Added `depends_on` to the fixture DSL.
|
6
13
|
|
@@ -79,6 +79,7 @@ module FluentFixtures::Collection
|
|
79
79
|
|
80
80
|
fixture_mod.extend( FluentFixtures::DSL )
|
81
81
|
fixture_mod.instance_variable_set( :@decorators, {} )
|
82
|
+
fixture_mod.instance_variable_set( :@decorator_options, {} )
|
82
83
|
fixture_mod.instance_variable_set( :@fixtured_class, nil )
|
83
84
|
fixture_mod.instance_variable_set( :@base_fixture, nil )
|
84
85
|
|
data/lib/fluent_fixtures/dsl.rb
CHANGED
@@ -14,6 +14,9 @@ module FluentFixtures::DSL
|
|
14
14
|
# The Hash of decorators declared for this fixture module
|
15
15
|
attr_reader :decorators
|
16
16
|
|
17
|
+
# The Hash of options hashes for declared decorators
|
18
|
+
attr_reader :decorator_options
|
19
|
+
|
17
20
|
##
|
18
21
|
# The name of the base fixture for the fixture module as a Symbol
|
19
22
|
attr_accessor :base_fixture
|
@@ -57,8 +60,10 @@ module FluentFixtures::DSL
|
|
57
60
|
|
58
61
|
### Declare a decorator for the fixture with the specified +name+ that will use the
|
59
62
|
### given +block+.
|
60
|
-
def decorator( name, &block )
|
61
|
-
|
63
|
+
def decorator( name, **options, &block )
|
64
|
+
name = name.to_sym
|
65
|
+
self.decorators[ name ] = block
|
66
|
+
self.decorator_options[ name ] = options
|
62
67
|
end
|
63
68
|
|
64
69
|
|
@@ -75,7 +75,7 @@ class FluentFixtures::Factory
|
|
75
75
|
if !decorator_name
|
76
76
|
self.apply_inline_decorator( instance, block )
|
77
77
|
elsif self.fixture_module.decorators.key?( decorator_name )
|
78
|
-
self.apply_named_decorator( instance, decorator_args, decorator_name )
|
78
|
+
instance = self.apply_named_decorator( instance, decorator_args, decorator_name )
|
79
79
|
else
|
80
80
|
self.apply_method_decorator( instance, decorator_args, decorator_name, block )
|
81
81
|
end
|
@@ -105,13 +105,7 @@ class FluentFixtures::Factory
|
|
105
105
|
def create( args={}, &block )
|
106
106
|
obj = self.with_transaction do
|
107
107
|
obj = self.instance( args, &block )
|
108
|
-
obj = self.
|
109
|
-
self.fixture_module.respond_to?( :call_before_saving )
|
110
|
-
|
111
|
-
self.try_to_save( obj )
|
112
|
-
|
113
|
-
obj = self.fixture_module.call_after_saving( obj ) if
|
114
|
-
self.fixture_module.respond_to?( :call_after_saving )
|
108
|
+
obj = self.try_to_save( obj )
|
115
109
|
obj
|
116
110
|
end
|
117
111
|
|
@@ -186,9 +180,14 @@ class FluentFixtures::Factory
|
|
186
180
|
### +decorator_name+ to the specified +instance+.
|
187
181
|
def apply_named_decorator( instance, args, decorator_name )
|
188
182
|
decorator_block = self.fixture_module.decorators[ decorator_name ]
|
189
|
-
self.
|
190
|
-
|
183
|
+
decorator_options = self.fixture_module.decorator_options[ decorator_name ] || {}
|
184
|
+
self.log.debug "Applying decorator %p (%p - %p) to a %p with args: %p" %
|
185
|
+
[ decorator_name, decorator_block, decorator_options, instance.class, args ]
|
186
|
+
|
187
|
+
instance = self.try_to_save( instance ) if decorator_options[:presave]
|
191
188
|
instance.instance_exec( *args, &decorator_block )
|
189
|
+
|
190
|
+
return instance
|
192
191
|
end
|
193
192
|
|
194
193
|
|
@@ -222,11 +221,23 @@ class FluentFixtures::Factory
|
|
222
221
|
### Try various methods for saving the given +object+, logging a warning if it doesn't
|
223
222
|
### respond to any of them.
|
224
223
|
def try_to_save( object )
|
225
|
-
|
226
|
-
|
224
|
+
object = self.fixture_module.call_before_saving( object ) if
|
225
|
+
self.fixture_module.respond_to?( :call_before_saving )
|
226
|
+
|
227
|
+
save_method = CREATE_METHODS.find do |methodname|
|
228
|
+
object.respond_to?( methodname )
|
227
229
|
end
|
228
230
|
|
229
|
-
|
231
|
+
if save_method
|
232
|
+
object.public_send( save_method )
|
233
|
+
else
|
234
|
+
self.log.warn "create: don't know how to save %p" % [ object ]
|
235
|
+
end
|
236
|
+
|
237
|
+
object = self.fixture_module.call_after_saving( object ) if
|
238
|
+
self.fixture_module.respond_to?( :call_after_saving )
|
239
|
+
|
240
|
+
return object
|
230
241
|
end
|
231
242
|
|
232
243
|
|
data/lib/fluent_fixtures.rb
CHANGED
@@ -11,10 +11,10 @@ module FluentFixtures
|
|
11
11
|
|
12
12
|
|
13
13
|
# Package version
|
14
|
-
VERSION = '0.
|
14
|
+
VERSION = '0.5.0'
|
15
15
|
|
16
16
|
# Version control revision
|
17
|
-
REVISION = %q$Revision:
|
17
|
+
REVISION = %q$Revision: ed67198925b5 $
|
18
18
|
|
19
19
|
|
20
20
|
# Loggability API -- set up a named logger
|
@@ -86,6 +86,17 @@ describe FluentFixtures::DSL do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
|
89
|
+
it "can indicate that an object needs to be saved before a decorator is applied" do
|
90
|
+
with_associated_object_block = Proc.new {|obj| self.associated_object = obj }
|
91
|
+
fixture_module.decorator( :with_associated_object, presave: true, &with_associated_object_block )
|
92
|
+
|
93
|
+
expect( fixture_module ).to have_decorator( :with_associated_object )
|
94
|
+
|
95
|
+
expect( fixture_module.decorators[:with_associated_object] ).to be( with_associated_object_block )
|
96
|
+
expect( fixture_module.decorator_options[:with_associated_object] ).to include( presave: true )
|
97
|
+
end
|
98
|
+
|
99
|
+
|
89
100
|
it "can declare an alias for an already-declared decorator" do
|
90
101
|
fixture_module.decorator( :with_no_email ) { self.email = nil }
|
91
102
|
fixture_module.alias_decorator( :emailless, :with_no_email )
|
@@ -15,14 +15,20 @@ describe FluentFixtures::Factory do
|
|
15
15
|
def initialize( params={} )
|
16
16
|
@saved = false
|
17
17
|
@deleted = false
|
18
|
+
@roles = []
|
19
|
+
@copied = false
|
18
20
|
params.each do |name, value|
|
19
21
|
self.send( "#{name}=", value )
|
20
22
|
end
|
21
23
|
yield if block_given?
|
22
24
|
end
|
23
|
-
|
25
|
+
def initialize_copy( _original )
|
26
|
+
@copied = true
|
27
|
+
end
|
28
|
+
attr_accessor :name, :login, :email, :roles
|
24
29
|
def save; @saved = true; end
|
25
30
|
def saved?; @saved; end
|
31
|
+
def copied?; @copied; end
|
26
32
|
def bizarroify
|
27
33
|
self.name = "Bizarro #{self.name}"
|
28
34
|
self.email = "bizarro+#{self.email}"
|
@@ -31,6 +37,10 @@ describe FluentFixtures::Factory do
|
|
31
37
|
end
|
32
38
|
def delete; @deleted = true; end
|
33
39
|
def deleted?; @deleted; end
|
40
|
+
def add_role( role )
|
41
|
+
raise "not saved" unless self.saved?
|
42
|
+
self.roles << role
|
43
|
+
end
|
34
44
|
end
|
35
45
|
end
|
36
46
|
|
@@ -266,6 +276,39 @@ describe FluentFixtures::Factory do
|
|
266
276
|
end
|
267
277
|
|
268
278
|
|
279
|
+
it "supports decorators that save the object before running" do
|
280
|
+
fixture_module.decorator( :with_role, presave: true ) do |role|
|
281
|
+
self.add_role( role )
|
282
|
+
end
|
283
|
+
|
284
|
+
object = factory.with_role( 'admin' ).instance
|
285
|
+
|
286
|
+
expect( object ).to be_saved
|
287
|
+
expect( object.roles ).to include( 'admin' )
|
288
|
+
end
|
289
|
+
|
290
|
+
|
291
|
+
it "calls pre- and post-save hooks for decorators with presaving" do
|
292
|
+
fixture_module.decorator( :with_role, presave: true ) do |role|
|
293
|
+
self.add_role( role )
|
294
|
+
end
|
295
|
+
def fixture_module.call_before_saving( instance )
|
296
|
+
instance.dup
|
297
|
+
end
|
298
|
+
def fixture_module.call_after_saving( instance )
|
299
|
+
instance.delete
|
300
|
+
instance
|
301
|
+
end
|
302
|
+
|
303
|
+
object = factory.with_role( 'admin' ).instance
|
304
|
+
|
305
|
+
expect( object ).to be_saved
|
306
|
+
expect( object ).to be_copied
|
307
|
+
expect( object ).to be_deleted
|
308
|
+
expect( object.roles ).to include( 'admin' )
|
309
|
+
end
|
310
|
+
|
311
|
+
|
269
312
|
it "allows ad-hoc decorators declared as inline blocks" do
|
270
313
|
counter = 0
|
271
314
|
result = factory.decorated_with do |obj|
|
metadata
CHANGED
@@ -1,41 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent_fixtures
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0.pre.20170515170202
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Granger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain:
|
11
|
-
-
|
12
|
-
|
13
|
-
MIIEbDCCAtSgAwIBAgIBATANBgkqhkiG9w0BAQsFADA+MQwwCgYDVQQDDANnZWQx
|
14
|
-
GTAXBgoJkiaJk/IsZAEZFglGYWVyaWVNVUQxEzARBgoJkiaJk/IsZAEZFgNvcmcw
|
15
|
-
HhcNMTYwODIwMTgxNzQyWhcNMTcwODIwMTgxNzQyWjA+MQwwCgYDVQQDDANnZWQx
|
16
|
-
GTAXBgoJkiaJk/IsZAEZFglGYWVyaWVNVUQxEzARBgoJkiaJk/IsZAEZFgNvcmcw
|
17
|
-
ggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQC/JWGRHO+USzR97vXjkFgt
|
18
|
-
83qeNf2KHkcvrRTSnR64i6um/ziin0I0oX23H7VYrDJC9A/uoUa5nGRJS5Zw/+wW
|
19
|
-
ENcvWVZS4iUzi4dsYJGY6yEOsXh2CcF46+QevV8iE+UmbkU75V7Dy1JCaUOyizEt
|
20
|
-
TH5UHsOtUU7k9TYARt/TgYZKuaoAMZZd5qyVqhF1vV+7/Qzmp89NGflXf2xYP26a
|
21
|
-
4MAX2qqKX/FKXqmFO+AGsbwYTEds1mksBF3fGsFgsQWxftG8GfZQ9+Cyu2+l1eOw
|
22
|
-
cZ+lPcg834G9DrqW2zhqUoLr1MTly4pqxYGb7XoDhoR7dd1kFE2a067+DzWC/ADt
|
23
|
-
+QkcqWUm5oh1fN0eqr7NsZlVJDulFgdiiYPQiIN7UNsii4Wc9aZqBoGcYfBeQNPZ
|
24
|
-
soo/6za/bWajOKUmDhpqvaiRv9EDpVLzuj53uDoukMMwxCMfgb04+ckQ0t2G7wqc
|
25
|
-
/D+K9JW9DDs3Yjgv9k4h7YMhW5gftosd+NkNC/+Y2CkCAwEAAaN1MHMwCQYDVR0T
|
26
|
-
BAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFHKN/nkRusdqCJEuq3lgB3fJvyTg
|
27
|
-
MBwGA1UdEQQVMBOBEWdlZEBGYWVyaWVNVUQub3JnMBwGA1UdEgQVMBOBEWdlZEBG
|
28
|
-
YWVyaWVNVUQub3JnMA0GCSqGSIb3DQEBCwUAA4IBgQAPJzKiT0zBU7kpqe0aS2qb
|
29
|
-
FI0PJ4y5I8buU4IZGUD5NEt/N7pZNfOyBxkrZkXhS44Fp+xwBH5ebLbq/WY78Bqd
|
30
|
-
db0z6ZgW4LMYMpWFfbXsRbd9TU2f52L8oMAhxOvF7Of5qJMVWuFQ8FPagk2iHrdH
|
31
|
-
inYLQagqAF6goWTXgAJCdPd6SNeeSNqA6vlY7CV1Jh5kfNJJ6xu/CVij1GzCLu/5
|
32
|
-
DMOr26DBv+qLJRRC/2h34uX71q5QgeOyxvMg+7V3u/Q06DXyQ2VgeeqiwDFFpEH0
|
33
|
-
PFkdPO6ZqbTRcLfNH7mFgCBJjsfSjJrn0sPBlYyOXgCoByfZnZyrIMH/UY+lgQqS
|
34
|
-
6Von1VDsfQm0eJh5zYZD64ZF86phSR7mUX3mXItwH04HrZwkWpvgd871DZVR3i1n
|
35
|
-
w8aNA5re5+Rt/Vvjxj5AcEnZnZiz5x959NaddQocX32Z1unHw44pzRNUur1GInfW
|
36
|
-
p4vpx2kUSFSAGjtCbDGTNV2AH8w9OU4xEmNz8c5lyoA=
|
37
|
-
-----END CERTIFICATE-----
|
38
|
-
date: 2016-12-14 00:00:00.000000000 Z
|
11
|
+
- certs/ged.pem
|
12
|
+
date: 2017-05-16 00:00:00.000000000 Z
|
39
13
|
dependencies:
|
40
14
|
- !ruby/object:Gem::Dependency
|
41
15
|
name: loggability
|
@@ -85,14 +59,14 @@ dependencies:
|
|
85
59
|
requirements:
|
86
60
|
- - "~>"
|
87
61
|
- !ruby/object:Gem::Version
|
88
|
-
version: '0.
|
62
|
+
version: '0.9'
|
89
63
|
type: :development
|
90
64
|
prerelease: false
|
91
65
|
version_requirements: !ruby/object:Gem::Requirement
|
92
66
|
requirements:
|
93
67
|
- - "~>"
|
94
68
|
- !ruby/object:Gem::Version
|
95
|
-
version: '0.
|
69
|
+
version: '0.9'
|
96
70
|
- !ruby/object:Gem::Dependency
|
97
71
|
name: hoe-highline
|
98
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -169,14 +143,14 @@ dependencies:
|
|
169
143
|
requirements:
|
170
144
|
- - "~>"
|
171
145
|
- !ruby/object:Gem::Version
|
172
|
-
version: '3.
|
146
|
+
version: '3.16'
|
173
147
|
type: :development
|
174
148
|
prerelease: false
|
175
149
|
version_requirements: !ruby/object:Gem::Requirement
|
176
150
|
requirements:
|
177
151
|
- - "~>"
|
178
152
|
- !ruby/object:Gem::Version
|
179
|
-
version: '3.
|
153
|
+
version: '3.16'
|
180
154
|
description: |-
|
181
155
|
FluentFixtures is a toolkit for building testing objects with a fluent interface.
|
182
156
|
|
@@ -232,12 +206,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
232
206
|
version: 2.2.0
|
233
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
234
208
|
requirements:
|
235
|
-
- - "
|
209
|
+
- - ">"
|
236
210
|
- !ruby/object:Gem::Version
|
237
|
-
version:
|
211
|
+
version: 1.3.1
|
238
212
|
requirements: []
|
239
213
|
rubyforge_project:
|
240
|
-
rubygems_version: 2.6.
|
214
|
+
rubygems_version: 2.6.12
|
241
215
|
signing_key:
|
242
216
|
specification_version: 4
|
243
217
|
summary: FluentFixtures is a toolkit for building testing objects with a fluent interface
|
checksums.yaml.gz.sig
DELETED
Binary file
|
data.tar.gz.sig
DELETED
Binary file
|
metadata.gz.sig
DELETED
Binary file
|