paper_trail 4.0.0.beta2 → 4.0.0.rc1
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/.gitignore +2 -0
- data/.travis.yml +9 -7
- data/CHANGELOG.md +38 -2
- data/README.md +30 -12
- data/Rakefile +1 -1
- data/gemfiles/3.0.gemfile +3 -1
- data/lib/generators/paper_trail/install_generator.rb +4 -1
- data/lib/paper_trail/cleaner.rb +1 -1
- data/lib/paper_trail/config.rb +6 -0
- data/lib/paper_trail/frameworks/sinatra.rb +1 -0
- data/lib/paper_trail/has_paper_trail.rb +80 -67
- data/lib/paper_trail/serializers/yaml.rb +2 -1
- data/lib/paper_trail/version_concern.rb +64 -19
- data/lib/paper_trail/version_number.rb +1 -1
- data/lib/paper_trail.rb +7 -3
- data/paper_trail.gemspec +2 -1
- data/spec/models/animal_spec.rb +19 -0
- data/spec/models/boolit_spec.rb +48 -0
- data/spec/models/json_version_spec.rb +80 -0
- data/spec/models/thing_spec.rb +11 -0
- data/spec/models/version_spec.rb +153 -78
- data/spec/models/widget_spec.rb +27 -6
- data/spec/modules/paper_trail_spec.rb +27 -0
- data/spec/requests/articles_spec.rb +0 -2
- data/test/dummy/app/models/animal.rb +2 -0
- data/test/dummy/app/models/boolit.rb +4 -0
- data/test/dummy/app/models/fruit.rb +5 -0
- data/test/dummy/app/models/song.rb +20 -0
- data/test/dummy/app/models/thing.rb +3 -0
- data/test/dummy/app/models/whatchamajigger.rb +4 -0
- data/test/dummy/app/models/widget.rb +1 -0
- data/test/dummy/app/versions/json_version.rb +3 -0
- data/test/dummy/config/initializers/paper_trail.rb +3 -0
- data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +44 -3
- data/test/dummy/db/schema.rb +13 -4
- data/test/functional/controller_test.rb +4 -2
- data/test/unit/model_test.rb +76 -12
- data/test/unit/serializer_test.rb +3 -3
- metadata +40 -6
data/spec/models/widget_spec.rb
CHANGED
@@ -121,8 +121,8 @@ describe Widget, :type => :model do
|
|
121
121
|
|
122
122
|
describe "Methods" do
|
123
123
|
describe "Instance", :versioning => true do
|
124
|
-
describe '#
|
125
|
-
it { is_expected.to respond_to(:
|
124
|
+
describe '#paper_trail_originator' do
|
125
|
+
it { is_expected.to respond_to(:paper_trail_originator) }
|
126
126
|
|
127
127
|
describe "return value" do
|
128
128
|
let(:orig_name) { Faker::Name.name }
|
@@ -133,9 +133,9 @@ describe Widget, :type => :model do
|
|
133
133
|
specify { expect(widget).to be_live }
|
134
134
|
|
135
135
|
it "should return the originator for the model at a given state" do
|
136
|
-
expect(widget.
|
136
|
+
expect(widget.paper_trail_originator).to eq(orig_name)
|
137
137
|
widget.whodunnit(new_name) { |w| w.update_attributes(:name => 'Elizabeth') }
|
138
|
-
expect(widget.
|
138
|
+
expect(widget.paper_trail_originator).to eq(new_name)
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
@@ -150,7 +150,7 @@ describe Widget, :type => :model do
|
|
150
150
|
let(:reified_widget) { widget.versions[1].reify }
|
151
151
|
|
152
152
|
it "should return the appropriate originator" do
|
153
|
-
expect(reified_widget.
|
153
|
+
expect(reified_widget.paper_trail_originator).to eq(orig_name)
|
154
154
|
end
|
155
155
|
|
156
156
|
it "should not create a new model instance" do
|
@@ -162,7 +162,7 @@ describe Widget, :type => :model do
|
|
162
162
|
let(:reified_widget) { widget.versions[1].reify(:dup => true) }
|
163
163
|
|
164
164
|
it "should return the appropriate originator" do
|
165
|
-
expect(reified_widget.
|
165
|
+
expect(reified_widget.paper_trail_originator).to eq(orig_name)
|
166
166
|
end
|
167
167
|
|
168
168
|
it "should not create a new model instance" do
|
@@ -173,6 +173,27 @@ describe Widget, :type => :model do
|
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
176
|
+
describe "#originator" do
|
177
|
+
subject { widget }
|
178
|
+
|
179
|
+
it { is_expected.to respond_to(:originator) }
|
180
|
+
let(:warning_msg) do
|
181
|
+
"DEPRECATED: use `paper_trail_originator` instead of `originator`." +
|
182
|
+
" Support for `originator` will be removed in PaperTrail 4.0"
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should set the invoke `paper_trail_originator`' do
|
186
|
+
is_expected.to receive(:warn)
|
187
|
+
is_expected.to receive(:paper_trail_originator)
|
188
|
+
subject.originator
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'should display a deprecation warning' do
|
192
|
+
is_expected.to receive(:warn).with(warning_msg)
|
193
|
+
subject.originator
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
176
197
|
describe '#version_at' do
|
177
198
|
it { is_expected.to respond_to(:version_at) }
|
178
199
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe PaperTrail, :type => :module, :versioning => true do
|
4
|
+
describe '#config' do
|
5
|
+
it { is_expected.to respond_to(:config) }
|
6
|
+
|
7
|
+
it "should allow for config values to be set" do
|
8
|
+
expect(subject.config.enabled).to eq(true)
|
9
|
+
subject.config.enabled = false
|
10
|
+
expect(subject.config.enabled).to eq(false)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should accept blocks and yield the config instance" do
|
14
|
+
expect(subject.config.enabled).to eq(true)
|
15
|
+
subject.config { |c| c.enabled = false }
|
16
|
+
expect(subject.config.enabled).to eq(false)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#configure' do
|
21
|
+
it { is_expected.to respond_to(:configure) }
|
22
|
+
|
23
|
+
it "should be an alias for the `config` method" do
|
24
|
+
expect(subject.method(:configure)).to eq(subject.method(:config))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -9,7 +9,6 @@ describe "Articles management", :type => :request, :order => :defined do
|
|
9
9
|
it "should not create a version" do
|
10
10
|
expect(PaperTrail).to be_enabled_for_controller
|
11
11
|
expect { post(articles_path, valid_params) }.to_not change(PaperTrail::Version, :count)
|
12
|
-
expect(PaperTrail).not_to be_enabled_for_controller
|
13
12
|
end
|
14
13
|
|
15
14
|
it "should not leak the state of the `PaperTrail.enabled_for_controller?` into the next test" do
|
@@ -24,7 +23,6 @@ describe "Articles management", :type => :request, :order => :defined do
|
|
24
23
|
it "should set that value as the `whodunnit`" do
|
25
24
|
expect { post articles_path, valid_params }.to change(PaperTrail::Version, :count).by(1)
|
26
25
|
expect(article.title).to eq('Doh')
|
27
|
-
expect(PaperTrail.whodunnit).to eq('foobar')
|
28
26
|
expect(article.versions.last.whodunnit).to eq('foobar')
|
29
27
|
end
|
30
28
|
end
|
@@ -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
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# Turn on associations tracking when the test suite is run on Travis CI
|
2
|
+
PaperTrail.config.track_associations = true if ENV['TRAVIS']
|
3
|
+
|
1
4
|
module PaperTrail
|
2
5
|
class Version < ActiveRecord::Base
|
3
6
|
attr_accessible :answer, :action, :question, :article_id, :ip, :user_agent, :title if ::PaperTrail.active_record_protected_attributes?
|
@@ -12,7 +12,7 @@ class SetUpTestTables < ActiveRecord::Migration
|
|
12
12
|
t.boolean :a_boolean
|
13
13
|
t.string :sacrificial_column
|
14
14
|
t.string :type
|
15
|
-
t.timestamps
|
15
|
+
t.timestamps :null => true
|
16
16
|
end
|
17
17
|
|
18
18
|
create_table :versions, :force => true do |t|
|
@@ -60,10 +60,23 @@ class SetUpTestTables < ActiveRecord::Migration
|
|
60
60
|
end
|
61
61
|
add_index :post_versions, [:item_type, :item_id]
|
62
62
|
|
63
|
+
if ENV['DB'] == 'postgres' && ::ActiveRecord::VERSION::MAJOR >= 4
|
64
|
+
create_table :json_versions, :force => true do |t|
|
65
|
+
t.string :item_type, :null => false
|
66
|
+
t.integer :item_id, :null => false
|
67
|
+
t.string :event, :null => false
|
68
|
+
t.string :whodunnit
|
69
|
+
t.json :object
|
70
|
+
t.json :object_changes
|
71
|
+
t.datetime :created_at
|
72
|
+
end
|
73
|
+
add_index :json_versions, [:item_type, :item_id]
|
74
|
+
end
|
75
|
+
|
63
76
|
create_table :wotsits, :force => true do |t|
|
64
77
|
t.integer :widget_id
|
65
78
|
t.string :name
|
66
|
-
t.timestamps
|
79
|
+
t.timestamps :null => true
|
67
80
|
end
|
68
81
|
|
69
82
|
create_table :fluxors, :force => true do |t|
|
@@ -71,6 +84,12 @@ class SetUpTestTables < ActiveRecord::Migration
|
|
71
84
|
t.string :name
|
72
85
|
end
|
73
86
|
|
87
|
+
create_table :whatchamajiggers, :force => true do |t|
|
88
|
+
t.string :owner_type
|
89
|
+
t.integer :owner_id
|
90
|
+
t.string :name
|
91
|
+
end
|
92
|
+
|
74
93
|
create_table :articles, :force => true do |t|
|
75
94
|
t.string :title
|
76
95
|
t.string :content
|
@@ -128,6 +147,10 @@ class SetUpTestTables < ActiveRecord::Migration
|
|
128
147
|
t.integer :version
|
129
148
|
end
|
130
149
|
|
150
|
+
create_table :things, :force => true do |t|
|
151
|
+
t.string :name
|
152
|
+
end
|
153
|
+
|
131
154
|
create_table :translations, :force => true do |t|
|
132
155
|
t.string :headline
|
133
156
|
t.string :content
|
@@ -138,7 +161,7 @@ class SetUpTestTables < ActiveRecord::Migration
|
|
138
161
|
create_table :gadgets, :force => true do |t|
|
139
162
|
t.string :name
|
140
163
|
t.string :brand
|
141
|
-
t.timestamps
|
164
|
+
t.timestamps :null => true
|
142
165
|
end
|
143
166
|
|
144
167
|
create_table :customers, :force => true do |t|
|
@@ -154,6 +177,16 @@ class SetUpTestTables < ActiveRecord::Migration
|
|
154
177
|
t.integer :order_id
|
155
178
|
t.string :product
|
156
179
|
end
|
180
|
+
|
181
|
+
create_table :fruits, :force => true do |t|
|
182
|
+
t.string :name
|
183
|
+
t.string :color
|
184
|
+
end
|
185
|
+
|
186
|
+
create_table :boolits, :force => true do |t|
|
187
|
+
t.string :name
|
188
|
+
t.boolean :scoped, :default => true
|
189
|
+
end
|
157
190
|
end
|
158
191
|
|
159
192
|
def self.down
|
@@ -166,20 +199,28 @@ class SetUpTestTables < ActiveRecord::Migration
|
|
166
199
|
drop_table :authorships
|
167
200
|
drop_table :books
|
168
201
|
drop_table :articles
|
202
|
+
drop_table :whatchamajiggers
|
169
203
|
drop_table :fluxors
|
170
204
|
drop_table :wotsits
|
171
205
|
remove_index :post_versions, :column => [:item_type, :item_id]
|
172
206
|
drop_table :post_versions
|
173
207
|
remove_index :versions, :column => [:item_type, :item_id]
|
174
208
|
drop_table :versions
|
209
|
+
if JsonVersion.table_exists?
|
210
|
+
remove_index :json_versions, :column => [:item_type, :item_id]
|
211
|
+
drop_table :json_versions
|
212
|
+
end
|
175
213
|
drop_table :widgets
|
176
214
|
drop_table :documents
|
177
215
|
drop_table :legacy_widgets
|
216
|
+
drop_table :things
|
178
217
|
drop_table :translations
|
179
218
|
drop_table :gadgets
|
180
219
|
drop_table :customers
|
181
220
|
drop_table :orders
|
182
221
|
drop_table :line_items
|
222
|
+
drop_table :fruits
|
223
|
+
drop_table :boolits
|
183
224
|
remove_index :version_associations, :column => [:version_id]
|
184
225
|
remove_index :version_associations, :name => 'index_version_associations_on_foreign_key'
|
185
226
|
drop_table :version_associations
|
data/test/dummy/db/schema.rb
CHANGED
@@ -84,12 +84,11 @@ ActiveRecord::Schema.define(version: 20110208155312) do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
create_table "post_versions", force: true do |t|
|
87
|
-
t.string "item_type",
|
88
|
-
t.integer "item_id",
|
89
|
-
t.string "event",
|
87
|
+
t.string "item_type", null: false
|
88
|
+
t.integer "item_id", null: false
|
89
|
+
t.string "event", null: false
|
90
90
|
t.string "whodunnit"
|
91
91
|
t.text "object"
|
92
|
-
t.integer "transaction_id"
|
93
92
|
t.datetime "created_at"
|
94
93
|
t.string "ip"
|
95
94
|
t.string "user_agent"
|
@@ -110,6 +109,10 @@ ActiveRecord::Schema.define(version: 20110208155312) do
|
|
110
109
|
t.integer "length"
|
111
110
|
end
|
112
111
|
|
112
|
+
create_table "things", force: true do |t|
|
113
|
+
t.string "name"
|
114
|
+
end
|
115
|
+
|
113
116
|
create_table "translations", force: true do |t|
|
114
117
|
t.string "headline"
|
115
118
|
t.string "content"
|
@@ -146,6 +149,12 @@ ActiveRecord::Schema.define(version: 20110208155312) do
|
|
146
149
|
|
147
150
|
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
|
148
151
|
|
152
|
+
create_table "whatchamajiggers", force: true do |t|
|
153
|
+
t.string "owner_type"
|
154
|
+
t.integer "owner_id"
|
155
|
+
t.string "name"
|
156
|
+
end
|
157
|
+
|
149
158
|
create_table "widgets", force: true do |t|
|
150
159
|
t.string "name"
|
151
160
|
t.text "a_text"
|
@@ -7,8 +7,10 @@ class ControllerTest < ActionController::TestCase
|
|
7
7
|
@request.env['REMOTE_ADDR'] = '127.0.0.1'
|
8
8
|
end
|
9
9
|
|
10
|
+
# Mimick what RequestStore will do outside of the test env, since it is
|
11
|
+
# middleware, and doesn't get executed in controller / request specs
|
10
12
|
teardown do
|
11
|
-
|
13
|
+
RequestStore.store[:paper_trail] = nil
|
12
14
|
end
|
13
15
|
|
14
16
|
test 'disable on create' do
|
@@ -82,7 +84,7 @@ class ControllerTest < ActionController::TestCase
|
|
82
84
|
@request.env['HTTP_USER_AGENT'] = 'Disable User-Agent'
|
83
85
|
post :create, :widget => { :name => 'Flugel' }
|
84
86
|
assert_equal 0, assigns(:widget).versions.length
|
85
|
-
assert !PaperTrail.enabled_for_controller?
|
87
|
+
assert !PaperTrail.enabled_for_controller?
|
86
88
|
assert PaperTrail.whodunnit.nil?
|
87
89
|
assert PaperTrail.controller_info.nil?
|
88
90
|
end
|
data/test/unit/model_test.rb
CHANGED
@@ -218,8 +218,8 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
218
218
|
|
219
219
|
should 'have changes' do
|
220
220
|
|
221
|
-
#TODO Postgres does not appear to pass back ActiveSupport::TimeWithZone,
|
222
|
-
# so chosing the lowest common denominator to test.
|
221
|
+
#TODO Postgres does not appear to pass back ActiveSupport::TimeWithZone,
|
222
|
+
# so chosing the lowest common denominator to test.
|
223
223
|
|
224
224
|
changes = {
|
225
225
|
'name' => [nil, 'Henry'],
|
@@ -332,6 +332,31 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
332
332
|
end
|
333
333
|
end
|
334
334
|
|
335
|
+
context 'and has many associated polymorphic objects' do
|
336
|
+
setup do
|
337
|
+
@f0 = @widget.whatchamajiggers.create :name => 'f-zero'
|
338
|
+
@f1 = @widget.whatchamajiggers.create :name => 'f-zero'
|
339
|
+
@reified_widget = @widget.versions.last.reify
|
340
|
+
end
|
341
|
+
|
342
|
+
should 'copy the has_many associations when reifying' do
|
343
|
+
assert_equal @widget.whatchamajiggers.length, @reified_widget.whatchamajiggers.length
|
344
|
+
assert_same_elements @widget.whatchamajiggers, @reified_widget.whatchamajiggers
|
345
|
+
|
346
|
+
assert_equal @widget.versions.length, @reified_widget.versions.length
|
347
|
+
assert_same_elements @widget.versions, @reified_widget.versions
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
context 'polymorphic objects by themselves' do
|
352
|
+
setup do
|
353
|
+
@widget = Whatchamajigger.new :name => 'f-zero'
|
354
|
+
end
|
355
|
+
|
356
|
+
should 'not fail with a nil pointer on the polymorphic association' do
|
357
|
+
@widget.save!
|
358
|
+
end
|
359
|
+
end
|
335
360
|
|
336
361
|
context 'and then destroyed' do
|
337
362
|
setup do
|
@@ -446,7 +471,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
446
471
|
@last = @widget.versions.last
|
447
472
|
end
|
448
473
|
|
449
|
-
teardown do
|
474
|
+
teardown do
|
450
475
|
restore_schema
|
451
476
|
end
|
452
477
|
|
@@ -571,9 +596,9 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
571
596
|
|
572
597
|
should 'track who made the change' do
|
573
598
|
assert_equal 'Alice', @version.whodunnit
|
574
|
-
assert_nil @version.
|
599
|
+
assert_nil @version.paper_trail_originator
|
575
600
|
assert_equal 'Alice', @version.terminator
|
576
|
-
assert_equal 'Alice', @widget.
|
601
|
+
assert_equal 'Alice', @widget.paper_trail_originator
|
577
602
|
end
|
578
603
|
|
579
604
|
context 'when a record is updated' do
|
@@ -585,9 +610,9 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
585
610
|
|
586
611
|
should 'track who made the change' do
|
587
612
|
assert_equal 'Bob', @version.whodunnit
|
588
|
-
assert_equal 'Alice', @version.
|
613
|
+
assert_equal 'Alice', @version.paper_trail_originator
|
589
614
|
assert_equal 'Bob', @version.terminator
|
590
|
-
assert_equal 'Bob', @widget.
|
615
|
+
assert_equal 'Bob', @widget.paper_trail_originator
|
591
616
|
end
|
592
617
|
|
593
618
|
context 'when a record is destroyed' do
|
@@ -599,9 +624,9 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
599
624
|
|
600
625
|
should 'track who made the change' do
|
601
626
|
assert_equal 'Charlie', @version.whodunnit
|
602
|
-
assert_equal 'Bob', @version.
|
627
|
+
assert_equal 'Bob', @version.paper_trail_originator
|
603
628
|
assert_equal 'Charlie', @version.terminator
|
604
|
-
assert_equal 'Charlie', @widget.
|
629
|
+
assert_equal 'Charlie', @widget.paper_trail_originator
|
605
630
|
end
|
606
631
|
end
|
607
632
|
end
|
@@ -620,7 +645,6 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
620
645
|
assert_not_nil @wotsit.versions.last.reify.updated_at
|
621
646
|
end
|
622
647
|
|
623
|
-
# Currently the gem generates a bunch of deprecation warnings about serialized attributes on AR 4.2
|
624
648
|
should 'not generate warning' do
|
625
649
|
# Tests that it doesn't try to write created_on as an attribute just because a created_on
|
626
650
|
# method exists.
|
@@ -651,7 +675,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
651
675
|
should 'should return the correct originator' do
|
652
676
|
PaperTrail.whodunnit = 'Ben'
|
653
677
|
@foo.update_attribute(:name, 'Geoffrey')
|
654
|
-
assert_equal PaperTrail.whodunnit, @foo.
|
678
|
+
assert_equal PaperTrail.whodunnit, @foo.paper_trail_originator
|
655
679
|
end
|
656
680
|
|
657
681
|
context 'when destroyed' do
|
@@ -1102,6 +1126,21 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
1102
1126
|
should 'return "overwritten" value on reified instance' do
|
1103
1127
|
assert_equal 4, @song.versions.last.reify.length
|
1104
1128
|
end
|
1129
|
+
|
1130
|
+
context 'Has a virtual attribute injected into the ActiveModel::Dirty changes' do
|
1131
|
+
setup do
|
1132
|
+
@song.name = 'Good Vibrations'
|
1133
|
+
@song.save
|
1134
|
+
@song.name = 'Yellow Submarine'
|
1135
|
+
end
|
1136
|
+
|
1137
|
+
should 'return persist the changes on the live instance properly' do
|
1138
|
+
assert_equal 'Yellow Submarine', @song.name
|
1139
|
+
end
|
1140
|
+
should 'return "overwritten" virtual attribute on the reified instance' do
|
1141
|
+
assert_equal 'Good Vibrations', @song.versions.last.reify.name
|
1142
|
+
end
|
1143
|
+
end
|
1105
1144
|
end
|
1106
1145
|
|
1107
1146
|
|
@@ -1189,6 +1228,31 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
1189
1228
|
assert_equal 'destroy', @fluxor.versions.last.event
|
1190
1229
|
end
|
1191
1230
|
end
|
1231
|
+
context 'on []' do
|
1232
|
+
setup do
|
1233
|
+
Fluxor.reset_callbacks :create
|
1234
|
+
Fluxor.reset_callbacks :update
|
1235
|
+
Fluxor.reset_callbacks :destroy
|
1236
|
+
Fluxor.instance_eval <<-END
|
1237
|
+
has_paper_trail :on => []
|
1238
|
+
END
|
1239
|
+
@fluxor = Fluxor.create
|
1240
|
+
@fluxor.update_attributes :name => 'blah'
|
1241
|
+
end
|
1242
|
+
|
1243
|
+
teardown do
|
1244
|
+
@fluxor.destroy
|
1245
|
+
end
|
1246
|
+
|
1247
|
+
should 'not have any versions' do
|
1248
|
+
assert_equal 0, @fluxor.versions.length
|
1249
|
+
end
|
1250
|
+
|
1251
|
+
should 'still respond to touch_with_version' do
|
1252
|
+
@fluxor.touch_with_version
|
1253
|
+
assert_equal 1, @fluxor.versions.length
|
1254
|
+
end
|
1255
|
+
end
|
1192
1256
|
context 'allows a symbol to be passed' do
|
1193
1257
|
setup do
|
1194
1258
|
Fluxor.reset_callbacks :create
|
@@ -1838,4 +1902,4 @@ class HasPaperTrailModelTransactionalTest < ActiveSupport::TestCase
|
|
1838
1902
|
end
|
1839
1903
|
end
|
1840
1904
|
end
|
1841
|
-
end
|
1905
|
+
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(:
|
13
|
+
@original_fluxor_attributes = @fluxor.send(:attributes_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(:
|
44
|
+
@original_fluxor_attributes = @fluxor.send(:attributes_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(:
|
86
|
+
@original_fluxor_attributes = @fluxor.send(:attributes_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
|
|