paper_trail 3.0.9 → 4.0.0.beta1
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/.rspec +1 -2
- data/.travis.yml +5 -0
- data/CHANGELOG.md +37 -23
- data/README.md +170 -63
- data/gemfiles/3.0.gemfile +10 -4
- data/lib/generators/paper_trail/install_generator.rb +19 -3
- data/lib/generators/paper_trail/templates/add_transaction_id_column_to_versions.rb +11 -0
- data/lib/generators/paper_trail/templates/create_version_associations.rb +17 -0
- data/lib/paper_trail.rb +24 -4
- data/lib/paper_trail/cleaner.rb +3 -3
- data/lib/paper_trail/config.rb +17 -0
- data/lib/paper_trail/frameworks/active_record/models/paper_trail/version_association.rb +7 -0
- data/lib/paper_trail/frameworks/rails.rb +1 -0
- data/lib/paper_trail/frameworks/rspec.rb +5 -0
- data/lib/paper_trail/has_paper_trail.rb +112 -38
- data/lib/paper_trail/version_association_concern.rb +13 -0
- data/lib/paper_trail/version_concern.rb +145 -38
- data/lib/paper_trail/version_number.rb +3 -3
- data/paper_trail.gemspec +11 -4
- data/spec/generators/install_generator_spec.rb +4 -4
- data/spec/models/fluxor_spec.rb +19 -0
- data/spec/models/gadget_spec.rb +10 -10
- data/spec/models/joined_version_spec.rb +9 -9
- data/spec/models/post_with_status_spec.rb +3 -3
- data/spec/models/version_spec.rb +49 -71
- data/spec/models/widget_spec.rb +124 -71
- data/spec/modules/version_concern_spec.rb +8 -8
- data/spec/modules/version_number_spec.rb +16 -16
- data/spec/paper_trail_spec.rb +17 -17
- data/spec/rails_helper.rb +34 -0
- data/spec/requests/articles_spec.rb +11 -11
- data/spec/spec_helper.rb +77 -36
- data/test/dummy/app/models/animal.rb +0 -2
- data/test/dummy/app/models/book.rb +4 -0
- data/test/dummy/app/models/customer.rb +4 -0
- data/test/dummy/app/models/editor.rb +4 -0
- data/test/dummy/app/models/editorship.rb +5 -0
- data/test/dummy/app/models/line_item.rb +4 -0
- data/test/dummy/app/models/order.rb +5 -0
- data/test/dummy/app/models/person.rb +1 -1
- data/test/dummy/app/models/post.rb +0 -1
- data/test/dummy/app/models/song.rb +0 -20
- data/test/dummy/app/models/widget.rb +4 -0
- data/test/dummy/config/application.rb +3 -0
- data/test/dummy/config/initializers/paper_trail.rb +1 -1
- data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +41 -0
- data/test/dummy/db/schema.rb +95 -25
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/javascripts/application.js +2 -0
- data/test/dummy/public/javascripts/controls.js +965 -0
- data/test/dummy/public/javascripts/dragdrop.js +974 -0
- data/test/dummy/public/javascripts/effects.js +1123 -0
- data/test/dummy/public/javascripts/rails.js +175 -0
- data/test/dummy/public/stylesheets/.gitkeep +0 -0
- data/test/test_helper.rb +2 -2
- data/test/time_travel_helper.rb +15 -0
- data/test/unit/model_test.rb +613 -185
- data/test/unit/serializer_test.rb +3 -3
- metadata +104 -54
- data/spec/models/animal_spec.rb +0 -19
- data/test/dummy/public/javascripts/prototype.js +0 -6001
@@ -1,21 +1,21 @@
|
|
1
|
-
require '
|
1
|
+
require 'rails_helper'
|
2
2
|
|
3
3
|
describe PaperTrail::VersionConcern do
|
4
4
|
|
5
5
|
before(:all) { require 'support/alt_db_init' }
|
6
6
|
|
7
7
|
it 'allows included class to have different connections' do
|
8
|
-
Foo::Version.connection.
|
8
|
+
expect(Foo::Version.connection).not_to eq(Bar::Version.connection)
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'allows custom version class to share connection with superclass' do
|
12
|
-
Foo::Version.connection.
|
13
|
-
Bar::Version.connection.
|
12
|
+
expect(Foo::Version.connection).to eq(Foo::Document.connection)
|
13
|
+
expect(Bar::Version.connection).to eq(Bar::Document.connection)
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'can be used with class_name option' do
|
17
|
-
Foo::Document.version_class_name.
|
18
|
-
Bar::Document.version_class_name.
|
17
|
+
expect(Foo::Document.version_class_name).to eq('Foo::Version')
|
18
|
+
expect(Bar::Document.version_class_name).to eq('Bar::Version')
|
19
19
|
end
|
20
20
|
|
21
21
|
describe 'persistence', :versioning => true do
|
@@ -25,8 +25,8 @@ describe PaperTrail::VersionConcern do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'should store versions in the correct corresponding db location' do
|
28
|
-
@foo_doc.versions.first.
|
29
|
-
@bar_doc.versions.first.
|
28
|
+
expect(@foo_doc.versions.first).to be_instance_of(Foo::Version)
|
29
|
+
expect(@bar_doc.versions.first).to be_instance_of(Bar::Version)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -1,35 +1,35 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe PaperTrail::VERSION do
|
4
4
|
|
5
5
|
describe "Constants" do
|
6
6
|
subject { PaperTrail::VERSION }
|
7
7
|
|
8
8
|
describe :MAJOR do
|
9
|
-
it {
|
10
|
-
it { subject::MAJOR.
|
9
|
+
it { is_expected.to be_const_defined(:MAJOR) }
|
10
|
+
it { expect(subject::MAJOR).to be_a(Integer) }
|
11
11
|
end
|
12
12
|
describe :MINOR do
|
13
|
-
it {
|
14
|
-
it { subject::MINOR.
|
13
|
+
it { is_expected.to be_const_defined(:MINOR) }
|
14
|
+
it { expect(subject::MINOR).to be_a(Integer) }
|
15
15
|
end
|
16
16
|
describe :TINY do
|
17
|
-
it {
|
18
|
-
it { subject::TINY.
|
17
|
+
it { is_expected.to be_const_defined(:TINY) }
|
18
|
+
it { expect(subject::TINY).to be_a(Integer) }
|
19
19
|
end
|
20
20
|
describe :PRE do
|
21
|
-
it {
|
21
|
+
it { is_expected.to be_const_defined(:PRE) }
|
22
22
|
if PaperTrail::VERSION::PRE
|
23
|
-
it { subject::PRE.
|
23
|
+
it { expect(subject::PRE).to be_instance_of(String) }
|
24
24
|
end
|
25
25
|
end
|
26
26
|
describe :STRING do
|
27
|
-
it {
|
28
|
-
it { subject::STRING.
|
27
|
+
it { is_expected.to be_const_defined(:STRING) }
|
28
|
+
it { expect(subject::STRING).to be_instance_of(String) }
|
29
29
|
|
30
30
|
it "should join the numbers into a period separated string" do
|
31
|
-
subject::STRING.
|
32
|
-
[subject::MAJOR, subject::MINOR, subject::TINY, subject::PRE].compact.join('.')
|
31
|
+
expect(subject::STRING).to eq(
|
32
|
+
[subject::MAJOR, subject::MINOR, subject::TINY, subject::PRE].compact.join('.'))
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -37,8 +37,8 @@ describe 'PaperTrail::VERSION' do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
describe PaperTrail do
|
40
|
-
describe
|
41
|
-
it {
|
42
|
-
|
40
|
+
describe '#version' do
|
41
|
+
it { is_expected.to respond_to(:version) }
|
42
|
+
it { expect(subject.version).to eq(PaperTrail::VERSION::STRING) }
|
43
43
|
end
|
44
44
|
end
|
data/spec/paper_trail_spec.rb
CHANGED
@@ -1,58 +1,58 @@
|
|
1
|
-
require '
|
1
|
+
require 'rails_helper'
|
2
2
|
|
3
3
|
describe "PaperTrail RSpec Helper" do
|
4
4
|
context 'default' do
|
5
5
|
it 'should have versioning off by default' do
|
6
|
-
|
6
|
+
expect(PaperTrail).not_to be_enabled
|
7
7
|
end
|
8
8
|
it 'should turn versioning on in a `with_versioning` block' do
|
9
|
-
|
9
|
+
expect(PaperTrail).not_to be_enabled
|
10
10
|
with_versioning do
|
11
|
-
|
11
|
+
expect(PaperTrail).to be_enabled
|
12
12
|
end
|
13
|
-
|
13
|
+
expect(PaperTrail).not_to be_enabled
|
14
14
|
end
|
15
15
|
|
16
16
|
context "error within `with_versioning` block" do
|
17
17
|
it "should revert the value of `PaperTrail.enabled?` to it's previous state" do
|
18
|
-
|
18
|
+
expect(PaperTrail).not_to be_enabled
|
19
19
|
expect { with_versioning { raise } }.to raise_error
|
20
|
-
|
20
|
+
expect(PaperTrail).not_to be_enabled
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
context '`versioning: true`', :versioning => true do
|
26
26
|
it 'should have versioning on by default' do
|
27
|
-
|
27
|
+
expect(PaperTrail).to be_enabled
|
28
28
|
end
|
29
29
|
it 'should keep versioning on after a with_versioning block' do
|
30
|
-
|
30
|
+
expect(PaperTrail).to be_enabled
|
31
31
|
with_versioning do
|
32
|
-
|
32
|
+
expect(PaperTrail).to be_enabled
|
33
33
|
end
|
34
|
-
|
34
|
+
expect(PaperTrail).to be_enabled
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
context '`with_versioning` block at class level' do
|
39
|
-
it {
|
39
|
+
it { expect(PaperTrail).not_to be_enabled }
|
40
40
|
|
41
41
|
with_versioning do
|
42
42
|
it 'should have versioning on by default' do
|
43
|
-
|
43
|
+
expect(PaperTrail).to be_enabled
|
44
44
|
end
|
45
45
|
end
|
46
46
|
it 'should not leak the `enabled?` state into successive tests' do
|
47
|
-
|
47
|
+
expect(PaperTrail).not_to be_enabled
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
describe :whodunnit do
|
52
|
-
before(:all) {
|
52
|
+
before(:all) { PaperTrail.whodunnit = 'foobar' }
|
53
53
|
|
54
54
|
it "should get set to `nil` by default" do
|
55
|
-
|
55
|
+
expect(PaperTrail.whodunnit).to be_nil
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -60,7 +60,7 @@ describe "PaperTrail RSpec Helper" do
|
|
60
60
|
before(:all) { ::PaperTrail.controller_info = {:foo => 'bar'} }
|
61
61
|
|
62
62
|
it "should get set to an empty hash before each test" do
|
63
|
-
|
63
|
+
expect(PaperTrail.controller_info).to eq({})
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
ENV["DB"] ||= 'sqlite'
|
4
|
+
|
5
|
+
unless File.exists?(File.expand_path('../../test/dummy/config/database.yml', __FILE__))
|
6
|
+
warn "WARNING: No database.yml detected for the dummy app, please run `rake prepare` first"
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'spec_helper'
|
10
|
+
require File.expand_path('../../test/dummy/config/environment', __FILE__)
|
11
|
+
require 'rspec/rails'
|
12
|
+
require 'paper_trail/frameworks/rspec'
|
13
|
+
require 'shoulda/matchers'
|
14
|
+
require 'ffaker'
|
15
|
+
|
16
|
+
# prevent Test::Unit's AutoRunner from executing during RSpec's rake task
|
17
|
+
Test::Unit.run = true if defined?(Test::Unit) && Test::Unit.respond_to?(:run=)
|
18
|
+
|
19
|
+
# Checks for pending migrations before tests are run.
|
20
|
+
# If you are not using ActiveRecord, you can remove this line.
|
21
|
+
ActiveRecord::Migration.check_pending! if ActiveRecord::Migration.respond_to?(:check_pending!)
|
22
|
+
|
23
|
+
RSpec.configure do |config|
|
24
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
25
|
+
|
26
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
27
|
+
# examples within a transaction, remove the following line or assign false
|
28
|
+
# instead of true.
|
29
|
+
config.use_transactional_fixtures = true
|
30
|
+
|
31
|
+
# The different available types are documented in the features, such as in
|
32
|
+
# https://relishapp.com/rspec/rspec-rails/docs
|
33
|
+
# config.infer_spec_type_from_file_location!
|
34
|
+
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
require '
|
1
|
+
require 'rails_helper'
|
2
2
|
|
3
|
-
describe "Articles" do
|
3
|
+
describe "Articles management", :type => :request, :order => :defined do
|
4
4
|
let(:valid_params) { { :article => { :title => 'Doh', :content => Faker::Lorem.sentence } } }
|
5
5
|
|
6
6
|
context "versioning disabled" do
|
7
|
-
specify { PaperTrail.
|
7
|
+
specify { expect(PaperTrail).not_to be_enabled }
|
8
8
|
|
9
9
|
it "should not create a version" do
|
10
|
-
PaperTrail.
|
11
|
-
expect { post
|
12
|
-
PaperTrail.
|
10
|
+
expect(PaperTrail).to be_enabled_for_controller
|
11
|
+
expect { post(articles_path, valid_params) }.to_not change(PaperTrail::Version, :count)
|
12
|
+
expect(PaperTrail).not_to be_enabled_for_controller
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should not leak the state of the `PaperTrail.enabled_for_controller?` into the next test" do
|
16
|
-
PaperTrail.
|
16
|
+
expect(PaperTrail).to be_enabled_for_controller
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -23,10 +23,10 @@ describe "Articles" do
|
|
23
23
|
context "`current_user` method returns a `String`" do
|
24
24
|
if RUBY_VERSION.to_f >= 1.9
|
25
25
|
it "should set that value as the `whodunnit`" do
|
26
|
-
expect { post articles_path
|
27
|
-
article.title.
|
28
|
-
PaperTrail.whodunnit.
|
29
|
-
article.versions.last.whodunnit.
|
26
|
+
expect { post articles_path, valid_params }.to change(PaperTrail::Version, :count).by(1)
|
27
|
+
expect(article.title).to eq('Doh')
|
28
|
+
expect(PaperTrail.whodunnit).to eq('foobar')
|
29
|
+
expect(article.versions.last.whodunnit).to eq('foobar')
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,48 +1,89 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
require
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
#
|
16
|
-
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
17
|
-
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
10
|
+
# a separate helper file that requires the additional dependencies and performs
|
11
|
+
# the additional setup, and require it from the spec files that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
18
16
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
17
|
RSpec.configure do |config|
|
20
|
-
config.
|
18
|
+
# rspec-expectations config goes here. You can use an alternate
|
19
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
20
|
+
# assertions if you prefer.
|
21
|
+
config.expect_with :rspec do |expectations|
|
22
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
23
|
+
# and `failure_message` of custom matchers include text for helper methods
|
24
|
+
# defined using `chain`, e.g.:
|
25
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
26
|
+
# # => "be bigger than 2 and smaller than 4"
|
27
|
+
# ...rather than:
|
28
|
+
# # => "be bigger than 2"
|
29
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
30
|
+
end
|
31
|
+
|
32
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
33
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
34
|
+
config.mock_with :rspec do |mocks|
|
35
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
36
|
+
# a real object. This is generally recommended, and will default to
|
37
|
+
# `true` in RSpec 4.
|
38
|
+
mocks.verify_partial_doubles = true
|
39
|
+
end
|
21
40
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
41
|
+
# The settings below are suggested to provide a good initial experience
|
42
|
+
# with RSpec, but feel free to customize to your heart's content.
|
43
|
+
=begin
|
44
|
+
# These two settings work together to allow you to limit a spec run
|
45
|
+
# to individual examples or groups you care about by tagging them with
|
46
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
47
|
+
# get run.
|
48
|
+
config.filter_run :focus
|
49
|
+
config.run_all_when_everything_filtered = true
|
29
50
|
|
30
|
-
#
|
31
|
-
#
|
51
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
52
|
+
# For more details, see:
|
53
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
54
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
55
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
56
|
+
config.disable_monkey_patching!
|
32
57
|
|
33
|
-
#
|
34
|
-
#
|
35
|
-
|
36
|
-
config.use_transactional_fixtures = true
|
58
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
59
|
+
# be too noisy due to issues in dependencies.
|
60
|
+
config.warnings = true
|
37
61
|
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
config.
|
62
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
63
|
+
# file, and it's useful to allow more verbose output when running an
|
64
|
+
# individual spec file.
|
65
|
+
if config.files_to_run.one?
|
66
|
+
# Use the documentation formatter for detailed output,
|
67
|
+
# unless a formatter has already been configured
|
68
|
+
# (e.g. via a command-line flag).
|
69
|
+
config.default_formatter = 'doc'
|
70
|
+
end
|
71
|
+
|
72
|
+
# Print the 10 slowest examples and example groups at the
|
73
|
+
# end of the spec run, to help surface which specs are running
|
74
|
+
# particularly slow.
|
75
|
+
config.profile_examples = 10
|
42
76
|
|
43
77
|
# Run specs in random order to surface order dependencies. If you find an
|
44
78
|
# order dependency and want to debug it, you can fix the order by providing
|
45
79
|
# the seed, which is printed after each run.
|
46
80
|
# --seed 1234
|
47
|
-
|
81
|
+
config.order = :random
|
82
|
+
|
83
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
84
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
85
|
+
# test failures related to randomization by passing the same `--seed` value
|
86
|
+
# as the one that triggered the failure.
|
87
|
+
Kernel.srand config.seed
|
88
|
+
=end
|
48
89
|
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
class Book < ActiveRecord::Base
|
2
2
|
has_many :authorships, :dependent => :destroy
|
3
3
|
has_many :authors, :through => :authorships, :source => :person
|
4
|
+
|
5
|
+
has_many :editorships, :dependent => :destroy
|
6
|
+
has_many :editors, :through => :editorships
|
7
|
+
|
4
8
|
has_paper_trail
|
5
9
|
end
|