composite_primary_keys 9.0.8 → 9.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0bb2d4ed4f66fb5eeaa389046650e232aa16e43c
4
- data.tar.gz: 796485685e062bd5eb966c9c58385c9d4d9e261b
2
+ SHA256:
3
+ metadata.gz: 2ff862b93eb239969238798e2bc089b2312861d32a269d3c2cabc8a0873efb9d
4
+ data.tar.gz: 6778a792c0849abc74826beb68c61b296199630974c24f855df1434a7c7b4aca
5
5
  SHA512:
6
- metadata.gz: e0ae9ddde5c369743572ae0cc03abc78ba22d9ff1411dbf37e3dc6dc23cc72515502a2958c403c467df1f62c8aaed554269fab712eb30421519e77be58f8c017
7
- data.tar.gz: fe38741609f9795b001924e889bc24229f654b90615683e2556a97dd7ec3dfdcd3f3cb3f50321a391e70509247a52f158899556fdbc78ee7bc7848e26688bb1a
6
+ metadata.gz: 7402eb2befdbaaf5a57b95d84921ca56049d0606fcb058b2ad65332b6523bdc8decf8ee92e0a474f718f6664f49758ce97798456c15f216c5c7b9bccf081647c
7
+ data.tar.gz: 36796097d0f1b1104561605179cecf0c8476ec2e4f69be288d04cb6b474804de0c9c1f79f85b72dd43d2fc40b6f9a13ef4823ce0b3256aa32f52504db2d37a48
@@ -1,3 +1,7 @@
1
+ == 9.0.9 (2018-03-06)
2
+
3
+ * Fix update statements that incorrectly pass NULL values for the primary key components (Sean Linsley)
4
+
1
5
  == 9.0.8 (2017-10-11)
2
6
 
3
7
  * Fix Paper Trail compatibility (Sean Linsley)
@@ -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
- attribute_changed?(key_attr) ? changed_attributes[key_attr] : self.ids_hash[key_attr]
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
- relation = @klass.unscoped.where(cpk_id_predicate(@klass.arel_table, @klass.primary_key, id_was || id))
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
@@ -2,7 +2,7 @@ module CompositePrimaryKeys
2
2
  module VERSION
3
3
  MAJOR = 9
4
4
  MINOR = 0
5
- TINY = 8
5
+ TINY = 9
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
@@ -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
 
@@ -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.8
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: 2017-10-11 00:00:00.000000000 Z
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.6.13
274
+ rubygems_version: 2.7.3
275
275
  signing_key:
276
276
  specification_version: 4
277
277
  summary: Composite key support for ActiveRecord