lawrencepit-machinery 0.3.1 → 0.4
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/lib/machinery/active_record.rb +21 -3
- data/lib/machinery.rb +17 -13
- metadata +1 -1
@@ -1,7 +1,7 @@
|
|
1
1
|
module Machinery
|
2
|
-
|
3
2
|
module ActiveRecord
|
4
3
|
@@toys = []
|
4
|
+
@@updated = []
|
5
5
|
@@recording = false
|
6
6
|
|
7
7
|
def self.record
|
@@ -15,10 +15,19 @@ module Machinery
|
|
15
15
|
@@toys = []
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.
|
18
|
+
def self.created(obj)
|
19
19
|
@@toys << obj if @@recording
|
20
20
|
end
|
21
21
|
|
22
|
+
def self.updated(obj)
|
23
|
+
@@updated << obj
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.reload_updated
|
27
|
+
@@updated.each { |obj| obj.reload }
|
28
|
+
@@updated = []
|
29
|
+
end
|
30
|
+
|
22
31
|
module Extensions
|
23
32
|
private
|
24
33
|
|
@@ -26,14 +35,23 @@ module Machinery
|
|
26
35
|
base.class_eval do
|
27
36
|
alias_method :create_without_machinery, :create
|
28
37
|
alias_method :create, :create_with_machinery
|
38
|
+
|
39
|
+
alias_method :update_without_machinery, :update
|
40
|
+
alias_method :update, :update_with_machinery
|
29
41
|
end
|
30
42
|
end
|
31
43
|
|
32
44
|
def create_with_machinery
|
33
45
|
id = create_without_machinery
|
34
|
-
Machinery::ActiveRecord.
|
46
|
+
Machinery::ActiveRecord.created(self)
|
35
47
|
id
|
36
48
|
end
|
49
|
+
|
50
|
+
def update_with_machinery
|
51
|
+
affected = update_without_machinery
|
52
|
+
Machinery::ActiveRecord.updated(self) if affected > 0
|
53
|
+
affected
|
54
|
+
end
|
37
55
|
end
|
38
56
|
|
39
57
|
end
|
data/lib/machinery.rb
CHANGED
@@ -9,9 +9,13 @@ module Machinery
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.load(file)
|
12
|
-
|
12
|
+
Machinery.instance_eval(File.read(file))
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
|
+
def self.define(&block)
|
16
|
+
Machinery.instance_eval(&block)
|
17
|
+
end
|
18
|
+
|
15
19
|
private
|
16
20
|
def self.make_scenario(context, names, &block)
|
17
21
|
Machinery::ActiveRecord.record do
|
@@ -26,30 +30,30 @@ module Machinery
|
|
26
30
|
end
|
27
31
|
alias_method :scenarios, :scenario
|
28
32
|
|
29
|
-
def
|
33
|
+
def rollback_scenario
|
30
34
|
Machinery::ActiveRecord.clear
|
31
35
|
end
|
36
|
+
alias_method :rollback_scenarios, :rollback_scenario
|
32
37
|
end
|
33
38
|
|
34
39
|
module ExampleGroupMacros
|
35
40
|
def scenario(*names, &block)
|
36
41
|
Machinery.scenario(names.first, &block) and return if block_given?
|
37
|
-
self.before(:all)
|
38
|
-
self.after(:all)
|
42
|
+
self.before(:all) { scenarios(*names) }
|
43
|
+
self.after(:all) { rollback_scenarios }
|
44
|
+
self.before(:each) { Machinery::ActiveRecord.reload_updated }
|
39
45
|
end
|
40
46
|
alias_method :scenarios, :scenario
|
41
47
|
end
|
42
48
|
end
|
43
49
|
|
50
|
+
if defined? Test::Unit::TestCase
|
51
|
+
Test::Unit::TestCase.extend Machinery::ExampleGroupMacros
|
52
|
+
Test::Unit::TestCase.send('include', Machinery::Helpers)
|
53
|
+
end
|
54
|
+
|
44
55
|
if defined? Spec::Example::ExampleGroup
|
45
56
|
Spec::Example::ExampleGroup.extend Machinery::ExampleGroupMacros
|
46
|
-
Spec::Example::ExampleGroupFactory[nil].
|
57
|
+
Spec::Example::ExampleGroupFactory[nil].send('include', Machinery::Helpers)
|
47
58
|
end
|
48
59
|
|
49
|
-
module Test # :nodoc: all
|
50
|
-
module Unit
|
51
|
-
class TestCase
|
52
|
-
include Machinery::Helpers
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|