paper_trail 3.0.9 → 4.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rspec +1 -2
  4. data/.travis.yml +5 -0
  5. data/CHANGELOG.md +37 -23
  6. data/README.md +170 -63
  7. data/gemfiles/3.0.gemfile +10 -4
  8. data/lib/generators/paper_trail/install_generator.rb +19 -3
  9. data/lib/generators/paper_trail/templates/add_transaction_id_column_to_versions.rb +11 -0
  10. data/lib/generators/paper_trail/templates/create_version_associations.rb +17 -0
  11. data/lib/paper_trail.rb +24 -4
  12. data/lib/paper_trail/cleaner.rb +3 -3
  13. data/lib/paper_trail/config.rb +17 -0
  14. data/lib/paper_trail/frameworks/active_record/models/paper_trail/version_association.rb +7 -0
  15. data/lib/paper_trail/frameworks/rails.rb +1 -0
  16. data/lib/paper_trail/frameworks/rspec.rb +5 -0
  17. data/lib/paper_trail/has_paper_trail.rb +112 -38
  18. data/lib/paper_trail/version_association_concern.rb +13 -0
  19. data/lib/paper_trail/version_concern.rb +145 -38
  20. data/lib/paper_trail/version_number.rb +3 -3
  21. data/paper_trail.gemspec +11 -4
  22. data/spec/generators/install_generator_spec.rb +4 -4
  23. data/spec/models/fluxor_spec.rb +19 -0
  24. data/spec/models/gadget_spec.rb +10 -10
  25. data/spec/models/joined_version_spec.rb +9 -9
  26. data/spec/models/post_with_status_spec.rb +3 -3
  27. data/spec/models/version_spec.rb +49 -71
  28. data/spec/models/widget_spec.rb +124 -71
  29. data/spec/modules/version_concern_spec.rb +8 -8
  30. data/spec/modules/version_number_spec.rb +16 -16
  31. data/spec/paper_trail_spec.rb +17 -17
  32. data/spec/rails_helper.rb +34 -0
  33. data/spec/requests/articles_spec.rb +11 -11
  34. data/spec/spec_helper.rb +77 -36
  35. data/test/dummy/app/models/animal.rb +0 -2
  36. data/test/dummy/app/models/book.rb +4 -0
  37. data/test/dummy/app/models/customer.rb +4 -0
  38. data/test/dummy/app/models/editor.rb +4 -0
  39. data/test/dummy/app/models/editorship.rb +5 -0
  40. data/test/dummy/app/models/line_item.rb +4 -0
  41. data/test/dummy/app/models/order.rb +5 -0
  42. data/test/dummy/app/models/person.rb +1 -1
  43. data/test/dummy/app/models/post.rb +0 -1
  44. data/test/dummy/app/models/song.rb +0 -20
  45. data/test/dummy/app/models/widget.rb +4 -0
  46. data/test/dummy/config/application.rb +3 -0
  47. data/test/dummy/config/initializers/paper_trail.rb +1 -1
  48. data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +41 -0
  49. data/test/dummy/db/schema.rb +95 -25
  50. data/test/dummy/public/404.html +26 -0
  51. data/test/dummy/public/422.html +26 -0
  52. data/test/dummy/public/500.html +26 -0
  53. data/test/dummy/public/favicon.ico +0 -0
  54. data/test/dummy/public/javascripts/application.js +2 -0
  55. data/test/dummy/public/javascripts/controls.js +965 -0
  56. data/test/dummy/public/javascripts/dragdrop.js +974 -0
  57. data/test/dummy/public/javascripts/effects.js +1123 -0
  58. data/test/dummy/public/javascripts/rails.js +175 -0
  59. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  60. data/test/test_helper.rb +2 -2
  61. data/test/time_travel_helper.rb +15 -0
  62. data/test/unit/model_test.rb +613 -185
  63. data/test/unit/serializer_test.rb +3 -3
  64. metadata +104 -54
  65. data/spec/models/animal_spec.rb +0 -19
  66. data/test/dummy/public/javascripts/prototype.js +0 -6001
@@ -1,21 +1,21 @@
1
- require 'spec_helper'
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.should_not == Bar::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.should == Foo::Document.connection
13
- Bar::Version.connection.should == Bar::Document.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.should == 'Foo::Version'
18
- Bar::Document.version_class_name.should == 'Bar::Version'
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.should be_instance_of(Foo::Version)
29
- @bar_doc.versions.first.should be_instance_of(Bar::Version)
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 'PaperTrail::VERSION' do
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 { should be_const_defined(:MAJOR) }
10
- it { subject::MAJOR.should be_a(Integer) }
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 { should be_const_defined(:MINOR) }
14
- it { subject::MINOR.should be_a(Integer) }
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 { should be_const_defined(:TINY) }
18
- it { subject::TINY.should be_a(Integer) }
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 { should be_const_defined(:PRE) }
21
+ it { is_expected.to be_const_defined(:PRE) }
22
22
  if PaperTrail::VERSION::PRE
23
- it { subject::PRE.should be_instance_of(String) }
23
+ it { expect(subject::PRE).to be_instance_of(String) }
24
24
  end
25
25
  end
26
26
  describe :STRING do
27
- it { should be_const_defined(:STRING) }
28
- it { subject::STRING.should be_instance_of(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.should ==
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 :version do
41
- it { should respond_to(:version) }
42
- its(:version) { should == PaperTrail::VERSION::STRING }
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
@@ -1,58 +1,58 @@
1
- require 'spec_helper'
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
- ::PaperTrail.should_not be_enabled
6
+ expect(PaperTrail).not_to be_enabled
7
7
  end
8
8
  it 'should turn versioning on in a `with_versioning` block' do
9
- ::PaperTrail.should_not be_enabled
9
+ expect(PaperTrail).not_to be_enabled
10
10
  with_versioning do
11
- ::PaperTrail.should be_enabled
11
+ expect(PaperTrail).to be_enabled
12
12
  end
13
- ::PaperTrail.should_not be_enabled
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
- ::PaperTrail.should_not be_enabled
18
+ expect(PaperTrail).not_to be_enabled
19
19
  expect { with_versioning { raise } }.to raise_error
20
- ::PaperTrail.should_not be_enabled
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
- ::PaperTrail.should be_enabled
27
+ expect(PaperTrail).to be_enabled
28
28
  end
29
29
  it 'should keep versioning on after a with_versioning block' do
30
- ::PaperTrail.should be_enabled
30
+ expect(PaperTrail).to be_enabled
31
31
  with_versioning do
32
- ::PaperTrail.should be_enabled
32
+ expect(PaperTrail).to be_enabled
33
33
  end
34
- ::PaperTrail.should be_enabled
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 { ::PaperTrail.should_not be_enabled }
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
- ::PaperTrail.should be_enabled
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
- ::PaperTrail.should_not be_enabled
47
+ expect(PaperTrail).not_to be_enabled
48
48
  end
49
49
  end
50
50
 
51
51
  describe :whodunnit do
52
- before(:all) { ::PaperTrail.whodunnit = 'foobar' }
52
+ before(:all) { PaperTrail.whodunnit = 'foobar' }
53
53
 
54
54
  it "should get set to `nil` by default" do
55
- ::PaperTrail.whodunnit.should be_nil
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
- ::PaperTrail.controller_info.should == {}
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 'spec_helper'
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.should_not be_enabled }
7
+ specify { expect(PaperTrail).not_to be_enabled }
8
8
 
9
9
  it "should not create a version" do
10
- PaperTrail.should be_enabled_for_controller
11
- expect { post articles_path(valid_params) }.to_not change(PaperTrail::Version, :count)
12
- PaperTrail.should_not be_enabled_for_controller
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.should be_enabled_for_controller
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(valid_params) }.to change(PaperTrail::Version, :count).by(1)
27
- article.title.should == 'Doh'
28
- PaperTrail.whodunnit.should == 'foobar'
29
- article.versions.last.whodunnit.should == 'foobar'
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
- ENV["RAILS_ENV"] ||= 'test'
2
- ENV["DB"] ||= 'sqlite'
3
-
4
- unless File.exists?(File.expand_path('../../test/dummy/config/database.yml', __FILE__))
5
- warn "WARNING: No database.yml detected for the dummy app, please run `rake prepare` first"
6
- end
7
-
8
- require File.expand_path('../../test/dummy/config/environment', __FILE__)
9
- require 'rspec/rails'
10
- require 'rspec/autorun'
11
- require 'shoulda/matchers'
12
- require 'ffaker'
13
-
14
- # Requires supporting ruby files with custom matchers and macros, etc,
15
- # in spec/support/ and its subdirectories.
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.treat_symbols_as_metadata_keys_with_true_values = true
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
- # ## Mock Framework
23
- #
24
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
25
- #
26
- # config.mock_with :mocha
27
- # config.mock_with :flexmock
28
- # config.mock_with :rr
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
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
31
- # config.fixture_path = "#{::Rails.root}/spec/fixtures"
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
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
34
- # examples within a transaction, remove the following line or assign false
35
- # instead of true.
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
- # If true, the base class of anonymous controllers will be inferred
39
- # automatically. This will be the default behavior in future versions of
40
- # rspec-rails.
41
- config.infer_base_class_for_anonymous_controllers = false
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
- # config.order = 'random'
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,6 +1,4 @@
1
1
  class Animal < ActiveRecord::Base
2
2
  has_paper_trail
3
3
  self.inheritance_column = 'species'
4
-
5
- attr_accessible :species, :name if ::PaperTrail.active_record_protected_attributes?
6
4
  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
@@ -0,0 +1,4 @@
1
+ class Customer < ActiveRecord::Base
2
+ has_many :orders, :dependent => :destroy
3
+ has_paper_trail
4
+ end
@@ -0,0 +1,4 @@
1
+ # to demonstrate a has_through association that does not have paper_trail enabled
2
+ class Editor < ActiveRecord::Base
3
+ has_many :editorships, :dependent => :destroy
4
+ end
@@ -0,0 +1,5 @@
1
+ class Editorship < ActiveRecord::Base
2
+ belongs_to :book
3
+ belongs_to :editor
4
+ has_paper_trail
5
+ end
@@ -0,0 +1,4 @@
1
+ class LineItem < ActiveRecord::Base
2
+ belongs_to :order, :dependent => :destroy
3
+ has_paper_trail
4
+ end
@@ -0,0 +1,5 @@
1
+ class Order < ActiveRecord::Base
2
+ belongs_to :customer
3
+ has_many :line_items
4
+ has_paper_trail
5
+ end
@@ -19,7 +19,7 @@ class Person < ActiveRecord::Base
19
19
  def dump(zone)
20
20
  zone.try(:name)
21
21
  end
22
-
22
+
23
23
  def load(value)
24
24
  ::Time.find_zone!(value) rescue nil
25
25
  end