paper_trail 4.0.1 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +2 -2
- data/gemfiles/3.0.gemfile +12 -4
- data/lib/paper_trail/version_concern.rb +24 -22
- data/lib/paper_trail/version_number.rb +1 -1
- data/paper_trail.gemspec +10 -2
- data/spec/models/json_version_spec.rb +20 -0
- data/test/unit/model_test.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a92875e074ba53155be9597997716e75f2dfa33
|
4
|
+
data.tar.gz: b87bb9cad5f094f61957c287e4a27db3cff0d5d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5e16e1229742e460df8c0d1c6315a8207653f756b5df16d88b82e17ae07530260a0dab228afc894aeb3dcc765a7aa15f2b1b46f9366364abbba1bcb12ed61f5
|
7
|
+
data.tar.gz: e5a3ad55b824efa44f70924a47e840ccc16733308298d66eb1de4ba07010eff61ba1ad6a54c50288c18b60d92462d94d025bbd1d14bf4f496349c1a39e43ea89
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## 4.0.2
|
2
|
+
|
3
|
+
### Breaking Changes
|
4
|
+
|
5
|
+
- None
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- None
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
|
13
|
+
- [#696](https://github.com/airblade/paper_trail/issues/696) /
|
14
|
+
[#697](https://github.com/airblade/paper_trail/pull/697)
|
15
|
+
Bind JSON query parameters in `where_object` and `where_object_changes`.
|
16
|
+
|
1
17
|
## 4.0.1
|
2
18
|
|
3
19
|
### Breaking Changes
|
data/README.md
CHANGED
@@ -70,7 +70,7 @@ has been destroyed.
|
|
70
70
|
|
71
71
|
1. Add PaperTrail to your `Gemfile`.
|
72
72
|
|
73
|
-
`gem 'paper_trail', '~> 4.0.
|
73
|
+
`gem 'paper_trail', '~> 4.0.2'`
|
74
74
|
|
75
75
|
2. Generate a migration which will add a `versions` table to your database.
|
76
76
|
|
@@ -93,7 +93,7 @@ setting up your app with PaperTrail will look something like this:
|
|
93
93
|
|
94
94
|
1. Add PaperTrail to your `Gemfile`.
|
95
95
|
|
96
|
-
`gem 'paper_trail', '~> 4.0.
|
96
|
+
`gem 'paper_trail', '~> 4.0.2'`
|
97
97
|
|
98
98
|
2. Generate a migration to add a `versions` table to your database.
|
99
99
|
|
data/gemfiles/3.0.gemfile
CHANGED
@@ -23,16 +23,24 @@ group :development, :test do
|
|
23
23
|
# To do proper transactional testing with ActiveSupport::TestCase on MySQL
|
24
24
|
gem 'database_cleaner', '~> 1.2.0'
|
25
25
|
|
26
|
-
# Allow time travel in testing. timecop is only supported after 1.9.2 but does a better cleanup at 'return'
|
27
26
|
if RUBY_VERSION < "1.9.2"
|
28
27
|
gem 'delorean'
|
28
|
+
|
29
|
+
# rack-cache 1.3 drops ruby 1.8.7 support
|
30
|
+
gem 'rack-cache', '1.2'
|
29
31
|
else
|
32
|
+
# timecop is only supported after 1.9.2 but does a better cleanup at 'return'
|
30
33
|
gem 'timecop'
|
31
34
|
end
|
32
35
|
|
33
|
-
platforms :ruby do
|
36
|
+
platforms :ruby do
|
34
37
|
gem 'sqlite3', '~> 1.2'
|
35
|
-
|
38
|
+
|
39
|
+
# We would prefer to only constrain mysql2 to '~> 0.3',
|
40
|
+
# but a rails bug (https://github.com/rails/rails/issues/21544)
|
41
|
+
# requires us to constrain to '~> 0.3.20' for now.
|
42
|
+
gem 'mysql2', '~> 0.3.20'
|
43
|
+
|
36
44
|
gem 'pg', '~> 0.17.1'
|
37
45
|
end
|
38
46
|
|
@@ -42,7 +50,7 @@ group :development, :test do
|
|
42
50
|
gem 'shoulda-matchers', '~> 1.5'
|
43
51
|
end
|
44
52
|
|
45
|
-
platforms :jruby do
|
53
|
+
platforms :jruby do
|
46
54
|
# Use jRuby's sqlite3 adapter for jRuby
|
47
55
|
gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3'
|
48
56
|
gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3'
|
@@ -89,23 +89,23 @@ module PaperTrail
|
|
89
89
|
raise ArgumentError, 'expected to receive a Hash' unless args.is_a?(Hash)
|
90
90
|
|
91
91
|
if columns_hash['object'].type == :jsonb
|
92
|
-
|
92
|
+
where("object @> ?", args.to_json)
|
93
93
|
elsif columns_hash['object'].type == :json
|
94
|
-
|
95
|
-
|
94
|
+
predicates = []
|
95
|
+
values = []
|
96
|
+
args.each do |field, value|
|
97
|
+
predicates.push "object->>? = ?"
|
98
|
+
values.concat([field, value.to_s])
|
96
99
|
end
|
97
|
-
|
100
|
+
sql = predicates.join(" and ")
|
101
|
+
where(sql, *values)
|
98
102
|
else
|
99
103
|
arel_field = arel_table[:object]
|
100
|
-
|
101
|
-
where_conditions = args.map do |field, value|
|
104
|
+
where_conditions = args.map { |field, value|
|
102
105
|
PaperTrail.serializer.where_object_condition(arel_field, field, value)
|
103
|
-
|
104
|
-
|
105
|
-
end
|
106
|
+
}.reduce { |a, e| a.and(e) }
|
107
|
+
where(where_conditions)
|
106
108
|
end
|
107
|
-
|
108
|
-
where(where_conditions)
|
109
109
|
end
|
110
110
|
|
111
111
|
def where_object_changes(args = {})
|
@@ -113,23 +113,25 @@ module PaperTrail
|
|
113
113
|
|
114
114
|
if columns_hash['object_changes'].type == :jsonb
|
115
115
|
args.each { |field, value| args[field] = [value] }
|
116
|
-
|
116
|
+
where("object_changes @> ?", args.to_json)
|
117
117
|
elsif columns_hash['object'].type == :json
|
118
|
-
|
119
|
-
|
118
|
+
predicates = []
|
119
|
+
values = []
|
120
|
+
args.each do |field, value|
|
121
|
+
predicates.push(
|
122
|
+
"((object_changes->>? ILIKE ?) OR (object_changes->>? ILIKE ?))"
|
123
|
+
)
|
124
|
+
values.concat([field, "[#{value.to_json},%", field, "[%,#{value.to_json}]%"])
|
120
125
|
end
|
121
|
-
|
126
|
+
sql = predicates.join(" and ")
|
127
|
+
where(sql, *values)
|
122
128
|
else
|
123
129
|
arel_field = arel_table[:object_changes]
|
124
|
-
|
125
|
-
where_conditions = args.map do |field, value|
|
130
|
+
where_conditions = args.map { |field, value|
|
126
131
|
PaperTrail.serializer.where_object_changes_condition(arel_field, field, value)
|
127
|
-
|
128
|
-
|
129
|
-
end
|
132
|
+
}.reduce { |a, e| a.and(e) }
|
133
|
+
where(where_conditions)
|
130
134
|
end
|
131
|
-
|
132
|
-
where(where_conditions)
|
133
135
|
end
|
134
136
|
|
135
137
|
def primary_key_is_int?
|
data/paper_trail.gemspec
CHANGED
@@ -34,17 +34,25 @@ Gem::Specification.new do |s|
|
|
34
34
|
s.add_development_dependency 'generator_spec'
|
35
35
|
s.add_development_dependency 'database_cleaner', '~> 1.2'
|
36
36
|
|
37
|
-
# Allow time travel in testing. timecop is only supported after 1.9.2 but does a better cleanup at 'return'
|
38
37
|
if RUBY_VERSION < "1.9.2"
|
39
38
|
s.add_development_dependency 'delorean'
|
39
|
+
|
40
|
+
# rack-cache 1.3 drops ruby 1.8.7 support
|
41
|
+
s.add_development_dependency 'rack-cache', '1.2'
|
40
42
|
else
|
43
|
+
# timecop is only supported after 1.9.2 but does a better cleanup at 'return'
|
41
44
|
s.add_development_dependency 'timecop'
|
42
45
|
end
|
43
46
|
|
44
47
|
# JRuby support for the test ENV
|
45
48
|
unless defined?(JRUBY_VERSION)
|
46
49
|
s.add_development_dependency 'sqlite3', '~> 1.2'
|
47
|
-
|
50
|
+
|
51
|
+
# We would prefer to only constrain mysql2 to '~> 0.3',
|
52
|
+
# but a rails bug (https://github.com/rails/rails/issues/21544)
|
53
|
+
# requires us to constrain to '~> 0.3.20' for now.
|
54
|
+
s.add_development_dependency 'mysql2', '~> 0.3.20'
|
55
|
+
|
48
56
|
s.add_development_dependency 'pg', '~> 0.17'
|
49
57
|
else
|
50
58
|
s.add_development_dependency 'activerecord-jdbcsqlite3-adapter', '~> 1.3'
|
@@ -13,6 +13,16 @@ if JsonVersion.table_exists?
|
|
13
13
|
describe '#where_object' do
|
14
14
|
it { expect(JsonVersion).to respond_to(:where_object) }
|
15
15
|
|
16
|
+
it "escapes values" do
|
17
|
+
f = Fruit.create(:name => 'Bobby')
|
18
|
+
expect(
|
19
|
+
f.
|
20
|
+
versions.
|
21
|
+
where_object(:name => "Robert'; DROP TABLE Students;--").
|
22
|
+
count
|
23
|
+
).to eq(0)
|
24
|
+
end
|
25
|
+
|
16
26
|
context "invalid arguments" do
|
17
27
|
it "should raise an error" do
|
18
28
|
expect { JsonVersion.where_object(:foo) }.to raise_error(ArgumentError)
|
@@ -42,6 +52,16 @@ if JsonVersion.table_exists?
|
|
42
52
|
describe '#where_object_changes' do
|
43
53
|
it { expect(JsonVersion).to respond_to(:where_object_changes) }
|
44
54
|
|
55
|
+
it "escapes values" do
|
56
|
+
f = Fruit.create(:name => 'Bobby')
|
57
|
+
expect(
|
58
|
+
f.
|
59
|
+
versions.
|
60
|
+
where_object_changes(:name => "Robert'; DROP TABLE Students;--").
|
61
|
+
count
|
62
|
+
).to eq(0)
|
63
|
+
end
|
64
|
+
|
45
65
|
context "invalid arguments" do
|
46
66
|
it "should raise an error" do
|
47
67
|
expect { JsonVersion.where_object_changes(:foo) }.to raise_error(ArgumentError)
|
data/test/unit/model_test.rb
CHANGED
@@ -442,7 +442,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
442
442
|
end
|
443
443
|
|
444
444
|
should 'handle decimals' do
|
445
|
-
assert_in_delta 2.
|
445
|
+
assert_in_delta 2.7183, @previous.a_decimal, 0.0001
|
446
446
|
end
|
447
447
|
|
448
448
|
should 'handle datetimes' do
|
@@ -484,7 +484,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
484
484
|
assert_equal 'The quick brown fox', @last.reify.a_text
|
485
485
|
assert_equal 42, @last.reify.an_integer
|
486
486
|
assert_in_delta 153.01, @last.reify.a_float, 0.001
|
487
|
-
assert_in_delta 2.
|
487
|
+
assert_in_delta 2.7183, @last.reify.a_decimal, 0.0001
|
488
488
|
assert_equal @date_time.to_time.utc.to_i, @last.reify.a_datetime.to_time.utc.to_i
|
489
489
|
assert_equal @time.utc.to_i, @last.reify.a_time.utc.to_i
|
490
490
|
assert_equal @date, @last.reify.a_date
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paper_trail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Stewart
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-01-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -231,14 +231,14 @@ dependencies:
|
|
231
231
|
requirements:
|
232
232
|
- - "~>"
|
233
233
|
- !ruby/object:Gem::Version
|
234
|
-
version:
|
234
|
+
version: 0.3.20
|
235
235
|
type: :development
|
236
236
|
prerelease: false
|
237
237
|
version_requirements: !ruby/object:Gem::Requirement
|
238
238
|
requirements:
|
239
239
|
- - "~>"
|
240
240
|
- !ruby/object:Gem::Version
|
241
|
-
version:
|
241
|
+
version: 0.3.20
|
242
242
|
- !ruby/object:Gem::Dependency
|
243
243
|
name: pg
|
244
244
|
requirement: !ruby/object:Gem::Requirement
|