jeffperrin-object_mother 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/object_mother.rb +8 -35
  2. metadata +1 -1
data/lib/object_mother.rb CHANGED
@@ -1,37 +1,10 @@
1
- module ObjectMother
2
- class Factory
3
- @@index = 0
4
- def self.spawn
5
- raise 'No create method specified'
6
- end
7
- def self.populate(model)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeffperrin-object_mother
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.1"
4
+ version: "0.2"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Perrin