freegenie-factory_girl 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/factory_girl.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  require 'active_support'
2
2
  require 'factory_girl/proxy'
3
3
  require 'factory_girl/proxy/build'
4
+ require 'factory_girl/proxy/find_or_create'
4
5
  require 'factory_girl/proxy/create'
5
6
  require 'factory_girl/proxy/attributes_for'
6
7
  require 'factory_girl/proxy/stub'
7
- require 'factory_girl/proxy/find_or_create'
8
+
8
9
  require 'factory_girl/factory'
9
10
  require 'factory_girl/attribute'
10
11
  require 'factory_girl/attribute/static'
@@ -0,0 +1,32 @@
1
+ module ActiveRecordHooks
2
+
3
+ def self.included(base)
4
+ base.class_eval do
5
+ extend ClassMethods
6
+ include InstanceMethods
7
+ after_create :after_create_hook
8
+ after_destroy :after_destroy_hook
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ end
14
+
15
+ module InstanceMethods
16
+ def after_create_hook
17
+ # puts "after_create_hook: self.attributes"
18
+ # puts Factory.live_registry
19
+ end
20
+
21
+ def after_destroy_hook
22
+ # put "after_destroy_hook"
23
+ Factory.delete_from_live_registry(self.class.name, self.id)
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+
30
+ ActiveRecord::Base.class_eval do
31
+ include ActiveRecordHooks
32
+ end
@@ -92,7 +92,7 @@ class Factory
92
92
  @options = options
93
93
  @attributes = []
94
94
  end
95
-
95
+
96
96
  def inherit_from(parent) #:nodoc:
97
97
  @options[:class] ||= parent.class_name
98
98
  parent.attributes.each do |attribute|
@@ -0,0 +1,10 @@
1
+ class Factory
2
+ class Proxy #:nodoc:
3
+ class FindOrCreate < Build #:nodoc:
4
+ def result
5
+ @instance.save!
6
+ @instance
7
+ end
8
+ end
9
+ end
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freegenie-factory_girl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Ferris
@@ -39,6 +39,8 @@ files:
39
39
  - lib/factory_girl/proxy/attributes_for.rb
40
40
  - lib/factory_girl/proxy/build.rb
41
41
  - lib/factory_girl/proxy/create.rb
42
+ - lib/factory_girl/proxy/find_or_create.rb
43
+ - lib/factory_girl/activerecord.rb
42
44
  - lib/factory_girl/proxy/stub.rb
43
45
  - lib/factory_girl/proxy.rb
44
46
  - lib/factory_girl/sequence.rb