once-ler 0.0.12 → 0.0.13
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.md +2 -2
- data/lib/onceler/basic_helpers.rb +15 -0
- data/lib/onceler/recordable.rb +4 -3
- data/lib/onceler/recorder.rb +6 -8
- metadata +2 -2
data/README.md
CHANGED
@@ -58,9 +58,9 @@ once-ler adds two new `before`/`after` scopes, `:record` and `:reset`, in
|
|
58
58
|
case you need to implement additional logic. `:record` runs in
|
59
59
|
conjunction with once-ler's recording phase (the implicit `before :all`).
|
60
60
|
`:reset` runs in conjunction with its cleanup phase (database rollback,
|
61
|
-
implicit `after :all`). As
|
61
|
+
implicit `after :all`). As opposed to `:all`/`:context` hooks, these ones
|
62
62
|
are inherited down, and will run before/after any nested once-ler setup/
|
63
|
-
teardown
|
63
|
+
teardown.
|
64
64
|
|
65
65
|
They can be used globally, or in a particular group. For example:
|
66
66
|
|
@@ -98,6 +98,21 @@ module Onceler
|
|
98
98
|
superclass.onceler
|
99
99
|
end
|
100
100
|
|
101
|
+
# Set this if you have multiple (or different) conns you will be
|
102
|
+
# once-ler'ing. Can either be an enumerable, or a proc that returns
|
103
|
+
# one. Note that if given a proc, it will only be called once (the
|
104
|
+
# first time it's needed) and cached after that.
|
105
|
+
#
|
106
|
+
# context "Foo" do
|
107
|
+
# self.onceler_connections = -> { [Foo.connection] }
|
108
|
+
# ...
|
109
|
+
attr_writer :onceler_connections
|
110
|
+
def onceler_connections
|
111
|
+
@onceler_connections ||= [ActiveRecord::Base.connection]
|
112
|
+
@onceler_connections = instance_eval(&@onceler_connections) if @onceler_connections.respond_to?(:call)
|
113
|
+
@onceler_connections
|
114
|
+
end
|
115
|
+
|
101
116
|
private
|
102
117
|
|
103
118
|
def add_onceler_hooks!
|
data/lib/onceler/recordable.rb
CHANGED
@@ -70,9 +70,10 @@ module Onceler
|
|
70
70
|
# if a nested once block updates an inherited object's associations,
|
71
71
|
# we want to know about it
|
72
72
|
def __associations_equal?(obj1, obj2)
|
73
|
-
cache1 = obj1.
|
74
|
-
cache2 = obj2.
|
75
|
-
cache1.
|
73
|
+
cache1 = obj1.association_cache
|
74
|
+
cache2 = obj2.association_cache
|
75
|
+
cache1.size == cache2.size &&
|
76
|
+
cache1.all? { |k, v| cache2.key?(k) && __values_equal?(v.target, cache2[k].target) }
|
76
77
|
end
|
77
78
|
|
78
79
|
def __data(inherit = false)
|
data/lib/onceler/recorder.rb
CHANGED
@@ -116,22 +116,20 @@ module Onceler
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
|
120
|
-
|
121
|
-
def transaction_classes
|
122
|
-
[ActiveRecord::Base]
|
119
|
+
def transactional_connections
|
120
|
+
@group_class.onceler_connections
|
123
121
|
end
|
124
122
|
|
125
123
|
def begin_transactions!
|
126
124
|
Onceler.open_transactions += 1
|
127
|
-
|
128
|
-
begin_transaction(
|
125
|
+
transactional_connections.each do |connection|
|
126
|
+
begin_transaction(connection)
|
129
127
|
end
|
130
128
|
end
|
131
129
|
|
132
130
|
def rollback_transactions!
|
133
|
-
|
134
|
-
rollback_transaction(
|
131
|
+
transactional_connections.each do |connection|
|
132
|
+
rollback_transaction(connection)
|
135
133
|
end
|
136
134
|
ensure
|
137
135
|
Onceler.open_transactions -= 1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: once-ler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-07-
|
12
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|