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 +4 -4
- data/.github/workflows/ci.yml +47 -0
- data/Gemfile +2 -0
- data/Gemfile.rails52 +1 -0
- data/Gemfile.rails_head +1 -0
- data/README.md +1 -1
- data/lib/ar_transaction_changes.rb +12 -2
- data/lib/ar_transaction_changes/version.rb +1 -1
- data/test/database.yml.default +2 -6
- data/test/models/user.rb +1 -0
- data/test/test_helper.rb +5 -2
- data/test/transaction_changes_test.rb +27 -0
- metadata +4 -4
- data/.travis.yml +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41a85de7f78cb23d9af300f5279a909db5ecab9b3e02bca9cf2ecd4703062b8b
|
4
|
+
data.tar.gz: cc04e7f4c6e884d4db4fe94c84b8a8ef55871613c0b0d737f9956a5f69d3ebcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/Gemfile.rails52
CHANGED
data/Gemfile.rails_head
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# ArTransactionChanges
|
2
|
-
[![Build Status](https://
|
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
|
-
|
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
|
-
|
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
|
data/test/database.yml.default
CHANGED
data/test/models/user.rb
CHANGED
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
|
-
|
14
|
-
ActiveRecord::Base.
|
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.
|
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:
|
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.
|
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
|