lawrencepit-machinery 0.4.2 → 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown CHANGED
@@ -10,7 +10,7 @@ in rake tasks to populate a database.
10
10
  Why write stuff like:
11
11
 
12
12
  users(:admin).should be_nil
13
-
13
+
14
14
  when you can just as well write:
15
15
 
16
16
  @user_admin.should be_nil
@@ -124,8 +124,9 @@ After using model_stubbing on a relatively large project for over a year I decid
124
124
  a simpler solution was needed. Object graphs need to be easily re-usable by specs,
125
125
  unit tests, cucumber stories and ad-hoc database loading.
126
126
 
127
- Machinery works especially great in combination with Machinist.
128
-
127
+ Machinery works especially great in combination with
128
+ [Machinist](http://github.com/notahat/machinist) or
129
+ [FactoryGirl](http://github.com/thoughtbot/factory_girl).
129
130
 
130
131
 
131
132
  ----
@@ -1,7 +1,6 @@
1
1
  module Machinery
2
2
  module ActiveRecord
3
3
  @@toys = []
4
- @@updated = []
5
4
  @@recording = false
6
5
 
7
6
  def self.record
@@ -25,15 +24,6 @@ module Machinery
25
24
  @@toys << obj if @@recording
26
25
  end
27
26
 
28
- def self.updated(obj)
29
- @@updated << obj
30
- end
31
-
32
- def self.reload_updated
33
- @@updated.each { |obj| obj.reload }
34
- @@updated = []
35
- end
36
-
37
27
  module Extensions
38
28
  private
39
29
 
@@ -41,9 +31,6 @@ module Machinery
41
31
  base.class_eval do
42
32
  alias_method :create_without_machinery, :create
43
33
  alias_method :create, :create_with_machinery
44
-
45
- alias_method :update_without_machinery, :update
46
- alias_method :update, :update_with_machinery
47
34
  end
48
35
  end
49
36
 
@@ -52,12 +39,6 @@ module Machinery
52
39
  Machinery::ActiveRecord.created(self)
53
40
  id
54
41
  end
55
-
56
- def update_with_machinery
57
- affected = update_without_machinery
58
- Machinery::ActiveRecord.updated(self) if affected > 0
59
- affected
60
- end
61
42
  end
62
43
 
63
44
  end
data/lib/machinery.rb CHANGED
@@ -29,19 +29,31 @@ module Machinery
29
29
  Machinery.make_scenario(self, names, &block)
30
30
  end
31
31
  alias_method :scenarios, :scenario
32
-
32
+
33
33
  def rollback_scenario
34
34
  Machinery::ActiveRecord.clear
35
35
  end
36
36
  alias_method :rollback_scenarios, :rollback_scenario
37
+
38
+ private
39
+ def clone_instance_variables
40
+ self.instance_variables.each do |ivar|
41
+ obj = self.instance_variable_get(ivar)
42
+ next unless obj.is_a?(::ActiveRecord::Base)
43
+ clone = obj.clone
44
+ clone.id = obj.id
45
+ clone.instance_variable_set('@new_record', obj.new_record?)
46
+ self.instance_variable_set(ivar, clone)
47
+ end
48
+ end
37
49
  end
38
-
50
+
39
51
  module ExampleGroupMacros
40
52
  def scenario(*names, &block)
41
53
  Machinery.scenario(names.first, &block) and return if block_given?
42
54
  self.before(:all) { scenarios(*names) }
43
55
  self.after(:all) { rollback_scenarios }
44
- self.after(:each) { Machinery::ActiveRecord.reload_updated }
56
+ self.before(:each) { clone_instance_variables }
45
57
  end
46
58
  alias_method :scenarios, :scenario
47
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lawrencepit-machinery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: "0.5"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lawrence Pit