ar_transaction_changes 1.1.7 → 1.1.8

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: 1b75ccc7bc393e60284a26e6077bdfc48e8032b52780770f0b762f292a6a3393
4
- data.tar.gz: 2a048448c70283320792559fd7f7ae90d339384fda9fa3b9d437abf2607fd701
3
+ metadata.gz: 41a85de7f78cb23d9af300f5279a909db5ecab9b3e02bca9cf2ecd4703062b8b
4
+ data.tar.gz: cc04e7f4c6e884d4db4fe94c84b8a8ef55871613c0b0d737f9956a5f69d3ebcf
5
5
  SHA512:
6
- metadata.gz: f3148c75a2a2bebc626451d1cbfbb7263cb1e39a56571af89761dc1f5b96a3a988de2a97ee2bef546744765f2b3eb569de77ce45fea5e7da1289821231435076
7
- data.tar.gz: e21dff998d73c00ee6f6b8b7d92d9814412bf3421b8dc009e41429b7fc33e014cd9cd4f01d05288bc5009fc530749628de7d19c6e97973c53a3ddd37bc8f9cd0
6
+ metadata.gz: 4fde634868ccbb2518edbde7841bce8ca6745a41c6ef398d1d20ce55bae6a7eefb9c35689ebecadd3ef8246200a6034bc202960457f42e430a351c56b7ef0742
7
+ data.tar.gz: d14df655313155febb0c769a2852efc8c1ce4888cfbaa05ea362ecdb3a1219bc98051b5da1b3583dd8add30ff40a6ea52f0a6ac86198cb54a4d7208520daecb4
@@ -0,0 +1,47 @@
1
+ name: CI
2
+
3
+ on:
4
+ push: {}
5
+ pull_request:
6
+ types: [opened, synchronize]
7
+
8
+ jobs:
9
+ build:
10
+ if: github.event_name == 'push' || github.event.pull_request.head.repo.owner.login != 'dylanahsmith'
11
+
12
+ runs-on: ubuntu-latest
13
+
14
+ strategy:
15
+ matrix:
16
+ entry:
17
+ - name: 'Minimum supported'
18
+ ruby: 2.4
19
+ gemfile: Gemfile.rails52
20
+ - name: "Latest released versions"
21
+ ruby: 3.0
22
+ gemfile: Gemfile
23
+ - name: "Rails main branch"
24
+ ruby: 3.0
25
+ gemfile: Gemfile.rails_head
26
+
27
+ name: ${{ matrix.entry.name }}
28
+
29
+ env:
30
+ BUNDLE_GEMFILE: ${{ matrix.entry.gemfile }}
31
+
32
+ steps:
33
+ - name: Install required packages
34
+ run: |
35
+ sudo apt-get update
36
+ sudo apt-get -y install libsqlite3-dev
37
+ - uses: actions/checkout@v2
38
+ - name: Set up Ruby
39
+ uses: ruby/setup-ruby@v1
40
+ with:
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
46
+ - name: Run tests
47
+ run: bundle exec rake
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ gem 'sqlite3', '~> 1.4'
data/Gemfile.rails52 CHANGED
@@ -1,5 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem 'activerecord', '~> 5.2.0'
4
+ gem "sqlite3", "~> 1.3", ">= 1.3.6"
4
5
 
5
6
  gemspec
data/Gemfile.rails_head CHANGED
@@ -1,5 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem 'activerecord', github: 'rails/rails'
4
+ gem 'sqlite3', '~> 1.4'
4
5
 
5
6
  gemspec
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # ArTransactionChanges
2
- [![Build Status](https://travis-ci.org/dylanahsmith/ar_transaction_changes.png?branch=master)](https://travis-ci.org/dylanahsmith/ar_transaction_changes)
2
+ [![Build Status](https://github.com/dylanahsmith/ar_transaction_changes/workflows/CI/badge.svg?branch=main)](https://github.com/dylanahsmith/ar_transaction_changes/actions?query=branch%3Amain)
3
3
 
4
4
  Store all attribute changes for active record objects during a
5
5
  transaction so that they are available in an after_commit callbacks.
@@ -41,14 +41,24 @@ module ArTransactionChanges
41
41
  old_value = _read_attribute_for_transaction(attr_name)
42
42
  ret = yield
43
43
  new_value = _read_attribute_for_transaction(attr_name)
44
- unless transaction_changed_attributes.key?(attr_name) || new_value == old_value
44
+ if !transaction_changed_attributes.key?(attr_name) && new_value != old_value
45
45
  attribute = @attributes[attr_name]
46
46
  transaction_changed_attributes[attr_name] = if attribute.type.is_a?(::ActiveRecord::Type::Serialized)
47
47
  attribute.type.deserialize(old_value)
48
48
  else
49
49
  old_value
50
50
  end
51
- transaction_changed_attributes
51
+ 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
56
+
57
+ stored_value = transaction_changed_attributes[attr_name]
58
+
59
+ if new_value == stored_value
60
+ transaction_changed_attributes.delete(attr_name)
61
+ end
52
62
  end
53
63
  ret
54
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ArTransactionChanges
4
- VERSION = "1.1.7"
4
+ VERSION = "1.1.8"
5
5
  end
@@ -1,7 +1,3 @@
1
1
  test:
2
- adapter: mysql2
3
- database: ar_transaction_changes_test
4
- host: 127.0.0.1
5
- encoding: utf8
6
- username: root
7
- password:
2
+ adapter: sqlite3
3
+ database: ':memory:'
data/test/models/user.rb CHANGED
@@ -10,6 +10,7 @@ class User < ActiveRecord::Base
10
10
  end
11
11
 
12
12
  serialize :connection_details, Array
13
+ serialize :notes, Array
13
14
 
14
15
  attr_accessor :stored_transaction_changes
15
16
 
data/test/test_helper.rb CHANGED
@@ -10,8 +10,10 @@ config_filename = test_dir.join("database.yml").exist? ? "database.yml" : "datab
10
10
  database_yml = YAML.load(test_dir.join(config_filename).read)
11
11
  database_config = database_yml.fetch("test")
12
12
 
13
- ActiveRecord::Base.establish_connection(database_config.except("database"))
14
- ActiveRecord::Base.connection.recreate_database(database_config.fetch("database"))
13
+ if database_config.fetch('adapter') != 'sqlite3'
14
+ ActiveRecord::Base.establish_connection(database_config.except("database"))
15
+ ActiveRecord::Base.connection.recreate_database(database_config.fetch("database"))
16
+ end
15
17
  ActiveRecord::Base.establish_connection(database_config)
16
18
 
17
19
  ActiveRecord::Base.connection.tap do |db|
@@ -20,6 +22,7 @@ ActiveRecord::Base.connection.tap do |db|
20
22
  t.string :occupation
21
23
  t.integer :age
22
24
  t.text :connection_details
25
+ t.text :notes
23
26
  t.timestamps null: false
24
27
  end
25
28
  end
@@ -126,4 +126,31 @@ class TransactionChangesTest < MiniTest::Unit::TestCase
126
126
  @user.save!
127
127
  assert_equal '2.2.2.2', @user.connection_details.first.client_ip
128
128
  end
129
+
130
+ def test_double_save_back_to_original_value
131
+ @user.transaction do
132
+ @user.name = "Dillon"
133
+ @user.save!(touch: false)
134
+
135
+ @user.name = "Dylan"
136
+ @user.save!(touch: false)
137
+ end
138
+
139
+ assert_empty @user.stored_transaction_changes
140
+ end
141
+
142
+ def test_double_save_back_to_original_value_for_serialized_attribute
143
+ @user.notes = ['a', 'b']
144
+ @user.save!
145
+
146
+ @user.transaction do
147
+ @user.notes = ['b', 'c']
148
+ @user.save!(touch: false)
149
+
150
+ @user.notes = ['a', 'b']
151
+ @user.save!(touch: false)
152
+ end
153
+
154
+ assert_empty @user.stored_transaction_changes
155
+ end
129
156
  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.7
4
+ version: 1.1.8
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: 2020-07-01 00:00:00.000000000 Z
11
+ date: 2021-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -60,8 +60,8 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
+ - ".github/workflows/ci.yml"
63
64
  - ".gitignore"
64
- - ".travis.yml"
65
65
  - Gemfile
66
66
  - Gemfile.rails52
67
67
  - Gemfile.rails_head
@@ -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.2
97
+ rubygems_version: 3.1.4
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: Store transaction changes for active record objects
data/.travis.yml DELETED
@@ -1,17 +0,0 @@
1
- language: ruby
2
- sudo: false
3
-
4
- jobs:
5
- include:
6
- - name: "Minimum supported versions"
7
- rvm: 2.4
8
- gemfile: Gemfile.rails52
9
- - name: "Latest released versions"
10
- rvm: 2.7
11
- gemfile: Gemfile
12
- - name: "Rails master branch"
13
- rvm: 2.7
14
- gemfile: Gemfile.rails_head
15
-
16
- services:
17
- - mysql