paper_trail 4.0.0.beta1 → 4.0.0.beta2
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/CHANGELOG.md +10 -2
- data/README.md +7 -1
- data/Rakefile +1 -1
- data/gemfiles/3.0.gemfile +1 -1
- data/lib/paper_trail/has_paper_trail.rb +19 -9
- data/lib/paper_trail/serializers/json.rb +13 -2
- data/lib/paper_trail/serializers/yaml.rb +15 -2
- data/lib/paper_trail/version_concern.rb +27 -13
- data/lib/paper_trail/version_number.rb +1 -1
- data/spec/models/gadget_spec.rb +3 -1
- data/spec/models/version_spec.rb +54 -0
- data/spec/requests/articles_spec.rb +5 -7
- data/spec/support/alt_db_init.rb +1 -1
- data/test/dummy/app/controllers/application_controller.rb +1 -1
- data/test/dummy/app/controllers/articles_controller.rb +4 -1
- data/test/dummy/config/environments/test.rb +5 -1
- data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +0 -1
- data/test/functional/modular_sinatra_test.rb +1 -1
- data/test/functional/sinatra_test.rb +1 -1
- data/test/unit/model_test.rb +2 -2
- data/test/unit/protected_attrs_test.rb +1 -1
- data/test/unit/serializer_test.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b96c067cab9f8789c0942d19fe7db30c83b0854
|
4
|
+
data.tar.gz: a2f6e330b8c28de3c575c9a7c13ba54c352702ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2eb6e5433a4e085a9ccaa41b5c1862f2c1b25fd4f77d08061470d4cf411560f02aa1cd18179f5fb058b446c0d3e26ba58ea917fbe20c4c13032128e8d3837c3a
|
7
|
+
data.tar.gz: 435e06ff6d5e3071f09cb3d4a1b415c132114efb6d01b36d9b15d794a6b249db0392ddad6a1f75f6d0fdbf826befa6509b01c1235cce54034f621e5ab5e04594
|
data/CHANGELOG.md
CHANGED
@@ -5,12 +5,20 @@
|
|
5
5
|
PaperTrail::Rails::Engine.eager_load!
|
6
6
|
```
|
7
7
|
|
8
|
+
*Also*
|
9
|
+
|
10
|
+
If you depend on the `RSpec` or `Cucumber` helpers, you will need to [manually load them into your test helper](https://github.com/airblade/paper_trail#testing).
|
11
|
+
|
12
|
+
- [#458](https://github.com/airblade/paper_trail/pull/458) - For `create` events, metadata pointing at attributes should attempt
|
13
|
+
to grab the current value instead of looking at the value prior to the change (which would always be `nil`)
|
14
|
+
- [#440](https://github.com/airblade/paper_trail/pull/440) - `versions` association should clear/reload after a transaction rollback.
|
8
15
|
- [#439](https://github.com/airblade/paper_trail/pull/439) / [#12](https://github.com/airblade/paper_trail/issues/12) -
|
9
16
|
Support for versioning of associations (Has Many, Has One, HABTM, etc.)
|
10
|
-
- [#440](https://github.com/airblade/paper_trail/pull/440) - `versions` association should clear/reload after a transaction rollback.
|
11
17
|
- [#438](https://github.com/airblade/paper_trail/issues/438) - `Model.paper_trail_enabled_for_model?` should return `false` if
|
12
18
|
`has_paper_trail` has not been declared on the class.
|
13
19
|
- [#427](https://github.com/airblade/paper_trail/pull/427) - Fix `reify` method in context of model where a column has been removed.
|
20
|
+
- [#420](https://github.com/airblade/paper_trail/issues/420) - Add `VersionConcern#where_object_changes` instance method;
|
21
|
+
acts as a helper for querying against the `object_changes` column in versions table.
|
14
22
|
- [#416](https://github.com/airblade/paper_trail/issues/416) - Added a `config` option for enabling/disabling
|
15
23
|
utilization of `serialized_attributes` for `ActiveRecord`, necessary because `serialized_attributes` has been
|
16
24
|
deprecated in `ActiveRecord` version `4.2` and will be removed in version `5.0`
|
@@ -85,7 +93,7 @@ in the `PaperTrail::Version` class through a `Rails::Engine` when the gem is use
|
|
85
93
|
with Rails `4.1.0.rc1`.
|
86
94
|
- [#334](https://github.com/airblade/paper_trail/pull/334) - Add small-scope `whodunnit` method to `PaperTrail::Model::InstanceMethods`.
|
87
95
|
- [#329](https://github.com/airblade/paper_trail/issues/329) - Add `touch_with_version` method to `PaperTrail::Model::InstanceMethods`,
|
88
|
-
to allow for generating a version `touch`ing a model.
|
96
|
+
to allow for generating a version while `touch`ing a model.
|
89
97
|
- [#328](https://github.com/airblade/paper_trail/pull/328) / [#326](https://github.com/airblade/paper_trail/issues/326) /
|
90
98
|
[#307](https://github.com/airblade/paper_trail/issues/307) - `Model.paper_trail_enabled_for_model?` and
|
91
99
|
`model_instance.without_versioning` is now thread-safe.
|
data/README.md
CHANGED
@@ -139,7 +139,7 @@ Widget.paper_trail_on!
|
|
139
139
|
|
140
140
|
# Check whether PaperTrail is enabled for all widgets.
|
141
141
|
Widget.paper_trail_enabled_for_model?
|
142
|
-
widget.paper_trail_enabled_for_model?
|
142
|
+
widget.paper_trail_enabled_for_model? # only available on instances of versioned models
|
143
143
|
```
|
144
144
|
|
145
145
|
And a `PaperTrail::Version` instance has these methods:
|
@@ -173,6 +173,12 @@ version.event
|
|
173
173
|
|
174
174
|
# Query versions objects by attributes.
|
175
175
|
PaperTrail::Version.where_object(attr1: val1, attr2: val2)
|
176
|
+
|
177
|
+
# Query versions object_changes field by attributes (requires
|
178
|
+
# `object_changes` column on versions table).
|
179
|
+
# Also can't guarantee consistent query results for numeric values
|
180
|
+
# due to limitations of SQL wildcard matchers against the serialized objects.
|
181
|
+
PaperTrail::Version.where_object_changes(attr1: val1)
|
176
182
|
```
|
177
183
|
|
178
184
|
In your controllers you can override these methods:
|
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ Bundler::GemHelper.install_tasks
|
|
4
4
|
desc 'Set a relevant database.yml for testing'
|
5
5
|
task :prepare do
|
6
6
|
ENV["DB"] ||= "sqlite"
|
7
|
-
if RUBY_VERSION
|
7
|
+
if RUBY_VERSION >= '1.9'
|
8
8
|
FileUtils.cp "test/dummy/config/database.#{ENV["DB"]}.yml", "test/dummy/config/database.yml"
|
9
9
|
else
|
10
10
|
require 'ftools'
|
data/gemfiles/3.0.gemfile
CHANGED
@@ -259,7 +259,7 @@ module PaperTrail
|
|
259
259
|
#
|
260
260
|
# TODO: lookinto leveraging the `after_touch` callback from `ActiveRecord` to allow the
|
261
261
|
# regular `touch` method go generate a version as normal. May make sense to switch the `record_update`
|
262
|
-
# method to leverage an `after_update` callback anyways (likely for
|
262
|
+
# method to leverage an `after_update` callback anyways (likely for v4.0.0)
|
263
263
|
def touch_with_version(name = nil)
|
264
264
|
raise ActiveRecordError, "can not touch on a new record object" unless persisted?
|
265
265
|
|
@@ -281,8 +281,7 @@ module PaperTrail
|
|
281
281
|
if paper_trail_switched_on?
|
282
282
|
data = {
|
283
283
|
:event => paper_trail_event || 'create',
|
284
|
-
:whodunnit => PaperTrail.whodunnit
|
285
|
-
:transaction_id => PaperTrail.transaction_id
|
284
|
+
:whodunnit => PaperTrail.whodunnit
|
286
285
|
}
|
287
286
|
if respond_to?(:created_at)
|
288
287
|
data[PaperTrail.timestamp_field] = created_at
|
@@ -291,6 +290,9 @@ module PaperTrail
|
|
291
290
|
data[:object_changes] = self.class.paper_trail_version_class.object_changes_col_is_json? ? changes_for_paper_trail :
|
292
291
|
PaperTrail.serializer.dump(changes_for_paper_trail)
|
293
292
|
end
|
293
|
+
if self.class.paper_trail_version_class.column_names.include?('transaction_id')
|
294
|
+
data[:transaction_id] = PaperTrail.transaction_id
|
295
|
+
end
|
294
296
|
version = send(self.class.versions_association_name).create! merge_metadata(data)
|
295
297
|
set_transaction_id(version)
|
296
298
|
save_associations(version)
|
@@ -303,8 +305,7 @@ module PaperTrail
|
|
303
305
|
data = {
|
304
306
|
:event => paper_trail_event || 'update',
|
305
307
|
:object => self.class.paper_trail_version_class.object_col_is_json? ? object_attrs : PaperTrail.serializer.dump(object_attrs),
|
306
|
-
:whodunnit => PaperTrail.whodunnit
|
307
|
-
:transaction_id => PaperTrail.transaction_id
|
308
|
+
:whodunnit => PaperTrail.whodunnit
|
308
309
|
}
|
309
310
|
if respond_to?(:updated_at)
|
310
311
|
data[PaperTrail.timestamp_field] = updated_at
|
@@ -313,6 +314,9 @@ module PaperTrail
|
|
313
314
|
data[:object_changes] = self.class.paper_trail_version_class.object_changes_col_is_json? ? changes_for_paper_trail :
|
314
315
|
PaperTrail.serializer.dump(changes_for_paper_trail)
|
315
316
|
end
|
317
|
+
if self.class.paper_trail_version_class.column_names.include?('transaction_id')
|
318
|
+
data[:transaction_id] = PaperTrail.transaction_id
|
319
|
+
end
|
316
320
|
version = send(self.class.versions_association_name).create merge_metadata(data)
|
317
321
|
set_transaction_id(version)
|
318
322
|
save_associations(version)
|
@@ -352,9 +356,11 @@ module PaperTrail
|
|
352
356
|
:item_type => self.class.base_class.name,
|
353
357
|
:event => paper_trail_event || 'destroy',
|
354
358
|
:object => self.class.paper_trail_version_class.object_col_is_json? ? object_attrs : PaperTrail.serializer.dump(object_attrs),
|
355
|
-
:whodunnit => PaperTrail.whodunnit
|
356
|
-
:transaction_id => PaperTrail.transaction_id
|
359
|
+
:whodunnit => PaperTrail.whodunnit
|
357
360
|
}
|
361
|
+
if self.class.paper_trail_version_class.column_names.include?('transaction_id')
|
362
|
+
data[:transaction_id] = PaperTrail.transaction_id
|
363
|
+
end
|
358
364
|
version = self.class.paper_trail_version_class.create(merge_metadata(data))
|
359
365
|
send("#{self.class.version_association_name}=", version)
|
360
366
|
send(self.class.versions_association_name).send :load_target
|
@@ -363,7 +369,9 @@ module PaperTrail
|
|
363
369
|
end
|
364
370
|
end
|
365
371
|
|
372
|
+
# saves associations if the join table for `VersionAssociation` exists
|
366
373
|
def save_associations(version)
|
374
|
+
return unless PaperTrail::VersionAssociation.table_exists?
|
367
375
|
self.class.reflect_on_all_associations(:belongs_to).each do |assoc|
|
368
376
|
if assoc.klass.paper_trail_enabled_for_model?
|
369
377
|
PaperTrail::VersionAssociation.create(
|
@@ -376,6 +384,7 @@ module PaperTrail
|
|
376
384
|
end
|
377
385
|
|
378
386
|
def set_transaction_id(version)
|
387
|
+
return unless self.class.paper_trail_version_class.column_names.include?('transaction_id')
|
379
388
|
if PaperTrail.transaction? && PaperTrail.transaction_id.nil?
|
380
389
|
PaperTrail.transaction_id = version.id
|
381
390
|
version.transaction_id = version.id
|
@@ -394,8 +403,9 @@ module PaperTrail
|
|
394
403
|
if v.respond_to?(:call)
|
395
404
|
v.call(self)
|
396
405
|
elsif v.is_a?(Symbol) && respond_to?(v)
|
397
|
-
# if it is an attribute that is changing
|
398
|
-
|
406
|
+
# if it is an attribute that is changing in an existing object,
|
407
|
+
# be sure to grab the current version
|
408
|
+
if has_attribute?(v) && send("#{v}_changed?".to_sym) && data[:event] != 'create'
|
399
409
|
send("#{v}_was".to_sym)
|
400
410
|
else
|
401
411
|
send(v)
|
@@ -13,8 +13,8 @@ module PaperTrail
|
|
13
13
|
ActiveSupport::JSON.encode object
|
14
14
|
end
|
15
15
|
|
16
|
-
# Returns a SQL condition to be used to match the given field and value
|
17
|
-
# the serialized object
|
16
|
+
# Returns a SQL condition to be used to match the given field and value
|
17
|
+
# in the serialized object
|
18
18
|
def where_object_condition(arel_field, field, value)
|
19
19
|
# Convert to JSON to handle strings and nulls correctly.
|
20
20
|
json_value = value.to_json
|
@@ -31,6 +31,17 @@ module PaperTrail
|
|
31
31
|
arel_field.matches("%\"#{field}\":#{json_value}%")
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
# Returns a SQL condition to be used to match the given field and value
|
36
|
+
# in the serialized object_changes
|
37
|
+
def where_object_changes_condition(arel_field, field, value)
|
38
|
+
# Convert to JSON to handle strings and nulls correctly.
|
39
|
+
json_value = value.to_json
|
40
|
+
|
41
|
+
# Need to check first (before) and secondary (after) fields
|
42
|
+
arel_field.matches("%\"#{field}\":[#{json_value},%").
|
43
|
+
or(arel_field.matches("%\"#{field}\":[%,#{json_value}]%"))
|
44
|
+
end
|
34
45
|
end
|
35
46
|
end
|
36
47
|
end
|
@@ -13,11 +13,24 @@ module PaperTrail
|
|
13
13
|
::YAML.dump object
|
14
14
|
end
|
15
15
|
|
16
|
-
# Returns a SQL condition to be used to match the given field and value
|
17
|
-
# the serialized object
|
16
|
+
# Returns a SQL condition to be used to match the given field and value
|
17
|
+
# in the serialized object
|
18
18
|
def where_object_condition(arel_field, field, value)
|
19
19
|
arel_field.matches("%\n#{field}: #{value}\n%")
|
20
20
|
end
|
21
|
+
|
22
|
+
# Returns a SQL condition to be used to match the given field and value
|
23
|
+
# in the serialized object_changes
|
24
|
+
def where_object_changes_condition(arel_field, field, value)
|
25
|
+
# Need to check first (before) and secondary (after) fields
|
26
|
+
if defined?(::YAML::ENGINE) && ::YAML::ENGINE.yamler == 'psych'
|
27
|
+
arel_field.matches("%\n#{field}:\n- #{value}\n%").
|
28
|
+
or(arel_field.matches("%\n#{field}:\n-%\n- #{value}\n%"))
|
29
|
+
else # Syck adds extra spaces into array dumps
|
30
|
+
arel_field.matches("%\n#{field}: \n%- #{value}\n%").
|
31
|
+
or(arel_field.matches("%\n#{field}: \n-%\n- #{value}\n%"))
|
32
|
+
end
|
33
|
+
end
|
21
34
|
end
|
22
35
|
end
|
23
36
|
end
|
@@ -88,6 +88,19 @@ module PaperTrail
|
|
88
88
|
where(where_conditions)
|
89
89
|
end
|
90
90
|
|
91
|
+
def where_object_changes(args = {})
|
92
|
+
raise ArgumentError, 'expected to receive a Hash' unless args.is_a?(Hash)
|
93
|
+
arel_field = arel_table[:object_changes]
|
94
|
+
|
95
|
+
where_conditions = args.map do |field, value|
|
96
|
+
PaperTrail.serializer.where_object_changes_condition(arel_field, field, value)
|
97
|
+
end.reduce do |condition1, condition2|
|
98
|
+
condition1.and(condition2)
|
99
|
+
end
|
100
|
+
|
101
|
+
where(where_conditions)
|
102
|
+
end
|
103
|
+
|
91
104
|
def primary_key_is_int?
|
92
105
|
@primary_key_is_int ||= columns_hash[primary_key].type == :integer
|
93
106
|
rescue
|
@@ -101,7 +114,7 @@ module PaperTrail
|
|
101
114
|
|
102
115
|
# Returns whether the `object_changes` column is using the `json` type supported by PostgreSQL
|
103
116
|
def object_changes_col_is_json?
|
104
|
-
@object_changes_col_is_json ||= columns_hash['object_changes'].type == :json
|
117
|
+
@object_changes_col_is_json ||= columns_hash['object_changes'].try(:type) == :json
|
105
118
|
end
|
106
119
|
end
|
107
120
|
|
@@ -283,7 +296,8 @@ module PaperTrail
|
|
283
296
|
# We lookup the first child versions after version_at timestamp or in same transaction.
|
284
297
|
def reify_has_manys(model, options = {})
|
285
298
|
assoc_has_many_through, assoc_has_many_directly =
|
286
|
-
|
299
|
+
model.class.reflect_on_all_associations(:has_many).
|
300
|
+
partition { |assoc| assoc.options[:through] }
|
287
301
|
reify_has_many_directly(assoc_has_many_directly, model, options)
|
288
302
|
reify_has_many_through(assoc_has_many_through, model, options)
|
289
303
|
end
|
@@ -294,12 +308,12 @@ module PaperTrail
|
|
294
308
|
associations.each do |assoc|
|
295
309
|
next unless assoc.klass.paper_trail_enabled_for_model?
|
296
310
|
version_id_subquery = PaperTrail::VersionAssociation.joins(model.class.version_association_name).
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
311
|
+
select("MIN(version_id)").
|
312
|
+
where("foreign_key_name = ?", assoc.foreign_key).
|
313
|
+
where("foreign_key_id = ?", model.id).
|
314
|
+
where("#{version_table_name}.item_type = ?", assoc.class_name).
|
315
|
+
where("created_at >= ? OR transaction_id = ?", options[:version_at], transaction_id).
|
316
|
+
group("item_id").to_sql
|
303
317
|
versions = model.class.paper_trail_version_class.where("id IN (#{version_id_subquery})").inject({}) do |acc, v|
|
304
318
|
acc.merge!(v.item_id => v)
|
305
319
|
end
|
@@ -335,11 +349,11 @@ module PaperTrail
|
|
335
349
|
collection_keys = through_collection.map { |through_model| through_model.send(assoc.foreign_key) }
|
336
350
|
|
337
351
|
version_id_subquery = assoc.klass.paper_trail_version_class.
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
352
|
+
select("MIN(id)").
|
353
|
+
where("item_type = ?", assoc.class_name).
|
354
|
+
where("item_id IN (?)", collection_keys).
|
355
|
+
where("created_at >= ? OR transaction_id = ?", options[:version_at], transaction_id).
|
356
|
+
group("item_id").to_sql
|
343
357
|
versions = assoc.klass.paper_trail_version_class.where("id IN (#{version_id_subquery})").inject({}) do |acc, v|
|
344
358
|
acc.merge!(v.item_id => v)
|
345
359
|
end
|
data/spec/models/gadget_spec.rb
CHANGED
@@ -26,8 +26,10 @@ describe Gadget, :type => :model do
|
|
26
26
|
subject { Gadget.new(:created_at => Time.now) }
|
27
27
|
|
28
28
|
# apparently the private methods list in Ruby18 is different than in Ruby19+
|
29
|
-
if RUBY_VERSION
|
29
|
+
if RUBY_VERSION >= '1.9'
|
30
30
|
it { expect(subject.private_methods).to include(:changed_notably?) }
|
31
|
+
else
|
32
|
+
it { expect(subject.private_methods).to include('changed_notably?') }
|
31
33
|
end
|
32
34
|
|
33
35
|
context "create events" do
|
data/spec/models/version_spec.rb
CHANGED
@@ -108,6 +108,60 @@ describe PaperTrail::Version, :type => :model do
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
111
|
+
|
112
|
+
describe '#where_object_changes' do
|
113
|
+
it { expect(PaperTrail::Version).to respond_to(:where_object_changes) }
|
114
|
+
|
115
|
+
context "invalid arguments" do
|
116
|
+
it "should raise an error" do
|
117
|
+
expect { PaperTrail::Version.where_object_changes(:foo) }.to raise_error(ArgumentError)
|
118
|
+
expect { PaperTrail::Version.where_object_changes([]) }.to raise_error(ArgumentError)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "valid arguments", :versioning => true do
|
123
|
+
let(:widget) { Widget.new }
|
124
|
+
let(:name) { Faker::Name.first_name }
|
125
|
+
let(:int) { rand(5) + 2 }
|
126
|
+
|
127
|
+
before do
|
128
|
+
widget.update_attributes!(:name => name, :an_integer => 0)
|
129
|
+
widget.update_attributes!(:name => 'foobar', :an_integer => 77)
|
130
|
+
widget.update_attributes!(:name => Faker::Name.last_name, :an_integer => int)
|
131
|
+
end
|
132
|
+
|
133
|
+
context "`serializer == YAML`" do
|
134
|
+
specify { expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML }
|
135
|
+
|
136
|
+
it "should be able to locate versions according to their `object_changes` contents" do
|
137
|
+
expect(widget.versions.where_object_changes(:name => name)).to eq(widget.versions[0..1])
|
138
|
+
expect(widget.versions.where_object_changes(:an_integer => 77)).to eq(widget.versions[1..2])
|
139
|
+
expect(widget.versions.where_object_changes(:an_integer => int)).to eq([widget.versions.last])
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should be able to handle queries for multiple attributes" do
|
143
|
+
expect(widget.versions.where_object_changes(:an_integer => 77, :name => 'foobar')).to eq(widget.versions[1..2])
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "`serializer == JSON`" do
|
148
|
+
before(:all) { PaperTrail.serializer = PaperTrail::Serializers::JSON }
|
149
|
+
specify { expect(PaperTrail.serializer).to be PaperTrail::Serializers::JSON }
|
150
|
+
|
151
|
+
it "should be able to locate versions according to their `object_changes` contents" do
|
152
|
+
expect(widget.versions.where_object_changes(:name => name)).to eq(widget.versions[0..1])
|
153
|
+
expect(widget.versions.where_object_changes(:an_integer => 77)).to eq(widget.versions[1..2])
|
154
|
+
expect(widget.versions.where_object_changes(:an_integer => int)).to eq([widget.versions.last])
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should be able to handle queries for multiple attributes" do
|
158
|
+
expect(widget.versions.where_object_changes(:an_integer => 77, :name => 'foobar')).to eq(widget.versions[1..2])
|
159
|
+
end
|
160
|
+
|
161
|
+
after(:all) { PaperTrail.serializer = PaperTrail::Serializers::YAML }
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
111
165
|
end
|
112
166
|
end
|
113
167
|
end
|
@@ -21,13 +21,11 @@ describe "Articles management", :type => :request, :order => :defined do
|
|
21
21
|
let(:article) { Article.last }
|
22
22
|
|
23
23
|
context "`current_user` method returns a `String`" do
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
expect(article.versions.last.whodunnit).to eq('foobar')
|
30
|
-
end
|
24
|
+
it "should set that value as the `whodunnit`" do
|
25
|
+
expect { post articles_path, valid_params }.to change(PaperTrail::Version, :count).by(1)
|
26
|
+
expect(article.title).to eq('Doh')
|
27
|
+
expect(PaperTrail.whodunnit).to eq('foobar')
|
28
|
+
expect(article.versions.last.whodunnit).to eq('foobar')
|
31
29
|
end
|
32
30
|
end
|
33
31
|
end
|
data/spec/support/alt_db_init.rb
CHANGED
@@ -9,7 +9,7 @@ configs = YAML.load_file("#{Rails.root}/config/database.yml")
|
|
9
9
|
db_directory = "#{Rails.root}/db"
|
10
10
|
# setup alternate databases
|
11
11
|
if ENV["DB"] == "sqlite"
|
12
|
-
if RUBY_VERSION
|
12
|
+
if RUBY_VERSION >= '1.9'
|
13
13
|
FileUtils.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-foo.sqlite3"
|
14
14
|
FileUtils.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-bar.sqlite3"
|
15
15
|
else
|
@@ -9,7 +9,7 @@ class ApplicationController < ActionController::Base
|
|
9
9
|
def current_user
|
10
10
|
@current_user ||= OpenStruct.new(:id => 153).tap do |obj|
|
11
11
|
# Invoking `id` returns the `object_id` value in Ruby18 unless specifically overwritten
|
12
|
-
def obj.id; 153; end if RUBY_VERSION
|
12
|
+
def obj.id; 153; end if RUBY_VERSION < '1.9'
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -9,6 +9,9 @@ class ArticlesController < ApplicationController
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def current_user
|
12
|
-
'foobar'
|
12
|
+
'foobar'.tap do |string|
|
13
|
+
# Invoking `id` returns the `object_id` value in Ruby18 by default
|
14
|
+
string.class_eval { undef_method(:id) } if RUBY_VERSION < '1.9'
|
15
|
+
end
|
13
16
|
end
|
14
17
|
end
|
@@ -11,7 +11,11 @@ Dummy::Application.configure do
|
|
11
11
|
config.eager_load = true
|
12
12
|
|
13
13
|
# Configure static asset server for tests with Cache-Control for performance
|
14
|
-
config.
|
14
|
+
if config.respond_to?(:serve_static_files=)
|
15
|
+
config.serve_static_files = true
|
16
|
+
else
|
17
|
+
config.serve_static_assets = true
|
18
|
+
end
|
15
19
|
config.static_cache_control = "public, max-age=3600"
|
16
20
|
|
17
21
|
# Show full error reports and disable caching
|
@@ -16,7 +16,7 @@ class BaseApp < Sinatra::Base
|
|
16
16
|
def current_user
|
17
17
|
@current_user ||= OpenStruct.new(:id => 'foobar').tap do |obj|
|
18
18
|
# Invoking `id` returns the `object_id` value in Ruby18 unless specifically overwritten
|
19
|
-
def obj.id; 'foobar'; end if RUBY_VERSION
|
19
|
+
def obj.id; 'foobar'; end if RUBY_VERSION < '1.9'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -16,7 +16,7 @@ class Sinatra::Application
|
|
16
16
|
def current_user
|
17
17
|
@current_user ||= OpenStruct.new(:id => 'raboof').tap do |obj|
|
18
18
|
# Invoking `id` returns the `object_id` value in Ruby18 unless specifically overwritten
|
19
|
-
def obj.id; 'raboof'; end if RUBY_VERSION
|
19
|
+
def obj.id; 'raboof'; end if RUBY_VERSION < '1.9'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
data/test/unit/model_test.rb
CHANGED
@@ -800,8 +800,8 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
800
800
|
assert_equal @article.action_data_provider_method, @article.versions.last.action
|
801
801
|
end
|
802
802
|
|
803
|
-
should 'store dynamic meta data based on an attribute of the item
|
804
|
-
assert_equal
|
803
|
+
should 'store dynamic meta data based on an attribute of the item at creation' do
|
804
|
+
assert_equal @initial_title, @article.versions.last.title
|
805
805
|
end
|
806
806
|
|
807
807
|
|
@@ -36,7 +36,7 @@ class ProtectedAttrsTest < ActiveSupport::TestCase
|
|
36
36
|
|
37
37
|
should 'the previous version should contain right attributes' do
|
38
38
|
# For some reason this test seems to be broken in JRuby 1.9 mode in the test env even though it works in the console. WTF?
|
39
|
-
unless ActiveRecord::VERSION::MAJOR >= 4 && defined?(JRUBY_VERSION) && RUBY_VERSION
|
39
|
+
unless ActiveRecord::VERSION::MAJOR >= 4 && defined?(JRUBY_VERSION) && RUBY_VERSION >= '1.9'
|
40
40
|
assert_equal @widget.previous_version.attributes, @initial_attributes
|
41
41
|
end
|
42
42
|
end
|
@@ -24,7 +24,7 @@ class SerializerTest < ActiveSupport::TestCase
|
|
24
24
|
assert_equal @original_fluxor_attributes, YAML.load(@fluxor.versions[1].object)
|
25
25
|
# This test can't consistently pass in Ruby1.8 because hashes do no preserve order, which means the order of the
|
26
26
|
# attributes in the `YAML` can't be ensured.
|
27
|
-
if RUBY_VERSION
|
27
|
+
if RUBY_VERSION >= '1.9'
|
28
28
|
assert_equal YAML.dump(@original_fluxor_attributes), @fluxor.versions[1].object
|
29
29
|
end
|
30
30
|
end
|
@@ -59,7 +59,7 @@ class SerializerTest < ActiveSupport::TestCase
|
|
59
59
|
assert_equal @original_fluxor_attributes, ActiveSupport::JSON.decode(@fluxor.versions[1].object)
|
60
60
|
# This test can't consistently pass in Ruby1.8 because hashes do no preserve order, which means the order of the
|
61
61
|
# attributes in the JSON can't be ensured.
|
62
|
-
if RUBY_VERSION
|
62
|
+
if RUBY_VERSION >= '1.9'
|
63
63
|
assert_equal ActiveSupport::JSON.encode(@original_fluxor_attributes), @fluxor.versions[1].object
|
64
64
|
end
|
65
65
|
end
|
@@ -101,7 +101,7 @@ class SerializerTest < ActiveSupport::TestCase
|
|
101
101
|
assert_equal @original_fluxor_attributes, ActiveSupport::JSON.decode(@fluxor.versions[1].object)
|
102
102
|
# This test can't consistently pass in Ruby1.8 because hashes do no preserve order, which means the order of the
|
103
103
|
# attributes in the JSON can't be ensured.
|
104
|
-
if RUBY_VERSION
|
104
|
+
if RUBY_VERSION >= '1.9'
|
105
105
|
assert_equal ActiveSupport::JSON.encode(@original_fluxor_attributes), @fluxor.versions[1].object
|
106
106
|
end
|
107
107
|
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: 4.0.0.
|
4
|
+
version: 4.0.0.beta2
|
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:
|
12
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|