paper_trail 5.2.2 → 5.2.3

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: 40131e454009216354dd82f76bfab5ecbc465efb
4
- data.tar.gz: b1cbd97963f0ef014c90b2462eceaac5e6df2e77
3
+ metadata.gz: 096e05463c63093078629b25f9be4449a57d3fa7
4
+ data.tar.gz: 56ab2c64e8a17af51d4acb67076740f4dd07d17e
5
5
  SHA512:
6
- metadata.gz: 42138b9e11f51e210cc11af893b77f1834727c4280dd522ef28465856f3af0072d7065c3a906ccdfcb28ee50d80eefa7535033a6c65a612287ea0d89cd7faf58
7
- data.tar.gz: 8a54e81675b6954778ebd715f596886991a47aba63fb0cf3a549be9410947e181a4084b323c64d156c8587306f2c2d6aec557479f3466dada0c34feefc400177
6
+ metadata.gz: 6e10ad3f94b5604ba97f8d49b9f5191ace437d5bd777fa78aa0f2459c82acd852aa62ddb73bd589f90b8d28f4cdd702cdc89438bb0dd63fa020edb265bf4a3db
7
+ data.tar.gz: 09ccd0195883ddba04a640c4a235ac4ca5ea94e006d39549d974f4181cc55c5f6856525fdcf39c32089fcfcb4cffb088b3b8894b2077ce07a46ab02a0faa2405
@@ -3,7 +3,7 @@
3
3
  This project follows [semver 2.0.0](http://semver.org/spec/v2.0.0.html) and the
4
4
  recommendations of [keepachangelog.com](http://keepachangelog.com/).
5
5
 
6
- ## Unreleased
6
+ ## 5.2.3 (2016-11-29)
7
7
 
8
8
  ### Breaking Changes
9
9
 
@@ -19,6 +19,11 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
19
19
 
20
20
  ### Fixed
21
21
 
22
+ - [#889](https://github.com/airblade/paper_trail/pull/889) -
23
+ Fix warning message in instances when a version can't be persisted due to validation errors.
24
+ - [#868](https://github.com/airblade/paper_trail/pull/868)
25
+ Fix usage of find_by_id when primary key is not id, affecting reifying certain records.
26
+
22
27
  ## 5.2.2 (2016-09-08)
23
28
 
24
29
  ### Breaking Changes
@@ -27,7 +32,7 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
27
32
 
28
33
  ### Deprecated
29
34
 
30
- - [#863](https://github.com/airblade/paper_trail/pull/863)
35
+ - [#863](https://github.com/airblade/paper_trail/pull/863) -
31
36
  PaperTrail.timestamp_field= deprecated without replacement.
32
37
  See [#861](https://github.com/airblade/paper_trail/pull/861) for discussion.
33
38
 
@@ -37,6 +42,8 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
37
42
 
38
43
  ### Fixed
39
44
 
45
+ - None
46
+
40
47
  ## 5.2.1 (2016-09-02)
41
48
 
42
49
  ### Breaking Changes
@@ -404,7 +411,7 @@ candidates.
404
411
  ## 3.0.5
405
412
 
406
413
  - [#401](https://github.com/airblade/paper_trail/issues/401) / [#406](https://github.com/airblade/paper_trail/issues/406) -
407
- `PaperTrail::Version` class is not loaded via a `Rails::Engine`, even when the gem is used with in Rails. This feature has
414
+ `PaperTrail::Version` class is not loaded via a `Rails::Engine`, even when the gem is used within Rails. This feature has
408
415
  will be re-introduced in version `4.0`.
409
416
  - [#398](https://github.com/airblade/paper_trail/pull/398) - Only require the `RSpec` helper if `RSpec::Core` is required.
410
417
 
data/README.md CHANGED
@@ -11,7 +11,7 @@ has been destroyed.
11
11
  | Version | Documentation |
12
12
  | -------------- | ------------- |
13
13
  | Unreleased | https://github.com/airblade/paper_trail/blob/master/README.md |
14
- | 5.2.2 | https://github.com/airblade/paper_trail/blob/v5.2.2/README.md |
14
+ | 5.2.3 | https://github.com/airblade/paper_trail/blob/v5.2.3/README.md |
15
15
  | 4.2.0 | https://github.com/airblade/paper_trail/blob/v4.2.0/README.md |
16
16
  | 3.0.9 | https://github.com/airblade/paper_trail/blob/v3.0.9/README.md |
17
17
  | 2.7.2 | https://github.com/airblade/paper_trail/blob/v2.7.2/README.md |
@@ -418,8 +418,8 @@ module PaperTrail
418
418
 
419
419
  def log_version_errors(version, action)
420
420
  version.logger.warn(
421
- "Unable to create version for #{action} of #{@record.class.name}##{id}: " +
422
- version.errors.full_messages.join(", ")
421
+ "Unable to create version for #{action} of #{@record.class.name}" +
422
+ "##{@record.id}: " + version.errors.full_messages.join(", ")
423
423
  )
424
424
  end
425
425
 
@@ -31,7 +31,8 @@ module PaperTrail
31
31
  klass = version_reification_class(version, attrs)
32
32
  # The `dup` option always returns a new object, otherwise we should
33
33
  # attempt to look for the item outside of default scope(s).
34
- if options[:dup] || (item_found = klass.unscoped.find_by_id(version.item_id)).nil?
34
+ find_cond = { klass.primary_key => version.item_id }
35
+ if options[:dup] || (item_found = klass.unscoped.where(find_cond).first).nil?
35
36
  model = klass.new
36
37
  elsif options[:unversioned_attributes] == :nil
37
38
  model = item_found
@@ -3,7 +3,7 @@ module PaperTrail
3
3
  module VERSION
4
4
  MAJOR = 5
5
5
  MINOR = 2
6
- TINY = 2
6
+ TINY = 3
7
7
  PRE = nil
8
8
 
9
9
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".").freeze
@@ -42,7 +42,13 @@ Gem::Specification.new do |s|
42
42
  s.add_development_dependency "activerecord-jdbcmysql-adapter", "~> 1.3.15"
43
43
  else
44
44
  s.add_development_dependency "sqlite3", "~> 1.2"
45
- s.add_development_dependency "pg", "~> 0.17"
45
+
46
+ # pg 0.19 requires ruby >= 2.0.0
47
+ if ::Gem.ruby_version >= ::Gem::Version.new("2.0.0")
48
+ s.add_development_dependency "pg", "~> 0.19.0"
49
+ else
50
+ s.add_development_dependency "pg", [">= 0.17", "< 0.19"]
51
+ end
46
52
 
47
53
  # activerecord >= 4.2.5 may use mysql2 >= 0.4
48
54
  s.add_development_dependency "mysql2", "~> 0.4.2"
@@ -0,0 +1,18 @@
1
+ require "rails_helper"
2
+
3
+ describe CustomPrimaryKeyRecord, type: :model do
4
+ it { is_expected.to be_versioned }
5
+
6
+ describe "#versions" do
7
+ it "returns instances of CustomPrimaryKeyRecordVersion", versioning: true do
8
+ custom_primary_key_record = described_class.create!
9
+ custom_primary_key_record.update_attributes!(name: "bob")
10
+ version = custom_primary_key_record.versions.last
11
+ expect(version).to be_a(CustomPrimaryKeyRecordVersion)
12
+ version_from_db = CustomPrimaryKeyRecordVersion.last
13
+ expect(version_from_db.reify).to be_a(CustomPrimaryKeyRecord)
14
+ custom_primary_key_record.destroy
15
+ expect(CustomPrimaryKeyRecordVersion.last.reify).to be_a(CustomPrimaryKeyRecord)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ require "securerandom"
2
+ class CustomPrimaryKeyRecord < ActiveRecord::Base
3
+ self.primary_key = :uuid
4
+
5
+ has_paper_trail class_name: "CustomPrimaryKeyRecordVersion"
6
+ # this unusual default_scope is to test the case of the Version#item association
7
+ # not returning the item due to unmatched default_scope on the model.
8
+ default_scope -> { where(name: "custom_primary_key_record") }
9
+
10
+ before_create do
11
+ self.uuid ||= SecureRandom.uuid
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ class CustomPrimaryKeyRecordVersion < PaperTrail::Version
2
+ self.table_name = "custom_primary_key_record_versions"
3
+ end
@@ -271,6 +271,24 @@ class SetUpTestTables < ActiveRecord::Migration
271
271
  end
272
272
  add_index :bar_habtms_foo_habtms, [:foo_habtm_id]
273
273
  add_index :bar_habtms_foo_habtms, [:bar_habtm_id]
274
+
275
+ # custom_primary_key_records use a uuid column (string)
276
+ create_table :custom_primary_key_records, id: false, force: true do |t|
277
+ t.column :uuid, :string, primary_key: true
278
+ t.string :name
279
+ t.timestamps null: true
280
+ end
281
+
282
+ # and custom_primary_key_record_versions stores the uuid in item_id, a string
283
+ create_table :custom_primary_key_record_versions, force: true do |t|
284
+ t.string :item_type, null: false
285
+ t.string :item_id, null: false
286
+ t.string :event, null: false
287
+ t.string :whodunnit
288
+ t.text :object
289
+ t.datetime :created_at
290
+ end
291
+ add_index :custom_primary_key_record_versions, [:item_type, :item_id], name: "idx_cust_pk_item"
274
292
  end
275
293
 
276
294
  def down
@@ -80,6 +80,24 @@ ActiveRecord::Schema.define(version: 20110208155312) do
80
80
  t.integer "quotation_id"
81
81
  end
82
82
 
83
+ create_table "custom_primary_key_record_versions", force: :cascade do |t|
84
+ t.string "item_type", null: false
85
+ t.string "item_id", null: false
86
+ t.string "event", null: false
87
+ t.string "whodunnit"
88
+ t.text "object"
89
+ t.datetime "created_at"
90
+ end
91
+
92
+ add_index "custom_primary_key_record_versions", ["item_type", "item_id"], name: "idx_cust_pk_item"
93
+
94
+ create_table "custom_primary_key_records", id: false, force: :cascade do |t|
95
+ t.string "uuid"
96
+ t.string "name"
97
+ t.datetime "created_at"
98
+ t.datetime "updated_at"
99
+ end
100
+
83
101
  create_table "customers", force: :cascade do |t|
84
102
  t.string "name"
85
103
  end
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: 5.2.2
4
+ version: 5.2.3
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: 2016-09-08 00:00:00.000000000 Z
12
+ date: 2016-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -239,14 +239,14 @@ dependencies:
239
239
  requirements:
240
240
  - - "~>"
241
241
  - !ruby/object:Gem::Version
242
- version: '0.17'
242
+ version: 0.19.0
243
243
  type: :development
244
244
  prerelease: false
245
245
  version_requirements: !ruby/object:Gem::Requirement
246
246
  requirements:
247
247
  - - "~>"
248
248
  - !ruby/object:Gem::Version
249
- version: '0.17'
249
+ version: 0.19.0
250
250
  - !ruby/object:Gem::Dependency
251
251
  name: mysql2
252
252
  requirement: !ruby/object:Gem::Requirement
@@ -327,6 +327,7 @@ files:
327
327
  - spec/models/boolit_spec.rb
328
328
  - spec/models/callback_modifier_spec.rb
329
329
  - spec/models/car_spec.rb
330
+ - spec/models/custom_primary_key_record_spec.rb
330
331
  - spec/models/fluxor_spec.rb
331
332
  - spec/models/gadget_spec.rb
332
333
  - spec/models/joined_version_spec.rb
@@ -367,6 +368,7 @@ files:
367
368
  - test/dummy/app/models/cat.rb
368
369
  - test/dummy/app/models/chapter.rb
369
370
  - test/dummy/app/models/citation.rb
371
+ - test/dummy/app/models/custom_primary_key_record.rb
370
372
  - test/dummy/app/models/customer.rb
371
373
  - test/dummy/app/models/document.rb
372
374
  - test/dummy/app/models/dog.rb
@@ -399,6 +401,7 @@ files:
399
401
  - test/dummy/app/models/whatchamajigger.rb
400
402
  - test/dummy/app/models/widget.rb
401
403
  - test/dummy/app/models/wotsit.rb
404
+ - test/dummy/app/versions/custom_primary_key_record_version.rb
402
405
  - test/dummy/app/versions/joined_version.rb
403
406
  - test/dummy/app/versions/json_version.rb
404
407
  - test/dummy/app/versions/kitchen/banana_version.rb
@@ -475,6 +478,7 @@ test_files:
475
478
  - spec/models/boolit_spec.rb
476
479
  - spec/models/callback_modifier_spec.rb
477
480
  - spec/models/car_spec.rb
481
+ - spec/models/custom_primary_key_record_spec.rb
478
482
  - spec/models/fluxor_spec.rb
479
483
  - spec/models/gadget_spec.rb
480
484
  - spec/models/joined_version_spec.rb
@@ -515,6 +519,7 @@ test_files:
515
519
  - test/dummy/app/models/cat.rb
516
520
  - test/dummy/app/models/chapter.rb
517
521
  - test/dummy/app/models/citation.rb
522
+ - test/dummy/app/models/custom_primary_key_record.rb
518
523
  - test/dummy/app/models/customer.rb
519
524
  - test/dummy/app/models/document.rb
520
525
  - test/dummy/app/models/dog.rb
@@ -547,6 +552,7 @@ test_files:
547
552
  - test/dummy/app/models/whatchamajigger.rb
548
553
  - test/dummy/app/models/widget.rb
549
554
  - test/dummy/app/models/wotsit.rb
555
+ - test/dummy/app/versions/custom_primary_key_record_version.rb
550
556
  - test/dummy/app/versions/joined_version.rb
551
557
  - test/dummy/app/versions/json_version.rb
552
558
  - test/dummy/app/versions/kitchen/banana_version.rb