ar_transaction_changes 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -15
- data/Gemfile.rails42 +5 -0
- data/Gemfile.rails50 +5 -0
- data/Gemfile.rails51 +5 -0
- data/Rakefile +0 -1
- data/ar_transaction_changes.gemspec +1 -2
- data/lib/ar_transaction_changes.rb +18 -38
- data/lib/ar_transaction_changes/version.rb +1 -1
- data/test/test_helper.rb +1 -6
- data/test/transaction_changes_test.rb +29 -1
- metadata +20 -43
- data/Appraisals +0 -22
- data/gemfiles/rails_3_2.gemfile +0 -8
- data/gemfiles/rails_4_0.gemfile +0 -8
- data/gemfiles/rails_4_1.gemfile +0 -8
- data/gemfiles/rails_4_2.gemfile +0 -7
- data/gemfiles/rails_5.gemfile +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 464cbfbf5ac37f36f38328159dc6c6d913d5db95
|
4
|
+
data.tar.gz: 59ae318875b3050ee7a4a2c71f196a6e2eb34669
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d46632d1585c8038490067757bb143fb0f0d32a2fd4465e03b424b148177454305042a9ad15ec9c9c761c8f743814e5b7d6a431c76b7cc56b482c896eda1b72
|
7
|
+
data.tar.gz: 86a9948798f5a517adb26262d73064e03f8cb4f7ae1da73e94a24e796fe7ff0590d1145389a1f46f24cdcb59abab2d43f4619bf14c31caf3de0bae61c2691b24
|
data/.travis.yml
CHANGED
@@ -2,25 +2,18 @@ language: ruby
|
|
2
2
|
sudo: false
|
3
3
|
|
4
4
|
rvm:
|
5
|
-
- 2.
|
6
|
-
- 2.1
|
7
|
-
- 2.2.4
|
5
|
+
- 2.2.5
|
6
|
+
- 2.3.1
|
8
7
|
|
9
8
|
gemfile:
|
10
|
-
-
|
11
|
-
-
|
12
|
-
-
|
13
|
-
- gemfiles/rails_4_2.gemfile
|
14
|
-
- gemfiles/rails_5.gemfile
|
9
|
+
- Gemfile.rails42
|
10
|
+
- Gemfile.rails50
|
11
|
+
- Gemfile.rails51
|
15
12
|
|
16
13
|
matrix:
|
17
|
-
|
18
|
-
- rvm: 2.
|
19
|
-
gemfile:
|
20
|
-
- rvm: 2.1.5
|
21
|
-
gemfile: gemfiles/rails_5.gemfile
|
22
|
-
- rvm: 2.2.4
|
23
|
-
gemfile: gemfiles/rails_3_2.gemfile
|
14
|
+
include:
|
15
|
+
- rvm: 2.1.9
|
16
|
+
gemfile: Gemfile.rails42
|
24
17
|
|
25
18
|
services:
|
26
19
|
- mysql
|
data/Gemfile.rails42
ADDED
data/Gemfile.rails50
ADDED
data/Gemfile.rails51
ADDED
data/Rakefile
CHANGED
@@ -17,9 +17,8 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_dependency "activerecord", ">=
|
20
|
+
gem.add_dependency "activerecord", ">= 4.2.4", "< 6.0"
|
21
21
|
|
22
22
|
gem.add_development_dependency("rake")
|
23
23
|
gem.add_development_dependency("mysql2")
|
24
|
-
gem.add_development_dependency("appraisal")
|
25
24
|
end
|
@@ -1,51 +1,31 @@
|
|
1
1
|
require "ar_transaction_changes/version"
|
2
2
|
|
3
3
|
module ArTransactionChanges
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
def _run_update_callbacks
|
12
|
-
ret = super
|
13
|
-
store_transaction_changed_attributes if ret != false
|
14
|
-
ret
|
15
|
-
end
|
16
|
-
|
17
|
-
def _run_commit_callbacks
|
18
|
-
super
|
19
|
-
ensure
|
20
|
-
@transaction_changed_attributes = nil
|
21
|
-
end
|
22
|
-
|
23
|
-
def _run_rollback_callbacks
|
24
|
-
super
|
25
|
-
ensure
|
26
|
-
@transaction_changed_attributes = nil
|
27
|
-
end
|
28
|
-
else
|
29
|
-
def run_callbacks(kind, *args)
|
30
|
-
ret = super
|
31
|
-
case kind.to_sym
|
32
|
-
when :create, :update
|
33
|
-
store_transaction_changed_attributes if ret != false
|
34
|
-
when :commit, :rollback
|
35
|
-
@transaction_changed_attributes = nil
|
36
|
-
end
|
4
|
+
def _run_commit_callbacks
|
5
|
+
super
|
6
|
+
ensure
|
7
|
+
@transaction_changed_attributes = nil
|
8
|
+
end
|
37
9
|
|
38
|
-
|
39
|
-
|
10
|
+
def _run_rollback_callbacks
|
11
|
+
super
|
12
|
+
ensure
|
13
|
+
@transaction_changed_attributes = nil
|
40
14
|
end
|
41
15
|
|
42
16
|
def transaction_changed_attributes
|
43
|
-
|
17
|
+
@transaction_changed_attributes ||= HashWithIndifferentAccess.new
|
44
18
|
end
|
45
19
|
|
46
20
|
private
|
47
21
|
|
48
|
-
def
|
49
|
-
|
22
|
+
def write_attribute(attr_name, value) # override
|
23
|
+
attr_name = attr_name.to_s
|
24
|
+
old_value = attributes[attr_name]
|
25
|
+
ret = super
|
26
|
+
unless transaction_changed_attributes.key?(attr_name) || value == old_value
|
27
|
+
transaction_changed_attributes[attr_name] = old_value
|
28
|
+
end
|
29
|
+
ret
|
50
30
|
end
|
51
31
|
end
|
data/test/test_helper.rb
CHANGED
@@ -10,17 +10,12 @@ 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
|
ActiveRecord::Base.establish_connection database_yml['test']
|
12
12
|
|
13
|
-
if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new("4.1")
|
14
|
-
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
15
|
-
NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
13
|
ActiveRecord::Base.connection.tap do |db|
|
20
14
|
db.drop_table(:users) if db.table_exists?(:users)
|
21
15
|
db.create_table(:users) do |t|
|
22
16
|
t.string :name
|
23
17
|
t.string :occupation
|
18
|
+
t.timestamps null: false
|
24
19
|
end
|
25
20
|
end
|
26
21
|
|
@@ -41,7 +41,7 @@ class TransactionChangesTest < MiniTest::Unit::TestCase
|
|
41
41
|
@user.save!
|
42
42
|
raise ActiveRecord::Rollback
|
43
43
|
end
|
44
|
-
|
44
|
+
assert_nil @user.stored_transaction_changes
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_transaction_changes_after_reload_saved
|
@@ -66,4 +66,32 @@ class TransactionChangesTest < MiniTest::Unit::TestCase
|
|
66
66
|
assert_equal ["Dylan", "Dillon"], @user.stored_transaction_changes["name"]
|
67
67
|
end
|
68
68
|
|
69
|
+
def test_transaction_changes_for_changing_updated_at
|
70
|
+
@user.update_attributes!(updated_at: Time.now - 1.second)
|
71
|
+
old_updated_at = @user.updated_at
|
72
|
+
@user.stored_transaction_changes = nil
|
73
|
+
|
74
|
+
@user.updated_at = Time.now
|
75
|
+
@user.save!
|
76
|
+
|
77
|
+
assert_equal [old_updated_at, @user.updated_at], @user.stored_transaction_changes["updated_at"]
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_transaction_changes_for_touch
|
81
|
+
@user.update_attributes!(updated_at: Time.now - 1.second)
|
82
|
+
old_updated_at = @user.updated_at
|
83
|
+
@user.stored_transaction_changes = nil
|
84
|
+
|
85
|
+
@user.touch
|
86
|
+
|
87
|
+
assert_equal [old_updated_at, @user.updated_at], @user.stored_transaction_changes["updated_at"]
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_transaction_changes_doesnt_record_non_changes
|
91
|
+
@user.transaction do
|
92
|
+
@user.name = "Dylan"
|
93
|
+
@user.save!
|
94
|
+
end
|
95
|
+
refute @user.stored_transaction_changes["name"]
|
96
|
+
end
|
69
97
|
end
|
metadata
CHANGED
@@ -1,81 +1,61 @@
|
|
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.1
|
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: 2017-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
- - <
|
19
|
+
version: 4.2.4
|
20
|
+
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '6.0'
|
23
|
-
- - '!='
|
24
|
-
- !ruby/object:Gem::Version
|
25
|
-
version: 4.2.3
|
26
23
|
type: :runtime
|
27
24
|
prerelease: false
|
28
25
|
version_requirements: !ruby/object:Gem::Requirement
|
29
26
|
requirements:
|
30
|
-
- -
|
27
|
+
- - ">="
|
31
28
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
33
|
-
- - <
|
29
|
+
version: 4.2.4
|
30
|
+
- - "<"
|
34
31
|
- !ruby/object:Gem::Version
|
35
32
|
version: '6.0'
|
36
|
-
- - '!='
|
37
|
-
- !ruby/object:Gem::Version
|
38
|
-
version: 4.2.3
|
39
33
|
- !ruby/object:Gem::Dependency
|
40
34
|
name: rake
|
41
35
|
requirement: !ruby/object:Gem::Requirement
|
42
36
|
requirements:
|
43
|
-
- -
|
37
|
+
- - ">="
|
44
38
|
- !ruby/object:Gem::Version
|
45
39
|
version: '0'
|
46
40
|
type: :development
|
47
41
|
prerelease: false
|
48
42
|
version_requirements: !ruby/object:Gem::Requirement
|
49
43
|
requirements:
|
50
|
-
- -
|
44
|
+
- - ">="
|
51
45
|
- !ruby/object:Gem::Version
|
52
46
|
version: '0'
|
53
47
|
- !ruby/object:Gem::Dependency
|
54
48
|
name: mysql2
|
55
49
|
requirement: !ruby/object:Gem::Requirement
|
56
50
|
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: '0'
|
60
|
-
type: :development
|
61
|
-
prerelease: false
|
62
|
-
version_requirements: !ruby/object:Gem::Requirement
|
63
|
-
requirements:
|
64
|
-
- - '>='
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: '0'
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
|
-
name: appraisal
|
69
|
-
requirement: !ruby/object:Gem::Requirement
|
70
|
-
requirements:
|
71
|
-
- - '>='
|
51
|
+
- - ">="
|
72
52
|
- !ruby/object:Gem::Version
|
73
53
|
version: '0'
|
74
54
|
type: :development
|
75
55
|
prerelease: false
|
76
56
|
version_requirements: !ruby/object:Gem::Requirement
|
77
57
|
requirements:
|
78
|
-
- -
|
58
|
+
- - ">="
|
79
59
|
- !ruby/object:Gem::Version
|
80
60
|
version: '0'
|
81
61
|
description: Solves the problem of trying to get all the changes to an object during
|
@@ -86,19 +66,16 @@ executables: []
|
|
86
66
|
extensions: []
|
87
67
|
extra_rdoc_files: []
|
88
68
|
files:
|
89
|
-
- .gitignore
|
90
|
-
- .travis.yml
|
91
|
-
- Appraisals
|
69
|
+
- ".gitignore"
|
70
|
+
- ".travis.yml"
|
92
71
|
- Gemfile
|
72
|
+
- Gemfile.rails42
|
73
|
+
- Gemfile.rails50
|
74
|
+
- Gemfile.rails51
|
93
75
|
- LICENSE.txt
|
94
76
|
- README.md
|
95
77
|
- Rakefile
|
96
78
|
- ar_transaction_changes.gemspec
|
97
|
-
- gemfiles/rails_3_2.gemfile
|
98
|
-
- gemfiles/rails_4_0.gemfile
|
99
|
-
- gemfiles/rails_4_1.gemfile
|
100
|
-
- gemfiles/rails_4_2.gemfile
|
101
|
-
- gemfiles/rails_5.gemfile
|
102
79
|
- lib/ar_transaction_changes.rb
|
103
80
|
- lib/ar_transaction_changes/version.rb
|
104
81
|
- test/database.yml.default
|
@@ -114,17 +91,17 @@ require_paths:
|
|
114
91
|
- lib
|
115
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
116
93
|
requirements:
|
117
|
-
- -
|
94
|
+
- - ">="
|
118
95
|
- !ruby/object:Gem::Version
|
119
96
|
version: '0'
|
120
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
98
|
requirements:
|
122
|
-
- -
|
99
|
+
- - ">="
|
123
100
|
- !ruby/object:Gem::Version
|
124
101
|
version: '0'
|
125
102
|
requirements: []
|
126
103
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
104
|
+
rubygems_version: 2.6.10
|
128
105
|
signing_key:
|
129
106
|
specification_version: 4
|
130
107
|
summary: Store transaction changes for active record objects
|
data/Appraisals
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
appraise "rails-3-2" do
|
2
|
-
gem "rails", "~> 3.2.21"
|
3
|
-
gem "mysql2", "~> 0.3.20"
|
4
|
-
end
|
5
|
-
|
6
|
-
appraise "rails-4-0" do
|
7
|
-
gem "rails", "~> 4.0.12"
|
8
|
-
gem "mysql2", "~> 0.3.20"
|
9
|
-
end
|
10
|
-
|
11
|
-
appraise "rails-4-1" do
|
12
|
-
gem "rails", "~> 4.1.8"
|
13
|
-
gem "mysql2", "~> 0.3.20"
|
14
|
-
end
|
15
|
-
|
16
|
-
appraise "rails-4-2" do
|
17
|
-
gem "rails", "~> 4.2.0"
|
18
|
-
end
|
19
|
-
|
20
|
-
appraise "rails-5" do
|
21
|
-
gem "rails", "~> 5.0.0.beta4"
|
22
|
-
end
|
data/gemfiles/rails_3_2.gemfile
DELETED
data/gemfiles/rails_4_0.gemfile
DELETED
data/gemfiles/rails_4_1.gemfile
DELETED
data/gemfiles/rails_4_2.gemfile
DELETED