paper_trail 3.0.7 → 3.0.8

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: d6b8b27c90bfd64f2b38cef59276076e4123f38b
4
- data.tar.gz: 02bc459e5c9ae9e74eafdc782eee7cb4708cfb3e
3
+ metadata.gz: 2341d38bf3de33be104cb0e608c3e6ba7681fb58
4
+ data.tar.gz: d692d110b6774f05b0cfaf446dabae5b39b544e0
5
5
  SHA512:
6
- metadata.gz: c0581395fd0a5782e279133c26ff723a62eda27470ecd57660d3b495c55ef542a9d08b99a5701762f585fefed54a5191c367469031a1a00cb2efede10690a7b8
7
- data.tar.gz: e12d54c3a6c00dfa21d2634ee6b2561bbf1aba2bbc907e82f0a651b12acf35a391c6ca81a0e589feca9e0c502efbdc052b5b2e18010e44a3a9ea60c7ec99b8fe
6
+ metadata.gz: beabb6745c775196c97df32b3442d427dca469d31fc3e92c30e8afb94dabff853ae6bf95a7ba4edc4a8652f214205ac06b56c9a7571cc04e7d6f623c76905b95
7
+ data.tar.gz: d840c40829ed5c82bedf4d5b21227d902809528a26e7cc2c28b04c6bbe04267572c8c816530fdd661df4a3825bffe626d992adff4e60e6abccf7eb576b390125
@@ -1,12 +1,18 @@
1
+ ## 3.0.8
2
+
3
+ - [#525](https://github.com/airblade/paper_trail/pull/525) / [#512](https://github.com/airblade/paper_trail/issues/512) -
4
+ Support for virtual accessors and redefined setter and getter methods. (Backported from v4)
5
+
1
6
  ## 3.0.7
2
7
 
3
8
  - [#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
9
+ Fix errors occuring when a user attempts to update the inheritance column on an STI model instance in `ActiveRecord` 4.1.x.
10
+ (Backported from v4)
5
11
 
6
12
  ## 3.0.6
7
13
 
8
14
  - [#414](https://github.com/airblade/paper_trail/issues/414) - Fix functionality `ignore` argument to `has_paper_trail`
9
- in `ActiveRecord` 4
15
+ in `ActiveRecord` 4. (Backported from v4)
10
16
 
11
17
  ## 3.0.5
12
18
 
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.7'`
45
+ `gem 'paper_trail', '~> 3.0.8'`
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.7'`
67
+ `gem 'paper_trail', '~> 3.0.8'`
68
68
 
69
69
  2. Generate a migration to add a `versions` table to your database.
70
70
 
@@ -1,11 +1,12 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'activerecord', '~> 3.0'
4
+ gem 'i18n', '~> 0.6.11'
4
5
 
5
6
  group :development, :test do
6
7
  gem 'rake', '~> 10.1.1'
7
8
  gem 'shoulda', '~> 3.5'
8
- gem 'ffaker', '>= 1.15'
9
+ gem 'ffaker', '<= 1.31.0'
9
10
 
10
11
  # Testing of Rails
11
12
  gem 'railties', '~> 3.0'
@@ -24,7 +25,7 @@ group :development, :test do
24
25
  platforms :ruby do
25
26
  gem 'sqlite3', '~> 1.2'
26
27
  gem 'mysql2', '~> 0.3'
27
- gem 'pg', '~> 0.17'
28
+ gem 'pg', '~> 0.17.1'
28
29
  end
29
30
 
30
31
  platforms :jruby, :ruby_18 do
@@ -38,5 +39,6 @@ group :development, :test do
38
39
  gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3'
39
40
  gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3'
40
41
  gem 'activerecord-jdbcmysql-adapter', '~> 1.3'
42
+ gem 'activerecord-jdbc-adapter', '1.3.15'
41
43
  end
42
44
  end
@@ -148,8 +148,10 @@ module PaperTrail
148
148
 
149
149
  # Set all the attributes in this version on the model
150
150
  attrs.each do |k, v|
151
- if model.respond_to?("#{k}=")
151
+ if model.has_attribute?(k)
152
152
  model[k.to_sym] = v
153
+ elsif model.respond_to?("#{k}=")
154
+ model.send("#{k}=", v)
153
155
  else
154
156
  logger.warn "Attribute #{k} does not exist on #{item_type} (Version id: #{id})."
155
157
  end
@@ -2,7 +2,7 @@ module PaperTrail
2
2
  module VERSION
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- TINY = 7
5
+ TINY = 8
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency 'rake', '~> 10.1.1'
26
26
  s.add_development_dependency 'shoulda', '~> 3.5'
27
27
  # s.add_development_dependency 'shoulda-matchers', '~> 1.5' # needed for ActiveRecord < 4
28
- s.add_development_dependency 'ffaker', '>= 1.15'
28
+ s.add_development_dependency 'ffaker', '<= 1.31.0'
29
29
  s.add_development_dependency 'railties', ['>= 3.0', '< 5.0']
30
30
  s.add_development_dependency 'sinatra', '~> 1.0'
31
31
  s.add_development_dependency 'rack-test', '>= 0.6'
@@ -15,12 +15,22 @@ class Person < ActiveRecord::Base
15
15
 
16
16
  # Store TimeZone objects as strings when serialized to database
17
17
  class TimeZoneSerializer
18
+ class << self
19
+ def dump(zone)
20
+ zone.try(:name)
21
+ end
22
+
23
+ def load(value)
24
+ ::Time.find_zone!(value) rescue nil
25
+ end
26
+ end
27
+
18
28
  def dump(zone)
19
- zone.try(:name)
29
+ self.class.dump(zone)
20
30
  end
21
-
31
+
22
32
  def load(value)
23
- ::Time.find_zone!(value) rescue nil
33
+ self.class.load(value)
24
34
  end
25
35
  end
26
36
 
@@ -1,6 +1,7 @@
1
1
  # Example from 'Overwriting default accessors' in ActiveRecord::Base.
2
2
  class Song < ActiveRecord::Base
3
3
  has_paper_trail
4
+ attr_accessor :name
4
5
 
5
6
  # Uses an integer of seconds to hold the length of the song
6
7
  def length=(minutes)
@@ -9,4 +10,23 @@ class Song < ActiveRecord::Base
9
10
  def length
10
11
  read_attribute(:length) / 60
11
12
  end
13
+
14
+ # override attributes hashes like some libraries do
15
+ def attributes_with_name
16
+ if name
17
+ attributes_without_name.merge(:name => name)
18
+ else
19
+ attributes_without_name
20
+ end
21
+ end
22
+ alias_method_chain :attributes, :name
23
+
24
+ def changed_attributes_with_name
25
+ if name
26
+ changed_attributes_without_name.merge(:name => name)
27
+ else
28
+ changed_attributes_without_name
29
+ end
30
+ end
31
+ alias_method_chain :changed_attributes, :name
12
32
  end
@@ -59,5 +59,8 @@ module Dummy
59
59
 
60
60
  # Rails 4 key for generating secret key
61
61
  config.secret_key_base = 'A fox regularly kicked the screaming pile of biscuits.'
62
+
63
+ # supress warnings about raises in transactional callbacks on AR 4.2+
64
+ config.active_record.raise_in_transactional_callbacks = true if ActiveRecord::VERSION::STRING >= '4.2'
62
65
  end
63
66
  end
@@ -616,15 +616,18 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
616
616
  assert_not_nil @wotsit.versions.last.reify.updated_at
617
617
  end
618
618
 
619
- should 'not generate warning' do
620
- # Tests that it doesn't try to write created_on as an attribute just because a created_on
621
- # method exists.
622
- warnings = capture(:stderr) { # Deprecation warning in Rails 3.2
623
- assert_nothing_raised { # ActiveModel::MissingAttributeError in Rails 4
624
- @wotsit.update_attributes! :name => 'changed'
619
+ # Currently the gem generates a bunch of deprecation warnings about serialized attributes on AR 4.2
620
+ if ActiveRecord::VERSION::STRING < '4.2'
621
+ should 'not generate warning' do
622
+ # Tests that it doesn't try to write created_on as an attribute just because a created_on
623
+ # method exists.
624
+ warnings = capture(:stderr) { # Deprecation warning in Rails 3.2
625
+ assert_nothing_raised { # ActiveModel::MissingAttributeError in Rails 4
626
+ @wotsit.update_attributes! :name => 'changed'
627
+ }
625
628
  }
626
- }
627
- assert_equal '', warnings
629
+ assert_equal '', warnings
630
+ end
628
631
  end
629
632
 
630
633
  end
@@ -1052,12 +1055,14 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
1052
1055
  should 'version.object_changes attribute should have stored the value returned by the attribute serializer' do
1053
1056
  as_stored_in_version = HashWithIndifferentAccess[YAML::load(@person.versions.last.object_changes)]
1054
1057
  assert_equal [nil, 'Samoa'], as_stored_in_version[:time_zone]
1055
- assert_equal @person.instance_variable_get(:@attributes)['time_zone'].serialized_value, as_stored_in_version[:time_zone].last
1058
+ serialized_value = Person::TimeZoneSerializer.dump(@person.time_zone)
1059
+ assert_equal serialized_value, as_stored_in_version[:time_zone].last
1056
1060
  end
1057
1061
 
1058
1062
  # Tests for unserialization:
1059
1063
  should 'version.changeset should convert the attribute value back to its original, unserialized value' do
1060
- assert_equal @person.instance_variable_get(:@attributes)['time_zone'].unserialized_value, @person.versions.last.changeset[:time_zone].last
1064
+ unserialized_value = Person::TimeZoneSerializer.load(@person.time_zone)
1065
+ assert_equal unserialized_value, @person.versions.last.changeset[:time_zone].last
1061
1066
  end
1062
1067
  should "record.changes (before save) returns the original, unserialized values" do
1063
1068
  assert_equal [NilClass, ActiveSupport::TimeZone], @changes_before_save[:time_zone].map(&:class)
@@ -1069,7 +1074,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
1069
1074
 
1070
1075
  context 'when that attribute is updated' do
1071
1076
  setup do
1072
- @attribute_value_before_change = @person.instance_variable_get(:@attributes)['time_zone']
1077
+ @attribute_value_before_change = @person.time_zone
1073
1078
  @person.assign_attributes({ :time_zone => 'Pacific Time (US & Canada)' })
1074
1079
  @changes_before_save = @person.changes.dup
1075
1080
  @person.save!
@@ -1078,7 +1083,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
1078
1083
  # Tests for serialization:
1079
1084
  # Before the serialized attributes fix, the object/object_changes value that was stored was ridiculously long (58723).
1080
1085
  should 'version.object should not have stored the default, ridiculously long (to_yaml) serialization of the TimeZone object' do
1081
- assert @person.versions.last.object. length < 105, "object length was #{@person.versions.last.object .length}"
1086
+ assert @person.versions.last.object.length < 105, "object length was #{@person.versions.last.object.length}"
1082
1087
  end
1083
1088
  # Need an additional clause to detect what version of ActiveRecord is being used for this test because AR4 injects the `updated_at` column into the changeset for updates to models
1084
1089
  should 'version.object_changes should not have stored the default, ridiculously long (to_yaml) serialization of the TimeZone object' do
@@ -1088,20 +1093,24 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
1088
1093
  should 'version.object attribute should have stored the value returned by the attribute serializer' do
1089
1094
  as_stored_in_version = HashWithIndifferentAccess[YAML::load(@person.versions.last.object)]
1090
1095
  assert_equal 'Samoa', as_stored_in_version[:time_zone]
1091
- assert_equal @attribute_value_before_change.serialized_value, as_stored_in_version[:time_zone]
1096
+ serialized_value = Person::TimeZoneSerializer.dump(@attribute_value_before_change)
1097
+ assert_equal serialized_value, as_stored_in_version[:time_zone]
1092
1098
  end
1093
1099
  should 'version.object_changes attribute should have stored the value returned by the attribute serializer' do
1094
1100
  as_stored_in_version = HashWithIndifferentAccess[YAML::load(@person.versions.last.object_changes)]
1095
1101
  assert_equal ['Samoa', 'Pacific Time (US & Canada)'], as_stored_in_version[:time_zone]
1096
- assert_equal @person.instance_variable_get(:@attributes)['time_zone'].serialized_value, as_stored_in_version[:time_zone].last
1102
+ serialized_value = Person::TimeZoneSerializer.dump(@person.time_zone)
1103
+ assert_equal serialized_value, as_stored_in_version[:time_zone].last
1097
1104
  end
1098
1105
 
1099
1106
  # Tests for unserialization:
1100
1107
  should 'version.reify should convert the attribute value back to its original, unserialized value' do
1101
- assert_equal @attribute_value_before_change.unserialized_value, @person.versions.last.reify.time_zone
1108
+ unserialized_value = Person::TimeZoneSerializer.load(@attribute_value_before_change)
1109
+ assert_equal unserialized_value, @person.versions.last.reify.time_zone
1102
1110
  end
1103
1111
  should 'version.changeset should convert the attribute value back to its original, unserialized value' do
1104
- assert_equal @person.instance_variable_get(:@attributes)['time_zone'].unserialized_value, @person.versions.last.changeset[:time_zone].last
1112
+ unserialized_value = Person::TimeZoneSerializer.load(@person.time_zone)
1113
+ assert_equal unserialized_value, @person.versions.last.changeset[:time_zone].last
1105
1114
  end
1106
1115
  should "record.changes (before save) returns the original, unserialized values" do
1107
1116
  assert_equal [ActiveSupport::TimeZone, ActiveSupport::TimeZone], @changes_before_save[:time_zone].map(&:class)
@@ -1165,6 +1174,21 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
1165
1174
  should 'return "overwritten" value on reified instance' do
1166
1175
  assert_equal 4, @song.versions.last.reify.length
1167
1176
  end
1177
+
1178
+ context 'Has a virtual attribute injected into the ActiveModel::Dirty changes' do
1179
+ setup do
1180
+ @song.name = 'Good Vibrations'
1181
+ @song.save
1182
+ @song.name = nil
1183
+ end
1184
+
1185
+ should 'return persist the changes on the live instance properly' do
1186
+ assert_equal nil, @song.name
1187
+ end
1188
+ should 'return "overwritten" virtual attribute on the reified instance' do
1189
+ assert_equal 'Good Vibrations', @song.versions.last.reify.name
1190
+ end
1191
+ end
1168
1192
  end
1169
1193
 
1170
1194
 
@@ -44,7 +44,11 @@ class JSONTest < ActiveSupport::TestCase
44
44
  PaperTrail::Version.arel_table[:object], :arg1, "Val 1")
45
45
 
46
46
  assert matches.instance_of?(Arel::Nodes::Matches)
47
- assert_equal matches.right, "%\"arg1\":\"Val 1\"%"
47
+ if Arel::VERSION >= '6'
48
+ assert_equal matches.right.val, "%\"arg1\":\"Val 1\"%"
49
+ else
50
+ assert_equal matches.right, "%\"arg1\":\"Val 1\"%"
51
+ end
48
52
  end
49
53
  end
50
54
 
@@ -54,7 +58,11 @@ class JSONTest < ActiveSupport::TestCase
54
58
  PaperTrail::Version.arel_table[:object], :arg1, nil)
55
59
 
56
60
  assert matches.instance_of?(Arel::Nodes::Matches)
57
- assert_equal matches.right, "%\"arg1\":null%"
61
+ if Arel::VERSION >= '6'
62
+ assert_equal matches.right.val, "%\"arg1\":null%"
63
+ else
64
+ assert_equal matches.right, "%\"arg1\":null%"
65
+ end
58
66
  end
59
67
  end
60
68
 
@@ -67,8 +75,13 @@ class JSONTest < ActiveSupport::TestCase
67
75
  matches = grouping.select { |v| v.instance_of?(Arel::Nodes::Matches) }
68
76
  # Numeric arguments need to ensure that they match for only the number, not the beginning
69
77
  # of a #, so it uses an Grouping matcher (See notes on `PaperTrail::Serializers::JSON`)
70
- assert_equal matches.first.right, "%\"arg1\":-3.5,%"
71
- assert_equal matches.last.right, "%\"arg1\":-3.5}%"
78
+ if Arel::VERSION >= '6'
79
+ assert_equal matches.first.right.val, "%\"arg1\":-3.5,%"
80
+ assert_equal matches.last.right.val, "%\"arg1\":-3.5}%"
81
+ else
82
+ assert_equal matches.first.right, "%\"arg1\":-3.5,%"
83
+ assert_equal matches.last.right, "%\"arg1\":-3.5}%"
84
+ end
72
85
  end
73
86
  end
74
87
  end
@@ -42,7 +42,11 @@ class YamlTest < ActiveSupport::TestCase
42
42
  matches = PaperTrail::Serializers::YAML.where_object_condition(
43
43
  PaperTrail::Version.arel_table[:object], :arg1, "Val 1")
44
44
  assert matches.instance_of?(Arel::Nodes::Matches)
45
- assert_equal matches.right, "%\narg1: Val 1\n%"
45
+ if Arel::VERSION >= '6'
46
+ assert_equal matches.right.val, "%\narg1: Val 1\n%"
47
+ else
48
+ assert_equal matches.right, "%\narg1: Val 1\n%"
49
+ end
46
50
  end
47
51
  end
48
52
  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: 3.0.7
4
+ version: 3.0.8
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-03-02 00:00:00.000000000 Z
12
+ date: 2015-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -83,16 +83,16 @@ dependencies:
83
83
  name: ffaker
84
84
  requirement: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - '>='
86
+ - - <=
87
87
  - !ruby/object:Gem::Version
88
- version: '1.15'
88
+ version: 1.31.0
89
89
  type: :development
90
90
  prerelease: false
91
91
  version_requirements: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - '>='
93
+ - - <=
94
94
  - !ruby/object:Gem::Version
95
- version: '1.15'
95
+ version: 1.31.0
96
96
  - !ruby/object:Gem::Dependency
97
97
  name: railties
98
98
  requirement: !ruby/object:Gem::Requirement