fabrication 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -1
- data/lib/fabrication.rb +2 -0
- data/lib/fabrication/errors.rb +2 -0
- data/lib/fabrication/version.rb +1 -1
- data/spec/fabrication_spec.rb +31 -4
- data/spec/spec_helper.rb +1 -0
- metadata +3 -3
data/README.markdown
CHANGED
@@ -52,4 +52,4 @@ So you already have a company fabricator, but you need one that specifically gen
|
|
52
52
|
type "LLC"
|
53
53
|
end
|
54
54
|
|
55
|
-
Setting the :from option will inherit the class and all the attributes from the named Fabricator.
|
55
|
+
Setting the :from option will inherit the class and all the attributes from the named Fabricator. Even if you haven't defined a :company Fabricator yet, it will still work as long as it references an actual class name.
|
data/lib/fabrication.rb
CHANGED
@@ -12,6 +12,7 @@ module Fabrication
|
|
12
12
|
class << self
|
13
13
|
|
14
14
|
def schematic(name, options, &block)
|
15
|
+
raise DuplicateFabricatorError if fabricators.has_key?(name)
|
15
16
|
parent = fabricators[options[:from]]
|
16
17
|
if parent
|
17
18
|
class_name = parent.class_name
|
@@ -53,6 +54,7 @@ module Fabrication
|
|
53
54
|
|
54
55
|
private
|
55
56
|
|
57
|
+
@@fabricators = nil
|
56
58
|
def fabricators
|
57
59
|
@@fabricators ||= {}
|
58
60
|
end
|
data/lib/fabrication/errors.rb
CHANGED
data/lib/fabrication/version.rb
CHANGED
data/spec/fabrication_spec.rb
CHANGED
@@ -117,7 +117,7 @@ describe Fabrication do
|
|
117
117
|
before(:all) { TestMigration.up }
|
118
118
|
after(:all) { TestMigration.down }
|
119
119
|
|
120
|
-
before do
|
120
|
+
before(:all) do
|
121
121
|
Fabricator(:company) do
|
122
122
|
name { Faker::Company.name }
|
123
123
|
divisions(:force => true, :count => 4) { Fabricate(:division) }
|
@@ -151,13 +151,15 @@ describe Fabrication do
|
|
151
151
|
|
152
152
|
context 'with a mongoid document' do
|
153
153
|
|
154
|
-
|
154
|
+
before(:all) do
|
155
155
|
Fabricator(:author) do
|
156
156
|
name "George Orwell"
|
157
157
|
books(:count => 4) { |author, i| "book title #{i}" }
|
158
|
-
end
|
158
|
+
end
|
159
159
|
end
|
160
160
|
|
161
|
+
let(:author) { Fabricate(:author) }
|
162
|
+
|
161
163
|
it "sets the author name" do
|
162
164
|
author.name.should == "George Orwell"
|
163
165
|
end
|
@@ -197,7 +199,6 @@ describe Fabrication do
|
|
197
199
|
context 'and a class name as a parent' do
|
198
200
|
|
199
201
|
before(:all) do
|
200
|
-
Fabrication.clear_definitions
|
201
202
|
Fabricator(:hemingway, :from => :author) do
|
202
203
|
name 'Ernest Hemingway'
|
203
204
|
end
|
@@ -230,4 +231,30 @@ describe Fabrication do
|
|
230
231
|
|
231
232
|
end
|
232
233
|
|
234
|
+
context 'when defining a fabricator twice' do
|
235
|
+
|
236
|
+
before(:all) do
|
237
|
+
Fabricator(:author) {}
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'throws an error' do
|
241
|
+
lambda { Fabricator(:author) {} }.should raise_error(Fabrication::DuplicateFabricatorError)
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
context 'when generating from a non-existant fabricator' do
|
247
|
+
|
248
|
+
it 'throws an error' do
|
249
|
+
lambda { Fabricate(:author) }.should raise_error(Fabrication::UnknownFabricatorError)
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
254
|
+
context 'defining a fabricator without a block' do
|
255
|
+
|
256
|
+
it 'works fine'
|
257
|
+
|
258
|
+
end
|
259
|
+
|
233
260
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fabrication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Paul Elliott
|