test_dummy 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +140 -15
- data/VERSION +1 -1
- data/lib/test_dummy.rb +85 -68
- data/lib/test_dummy/railtie.rb +2 -0
- data/lib/test_dummy/support.rb +40 -0
- data/test/db/migrate/0002_create_accounts.rb +3 -0
- data/test/db/migrate/0003_create_bills.rb +1 -0
- data/test/dummy/account.rb +14 -0
- data/test/dummy/bill.rb +7 -1
- data/test/dummy/item.rb +6 -0
- data/test/helper.rb +1 -1
- data/test/models/bill.rb +6 -0
- data/test/unit/test_bill.rb +18 -0
- data/test_dummy.gemspec +4 -3
- metadata +4 -3
data/README.md
CHANGED
@@ -1,37 +1,153 @@
|
|
1
1
|
# test_dummy
|
2
2
|
|
3
3
|
Test Dummy is an easy fake data generator library with the ability to create
|
4
|
-
fake models or
|
4
|
+
individual fake models or complex, inter-linked sets of models on-demand.
|
5
|
+
|
6
|
+
ActiveRecord models, the default for Ruby on Rails, is the only type supported
|
7
|
+
at this time.
|
8
|
+
|
9
|
+
The generators produced by Test Dummy can simplify automated testing by making
|
10
|
+
it possible to have test records created in a known-good state every time
|
11
|
+
instead of depending on fixture files which may contain irregularities.
|
5
12
|
|
6
13
|
After installing the gem, methods to declare how to fake data are made
|
7
14
|
available within ActiveRecord-derived models. There are several ways to
|
8
|
-
declare how to dummy something
|
15
|
+
declare how to dummy something.
|
16
|
+
|
17
|
+
## Getting Started
|
18
|
+
|
19
|
+
### Add Gem Dependency
|
20
|
+
|
21
|
+
To add Test Dummy functionality to an application, add the dependency to the
|
22
|
+
`Gemfile`:
|
23
|
+
|
24
|
+
gem 'test_dummy'
|
25
|
+
|
26
|
+
Most application frameworks provide some kind of test helper foundation,
|
27
|
+
like `test/test_helper.rb` in Rails or `test/helper.rb` in many gem templates.
|
28
|
+
|
29
|
+
Include the following line in there at an appropriate location:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'test_dummy'
|
33
|
+
```
|
34
|
+
|
35
|
+
This is usually inserted after all the foundational dependencies are taken
|
36
|
+
care of, so typically later in the file.
|
37
|
+
|
38
|
+
### Dummy Attributes
|
39
|
+
|
40
|
+
If a model has no validation requirements, it will already have some basic
|
41
|
+
dummy functionality. Models can be created simply:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
dummy_example = ExampleModel.create_dummy
|
45
|
+
```
|
46
|
+
|
47
|
+
Like the default `create` method, `create_dummy` also takes arguments that
|
48
|
+
can be used to supply pre-defined attributes:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
named_example = ExampleModel.create_dummy(:name => 'Example')
|
52
|
+
```
|
53
|
+
|
54
|
+
Any attribute which has validation requirements will need to have a generator
|
55
|
+
or the models emitted by `create_dummy` cannot be saved. In this example,
|
56
|
+
if `name` was a required field, this would have to be populated by TestDummy.
|
57
|
+
|
58
|
+
For convenience, you can add this directly to the model in question:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
class ExampleModel < ActiveRecord::Base
|
62
|
+
dummy :name do
|
63
|
+
'Test Name'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
```
|
9
67
|
|
68
|
+
The `dummy` definition defines an operation that will occur if the attribute
|
69
|
+
name is not specified. In this case, if `name` is not supplied as an argument
|
70
|
+
to `create_dummy` then it will be filled in. These operations are attempted in
|
71
|
+
the order they are defined.
|
72
|
+
|
73
|
+
Keep in mind it is possible to create invalid model instances if the parameters
|
74
|
+
sent in would result in a validation error. For instance:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
broken_example = ExampleModel.create_dummy(:name => nil)
|
78
|
+
|
79
|
+
broken_example.valid?
|
80
|
+
# => false
|
81
|
+
```
|
82
|
+
|
83
|
+
The `dummy` function can be used in several ways to handle a variety of
|
84
|
+
situations. The default usage is simple:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
dummy :name do
|
88
|
+
'Fake Name'
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
In this case, whatever is returned by the block is inserted into the listed
|
93
|
+
attribute if that attribute was not speficied in the options.
|
94
|
+
|
95
|
+
It is possible to dummy several attributes at the same time:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
dummy :password, :password_confirmation do
|
99
|
+
'testpassword'
|
100
|
+
end
|
10
101
|
```
|
11
|
-
|
12
|
-
|
102
|
+
This will be applied to any of the listed attributes that have not been
|
103
|
+
specified in the options.
|
104
|
+
|
105
|
+
If access to the model that's being constructed is required, it is passed in
|
106
|
+
as the first argument to the block:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
dummy :description do |example|
|
110
|
+
"Example with a name of length %d" % example.name.length
|
111
|
+
end
|
112
|
+
```
|
113
|
+
The model itself can be manipulated in any way that's required, such as setting
|
114
|
+
other fields, calling methods, and so forth, but it's important to be careful
|
115
|
+
here as the model at this point is incomplete if there are other attributes
|
116
|
+
which have yet to have had their `dummy` generator called.
|
117
|
+
|
118
|
+
### Separate Definition File
|
119
|
+
|
120
|
+
If including the attribute dummy generators in the main model file produces
|
121
|
+
too much clutter, they can be relocated to an alternate location. This has the
|
122
|
+
advantage in that they will only be loaded if a dummy operation is performed,
|
123
|
+
so a production application will not be affected by their presence.
|
124
|
+
|
125
|
+
An example model `app/models/example_model.rb` file looks like:
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
class ExampleModel < ActiveRecord::Base
|
13
129
|
dummy :name do
|
14
|
-
"
|
130
|
+
"Random Name \#%d" % rand(10e6)
|
15
131
|
end
|
16
132
|
|
17
|
-
# Pass a block that defines how to dummy several attributes
|
18
133
|
dummy :password, :password_confirmation do
|
19
134
|
'tester'
|
20
135
|
end
|
21
136
|
|
22
|
-
# Use one of the pre-defined helper methods to dummy this attribute
|
23
137
|
dummy :nickname, :use => :random_phonetic_string
|
24
138
|
end
|
25
139
|
```
|
26
140
|
|
27
|
-
|
28
|
-
|
29
|
-
|
141
|
+
To avoid cluttering up your models with lots of dummy-related code, this can
|
142
|
+
be stored in the `test/dummy` directory as a secondary file that's loaded as
|
143
|
+
required.
|
144
|
+
|
145
|
+
An example `test/dummy/example_model.rb` looks like this:
|
30
146
|
|
31
147
|
```ruby
|
32
|
-
|
148
|
+
class ExampleModel
|
33
149
|
dummy :name do
|
34
|
-
"
|
150
|
+
"Random Name \#%d" % rand(10e6)
|
35
151
|
end
|
36
152
|
|
37
153
|
dummy :password, :password_confirmation do
|
@@ -42,10 +158,19 @@ TestDummy.declare(MyModel) do
|
|
42
158
|
end
|
43
159
|
```
|
44
160
|
|
161
|
+
Note that, like any patch to an existing class, it is not strictly required to
|
162
|
+
re-declare the parent class.
|
163
|
+
|
45
164
|
The name of the test/dummy file should be the same as the main model
|
46
165
|
defined in app/models. For instance, app/models/my_model.rb would have a
|
47
|
-
corresponding test/dummy/my_model.rb
|
166
|
+
corresponding test/dummy/my_model.rb which is loaded on demand.
|
167
|
+
|
168
|
+
## Development and Testing
|
169
|
+
|
170
|
+
For simplicity and portability, SQLite3 is used as the database back-end for
|
171
|
+
testing. If any changes are made to existing migrations the temporary database
|
172
|
+
will need to be deleted before they're applied.
|
48
173
|
|
49
|
-
|
174
|
+
## Copyright
|
50
175
|
|
51
|
-
Copyright (c) 2010-
|
176
|
+
Copyright (c) 2010-2013 Scott Tadman, The Working Group Inc.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/test_dummy.rb
CHANGED
@@ -1,15 +1,25 @@
|
|
1
1
|
module TestDummy
|
2
|
+
# == Submodules ============================================================
|
3
|
+
|
4
|
+
autoload(:Helper, 'test_dummy/helper')
|
5
|
+
autoload(:Support, 'test_dummy/support')
|
6
|
+
autoload(:TestHelper, 'test_dummy/test_helper')
|
7
|
+
|
8
|
+
# == Rails Hook ============================================================
|
9
|
+
|
10
|
+
# Only load the Railtie if Rails is loaded.
|
2
11
|
if (defined?(Rails))
|
3
|
-
# Only load the Railtie if Rails is loaded.
|
4
12
|
require 'test_dummy/railtie'
|
5
13
|
end
|
6
14
|
|
15
|
+
# == Utility Classes ======================================================
|
16
|
+
|
17
|
+
# TestDummy::Exception is thrown instead of the master exception type.
|
7
18
|
class Exception < ::Exception
|
8
19
|
end
|
9
20
|
|
10
|
-
|
11
|
-
|
12
|
-
|
21
|
+
# == Module Methods =======================================================
|
22
|
+
|
13
23
|
# Returns the current path used to load dummy extensions into models, or
|
14
24
|
# nil if no path is currently defined. Defaults to "test/dummy" off of the
|
15
25
|
# Rails root if Rails is available.
|
@@ -23,6 +33,8 @@ module TestDummy
|
|
23
33
|
end
|
24
34
|
end
|
25
35
|
|
36
|
+
# Defines the dummy extension path. The full path to the destination should
|
37
|
+
# be specified.
|
26
38
|
def self.dummy_extensions_path=(value)
|
27
39
|
@dummy_extensions_path = value
|
28
40
|
end
|
@@ -35,47 +47,6 @@ module TestDummy
|
|
35
47
|
def self.declare(on_class, &block)
|
36
48
|
on_class.instance_eval(&block)
|
37
49
|
end
|
38
|
-
|
39
|
-
module Support
|
40
|
-
# Combines several sets of parameters together into a single set in order
|
41
|
-
# of lowest priority to highest priority. Supplied list can contain nil
|
42
|
-
# values which will be ignored. Returns a Hash with symbolized keys.
|
43
|
-
def self.combine_attributes(*sets)
|
44
|
-
combined_attributes = { }
|
45
|
-
|
46
|
-
# Apply sets in order they are listed
|
47
|
-
sets.compact.each do |set|
|
48
|
-
set.each do |k, v|
|
49
|
-
case (v)
|
50
|
-
when nil
|
51
|
-
# Ignore nil assignments
|
52
|
-
else
|
53
|
-
combined_attributes[k.to_sym] = v
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
combined_attributes
|
59
|
-
end
|
60
|
-
|
61
|
-
# This method is used to provide a unified interface to the otherwise
|
62
|
-
# irregular methods to discover information on assocations. Rails 3
|
63
|
-
# introduces a new method. Returns the reflected class and foreign key
|
64
|
-
# properties for a named attribute, or nil if no association could be found.
|
65
|
-
def self.reflection_properties(model_class, attribute)
|
66
|
-
if (model_class.respond_to?(:reflect_on_association) and reflection = model_class.reflect_on_association(attribute))
|
67
|
-
[
|
68
|
-
reflection.klass,
|
69
|
-
(reflection.respond_to?(:foreign_key) ? reflection.foreign_key : reflection.primary_key_name).to_sym
|
70
|
-
]
|
71
|
-
elsif (model_class.respond_to?(:association_reflection) and reflection = model_class.association_reflection(attribute))
|
72
|
-
[
|
73
|
-
reflection[:associated_class],
|
74
|
-
reflection[:key] || :"#{attribute.to_s.underscore}_id"
|
75
|
-
]
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
50
|
|
80
51
|
# Adds a mixin to the core Helper module
|
81
52
|
def self.add_module(new_module)
|
@@ -141,6 +112,7 @@ module TestDummy
|
|
141
112
|
|
142
113
|
@test_dummy ||= { }
|
143
114
|
@test_dummy_order ||= [ ]
|
115
|
+
@test_dummy_tags ||= { }
|
144
116
|
|
145
117
|
names.flatten.each do |name|
|
146
118
|
name = name.to_sym
|
@@ -148,6 +120,26 @@ module TestDummy
|
|
148
120
|
create_options_proc = nil
|
149
121
|
|
150
122
|
if (options)
|
123
|
+
if (options[:only])
|
124
|
+
tags = [ options[:only] ].flatten.compact
|
125
|
+
|
126
|
+
if (tags.any?)
|
127
|
+
set = @test_dummy_tags[name] ||= { }
|
128
|
+
|
129
|
+
set[:only] = tags
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
if (options[:except])
|
134
|
+
tags = [ options[:except] ].flatten.compact
|
135
|
+
|
136
|
+
if (tags.any?)
|
137
|
+
set = @test_dummy_tags[name] ||= { }
|
138
|
+
|
139
|
+
set[:except] = tags
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
151
143
|
if (options[:with])
|
152
144
|
if (block)
|
153
145
|
raise TestDummy::Exception, "Cannot use block and :with option at the same time."
|
@@ -215,10 +207,10 @@ module TestDummy
|
|
215
207
|
end
|
216
208
|
end
|
217
209
|
|
218
|
-
|
219
|
-
reflection_class, foreign_key = TestDummy::Support.reflection_properties(self, name)
|
210
|
+
reflection_class, foreign_key = TestDummy::Support.reflection_properties(self, name)
|
220
211
|
|
221
|
-
|
212
|
+
if (reflection_class and foreign_key)
|
213
|
+
block = lambda do |model, with_attributes|
|
222
214
|
unless ((with_attributes and (with_attributes.key?(name) or with_attributes.key?(foreign_key))) or model.send(name).present?)
|
223
215
|
object = from && from.inject(model) do |_model, _method|
|
224
216
|
_model ? _model.send(_method) : nil
|
@@ -260,7 +252,7 @@ module TestDummy
|
|
260
252
|
# new model is provided to the optional block for manipulation before
|
261
253
|
# the dummy operation is completed. Returns a dummy model which has not
|
262
254
|
# been saved.
|
263
|
-
def build_dummy(with_attributes = nil)
|
255
|
+
def build_dummy(with_attributes = nil, tags = nil)
|
264
256
|
load_dummy_declaration!
|
265
257
|
|
266
258
|
build_scope = (method(:scoped).arity == 1) ? scoped(nil).scope(:create) : scoped.scope_for_create
|
@@ -269,7 +261,7 @@ module TestDummy
|
|
269
261
|
|
270
262
|
yield(model) if (block_given?)
|
271
263
|
|
272
|
-
self.execute_dummy_operation(model, with_attributes)
|
264
|
+
self.execute_dummy_operation(model, with_attributes, tags)
|
273
265
|
|
274
266
|
model
|
275
267
|
end
|
@@ -279,8 +271,12 @@ module TestDummy
|
|
279
271
|
# the dummy operation is completed and the model is saved. Returns a
|
280
272
|
# dummy model. The model may not have been saved if there was a
|
281
273
|
# validation failure, or if it was blocked by a callback.
|
282
|
-
def create_dummy(
|
283
|
-
|
274
|
+
def create_dummy(*args, &block)
|
275
|
+
if (args.last.is_a?(Hash))
|
276
|
+
with_attributes = args.pop
|
277
|
+
end
|
278
|
+
|
279
|
+
model = build_dummy(with_attributes, args, &block)
|
284
280
|
|
285
281
|
model.save
|
286
282
|
|
@@ -293,8 +289,12 @@ module TestDummy
|
|
293
289
|
# dummy model. Will throw ActiveRecord::RecordInvalid if there was al20
|
294
290
|
# validation failure, or ActiveRecord::RecordNotSaved if the save was
|
295
291
|
# blocked by a callback.
|
296
|
-
def create_dummy!(
|
297
|
-
|
292
|
+
def create_dummy!(*args, &block)
|
293
|
+
if (args.last.is_a?(Hash))
|
294
|
+
with_attributes = args.pop
|
295
|
+
end
|
296
|
+
|
297
|
+
model = build_dummy(with_attributes, args, &block)
|
298
298
|
|
299
299
|
model.save!
|
300
300
|
|
@@ -310,20 +310,24 @@ module TestDummy
|
|
310
310
|
|
311
311
|
# Produces a complete set of dummy attributes. These can be used to
|
312
312
|
# create a model.
|
313
|
-
def dummy_attributes(with_attributes = nil)
|
313
|
+
def dummy_attributes(with_attributes = nil, tags = nil)
|
314
314
|
with_attributes = TestDummy.combine_attributes(scoped.scope_for_create, with_attributes)
|
315
315
|
|
316
316
|
@test_dummy_order.each do |field|
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
317
|
+
next if (with_attributes.key?(field))
|
318
|
+
|
319
|
+
if (when_tagged = @test_dummy_when[field])
|
320
|
+
next if (!tags or (tags & when_tagged).empty?)
|
321
|
+
end
|
322
|
+
|
323
|
+
result = dummy(field, with_attributes)
|
324
|
+
|
325
|
+
case (result)
|
326
|
+
when nil, with_attributes
|
327
|
+
# Declined to populate parameters if method returns nil
|
328
|
+
# or returns the existing parameter set.
|
329
|
+
else
|
330
|
+
with_attributes[field] = result
|
327
331
|
end
|
328
332
|
end
|
329
333
|
|
@@ -332,12 +336,22 @@ module TestDummy
|
|
332
336
|
|
333
337
|
# This performs the dummy operation on a model with an optional set
|
334
338
|
# of parameters.
|
335
|
-
def execute_dummy_operation(model, with_attributes = nil)
|
339
|
+
def execute_dummy_operation(model, with_attributes = nil, tags = nil)
|
336
340
|
load_dummy_declaration!
|
337
341
|
|
338
342
|
return model unless (@test_dummy_order)
|
339
|
-
|
343
|
+
|
340
344
|
@test_dummy_order.each do |name|
|
345
|
+
if (tag_conditions = @test_dummy_tags[name])
|
346
|
+
if (required_tags = tag_conditions[:only])
|
347
|
+
next if (!tags or (tags & required_tags).empty?)
|
348
|
+
end
|
349
|
+
|
350
|
+
if (excluding_tags = tag_conditions[:except])
|
351
|
+
next if (tags and (tags & excluding_tags).any?)
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
341
355
|
if (respond_to?(:reflect_on_association) and reflection = reflect_on_association(name))
|
342
356
|
foreign_key = (reflection.respond_to?(:foreign_key) ? reflection.foreign_key : reflection.primary_key_name).to_sym
|
343
357
|
|
@@ -366,7 +380,10 @@ module TestDummy
|
|
366
380
|
|
367
381
|
@_dummy_module =
|
368
382
|
begin
|
369
|
-
dummy_path = File.expand_path(
|
383
|
+
dummy_path = File.expand_path(
|
384
|
+
"#{name.underscore}.rb",
|
385
|
+
TestDummy.dummy_extensions_path
|
386
|
+
)
|
370
387
|
|
371
388
|
if (File.exist?(dummy_path))
|
372
389
|
load(dummy_path)
|
data/lib/test_dummy/railtie.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
module TestDummy::Support
|
2
|
+
# Combines several sets of parameters together into a single set in order
|
3
|
+
# of lowest priority to highest priority. Supplied list can contain nil
|
4
|
+
# values which will be ignored. Returns a Hash with symbolized keys.
|
5
|
+
def self.combine_attributes(*sets)
|
6
|
+
combined_attributes = { }
|
7
|
+
|
8
|
+
# Apply sets in order they are listed
|
9
|
+
sets.compact.each do |set|
|
10
|
+
set.each do |k, v|
|
11
|
+
case (v)
|
12
|
+
when nil
|
13
|
+
# Ignore nil assignments
|
14
|
+
else
|
15
|
+
combined_attributes[k.to_sym] = v
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
combined_attributes
|
21
|
+
end
|
22
|
+
|
23
|
+
# This method is used to provide a unified interface to the otherwise
|
24
|
+
# irregular methods to discover information on assocations. Rails 3
|
25
|
+
# introduces a new method. Returns the reflected class and foreign key
|
26
|
+
# properties for a named attribute, or nil if no association could be found.
|
27
|
+
def self.reflection_properties(model_class, attribute)
|
28
|
+
if (model_class.respond_to?(:reflect_on_association) and reflection = model_class.reflect_on_association(attribute))
|
29
|
+
[
|
30
|
+
reflection.klass,
|
31
|
+
(reflection.respond_to?(:foreign_key) ? reflection.foreign_key : reflection.primary_key_name).to_sym
|
32
|
+
]
|
33
|
+
elsif (model_class.respond_to?(:association_reflection) and reflection = model_class.association_reflection(attribute))
|
34
|
+
[
|
35
|
+
reflection[:associated_class],
|
36
|
+
reflection[:key] || :"#{attribute.to_s.underscore}_id"
|
37
|
+
]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/test/dummy/account.rb
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
class Account
|
2
|
+
# Populate the name attribute unless already defined.
|
2
3
|
dummy :name do
|
3
4
|
TestDummy::Helper.random_string(8)
|
4
5
|
end
|
6
|
+
|
7
|
+
# Runs unconditionally on every dummy object created.
|
8
|
+
dummy do |account|
|
9
|
+
account.source = 'dummy'
|
10
|
+
end
|
11
|
+
|
12
|
+
dummy :activated_at, :except => :unactivated do
|
13
|
+
Time.now - rand(86400 * 365) - 86400
|
14
|
+
end
|
15
|
+
|
16
|
+
dummy :closed_at, :only => [ :closed ] do |m|
|
17
|
+
m.activated_at + rand(86400)
|
18
|
+
end
|
5
19
|
end
|
data/test/dummy/bill.rb
CHANGED
@@ -2,6 +2,12 @@ class Bill
|
|
2
2
|
dummy :account
|
3
3
|
|
4
4
|
dummy :order_date do
|
5
|
-
Date.today.advance(:days => rand(-
|
5
|
+
Date.today.advance(:days => rand(-365))
|
6
|
+
end
|
7
|
+
|
8
|
+
dummy :due_date, :only => :overdue do |bill|
|
9
|
+
date = bill.order_date.advance(:days => 90)
|
10
|
+
|
11
|
+
(date >= Date.today) ? Date.today.advance(:days => -1) : date
|
6
12
|
end
|
7
13
|
end
|
data/test/dummy/item.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
class Item
|
2
|
+
# The bill is associated with an account, so this item should copy that
|
3
|
+
# relationship if one is not explicitly defined. This is done by requesting
|
4
|
+
# that the `account` attribute is inherited from bill.account if defined.
|
2
5
|
dummy :account,
|
3
6
|
:from => 'bill.account'
|
4
7
|
|
8
|
+
# The bill is associated with an account, so this item should copy that
|
9
|
+
# relationship if one is not explicitly defined. This is done by requesting
|
10
|
+
# that the `account_id` attribute is inherited from account.id if defined.
|
5
11
|
dummy :bill,
|
6
12
|
:inherit => {
|
7
13
|
:account_id => [ :account, :id ]
|
data/test/helper.rb
CHANGED
@@ -30,7 +30,7 @@ TestDummy.dummy_extensions_path = File.expand_path('dummy', File.dirname(__FILE_
|
|
30
30
|
|
31
31
|
ActiveRecord::Base.establish_connection(
|
32
32
|
'adapter' => "sqlite3",
|
33
|
-
'database'
|
33
|
+
'database' => File.expand_path('db/test.sqlite3', base_path)
|
34
34
|
)
|
35
35
|
|
36
36
|
ActiveRecord::Migrator.migrate(File.expand_path('db/migrate', base_path))
|
data/test/models/bill.rb
CHANGED
data/test/unit/test_bill.rb
CHANGED
@@ -34,4 +34,22 @@ class TestBill < ActiveSupport::TestCase
|
|
34
34
|
|
35
35
|
assert_equal [ bill.id ], account.bills.collect(&:id)
|
36
36
|
end
|
37
|
+
|
38
|
+
def test_with_overdue_tag
|
39
|
+
account = an Account
|
40
|
+
|
41
|
+
bill = Bill.create_dummy(:overdue, :account => account)
|
42
|
+
|
43
|
+
assert bill
|
44
|
+
assert_equal true, bill.valid?
|
45
|
+
assert_equal false, bill.new_record?
|
46
|
+
|
47
|
+
assert bill.due_date
|
48
|
+
|
49
|
+
assert_equal true, bill.overdue?
|
50
|
+
|
51
|
+
assert_equal account.id, bill.account_id
|
52
|
+
|
53
|
+
assert_equal [ bill.id ], account.bills.collect(&:id)
|
54
|
+
end
|
37
55
|
end
|
data/test_dummy.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "test_dummy"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["tadman"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2013-05-06"
|
13
13
|
s.description = "Test Dummy allows you to define how to fake models automatically so that you can use dummy data for testing instead of fixtures. Dummy models are always generated using the current schema and don't need to me migrated like fixtures."
|
14
14
|
s.email = "github@tadman.ca"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"lib/test_dummy.rb",
|
27
27
|
"lib/test_dummy/helper.rb",
|
28
28
|
"lib/test_dummy/railtie.rb",
|
29
|
+
"lib/test_dummy/support.rb",
|
29
30
|
"lib/test_dummy/test_helper.rb",
|
30
31
|
"test/db/.gitignore",
|
31
32
|
"test/db/migrate/0001_create_examples.rb",
|
@@ -48,7 +49,7 @@ Gem::Specification.new do |s|
|
|
48
49
|
]
|
49
50
|
s.homepage = "http://github.com/tadman/test_dummy"
|
50
51
|
s.require_paths = ["lib"]
|
51
|
-
s.rubygems_version = "1.8.
|
52
|
+
s.rubygems_version = "1.8.25"
|
52
53
|
s.summary = "Quick test data generator and fake model maker"
|
53
54
|
|
54
55
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test_dummy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.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:
|
12
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- lib/test_dummy.rb
|
79
79
|
- lib/test_dummy/helper.rb
|
80
80
|
- lib/test_dummy/railtie.rb
|
81
|
+
- lib/test_dummy/support.rb
|
81
82
|
- lib/test_dummy/test_helper.rb
|
82
83
|
- test/db/.gitignore
|
83
84
|
- test/db/migrate/0001_create_examples.rb
|
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
118
|
version: '0'
|
118
119
|
requirements: []
|
119
120
|
rubyforge_project:
|
120
|
-
rubygems_version: 1.8.
|
121
|
+
rubygems_version: 1.8.25
|
121
122
|
signing_key:
|
122
123
|
specification_version: 3
|
123
124
|
summary: Quick test data generator and fake model maker
|