ar_transaction_changes 1.1.1 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +10 -15
- data/{Gemfile.rails42 → Gemfile.rails52} +1 -1
- data/Gemfile.rails_head +5 -0
- data/README.md +13 -0
- data/ar_transaction_changes.gemspec +2 -1
- data/lib/ar_transaction_changes.rb +20 -4
- data/lib/ar_transaction_changes/version.rb +1 -1
- data/test/test_helper.rb +8 -4
- data/test/transaction_changes_test.rb +19 -3
- metadata +9 -16
- data/Gemfile.rails50 +0 -5
- data/Gemfile.rails51 +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4a6cb7a7d939217a2aa0ce44c25c2f89a97ed7457be1c1836d6e7d82e2250c9a
|
4
|
+
data.tar.gz: 4d7295698fedf9d8981be7266b86f5c0ef75794ded3f0fce511b3aec151df76e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3fbd5e913fc97722ea9181f088f9dd2b0282751ceb5cc1588a9f73c63b5f3e1df97dfad7f4aa9ee9952b3bb52bba49edafa65419ca904623475806aad5ebb92
|
7
|
+
data.tar.gz: 8bbbcf7edd439aa32bed2d1ef988a20adc49629256b779f1e6c473193c9b28c50c0d246e80b57195b37e452d81324a7ec71fd448a35f4b8f5bebe9abd4f4b7b8
|
data/.travis.yml
CHANGED
@@ -1,22 +1,17 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
3
|
|
4
|
-
|
5
|
-
- 2.2.5
|
6
|
-
- 2.3.1
|
7
|
-
|
8
|
-
gemfile:
|
9
|
-
- Gemfile.rails42
|
10
|
-
- Gemfile.rails50
|
11
|
-
- Gemfile.rails51
|
12
|
-
|
13
|
-
matrix:
|
4
|
+
jobs:
|
14
5
|
include:
|
15
|
-
-
|
16
|
-
|
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
|
17
15
|
|
18
16
|
services:
|
19
17
|
- mysql
|
20
|
-
|
21
|
-
before_script:
|
22
|
-
- mysql -e 'create database ar_transaction_changes_test'
|
data/Gemfile.rails_head
ADDED
data/README.md
CHANGED
@@ -44,6 +44,19 @@ class User < ActiveRecord::Base
|
|
44
44
|
end
|
45
45
|
```
|
46
46
|
|
47
|
+
## Important Notes
|
48
|
+
|
49
|
+
`ar_transaction_changes` may have conflict with another gems who modify
|
50
|
+
`active_record#write_attribute` method, e.g. `globalize` gem
|
51
|
+
|
52
|
+
the workaround is by requiring this gem first, for example:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
gem 'ar_transaction_changes', require: false
|
56
|
+
gem 'globalize', require: ['ar_transaction_changes', 'globalize']
|
57
|
+
|
58
|
+
```
|
59
|
+
|
47
60
|
## Contributing
|
48
61
|
|
49
62
|
1. Fork it
|
@@ -11,13 +11,14 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.description = %q{Solves the problem of trying to get all the changes to an object during a transaction in an after_commit callbacks.}
|
12
12
|
gem.summary = %q{Store transaction changes for active record objects}
|
13
13
|
gem.homepage = "https://github.com/dylanahsmith/ar_transaction_changes"
|
14
|
+
gem.license = "MIT"
|
14
15
|
|
15
16
|
gem.files = `git ls-files`.split($/)
|
16
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
19
|
gem.require_paths = ["lib"]
|
19
20
|
|
20
|
-
gem.add_dependency "activerecord", ">=
|
21
|
+
gem.add_dependency "activerecord", ">= 5.2.0"
|
21
22
|
|
22
23
|
gem.add_development_dependency("rake")
|
23
24
|
gem.add_development_dependency("mysql2")
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "ar_transaction_changes/version"
|
2
|
+
require "active_record"
|
2
3
|
|
3
4
|
module ArTransactionChanges
|
4
5
|
def _run_commit_callbacks
|
@@ -17,13 +18,28 @@ module ArTransactionChanges
|
|
17
18
|
@transaction_changed_attributes ||= HashWithIndifferentAccess.new
|
18
19
|
end
|
19
20
|
|
21
|
+
def _write_attribute(attr_name, value)
|
22
|
+
_store_transaction_changed_attributes(attr_name) do
|
23
|
+
super(attr_name, value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if ActiveRecord.version >= Gem::Version.new('6.1.0.alpha')
|
28
|
+
def write_attribute(attr_name, value)
|
29
|
+
_store_transaction_changed_attributes(attr_name) do
|
30
|
+
super(attr_name, value)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
20
35
|
private
|
21
36
|
|
22
|
-
def
|
37
|
+
def _store_transaction_changed_attributes(attr_name)
|
23
38
|
attr_name = attr_name.to_s
|
24
|
-
old_value =
|
25
|
-
ret =
|
26
|
-
|
39
|
+
old_value = read_attribute(attr_name)
|
40
|
+
ret = yield
|
41
|
+
new_value = read_attribute(attr_name)
|
42
|
+
unless transaction_changed_attributes.key?(attr_name) || new_value == old_value
|
27
43
|
transaction_changed_attributes[attr_name] = old_value
|
28
44
|
end
|
29
45
|
ret
|
data/test/test_helper.rb
CHANGED
@@ -1,20 +1,24 @@
|
|
1
|
-
ENV["RAILS_ENV"] = "test"
|
2
1
|
require 'pathname'
|
3
2
|
require 'yaml'
|
4
|
-
require 'active_record'
|
5
3
|
require 'ar_transaction_changes'
|
6
4
|
require 'minitest/autorun'
|
7
5
|
|
6
|
+
ENV["RAILS_ENV"] = "test"
|
7
|
+
|
8
8
|
test_dir = Pathname.new(File.dirname(__FILE__))
|
9
9
|
config_filename = test_dir.join("database.yml").exist? ? "database.yml" : "database.yml.default"
|
10
10
|
database_yml = YAML.load(test_dir.join(config_filename).read)
|
11
|
-
|
11
|
+
database_config = database_yml.fetch("test")
|
12
|
+
|
13
|
+
ActiveRecord::Base.establish_connection(database_config.except("database"))
|
14
|
+
ActiveRecord::Base.connection.recreate_database(database_config.fetch("database"))
|
15
|
+
ActiveRecord::Base.establish_connection(database_config)
|
12
16
|
|
13
17
|
ActiveRecord::Base.connection.tap do |db|
|
14
|
-
db.drop_table(:users) if db.table_exists?(:users)
|
15
18
|
db.create_table(:users) do |t|
|
16
19
|
t.string :name
|
17
20
|
t.string :occupation
|
21
|
+
t.integer :age
|
18
22
|
t.timestamps null: false
|
19
23
|
end
|
20
24
|
end
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class TransactionChangesTest < MiniTest::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
@user = User.new(:name => "Dylan", :occupation => "Developer")
|
5
|
+
@user = User.new(:name => "Dylan", :occupation => "Developer", age: 20)
|
6
6
|
@user.save!
|
7
7
|
@user.stored_transaction_changes = nil
|
8
8
|
end
|
@@ -23,6 +23,13 @@ class TransactionChangesTest < MiniTest::Unit::TestCase
|
|
23
23
|
assert_equal ["Dylan", "Dillon"], @user.stored_transaction_changes["name"]
|
24
24
|
end
|
25
25
|
|
26
|
+
def test_transaction_changes_for_updating_attribute
|
27
|
+
@user[:name] = "Dillon"
|
28
|
+
@user.save!
|
29
|
+
|
30
|
+
assert_equal ["Dylan", "Dillon"], @user.stored_transaction_changes["name"]
|
31
|
+
end
|
32
|
+
|
26
33
|
def test_transaction_changes_for_double_save
|
27
34
|
@user.transaction do
|
28
35
|
@user.name = "Dillon"
|
@@ -67,7 +74,7 @@ class TransactionChangesTest < MiniTest::Unit::TestCase
|
|
67
74
|
end
|
68
75
|
|
69
76
|
def test_transaction_changes_for_changing_updated_at
|
70
|
-
@user.
|
77
|
+
@user.update!(updated_at: Time.now - 1.second)
|
71
78
|
old_updated_at = @user.updated_at
|
72
79
|
@user.stored_transaction_changes = nil
|
73
80
|
|
@@ -78,7 +85,7 @@ class TransactionChangesTest < MiniTest::Unit::TestCase
|
|
78
85
|
end
|
79
86
|
|
80
87
|
def test_transaction_changes_for_touch
|
81
|
-
@user.
|
88
|
+
@user.update!(updated_at: Time.now - 1.second)
|
82
89
|
old_updated_at = @user.updated_at
|
83
90
|
@user.stored_transaction_changes = nil
|
84
91
|
|
@@ -94,4 +101,13 @@ class TransactionChangesTest < MiniTest::Unit::TestCase
|
|
94
101
|
end
|
95
102
|
refute @user.stored_transaction_changes["name"]
|
96
103
|
end
|
104
|
+
|
105
|
+
def test_transaction_changes_type_cast
|
106
|
+
# "20" will be converted to 20 by read_attribute https://apidock.com/rails/ActiveRecord/AttributeMethods/read_attribute
|
107
|
+
@user.transaction do
|
108
|
+
@user.age = "20"
|
109
|
+
@user.save!
|
110
|
+
end
|
111
|
+
assert_empty @user.stored_transaction_changes
|
112
|
+
end
|
97
113
|
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.6
|
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: 2020-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,20 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '6.0'
|
19
|
+
version: 5.2.0
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '6.0'
|
26
|
+
version: 5.2.0
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: rake
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,9 +63,8 @@ files:
|
|
69
63
|
- ".gitignore"
|
70
64
|
- ".travis.yml"
|
71
65
|
- Gemfile
|
72
|
-
- Gemfile.
|
73
|
-
- Gemfile.
|
74
|
-
- Gemfile.rails51
|
66
|
+
- Gemfile.rails52
|
67
|
+
- Gemfile.rails_head
|
75
68
|
- LICENSE.txt
|
76
69
|
- README.md
|
77
70
|
- Rakefile
|
@@ -83,7 +76,8 @@ files:
|
|
83
76
|
- test/test_helper.rb
|
84
77
|
- test/transaction_changes_test.rb
|
85
78
|
homepage: https://github.com/dylanahsmith/ar_transaction_changes
|
86
|
-
licenses:
|
79
|
+
licenses:
|
80
|
+
- MIT
|
87
81
|
metadata: {}
|
88
82
|
post_install_message:
|
89
83
|
rdoc_options: []
|
@@ -100,8 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
94
|
- !ruby/object:Gem::Version
|
101
95
|
version: '0'
|
102
96
|
requirements: []
|
103
|
-
|
104
|
-
rubygems_version: 2.6.10
|
97
|
+
rubygems_version: 3.1.2
|
105
98
|
signing_key:
|
106
99
|
specification_version: 4
|
107
100
|
summary: Store transaction changes for active record objects
|
data/Gemfile.rails50
DELETED