paper_trail 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -126,7 +126,7 @@ module PaperTrail
126
126
  previous = self.clone
127
127
  previous.id = id
128
128
  changes.each do |attr, ary|
129
- previous.send "#{attr}=", ary.first
129
+ previous.send :write_attribute, attr.to_sym, ary.first
130
130
  end
131
131
  previous
132
132
  end
@@ -42,7 +42,7 @@ class Version < ActiveRecord::Base
42
42
 
43
43
  attrs.each do |k, v|
44
44
  begin
45
- model.send "#{k}=", v
45
+ model.send :write_attribute, k.to_sym , v
46
46
  rescue NoMethodError
47
47
  logger.warn "Attribute #{k} does not exist on #{item_type} (Version id: #{id})."
48
48
  end
@@ -102,7 +102,7 @@ class Version < ActiveRecord::Base
102
102
  # and therefore impossible to know when "just before" was.
103
103
  if (child_as_it_was = child.version_at(created_at - lookback.seconds))
104
104
  child_as_it_was.attributes.each do |k,v|
105
- model.send(assoc.name).send "#{k}=", v rescue nil
105
+ model.send(assoc.name).send :write_attribute, k.to_sym, v rescue nil
106
106
  end
107
107
  else
108
108
  model.send "#{assoc.name}=", nil
@@ -1,3 +1,3 @@
1
1
  module PaperTrail
2
- VERSION = '1.6.1'
2
+ VERSION = '1.6.2'
3
3
  end
@@ -43,6 +43,19 @@ class Person < ActiveRecord::Base
43
43
  has_paper_trail
44
44
  end
45
45
 
46
+ # Example from 'Overwriting default accessors' in ActiveRecord::Base.
47
+ class Song < ActiveRecord::Base
48
+ has_paper_trail
49
+
50
+ # Uses an integer of seconds to hold the length of the song
51
+ def length=(minutes)
52
+ write_attribute(:length, minutes.to_i * 60)
53
+ end
54
+ def length
55
+ read_attribute(:length) / 60
56
+ end
57
+ end
58
+
46
59
 
47
60
  class HasPaperTrailModelTest < Test::Unit::TestCase
48
61
  load_schema
@@ -740,6 +753,22 @@ class HasPaperTrailModelTest < Test::Unit::TestCase
740
753
  end
741
754
  end
742
755
 
756
+
757
+ context 'An overwritten default accessor' do
758
+ setup do
759
+ @song = Song.create :length => 4
760
+ @song.update_attributes :length => 5
761
+ end
762
+
763
+ should 'return "overwritten" value on live instance' do
764
+ assert_equal 5, @song.length
765
+ end
766
+ should 'return "overwritten" value on reified instance' do
767
+ assert_equal 4, @song.versions.last.reify.length
768
+ end
769
+ end
770
+
771
+
743
772
  private
744
773
 
745
774
  # Updates `model`'s last version so it looks like the version was
@@ -63,4 +63,8 @@ ActiveRecord::Schema.define(:version => 0) do
63
63
  t.string :name
64
64
  end
65
65
 
66
+ create_table :songs, :force => true do |t|
67
+ t.integer :length
68
+ end
69
+
66
70
  end
@@ -9,7 +9,7 @@ require 'action_controller/test_process'
9
9
  require 'active_support'
10
10
  require 'active_support/test_case'
11
11
 
12
- require 'lib/paper_trail'
12
+ require File.expand_path('../../lib/paper_trail', __FILE__)
13
13
 
14
14
  def connect_to_database
15
15
  ActiveRecord::Base.establish_connection(
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_trail
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 6
9
- - 1
10
- version: 1.6.1
9
+ - 2
10
+ version: 1.6.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andy Stewart
@@ -15,13 +15,14 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-21 00:00:00 +01:00
18
+ date: 2010-10-28 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: bundler
23
+ type: :development
23
24
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
26
  none: false
26
27
  requirements:
27
28
  - - ~>
@@ -31,12 +32,12 @@ dependencies:
31
32
  - 1
32
33
  - 0
33
34
  version: "1.0"
34
- type: :development
35
- version_requirements: *id001
35
+ requirement: *id001
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
+ type: :development
38
39
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
41
  none: false
41
42
  requirements:
42
43
  - - "="
@@ -47,12 +48,12 @@ dependencies:
47
48
  - 8
48
49
  - 7
49
50
  version: 0.8.7
50
- type: :development
51
- version_requirements: *id002
51
+ requirement: *id002
52
52
  - !ruby/object:Gem::Dependency
53
53
  name: shoulda
54
+ type: :development
54
55
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
56
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
57
  none: false
57
58
  requirements:
58
59
  - - "="
@@ -63,12 +64,12 @@ dependencies:
63
64
  - 10
64
65
  - 3
65
66
  version: 2.10.3
66
- type: :development
67
- version_requirements: *id003
67
+ requirement: *id003
68
68
  - !ruby/object:Gem::Dependency
69
69
  name: activesupport
70
+ type: :development
70
71
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
72
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
73
  none: false
73
74
  requirements:
74
75
  - - ~>
@@ -78,12 +79,12 @@ dependencies:
78
79
  - 2
79
80
  - 3
80
81
  version: "2.3"
81
- type: :development
82
- version_requirements: *id004
82
+ requirement: *id004
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: sqlite3-ruby
85
+ type: :development
85
86
  prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
87
+ version_requirements: &id005 !ruby/object:Gem::Requirement
87
88
  none: false
88
89
  requirements:
89
90
  - - ~>
@@ -93,12 +94,12 @@ dependencies:
93
94
  - 1
94
95
  - 2
95
96
  version: "1.2"
96
- type: :development
97
- version_requirements: *id005
97
+ requirement: *id005
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: activerecord
100
+ type: :runtime
100
101
  prerelease: false
101
- requirement: &id006 !ruby/object:Gem::Requirement
102
+ version_requirements: &id006 !ruby/object:Gem::Requirement
102
103
  none: false
103
104
  requirements:
104
105
  - - ">="
@@ -108,12 +109,12 @@ dependencies:
108
109
  - 2
109
110
  - 3
110
111
  version: "2.3"
111
- type: :runtime
112
- version_requirements: *id006
112
+ requirement: *id006
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: actionpack
115
+ type: :runtime
115
116
  prerelease: false
116
- requirement: &id007 !ruby/object:Gem::Requirement
117
+ version_requirements: &id007 !ruby/object:Gem::Requirement
117
118
  none: false
118
119
  requirements:
119
120
  - - ">="
@@ -123,8 +124,7 @@ dependencies:
123
124
  - 2
124
125
  - 3
125
126
  version: "2.3"
126
- type: :runtime
127
- version_requirements: *id007
127
+ requirement: *id007
128
128
  description: Track changes to your models' data. Good for auditing or versioning.
129
129
  email: boss@airbladesoftware.com
130
130
  executables: []