paper_trail 4.0.1 → 4.0.2

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
  SHA1:
3
- metadata.gz: 047fe27b3f2154c19030502f4d129dcdd2873146
4
- data.tar.gz: 6b6f268b260b459e0e6df8340ec9d33cb5c07824
3
+ metadata.gz: 8a92875e074ba53155be9597997716e75f2dfa33
4
+ data.tar.gz: b87bb9cad5f094f61957c287e4a27db3cff0d5d1
5
5
  SHA512:
6
- metadata.gz: 49c10975deb4b0f20617b4b770a1f6b99d2980df4072dd71da1dc48c7da85e409c6eeadcbfcc74f86f239b320e7ae73f6d7d2f72971439a39330d6f353b9f33e
7
- data.tar.gz: 3ecddc1755c7d139e04716582bbe136163605eb33354acaf7e520bc0178dfe7c9d184c8f673f4bb744440c4e7113a58017c6de4fca9262ff99575bee764d804d
6
+ metadata.gz: f5e16e1229742e460df8c0d1c6315a8207653f756b5df16d88b82e17ae07530260a0dab228afc894aeb3dcc765a7aa15f2b1b46f9366364abbba1bcb12ed61f5
7
+ data.tar.gz: e5a3ad55b824efa44f70924a47e840ccc16733308298d66eb1de4ba07010eff61ba1ad6a54c50288c18b60d92462d94d025bbd1d14bf4f496349c1a39e43ea89
@@ -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.1'`
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.1'`
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
 
@@ -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
- gem 'mysql2', '~> 0.3'
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
- where_conditions = "object @> '#{args.to_json}'::jsonb"
92
+ where("object @> ?", args.to_json)
93
93
  elsif columns_hash['object'].type == :json
94
- where_conditions = args.map do |field, value|
95
- "object->>'#{field}' = '#{value}'"
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
- where_conditions = where_conditions.join(" AND ")
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
- end.reduce do |condition1, condition2|
104
- condition1.and(condition2)
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
- where_conditions = "object_changes @> '#{args.to_json}'::jsonb"
116
+ where("object_changes @> ?", args.to_json)
117
117
  elsif columns_hash['object'].type == :json
118
- where_conditions = args.map do |field, value|
119
- "((object_changes->>'#{field}' ILIKE '[#{value.to_json},%') OR (object_changes->>'#{field}' ILIKE '[%,#{value.to_json}]%'))"
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
- where_conditions = where_conditions.join(" AND ")
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
- end.reduce do |condition1, condition2|
128
- condition1.and(condition2)
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?
@@ -2,7 +2,7 @@ module PaperTrail
2
2
  module VERSION
3
3
  MAJOR = 4
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
@@ -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
- s.add_development_dependency 'mysql2', '~> 0.3'
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)
@@ -442,7 +442,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
442
442
  end
443
443
 
444
444
  should 'handle decimals' do
445
- assert_in_delta 2.71828, @previous.a_decimal, 0.00001
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.71828, @last.reify.a_decimal, 0.00001
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.1
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: 2015-12-14 00:00:00.000000000 Z
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: '0.3'
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: '0.3'
241
+ version: 0.3.20
242
242
  - !ruby/object:Gem::Dependency
243
243
  name: pg
244
244
  requirement: !ruby/object:Gem::Requirement