modelfactory 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/README.txt +3 -3
- data/lib/modelfactory/factory.rb +3 -3
- data/lib/modelfactory/version.rb +1 -1
- data/test/modelfactory_test.rb +4 -0
- metadata +1 -1
data/History.txt
CHANGED
data/README.txt
CHANGED
@@ -17,7 +17,7 @@ opaque ActiveRecord objects whose contents are unimportant.
|
|
17
17
|
|
18
18
|
require 'modelfactory'
|
19
19
|
|
20
|
-
ModelFactory.
|
20
|
+
ModelFactory.configure do
|
21
21
|
default(User) do
|
22
22
|
name { "Factory User" }
|
23
23
|
email { "user@factory.ws" }
|
@@ -73,7 +73,7 @@ keeps a counter for each type that increments when each new instance is
|
|
73
73
|
created. This counter is passed to model initialization blocks to make it
|
74
74
|
easier to generate unique values:
|
75
75
|
|
76
|
-
ModelFactory.
|
76
|
+
ModelFactory.configure do
|
77
77
|
default(User) do
|
78
78
|
name {|i| "Factory User #{i}" }
|
79
79
|
email {|i| "user#{i}@factory.ws" }
|
@@ -85,7 +85,7 @@ easier to generate unique values:
|
|
85
85
|
|
86
86
|
It's possible to configure named factories:
|
87
87
|
|
88
|
-
ModelFactory.
|
88
|
+
ModelFactory.configure do
|
89
89
|
admin(User) do
|
90
90
|
name {|i| "Admin User #{i}" }
|
91
91
|
admin { true }
|
data/lib/modelfactory/factory.rb
CHANGED
@@ -34,13 +34,13 @@ module ModelFactory # :nodoc:
|
|
34
34
|
@counter += 1
|
35
35
|
end
|
36
36
|
|
37
|
-
def new_named(name, opt
|
37
|
+
def new_named(name, opt, &block)
|
38
38
|
instance = @class.new
|
39
39
|
InstanceBuilder.new(instance, opt, next_counter, &@options[name])
|
40
40
|
instance
|
41
41
|
end
|
42
42
|
|
43
|
-
def create_named(name, opt
|
43
|
+
def create_named(name, opt, &block)
|
44
44
|
instance = new_named(name, opt, &block)
|
45
45
|
instance.save!
|
46
46
|
instance.reload
|
@@ -52,7 +52,7 @@ module ModelFactory # :nodoc:
|
|
52
52
|
class InstanceBuilder # :nodoc:
|
53
53
|
def initialize(instance, params, counter, &block)
|
54
54
|
@instance = instance
|
55
|
-
@params = params
|
55
|
+
@params = params || {}
|
56
56
|
@counter = counter
|
57
57
|
@params.each { |attr, value| @instance.send "#{attr}=", value }
|
58
58
|
instance_eval(&block) if block_given?
|
data/lib/modelfactory/version.rb
CHANGED
data/test/modelfactory_test.rb
CHANGED
@@ -15,6 +15,10 @@ class ModelFactoryTest < Test::Unit::TestCase
|
|
15
15
|
assert_raises(ActiveRecord::RecordInvalid) { StrictWidget.factory.create }
|
16
16
|
end
|
17
17
|
|
18
|
+
should "not raise on nil params" do
|
19
|
+
assert_nothing_raised { Widget.factory.create(nil) }
|
20
|
+
end
|
21
|
+
|
18
22
|
context "with a specified default" do
|
19
23
|
setup do
|
20
24
|
ModelFactory.configure do
|