jeffperrin-object_mother 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/object_mother.rb +8 -35
- metadata +1 -1
data/lib/object_mother.rb
CHANGED
@@ -1,37 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
raise 'No populate method specified for ' + model.to_s
|
9
|
-
end
|
10
|
-
def self.to_hash(model)
|
11
|
-
raise 'No to_hash method specified'
|
12
|
-
end
|
13
|
-
def self.unique(val)
|
14
|
-
@@index += 1
|
15
|
-
val.to_s + @@index.to_s
|
16
|
-
end
|
17
|
-
def self.unique_email(val)
|
18
|
-
user, domain = val.split('@')
|
19
|
-
unique(user) + '@' + domain
|
20
|
-
end
|
21
|
-
def self.create
|
22
|
-
obj = spawn
|
23
|
-
populate(obj)
|
24
|
-
yield obj if block_given?
|
25
|
-
obj
|
26
|
-
end
|
27
|
-
def self.create!(&block)
|
28
|
-
obj = create(&block)
|
29
|
-
obj.save!
|
30
|
-
obj
|
31
|
-
end
|
32
|
-
def self.create_as_hash(&block)
|
33
|
-
obj = create(&block)
|
34
|
-
to_hash obj
|
1
|
+
require 'object_mother/factory'
|
2
|
+
|
3
|
+
if defined? Rails.configuration
|
4
|
+
Rails.configuration.after_initialize do
|
5
|
+
path = File.join(RAILS_ROOT, 'test', 'object_mother')
|
6
|
+
Dir[File.join(path, '*.rb')].each do |file|
|
7
|
+
require file
|
35
8
|
end
|
36
9
|
end
|
37
|
-
end
|
10
|
+
end
|