composite_primary_keys 14.0.3 → 14.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9cb00a73781e630f40a83391449a048e05a28e6c93ab41b71af55ad7d0e5aa1
4
- data.tar.gz: ef9cdf02f59b135080e2eefa621d35764a7a4002904aaa066031675b2bf05873
3
+ metadata.gz: f7f4289f2367e4fc8315bd9055e077e7daa2f3ca842bbb1c40e5755241379416
4
+ data.tar.gz: 5f247da837ba1da9f64ba23efaa9cbe9aade3f12f2f9c879736106b9c14570ff
5
5
  SHA512:
6
- metadata.gz: 422d8d5bc43d9b477e2d8dee49235580ff532c961ce1947ac8a09e47b13b2e6eaa484e0ee8045f4fc9bdebf1c0ffb50ca197e243a4d8e93c43909d16640a8433
7
- data.tar.gz: 7cc5b56bbb3749d9edf5aef12d4e231e07496eb5f76a605cb7de436b99958a7b6a9aaab9160bdf51b43404b15175a7c93ee02ce6d00d5140e92a68bd7b42f0cc
6
+ metadata.gz: 01fc103302338a90c5b914e3da13fab9bfa4ca1a8d37a5f182de3755e3893321094fc018dbda672351a43cda77a0c73ef00cb7a63adeafe5b8688335f26fed64
7
+ data.tar.gz: fb900706022a8d2ccfb4169e18292c6e412c9d20b1ccea6e3f25c83ddfbea993546605e34ea8addf152cd1a3f13133186a480253a3542e697e7324879bcc2662
data/History.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ == 14.0.4 (2022-02-13)
2
+ * Fix for changed method in Rails 7.0.2 (Yota)
3
+
1
4
  == 14.0.3 (2022-01-09)
2
5
  * Remove override on ActiveRecord::Base#to_param. That method has moved to Integration
3
6
  so no longer works. #541. (Charlie Savage)
@@ -1,60 +1,60 @@
1
- module ActiveRecord
2
- module AutosaveAssociation
3
- def save_has_one_association(reflection)
4
- association = association_instance_get(reflection.name)
5
- record = association && association.load_target
6
-
7
- if record && !record.destroyed?
8
- autosave = reflection.options[:autosave]
9
-
10
- if autosave && record.marked_for_destruction?
11
- record.destroy
12
- elsif autosave != false
13
- # CPK
14
- #key = reflection.options[:primary_key] ? send(reflection.options[:primary_key]) : id
15
- key = reflection.options[:primary_key] ? self[reflection.options[:primary_key]] : id
16
-
17
- if (autosave && record.changed_for_autosave?) || new_record? || record_changed?(reflection, record, key)
18
- unless reflection.through_reflection
19
- record[reflection.foreign_key] = key
20
- if inverse_reflection = reflection.inverse_of
21
- record.association(inverse_reflection.name).loaded!
22
- end
23
- end
24
-
25
- saved = record.save(validate: !autosave)
26
- raise ActiveRecord::Rollback if !saved && autosave
27
- saved
28
- end
29
- end
30
- end
31
- end
32
-
33
- def save_belongs_to_association(reflection)
34
- association = association_instance_get(reflection.name)
35
- return unless association && association.loaded? && !association.stale_target?
36
-
37
- record = association.load_target
38
- if record && !record.destroyed?
39
- autosave = reflection.options[:autosave]
40
-
41
- if autosave && record.marked_for_destruction?
42
- self[reflection.foreign_key] = nil
43
- record.destroy
44
- elsif autosave != false
45
- saved = record.save(validate: !autosave) if record.new_record? || (autosave && record.changed_for_autosave?)
46
-
47
- if association.updated?
48
- # CPK
49
- # association_id = record.send(reflection.options[:primary_key] || :id)
50
- association_id = reflection.options[:primary_key] ? record[reflection.options[:primary_key]] : record.id
51
- self[reflection.foreign_key] = association_id
52
- association.loaded!
53
- end
54
-
55
- saved if autosave
56
- end
57
- end
58
- end
59
- end
60
- end
1
+ module ActiveRecord
2
+ module AutosaveAssociation
3
+ def save_has_one_association(reflection)
4
+ association = association_instance_get(reflection.name)
5
+ record = association && association.load_target
6
+
7
+ if record && !record.destroyed?
8
+ autosave = reflection.options[:autosave]
9
+
10
+ if autosave && record.marked_for_destruction?
11
+ record.destroy
12
+ elsif autosave != false
13
+ # CPK
14
+ #key = reflection.options[:primary_key] ? send(reflection.options[:primary_key]) : id
15
+ key = reflection.options[:primary_key] ? self[reflection.options[:primary_key]] : id
16
+
17
+ if (autosave && record.changed_for_autosave?) || new_record? || _record_changed?(reflection, record, key)
18
+ unless reflection.through_reflection
19
+ record[reflection.foreign_key] = key
20
+ if inverse_reflection = reflection.inverse_of
21
+ record.association(inverse_reflection.name).loaded!
22
+ end
23
+ end
24
+
25
+ saved = record.save(validate: !autosave)
26
+ raise ActiveRecord::Rollback if !saved && autosave
27
+ saved
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ def save_belongs_to_association(reflection)
34
+ association = association_instance_get(reflection.name)
35
+ return unless association && association.loaded? && !association.stale_target?
36
+
37
+ record = association.load_target
38
+ if record && !record.destroyed?
39
+ autosave = reflection.options[:autosave]
40
+
41
+ if autosave && record.marked_for_destruction?
42
+ self[reflection.foreign_key] = nil
43
+ record.destroy
44
+ elsif autosave != false
45
+ saved = record.save(validate: !autosave) if record.new_record? || (autosave && record.changed_for_autosave?)
46
+
47
+ if association.updated?
48
+ # CPK
49
+ # association_id = record.send(reflection.options[:primary_key] || :id)
50
+ association_id = reflection.options[:primary_key] ? record[reflection.options[:primary_key]] : record.id
51
+ self[reflection.foreign_key] = association_id
52
+ association.loaded!
53
+ end
54
+
55
+ saved if autosave
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -2,7 +2,7 @@ module CompositePrimaryKeys
2
2
  module VERSION
3
3
  MAJOR = 14
4
4
  MINOR = 0
5
- TINY = 3
5
+ TINY = 4
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
@@ -13,4 +13,8 @@ class Department < ActiveRecord::Base
13
13
  :primary_key => [:id, :location_id],
14
14
  :foreign_key => [:department_id, :location_id]
15
15
 
16
+ has_one :head_without_autosave, :class_name => 'Employee',
17
+ # We intentionally redefine primary key for test purposes. #455
18
+ :primary_key => [:id, :location_id],
19
+ :foreign_key => [:department_id, :location_id]
16
20
  end
@@ -124,6 +124,15 @@ class TestAssociations < ActiveSupport::TestCase
124
124
  assert_equal('Sarah1', department.head.name)
125
125
  end
126
126
 
127
+ def test_has_no_autosave
128
+ department = departments(:engineering)
129
+ assert_equal('Sarah', department.head_without_autosave.name)
130
+
131
+ department.head_without_autosave.name = 'Sarah1'
132
+ department.save!
133
+ assert_equal('Sarah1', department.head_without_autosave.name)
134
+ end
135
+
127
136
  def test_has_many_association_is_not_cached_to_where_it_returns_the_wrong_ones
128
137
  engineering = departments(:engineering)
129
138
  engineering_employees = engineering.employees
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: 14.0.3
4
+ version: 14.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Savage
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-09 00:00:00.000000000 Z
11
+ date: 2022-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 7.0.0
19
+ version: 7.0.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 7.0.0
26
+ version: 7.0.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement