paper_trail 3.0.6 → 3.0.7

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: 342a6b8d2c4c6685107d14ae36f6711d7fe09d78
4
- data.tar.gz: f7d83394a6bb503a898509b26e9adf0f712c1dfb
3
+ metadata.gz: d6b8b27c90bfd64f2b38cef59276076e4123f38b
4
+ data.tar.gz: 02bc459e5c9ae9e74eafdc782eee7cb4708cfb3e
5
5
  SHA512:
6
- metadata.gz: d240d05e510adf0a4e178a27cda8e490b99750384a15af935daa6019f02f8ce944c7894fdea76fb970a07dde7bdbbf62de8c314a24f5684f961d8da949fe3b64
7
- data.tar.gz: 078716e13039aebf41ea3c10e78180e78d1879ab30095a39298678bb88e6e5659a760f67449cbffee22492419943988df53eac04417fd8da8259804a08fe4732
6
+ metadata.gz: c0581395fd0a5782e279133c26ff723a62eda27470ecd57660d3b495c55ef542a9d08b99a5701762f585fefed54a5191c367469031a1a00cb2efede10690a7b8
7
+ data.tar.gz: e12d54c3a6c00dfa21d2634ee6b2561bbf1aba2bbc907e82f0a651b12acf35a391c6ca81a0e589feca9e0c502efbdc052b5b2e18010e44a3a9ea60c7ec99b8fe
@@ -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.6'`
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.6'`
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 = :post_version_id_seq
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
- previous = self.dup
342
- # `dup` clears timestamps so we add them back.
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 object attributes (with appropriate attributes serialized), ommitting attributes to be skipped
357
- def object_attrs_for_paper_trail(object)
358
- _attrs = object.attributes.except(*self.paper_trail_options[:skip]).tap do |attributes|
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
@@ -2,7 +2,7 @@ module PaperTrail
2
2
  module VERSION
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- TINY = 6
5
+ TINY = 7
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
@@ -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
@@ -1,4 +1,6 @@
1
1
  class Animal < ActiveRecord::Base
2
2
  has_paper_trail
3
3
  self.inheritance_column = 'species'
4
+
5
+ attr_accessible :species, :name if ::PaperTrail.active_record_protected_attributes?
4
6
  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).attributes # this is exactly what PaperTrail serializes
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).attributes # this is exactly what PaperTrail serializes
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).attributes.reject { |k,v| v.nil? } # this is exactly what PaperTrail serializes
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.6
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: 2014-10-09 00:00:00.000000000 Z
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.2.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