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.
- data/lib/paper_trail/has_paper_trail.rb +1 -1
- data/lib/paper_trail/version.rb +2 -2
- data/lib/paper_trail/version_number.rb +1 -1
- data/test/paper_trail_model_test.rb +29 -0
- data/test/schema.rb +4 -0
- data/test/test_helper.rb +1 -1
- metadata +25 -25
data/lib/paper_trail/version.rb
CHANGED
@@ -42,7 +42,7 @@ class Version < ActiveRecord::Base
|
|
42
42
|
|
43
43
|
attrs.each do |k, v|
|
44
44
|
begin
|
45
|
-
model.send
|
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
|
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
|
@@ -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
|
data/test/schema.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -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:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 1.6.
|
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-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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: []
|