fluent_fixtures 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/History.md +8 -0
- data/lib/fluent_fixtures/factory.rb +14 -9
- data/lib/fluent_fixtures.rb +2 -2
- data/spec/fluent_fixtures/factory_spec.rb +48 -0
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdc1f6ce5b49218750ef162d0f73ae7b9150be8b
|
4
|
+
data.tar.gz: 9c6edc393f5b5966ceeaf4ce91a32dbc1d92b5ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10965916800b2b08931ffceff65b124de14e570d262851ba8d7c9e5942142cc8b9270a09dbbe22e90f037e036018486297e7902f7869217f720a37f1a3f0522b
|
7
|
+
data.tar.gz: dce961bbe9d5eaae9e2582bde164e9bc8d8c98dea9905fa270e9ee649237d4ae3e4d6258827f2c3d3109cd4c597a496b4f3d8e11d1547634b5fa484f1889c0da
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/History.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## v0.2.0 [2016-10-28] Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
Bugfixes:
|
4
|
+
- Fix the way #create and #instance handle their arguments. Arguments are
|
5
|
+
now iterated over and used to set attributes instead of just being
|
6
|
+
discarded.
|
7
|
+
|
8
|
+
|
1
9
|
## v0.1.0 [2016-10-28] Michael Granger <ged@FaerieMUD.org>
|
2
10
|
|
3
11
|
New feature:
|
@@ -62,29 +62,34 @@ class FluentFixtures::Factory
|
|
62
62
|
|
63
63
|
### Create an instance, apply declared decorators in order, and return the resulting
|
64
64
|
### object.
|
65
|
-
def instance(
|
65
|
+
def instance( args={}, &block )
|
66
66
|
instance = self.fixture_module.
|
67
67
|
fixtured_instance( *self.constructor_args, &self.constructor_block )
|
68
68
|
|
69
|
-
self.decorators.each do |decorator_name,
|
70
|
-
# :TODO: Reify other fixtures in `
|
69
|
+
self.decorators.each do |decorator_name, decorator_args, block|
|
70
|
+
# :TODO: Reify other fixtures in `decorator_args` here?
|
71
71
|
if !decorator_name
|
72
72
|
self.apply_inline_decorator( instance, block )
|
73
73
|
elsif self.fixture_module.decorators.key?( decorator_name )
|
74
|
-
self.apply_named_decorator( instance,
|
74
|
+
self.apply_named_decorator( instance, decorator_args, decorator_name )
|
75
75
|
else
|
76
|
-
self.apply_method_decorator( instance,
|
76
|
+
self.apply_method_decorator( instance, decorator_args, decorator_name, block )
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
args.each_pair do |attrname, value|
|
81
|
+
# :TODO: Reify the `value` if it responds to #create?
|
82
|
+
instance.public_send( "#{attrname}=", value )
|
83
|
+
end
|
84
|
+
|
80
85
|
# If the factory was called with a block, use it as a final decorator before
|
81
86
|
# returning it.
|
82
87
|
if block
|
83
88
|
self.log.debug "Applying inline decorator %p" % [ block ]
|
84
89
|
if block.arity.zero?
|
85
|
-
instance.instance_exec(
|
90
|
+
instance.instance_exec( &block )
|
86
91
|
else
|
87
|
-
block.call( instance
|
92
|
+
block.call( instance )
|
88
93
|
end
|
89
94
|
end
|
90
95
|
|
@@ -93,9 +98,9 @@ class FluentFixtures::Factory
|
|
93
98
|
|
94
99
|
|
95
100
|
### Return a saved #instance of the fixtured object.
|
96
|
-
def create(
|
101
|
+
def create( args={}, &block )
|
97
102
|
obj = self.with_transaction do
|
98
|
-
obj = self.instance(
|
103
|
+
obj = self.instance( args, &block )
|
99
104
|
obj = self.fixture_module.call_before_saving( obj ) if
|
100
105
|
self.fixture_module.respond_to?( :call_before_saving )
|
101
106
|
|
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.2.0'
|
15
15
|
|
16
16
|
# Version control revision
|
17
|
-
REVISION = %q$Revision:
|
17
|
+
REVISION = %q$Revision: bde330b02946 $
|
18
18
|
|
19
19
|
|
20
20
|
# Loggability API -- set up a named logger
|
@@ -110,6 +110,36 @@ describe FluentFixtures::Factory do
|
|
110
110
|
end
|
111
111
|
|
112
112
|
|
113
|
+
it "sets attributes on the object when #instance is passed hash arguments" do
|
114
|
+
object = factory.instance( name: 'Dan', login: 'danp', email: 'danp@example.com' )
|
115
|
+
|
116
|
+
expect( object ).to be_a( fixtured_class )
|
117
|
+
expect( object.name ).to eq( 'Dan' )
|
118
|
+
expect( object.login ).to eq( 'danp' )
|
119
|
+
expect( object.email ).to eq( 'danp@example.com' )
|
120
|
+
expect( object ).to_not be_saved
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
it "sets attributes on the object when #instance is passed a Hash" do
|
125
|
+
values = { name: 'Dan', login: 'danp', email: 'danp@example.com' }
|
126
|
+
object = factory.instance( values )
|
127
|
+
|
128
|
+
expect( object ).to be_a( fixtured_class )
|
129
|
+
expect( object.name ).to eq( 'Dan' )
|
130
|
+
expect( object.login ).to eq( 'danp' )
|
131
|
+
expect( object.email ).to eq( 'danp@example.com' )
|
132
|
+
expect( object ).to_not be_saved
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
it "raises an argument when #instance is passed something that doesn't #each_pair" do
|
137
|
+
expect {
|
138
|
+
factory.instance( [:missiles, :weasels] )
|
139
|
+
}.to raise_error( NoMethodError, /each_pair/i )
|
140
|
+
end
|
141
|
+
|
142
|
+
|
113
143
|
it "executes a block passed to #instance in the context of the new object if it doesn't declare arguments" do
|
114
144
|
object = factory.instance do
|
115
145
|
self.name = 'Dan'
|
@@ -140,6 +170,24 @@ describe FluentFixtures::Factory do
|
|
140
170
|
end
|
141
171
|
|
142
172
|
|
173
|
+
it "sets attributes before saving when #create is passed a Hash" do
|
174
|
+
object = factory.create( name: 'Jenn', login: 'jennnn', email: 'jennnn@allthejennifers.org' )
|
175
|
+
|
176
|
+
expect( object ).to be_a( fixtured_class )
|
177
|
+
expect( object.name ).to eq( 'Jenn' )
|
178
|
+
expect( object.login ).to eq( 'jennnn' )
|
179
|
+
expect( object.email ).to eq( 'jennnn@allthejennifers.org' )
|
180
|
+
expect( object ).to be_saved
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
it "raises an argument when #create is passed something that doesn't #each_pair" do
|
185
|
+
expect {
|
186
|
+
factory.create( [:chocolate, :darkroom] )
|
187
|
+
}.to raise_error( NoMethodError, /each_pair/i )
|
188
|
+
end
|
189
|
+
|
190
|
+
|
143
191
|
it "executes a block passed to #create in the context of the new object" do
|
144
192
|
object = factory.create do
|
145
193
|
self.name = 'Jenn'
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|