traka 0.0.4 → 0.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.md +36 -12
- data/lib/traka/change.rb +18 -12
- data/lib/traka/is_trakable.rb +7 -3
- data/lib/traka/version.rb +1 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +7426 -0
- data/test/traka_change_test.rb +77 -7
- metadata +2 -2
data/test/traka_change_test.rb
CHANGED
@@ -41,9 +41,27 @@ class TrakaChangeTest < ActiveSupport::TestCase
|
|
41
41
|
assert_equal Traka::Change.staged_changes.count, 1
|
42
42
|
assert_equal Traka::Change.staged_changes.first.klass, "Product"
|
43
43
|
|
44
|
-
assert_equal Traka::Change.
|
45
|
-
assert_equal Traka::Change.
|
46
|
-
assert_equal Traka::Change.
|
44
|
+
assert_equal Traka::Change.staged_changes(:version => 1).count, 3
|
45
|
+
assert_equal Traka::Change.staged_changes(:version => 1).map(&:klass), ["Product", "Cheese", "Product"]
|
46
|
+
assert_equal Traka::Change.staged_changes(:version => 1).map(&:action_type), ["create", "create", "create"]
|
47
|
+
end
|
48
|
+
|
49
|
+
test "TrakaChange can list changes for a particular version" do
|
50
|
+
p = Product.create(:name => "Product A")
|
51
|
+
c = Cheese.create(:name => "Cheese A")
|
52
|
+
|
53
|
+
assert_equal Traka::Change.staged_changes.count, 2
|
54
|
+
|
55
|
+
Traka::Change.publish_new_version!
|
56
|
+
|
57
|
+
p2 = Product.create(:name => "Product B")
|
58
|
+
|
59
|
+
assert_equal Traka::Change.staged_changes.count, 1
|
60
|
+
assert_equal Traka::Change.staged_changes.first.klass, "Product"
|
61
|
+
|
62
|
+
assert_equal Traka::Change.staged_changes(:version => (2..2)).count, 2
|
63
|
+
assert_equal Traka::Change.staged_changes(:version => (2..2)).map(&:klass), ["Product", "Cheese"]
|
64
|
+
assert_equal Traka::Change.staged_changes(:version => (2..2)).map(&:action_type), ["create", "create"]
|
47
65
|
end
|
48
66
|
|
49
67
|
test "TrakaChange can list differing changes" do
|
@@ -141,10 +159,62 @@ class TrakaChangeTest < ActiveSupport::TestCase
|
|
141
159
|
p.destroy
|
142
160
|
c.destroy
|
143
161
|
|
144
|
-
# Abridged version would be empty because destroys would cancel out creates.
|
145
|
-
assert_equal Traka::Change.staged_changes(false).count, 6
|
146
|
-
assert_equal Traka::Change.staged_changes(false).map(&:klass), ["Product", "Cheese", "Product", "Product", "Product", "Cheese"]
|
147
|
-
assert_equal Traka::Change.staged_changes(false).map(&:action_type), ["create", "create", "update", "update", "destroy", "destroy"]
|
162
|
+
# Abridged version would be empty because destroys would cancel out creates and updates.
|
163
|
+
assert_equal Traka::Change.staged_changes(:filter => false).count, 6
|
164
|
+
assert_equal Traka::Change.staged_changes(:filter => false).map(&:klass), ["Product", "Cheese", "Product", "Product", "Product", "Cheese"]
|
165
|
+
assert_equal Traka::Change.staged_changes(:filter => false).map(&:action_type), ["create", "create", "update", "update", "destroy", "destroy"]
|
166
|
+
end
|
167
|
+
|
168
|
+
test "TrakaChange can give changes for sub-set of resources" do
|
169
|
+
p = Product.create(:name => "Product A")
|
170
|
+
c = Cheese.create(:name => "Cheese A")
|
171
|
+
|
172
|
+
p.name = "New name"
|
173
|
+
p.save
|
174
|
+
|
175
|
+
c.name = "Another name"
|
176
|
+
c.save
|
177
|
+
|
178
|
+
assert_equal Traka::Change.staged_changes(:only => [Product], :filter => false).count, 2
|
179
|
+
assert_equal Traka::Change.staged_changes(:only => [Product], :filter => false).map(&:klass), ["Product", "Product"]
|
180
|
+
assert_equal Traka::Change.staged_changes(:only => [Product], :filter => false).map(&:action_type), ["create", "update"]
|
181
|
+
end
|
182
|
+
|
183
|
+
test "TrakaChange can give changes for sub-set of actions" do
|
184
|
+
p = Product.create(:name => "Product A")
|
185
|
+
c = Cheese.create(:name => "Cheese A")
|
186
|
+
|
187
|
+
p.name = "New name"
|
188
|
+
p.save
|
189
|
+
|
190
|
+
p.name = "Another name"
|
191
|
+
p.save
|
192
|
+
|
193
|
+
assert_equal Traka::Change.staged_changes(:actions => [:create]).count, 2
|
194
|
+
assert_equal Traka::Change.staged_changes(:actions => [:create]).map(&:klass), ["Product", "Cheese"]
|
195
|
+
assert_equal Traka::Change.staged_changes(:actions => [:create]).map(&:action_type), ["create", "create"]
|
196
|
+
end
|
197
|
+
|
198
|
+
test "TrakaChange can accept multiple options" do
|
199
|
+
p = Product.create(:name => "Product A")
|
200
|
+
c = Cheese.create(:name => "Cheese A")
|
201
|
+
|
202
|
+
p.name = "New name"
|
203
|
+
p.save
|
204
|
+
|
205
|
+
p.name = "Another name"
|
206
|
+
p.save
|
207
|
+
|
208
|
+
p.destroy
|
209
|
+
c.destroy
|
210
|
+
|
211
|
+
assert_equal Traka::Change.staged_changes(:actions => [:create], :filter => false, :only => [Product, Cheese]).count, 2
|
212
|
+
assert_equal Traka::Change.staged_changes(:actions => [:create], :filter => false, :only => [Product, Cheese]).map(&:klass), ["Product", "Cheese"]
|
213
|
+
assert_equal Traka::Change.staged_changes(:actions => [:create], :filter => false, :only => [Product, Cheese]).map(&:action_type), ["create", "create"]
|
214
|
+
|
215
|
+
assert_equal Traka::Change.staged_changes(:actions => [:create, :update], :filter => false).count, 4
|
216
|
+
assert_equal Traka::Change.staged_changes(:actions => [:create, :update], :filter => false, :only => [Product, Cheese]).map(&:klass), ["Product", "Cheese", "Product", "Product"]
|
217
|
+
assert_equal Traka::Change.staged_changes(:actions => [:create, :update], :filter => false, :only => [Product, Cheese]).map(&:action_type), ["create", "create", "update", "update"]
|
148
218
|
end
|
149
219
|
|
150
220
|
test "TrakaChange can resolve AR objects" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
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-01-
|
12
|
+
date: 2014-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|