ar_transaction_changes 1.1.8 → 1.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41a85de7f78cb23d9af300f5279a909db5ecab9b3e02bca9cf2ecd4703062b8b
4
- data.tar.gz: cc04e7f4c6e884d4db4fe94c84b8a8ef55871613c0b0d737f9956a5f69d3ebcf
3
+ metadata.gz: 5871403ece76d3c6fceb41b1a5aecd240d5460363e0d86a88f4b27ba4fc1d562
4
+ data.tar.gz: fda845379838e83afc84c11bc23005f4af0ac8e12df804c48c5010d724b52ba3
5
5
  SHA512:
6
- metadata.gz: 4fde634868ccbb2518edbde7841bce8ca6745a41c6ef398d1d20ce55bae6a7eefb9c35689ebecadd3ef8246200a6034bc202960457f42e430a351c56b7ef0742
7
- data.tar.gz: d14df655313155febb0c769a2852efc8c1ce4888cfbaa05ea362ecdb3a1219bc98051b5da1b3583dd8add30ff40a6ea52f0a6ac86198cb54a4d7208520daecb4
6
+ metadata.gz: 386cd79e7207afdc17fc9f019183fe14674c5a3af5fe6b35c87433417bfe0ce94573abbe43954f46812e22911051aa3ab80a8d47ddee7a78b6f5801b6d10fef2
7
+ data.tar.gz: 628f82d89b3c54455dc9c5071e9beb1610deb710bbfa158f616d886b04c9136f446bc25ad04d8f1ba9e6f3096dd5c93f64340a207cc4541f53e6420ab74db115
@@ -15,13 +15,13 @@ jobs:
15
15
  matrix:
16
16
  entry:
17
17
  - name: 'Minimum supported'
18
- ruby: 2.4
19
- gemfile: Gemfile.rails52
18
+ ruby: 2.7
19
+ gemfile: Gemfile.rails6
20
20
  - name: "Latest released versions"
21
- ruby: 3.0
21
+ ruby: 3.2
22
22
  gemfile: Gemfile
23
23
  - name: "Rails main branch"
24
- ruby: 3.0
24
+ ruby: 3.2
25
25
  gemfile: Gemfile.rails_head
26
26
 
27
27
  name: ${{ matrix.entry.name }}
@@ -34,14 +34,11 @@ jobs:
34
34
  run: |
35
35
  sudo apt-get update
36
36
  sudo apt-get -y install libsqlite3-dev
37
- - uses: actions/checkout@v2
37
+ - uses: actions/checkout@v3
38
38
  - name: Set up Ruby
39
39
  uses: ruby/setup-ruby@v1
40
40
  with:
41
41
  ruby-version: ${{ matrix.entry.ruby }}
42
- - name: Install bundler and gems
43
- run: |
44
- gem install bundler
45
- bundle install --jobs 4 --retry 3
42
+ bundler-cache: true
46
43
  - name: Run tests
47
44
  run: bundle exec rake
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'activerecord', '~> 5.2.0'
3
+ gem 'activerecord', '~> 6.0.0'
4
4
  gem "sqlite3", "~> 1.3", ">= 1.3.6"
5
5
 
6
6
  gemspec
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ArTransactionChanges
4
- VERSION = "1.1.8"
4
+ VERSION = "1.1.9"
5
5
  end
@@ -34,25 +34,37 @@ module ArTransactionChanges
34
34
  end
35
35
  end
36
36
 
37
+ def attribute_will_change!(attr_name)
38
+ unless transaction_changed_attributes.key?(attr_name)
39
+ value = _read_attribute_for_transaction(attr_name)
40
+ value = _deserialize_transaction_change_value(attr_name, value)
41
+ transaction_changed_attributes[attr_name] = value
42
+ end
43
+ super
44
+ end
45
+
37
46
  private
38
47
 
48
+ def init_internals
49
+ super
50
+ @transaction_changed_attributes = nil
51
+ end
52
+
53
+ def _deserialize_transaction_change_value(attr_name, value)
54
+ attribute = @attributes[attr_name]
55
+ return value unless attribute.type.is_a?(::ActiveRecord::Type::Serialized)
56
+ attribute.type.deserialize(value)
57
+ end
58
+
39
59
  def _store_transaction_changed_attributes(attr_name)
40
60
  attr_name = attr_name.to_s
41
61
  old_value = _read_attribute_for_transaction(attr_name)
42
62
  ret = yield
43
63
  new_value = _read_attribute_for_transaction(attr_name)
44
64
  if !transaction_changed_attributes.key?(attr_name) && new_value != old_value
45
- attribute = @attributes[attr_name]
46
- transaction_changed_attributes[attr_name] = if attribute.type.is_a?(::ActiveRecord::Type::Serialized)
47
- attribute.type.deserialize(old_value)
48
- else
49
- old_value
50
- end
65
+ transaction_changed_attributes[attr_name] = _deserialize_transaction_change_value(attr_name, old_value)
51
66
  elsif transaction_changed_attributes.key?(attr_name)
52
- attribute = @attributes[attr_name]
53
- if attribute.type.is_a?(::ActiveRecord::Type::Serialized)
54
- new_value = attribute.type.deserialize(new_value)
55
- end
67
+ new_value = _deserialize_transaction_change_value(attr_name, new_value)
56
68
 
57
69
  stored_value = transaction_changed_attributes[attr_name]
58
70
 
data/test/test_helper.rb CHANGED
@@ -28,3 +28,10 @@ ActiveRecord::Base.connection.tap do |db|
28
28
  end
29
29
 
30
30
  Dir[test_dir.join("models/*.rb")].each{ |file| require file }
31
+
32
+ serializable_classes = [User::ConnectionDetails]
33
+ if ActiveRecord::VERSION::MAJOR >= 7
34
+ ActiveRecord.yaml_column_permitted_classes += serializable_classes
35
+ else
36
+ ActiveRecord::Base.yaml_column_permitted_classes += serializable_classes
37
+ end
@@ -153,4 +153,25 @@ class TransactionChangesTest < MiniTest::Unit::TestCase
153
153
 
154
154
  assert_empty @user.stored_transaction_changes
155
155
  end
156
+
157
+ def test_mutating_serialized_attribute_in_place_with_attribute_will_change
158
+ @user.notes_will_change!
159
+ @user.notes.push('a')
160
+ @user.save!
161
+
162
+ assert_equal [[], ['a']], @user.stored_transaction_changes['notes']
163
+ end
164
+
165
+ def test_double_modification_with_attribute_will_change
166
+ @user.transaction do
167
+ @user.notes = ['a']
168
+ @user.save!
169
+
170
+ @user.notes_will_change!
171
+ @user.notes.push('b')
172
+ @user.save!
173
+ end
174
+
175
+ assert_equal [[], ['a', 'b']], @user.stored_transaction_changes['notes']
176
+ end
156
177
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_transaction_changes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.8
4
+ version: 1.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Thacker-Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-04 00:00:00.000000000 Z
11
+ date: 2023-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -63,7 +63,7 @@ files:
63
63
  - ".github/workflows/ci.yml"
64
64
  - ".gitignore"
65
65
  - Gemfile
66
- - Gemfile.rails52
66
+ - Gemfile.rails6
67
67
  - Gemfile.rails_head
68
68
  - LICENSE.txt
69
69
  - README.md
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  requirements: []
97
- rubygems_version: 3.1.4
97
+ rubygems_version: 3.4.1
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: Store transaction changes for active record objects