paper_trail 3.0.6 → 3.0.7
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 +8 -3
- data/README.md +20 -3
- data/lib/paper_trail/has_paper_trail.rb +6 -11
- data/lib/paper_trail/version_number.rb +1 -1
- data/spec/models/animal_spec.rb +19 -0
- data/test/dummy/app/models/animal.rb +2 -0
- data/test/unit/serializer_test.rb +3 -3
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6b8b27c90bfd64f2b38cef59276076e4123f38b
|
4
|
+
data.tar.gz: 02bc459e5c9ae9e74eafdc782eee7cb4708cfb3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0581395fd0a5782e279133c26ff723a62eda27470ecd57660d3b495c55ef542a9d08b99a5701762f585fefed54a5191c367469031a1a00cb2efede10690a7b8
|
7
|
+
data.tar.gz: e12d54c3a6c00dfa21d2634ee6b2561bbf1aba2bbc907e82f0a651b12acf35a391c6ca81a0e589feca9e0c502efbdc052b5b2e18010e44a3a9ea60c7ec99b8fe
|
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,16 @@
|
|
1
|
+
## 3.0.7
|
2
|
+
|
3
|
+
- [#404](https://github.com/airblade/paper_trail/issues/404) / [#428](https://github.com/airblade/paper_trail/issues/428) -
|
4
|
+
Fix errors occuring when a user attempts to update the inheritance column on an STI model instance in `ActiveRecord` 4.1.x
|
5
|
+
|
1
6
|
## 3.0.6
|
2
7
|
|
3
8
|
- [#414](https://github.com/airblade/paper_trail/issues/414) - Fix functionality `ignore` argument to `has_paper_trail`
|
4
|
-
in `ActiveRecord` 4
|
9
|
+
in `ActiveRecord` 4
|
5
10
|
|
6
11
|
## 3.0.5
|
7
12
|
|
8
|
-
- [#401](https://github.com/airblade/paper_trail/issues/401) / [#406](https://github.com/airblade/paper_trail/issues/406)
|
13
|
+
- [#401](https://github.com/airblade/paper_trail/issues/401) / [#406](https://github.com/airblade/paper_trail/issues/406) -
|
9
14
|
`PaperTrail::Version` class is not loaded via a `Rails::Engine`, even when the gem is used with in Rails. This feature has
|
10
15
|
will be re-introduced in version `3.1.0`.
|
11
16
|
- [#398](https://github.com/airblade/paper_trail/pull/398) - Only require the `RSpec` helper if `RSpec::Core` is required.
|
@@ -20,7 +25,7 @@ in the `PaperTrail::Version` class through a `Rails::Engine` when the gem is use
|
|
20
25
|
- [#383](https://github.com/airblade/paper_trail/pull/383) - Make gem compatible with `ActiveRecord::Enum` (available in `ActiveRecord` 4.1+).
|
21
26
|
- [#380](https://github.com/airblade/paper_trail/pull/380) / [#377](https://github.com/airblade/paper_trail/issues/377) -
|
22
27
|
Add `VersionConcern#where_object` instance method; acts as a helper for querying against the `object` column in versions table.
|
23
|
-
- [#373](https://github.com/airblade/paper_trail/pull/373) - Fix default sort order for the `versions` association in `ActiveRecord` 4.1
|
28
|
+
- [#373](https://github.com/airblade/paper_trail/pull/373) - Fix default sort order for the `versions` association in `ActiveRecord` 4.1+
|
24
29
|
- [#372](https://github.com/airblade/paper_trail/pull/372) - Use [Arel](https://github.com/rails/arel) for SQL construction.
|
25
30
|
- [#365](https://github.com/airblade/paper_trail/issues/365) - `VersionConcern#version_at` should return `nil` when receiving a timestamp
|
26
31
|
that occured after the object was destroyed.
|
data/README.md
CHANGED
@@ -42,7 +42,7 @@ The Rails 2.3 code is on the [`rails2`](https://github.com/airblade/paper_trail/
|
|
42
42
|
|
43
43
|
1. Add PaperTrail to your `Gemfile`.
|
44
44
|
|
45
|
-
`gem 'paper_trail', '~> 3.0.
|
45
|
+
`gem 'paper_trail', '~> 3.0.7'`
|
46
46
|
|
47
47
|
2. Generate a migration which will add a `versions` table to your database.
|
48
48
|
|
@@ -64,7 +64,7 @@ your applications `ActiveRecord` connection in a manner similar to the way `Rail
|
|
64
64
|
|
65
65
|
1. Add PaperTrail to your `Gemfile`.
|
66
66
|
|
67
|
-
`gem 'paper_trail', '~> 3.0.
|
67
|
+
`gem 'paper_trail', '~> 3.0.7'`
|
68
68
|
|
69
69
|
2. Generate a migration to add a `versions` table to your database.
|
70
70
|
|
@@ -545,7 +545,7 @@ If you are using Postgres, you should also define the sequence that your custom
|
|
545
545
|
```ruby
|
546
546
|
class PostVersion < PaperTrail::Version
|
547
547
|
self.table_name = :post_versions
|
548
|
-
self.sequence_name = :
|
548
|
+
self.sequence_name = :post_versions_id_seq
|
549
549
|
end
|
550
550
|
```
|
551
551
|
|
@@ -890,6 +890,23 @@ A valid serializer is a `module` (or `class`) that defines a `load` and `dump` m
|
|
890
890
|
* [YAML](https://github.com/airblade/paper_trail/blob/master/lib/paper_trail/serializers/yaml.rb) - Default
|
891
891
|
* [JSON](https://github.com/airblade/paper_trail/blob/master/lib/paper_trail/serializers/json.rb)
|
892
892
|
|
893
|
+
### PostgreSQL JSON column type support
|
894
|
+
|
895
|
+
If you use PostgreSQL, and would like to store your `object` (and/or `object_changes`) data in a column of
|
896
|
+
[type `JSON`](http://www.postgresql.org/docs/9.4/static/datatype-json.html),
|
897
|
+
specify `json` instead of `text` for these columns in your migration:
|
898
|
+
|
899
|
+
```ruby
|
900
|
+
create_table :versions do |t|
|
901
|
+
...
|
902
|
+
t.json :object # Full object changes
|
903
|
+
t.json :object_changes # Optional column-level changes
|
904
|
+
...
|
905
|
+
end
|
906
|
+
```
|
907
|
+
|
908
|
+
Note: You don't need to use a particular serializer for the PostgreSQL `JSON` column type.
|
909
|
+
|
893
910
|
## Limiting the number of versions created per object instance
|
894
911
|
|
895
912
|
If you are wary of your `versions` table growing to an unwieldy size, or just don't care to track more than a certain number of versions per object,
|
@@ -338,14 +338,8 @@ module PaperTrail
|
|
338
338
|
end
|
339
339
|
|
340
340
|
def item_before_change
|
341
|
-
|
342
|
-
|
343
|
-
all_timestamp_attributes.each do |column|
|
344
|
-
previous[column] = send(column) if self.class.column_names.include?(column.to_s) and not send(column).nil?
|
345
|
-
end
|
346
|
-
enums = previous.respond_to?(:defined_enums) ? previous.defined_enums : {}
|
347
|
-
previous.tap do |prev|
|
348
|
-
prev.id = id # `dup` clears the `id` so we add that back
|
341
|
+
attributes.tap do |prev|
|
342
|
+
enums = self.respond_to?(:defined_enums) ? self.defined_enums : {}
|
349
343
|
changed_attributes.select { |k,v| self.class.column_names.include?(k) }.each do |attr, before|
|
350
344
|
before = enums[attr][before] if enums[attr]
|
351
345
|
prev[attr] = before
|
@@ -353,9 +347,10 @@ module PaperTrail
|
|
353
347
|
end
|
354
348
|
end
|
355
349
|
|
356
|
-
# returns hash of
|
357
|
-
|
358
|
-
|
350
|
+
# returns hash of attributes (with appropriate attributes serialized),
|
351
|
+
# ommitting attributes to be skipped
|
352
|
+
def object_attrs_for_paper_trail(attributes_hash)
|
353
|
+
attributes_hash.except(*self.paper_trail_options[:skip]).tap do |attributes|
|
359
354
|
self.class.serialize_attributes_for_paper_trail(attributes)
|
360
355
|
end
|
361
356
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Animal, :type => :model do
|
4
|
+
it { is_expected.to be_versioned }
|
5
|
+
|
6
|
+
describe "STI", :versioning => true do
|
7
|
+
it { expect(Animal.inheritance_column).to eq('species') }
|
8
|
+
|
9
|
+
describe "updates to the `inheritance_column`" do
|
10
|
+
subject { Cat.create!(:name => 'Leo') }
|
11
|
+
|
12
|
+
it "should be allowed" do
|
13
|
+
subject.update_attributes(:name => 'Spike', :species => 'Dog')
|
14
|
+
dog = Animal.find(subject.id)
|
15
|
+
expect(dog).to be_instance_of(Dog)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -10,7 +10,7 @@ class SerializerTest < ActiveSupport::TestCase
|
|
10
10
|
END
|
11
11
|
|
12
12
|
@fluxor = Fluxor.create :name => 'Some text.'
|
13
|
-
@original_fluxor_attributes = @fluxor.send(:item_before_change)
|
13
|
+
@original_fluxor_attributes = @fluxor.send(:item_before_change) # this is exactly what PaperTrail serializes
|
14
14
|
@fluxor.update_attributes :name => 'Some more text.'
|
15
15
|
end
|
16
16
|
|
@@ -41,7 +41,7 @@ class SerializerTest < ActiveSupport::TestCase
|
|
41
41
|
END
|
42
42
|
|
43
43
|
@fluxor = Fluxor.create :name => 'Some text.'
|
44
|
-
@original_fluxor_attributes = @fluxor.send(:item_before_change)
|
44
|
+
@original_fluxor_attributes = @fluxor.send(:item_before_change) # this is exactly what PaperTrail serializes
|
45
45
|
@fluxor.update_attributes :name => 'Some more text.'
|
46
46
|
end
|
47
47
|
|
@@ -83,7 +83,7 @@ class SerializerTest < ActiveSupport::TestCase
|
|
83
83
|
END
|
84
84
|
|
85
85
|
@fluxor = Fluxor.create
|
86
|
-
@original_fluxor_attributes = @fluxor.send(:item_before_change).
|
86
|
+
@original_fluxor_attributes = @fluxor.send(:item_before_change).reject { |k,v| v.nil? } # this is exactly what PaperTrail serializes
|
87
87
|
@fluxor.update_attributes :name => 'Some more text.'
|
88
88
|
end
|
89
89
|
|
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: 3.0.
|
4
|
+
version: 3.0.7
|
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: 2015-03-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -263,6 +263,7 @@ files:
|
|
263
263
|
- lib/paper_trail/version_number.rb
|
264
264
|
- paper_trail.gemspec
|
265
265
|
- spec/generators/install_generator_spec.rb
|
266
|
+
- spec/models/animal_spec.rb
|
266
267
|
- spec/models/gadget_spec.rb
|
267
268
|
- spec/models/joined_version_spec.rb
|
268
269
|
- spec/models/post_with_status_spec.rb
|
@@ -374,12 +375,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
374
375
|
version: 1.3.6
|
375
376
|
requirements: []
|
376
377
|
rubyforge_project:
|
377
|
-
rubygems_version: 2.
|
378
|
+
rubygems_version: 2.4.4
|
378
379
|
signing_key:
|
379
380
|
specification_version: 4
|
380
381
|
summary: Track changes to your models' data. Good for auditing or versioning.
|
381
382
|
test_files:
|
382
383
|
- spec/generators/install_generator_spec.rb
|
384
|
+
- spec/models/animal_spec.rb
|
383
385
|
- spec/models/gadget_spec.rb
|
384
386
|
- spec/models/joined_version_spec.rb
|
385
387
|
- spec/models/post_with_status_spec.rb
|