composite_primary_keys 9.0.8 → 9.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/History.rdoc +4 -0
- data/lib/composite_primary_keys/attribute_methods/primary_key.rb +1 -1
- data/lib/composite_primary_keys/relation.rb +6 -1
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/fixtures/tariffs.yml +14 -14
- data/test/test_counter_cache.rb +30 -30
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2ff862b93eb239969238798e2bc089b2312861d32a269d3c2cabc8a0873efb9d
|
4
|
+
data.tar.gz: 6778a792c0849abc74826beb68c61b296199630974c24f855df1434a7c7b4aca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7402eb2befdbaaf5a57b95d84921ca56049d0606fcb058b2ad65332b6523bdc8decf8ee92e0a474f718f6664f49758ce97798456c15f216c5c7b9bccf081647c
|
7
|
+
data.tar.gz: 36796097d0f1b1104561605179cecf0c8476ec2e4f69be288d04cb6b474804de0c9c1f79f85b72dd43d2fc40b6f9a13ef4823ce0b3256aa32f52504db2d37a48
|
data/History.rdoc
CHANGED
@@ -9,7 +9,7 @@ module ActiveRecord
|
|
9
9
|
# attribute_was(self.class.primary_key)
|
10
10
|
if self.composite?
|
11
11
|
self.class.primary_keys.map do |key_attr|
|
12
|
-
|
12
|
+
attribute_was(key_attr)
|
13
13
|
end
|
14
14
|
else
|
15
15
|
attribute_was(self.class.primary_key)
|
@@ -28,7 +28,12 @@ module ActiveRecord
|
|
28
28
|
|
29
29
|
# CPK
|
30
30
|
if self.composite?
|
31
|
-
|
31
|
+
# Not sure if this is a good idea, but replace nil id_was with the new id
|
32
|
+
id_update = id_was.each_with_index.map do |value, i|
|
33
|
+
value || id[i]
|
34
|
+
end
|
35
|
+
|
36
|
+
relation = @klass.unscoped.where(cpk_id_predicate(@klass.arel_table, @klass.primary_key, id_update))
|
32
37
|
else
|
33
38
|
relation = scope.where(@klass.primary_key => (id_was || id))
|
34
39
|
end
|
data/test/fixtures/tariffs.yml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
flat:
|
2
|
-
tariff_id: 1
|
3
|
-
start_date: <%= Date.today.to_s(:db) %>
|
4
|
-
amount: 50
|
5
|
-
|
6
|
-
free:
|
7
|
-
tariff_id: 2
|
8
|
-
start_date: <%= Date.today.to_s(:db) %>
|
9
|
-
amount: 0
|
10
|
-
|
11
|
-
flat_future:
|
12
|
-
tariff_id: 1
|
13
|
-
start_date: <%= Date.today.next.to_s(:db) %>
|
14
|
-
amount: 100
|
1
|
+
flat:
|
2
|
+
tariff_id: 1
|
3
|
+
start_date: <%= Date.today.to_s(:db) %>
|
4
|
+
amount: 50
|
5
|
+
|
6
|
+
free:
|
7
|
+
tariff_id: 2
|
8
|
+
start_date: <%= Date.today.to_s(:db) %>
|
9
|
+
amount: 0
|
10
|
+
|
11
|
+
flat_future:
|
12
|
+
tariff_id: 1
|
13
|
+
start_date: <%= Date.today.next.to_s(:db) %>
|
14
|
+
amount: 100
|
15
15
|
|
data/test/test_counter_cache.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
-
|
3
|
-
class TestCalculations < ActiveSupport::TestCase
|
4
|
-
fixtures :tariffs
|
5
|
-
|
6
|
-
def test_update_counter
|
7
|
-
tariff = tariffs(:flat)
|
8
|
-
assert_equal(50, tariff.amount)
|
9
|
-
Tariff.update_counters(tariff.id, :amount => 1)
|
10
|
-
tariff.reload
|
11
|
-
assert_equal(51, tariff.amount)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_increment_counter
|
15
|
-
tariff = tariffs(:flat)
|
16
|
-
assert_equal(50, tariff.amount)
|
17
|
-
Tariff.increment_counter(:amount, tariff.id)
|
18
|
-
|
19
|
-
tariff.reload
|
20
|
-
assert_equal(51, tariff.amount)
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_decrement_counter
|
24
|
-
tariff = tariffs(:flat)
|
25
|
-
assert_equal(50, tariff.amount)
|
26
|
-
Tariff.decrement_counter(:amount, tariff.id)
|
27
|
-
|
28
|
-
tariff.reload
|
29
|
-
assert_equal(49, tariff.amount)
|
30
|
-
end
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
class TestCalculations < ActiveSupport::TestCase
|
4
|
+
fixtures :tariffs
|
5
|
+
|
6
|
+
def test_update_counter
|
7
|
+
tariff = tariffs(:flat)
|
8
|
+
assert_equal(50, tariff.amount)
|
9
|
+
Tariff.update_counters(tariff.id, :amount => 1)
|
10
|
+
tariff.reload
|
11
|
+
assert_equal(51, tariff.amount)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_increment_counter
|
15
|
+
tariff = tariffs(:flat)
|
16
|
+
assert_equal(50, tariff.amount)
|
17
|
+
Tariff.increment_counter(:amount, tariff.id)
|
18
|
+
|
19
|
+
tariff.reload
|
20
|
+
assert_equal(51, tariff.amount)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_decrement_counter
|
24
|
+
tariff = tariffs(:flat)
|
25
|
+
assert_equal(50, tariff.amount)
|
26
|
+
Tariff.decrement_counter(:amount, tariff.id)
|
27
|
+
|
28
|
+
tariff.reload
|
29
|
+
assert_equal(49, tariff.amount)
|
30
|
+
end
|
31
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: composite_primary_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.0.
|
4
|
+
version: 9.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Savage
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -271,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
271
271
|
version: '0'
|
272
272
|
requirements: []
|
273
273
|
rubyforge_project:
|
274
|
-
rubygems_version: 2.
|
274
|
+
rubygems_version: 2.7.3
|
275
275
|
signing_key:
|
276
276
|
specification_version: 4
|
277
277
|
summary: Composite key support for ActiveRecord
|