paper_trail_manager 0.5.0 → 0.7.0

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.
Files changed (154) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +88 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +33 -0
  5. data/Appraisals +26 -34
  6. data/CHANGES.md +14 -2
  7. data/Gemfile +2 -1
  8. data/README.md +10 -1
  9. data/Rakefile +17 -5
  10. data/app/controllers/paper_trail_manager/changes_controller.rb +103 -100
  11. data/app/helpers/paper_trail_manager/changes_helper.rb +34 -51
  12. data/app/views/paper_trail_manager/changes/_version.html.erb +7 -3
  13. data/app/views/paper_trail_manager/changes/index.atom.builder +23 -19
  14. data/gemfiles/rails_4.2.2_paper_trail_3.0_kaminari.gemfile +13 -0
  15. data/gemfiles/rails_4.2.2_paper_trail_3.0_will_paginate.gemfile +13 -0
  16. data/gemfiles/rails_4.2.2_paper_trail_4.0_kaminari.gemfile +13 -0
  17. data/gemfiles/rails_4.2.2_paper_trail_4.0_will_paginate.gemfile +13 -0
  18. data/gemfiles/rails_4.2.2_paper_trail_5.0_kaminari.gemfile +13 -0
  19. data/gemfiles/rails_4.2.2_paper_trail_5.0_will_paginate.gemfile +13 -0
  20. data/gemfiles/rails_4.2.2_paper_trail_6.0_kaminari.gemfile +13 -0
  21. data/gemfiles/rails_4.2.2_paper_trail_6.0_will_paginate.gemfile +13 -0
  22. data/gemfiles/rails_4.2.2_paper_trail_7.0_kaminari.gemfile +13 -0
  23. data/gemfiles/rails_4.2.2_paper_trail_7.0_will_paginate.gemfile +13 -0
  24. data/gemfiles/rails_4.2.2_paper_trail_8.0_kaminari.gemfile +13 -0
  25. data/gemfiles/rails_4.2.2_paper_trail_8.0_will_paginate.gemfile +13 -0
  26. data/gemfiles/rails_5.0.0_paper_trail_5.0_kaminari.gemfile +13 -0
  27. data/gemfiles/rails_5.0.0_paper_trail_5.0_will_paginate.gemfile +13 -0
  28. data/gemfiles/rails_5.0.0_paper_trail_6.0_kaminari.gemfile +13 -0
  29. data/gemfiles/rails_5.0.0_paper_trail_6.0_will_paginate.gemfile +13 -0
  30. data/gemfiles/rails_5.0.0_paper_trail_7.0_kaminari.gemfile +13 -0
  31. data/gemfiles/rails_5.0.0_paper_trail_7.0_will_paginate.gemfile +13 -0
  32. data/gemfiles/rails_5.0.0_paper_trail_8.0_kaminari.gemfile +13 -0
  33. data/gemfiles/rails_5.0.0_paper_trail_8.0_will_paginate.gemfile +13 -0
  34. data/gemfiles/rails_5.1.0_paper_trail_10.0_kaminari.gemfile +13 -0
  35. data/gemfiles/rails_5.1.0_paper_trail_10.0_will_paginate.gemfile +13 -0
  36. data/gemfiles/rails_5.1.0_paper_trail_7.0_kaminari.gemfile +13 -0
  37. data/gemfiles/rails_5.1.0_paper_trail_7.0_will_paginate.gemfile +13 -0
  38. data/gemfiles/rails_5.1.0_paper_trail_8.0_kaminari.gemfile +13 -0
  39. data/gemfiles/rails_5.1.0_paper_trail_8.0_will_paginate.gemfile +13 -0
  40. data/gemfiles/rails_5.1.0_paper_trail_9.0_kaminari.gemfile +13 -0
  41. data/gemfiles/rails_5.1.0_paper_trail_9.0_will_paginate.gemfile +13 -0
  42. data/gemfiles/rails_5.2.0_paper_trail_10.0_kaminari.gemfile +13 -0
  43. data/gemfiles/rails_5.2.0_paper_trail_10.0_will_paginate.gemfile +13 -0
  44. data/gemfiles/rails_5.2.0_paper_trail_9.0_kaminari.gemfile +13 -0
  45. data/gemfiles/rails_5.2.0_paper_trail_9.0_will_paginate.gemfile +13 -0
  46. data/gemfiles/rails_6.0.0_paper_trail_10.0_kaminari.gemfile +14 -0
  47. data/gemfiles/rails_6.0.0_paper_trail_10.0_will_paginate.gemfile +15 -0
  48. data/lib/paper_trail_manager.rb +22 -27
  49. data/paper_trail_manager.gemspec +22 -21
  50. data/spec/app_template.rb +30 -0
  51. data/spec/integration/navigation_spec.rb +4 -2
  52. data/spec/integration/paper_trail_manager_spec.rb +94 -110
  53. data/spec/rails_helper.rb +6 -4
  54. data/spec/spec_helper.rb +7 -5
  55. data/spec/support/factories.rb +2 -1
  56. data/spec/support/rspec_html_matchers.rb +7 -0
  57. metadata +87 -224
  58. data/.travis.yml +0 -15
  59. data/gemfiles/rails_3.2_kaminari.gemfile +0 -8
  60. data/gemfiles/rails_3.2_will_paginate.gemfile +0 -8
  61. data/gemfiles/rails_4.0_kaminari.gemfile +0 -8
  62. data/gemfiles/rails_4.0_will_paginate.gemfile +0 -8
  63. data/gemfiles/rails_4.1_kaminari.gemfile +0 -8
  64. data/gemfiles/rails_4.1_will_paginate.gemfile +0 -8
  65. data/gemfiles/rails_4.2_kaminari.gemfile +0 -8
  66. data/gemfiles/rails_4.2_will_paginate.gemfile +0 -8
  67. data/spec/controllers/entities_controller_spec.rb +0 -125
  68. data/spec/controllers/platforms_controller_spec.rb +0 -125
  69. data/spec/dummy/.gitignore +0 -15
  70. data/spec/dummy/Gemfile +0 -9
  71. data/spec/dummy/README.rdoc +0 -261
  72. data/spec/dummy/Rakefile +0 -7
  73. data/spec/dummy/app/assets/images/rails.png +0 -0
  74. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  75. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  76. data/spec/dummy/app/controllers/application_controller.rb +0 -6
  77. data/spec/dummy/app/controllers/entities_controller.rb +0 -83
  78. data/spec/dummy/app/controllers/platforms_controller.rb +0 -83
  79. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  80. data/spec/dummy/app/helpers/entities_helper.rb +0 -2
  81. data/spec/dummy/app/helpers/platforms_helper.rb +0 -2
  82. data/spec/dummy/app/mailers/.gitkeep +0 -0
  83. data/spec/dummy/app/models/.gitkeep +0 -0
  84. data/spec/dummy/app/models/entity.rb +0 -6
  85. data/spec/dummy/app/models/platform.rb +0 -6
  86. data/spec/dummy/app/views/application/index.html.erb +0 -6
  87. data/spec/dummy/app/views/entities/_form.html.erb +0 -17
  88. data/spec/dummy/app/views/entities/edit.html.erb +0 -6
  89. data/spec/dummy/app/views/entities/index.html.erb +0 -21
  90. data/spec/dummy/app/views/entities/new.html.erb +0 -5
  91. data/spec/dummy/app/views/entities/show.html.erb +0 -5
  92. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  93. data/spec/dummy/app/views/platforms/_form.html.erb +0 -17
  94. data/spec/dummy/app/views/platforms/edit.html.erb +0 -6
  95. data/spec/dummy/app/views/platforms/index.html.erb +0 -21
  96. data/spec/dummy/app/views/platforms/new.html.erb +0 -5
  97. data/spec/dummy/app/views/platforms/show.html.erb +0 -5
  98. data/spec/dummy/config/application.rb +0 -64
  99. data/spec/dummy/config/boot.rb +0 -6
  100. data/spec/dummy/config/database.yml +0 -22
  101. data/spec/dummy/config/environment.rb +0 -5
  102. data/spec/dummy/config/environments/development.rb +0 -37
  103. data/spec/dummy/config/environments/production.rb +0 -67
  104. data/spec/dummy/config/environments/test.rb +0 -36
  105. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  106. data/spec/dummy/config/initializers/inflections.rb +0 -15
  107. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  108. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  109. data/spec/dummy/config/initializers/session_store.rb +0 -8
  110. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  111. data/spec/dummy/config/locales/en.yml +0 -5
  112. data/spec/dummy/config/routes.rb +0 -8
  113. data/spec/dummy/config.ru +0 -4
  114. data/spec/dummy/db/migrate/20110228091428_create_entities.rb +0 -14
  115. data/spec/dummy/db/migrate/20110228093241_create_platforms.rb +0 -14
  116. data/spec/dummy/db/migrate/20110228094444_create_versions.rb +0 -18
  117. data/spec/dummy/db/schema.rb +0 -41
  118. data/spec/dummy/db/seeds.rb +0 -7
  119. data/spec/dummy/doc/README_FOR_APP +0 -2
  120. data/spec/dummy/lib/assets/.gitkeep +0 -0
  121. data/spec/dummy/lib/tasks/.gitkeep +0 -0
  122. data/spec/dummy/log/.gitkeep +0 -0
  123. data/spec/dummy/public/404.html +0 -26
  124. data/spec/dummy/public/422.html +0 -26
  125. data/spec/dummy/public/500.html +0 -25
  126. data/spec/dummy/public/favicon.ico +0 -0
  127. data/spec/dummy/public/index.html +0 -241
  128. data/spec/dummy/public/robots.txt +0 -5
  129. data/spec/dummy/script/rails +0 -6
  130. data/spec/dummy/test/fixtures/.gitkeep +0 -0
  131. data/spec/dummy/test/functional/.gitkeep +0 -0
  132. data/spec/dummy/test/integration/.gitkeep +0 -0
  133. data/spec/dummy/test/performance/browsing_test.rb +0 -12
  134. data/spec/dummy/test/test_helper.rb +0 -13
  135. data/spec/dummy/test/unit/.gitkeep +0 -0
  136. data/spec/dummy/vendor/assets/javascripts/.gitkeep +0 -0
  137. data/spec/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  138. data/spec/dummy/vendor/plugins/.gitkeep +0 -0
  139. data/spec/helpers/entities_helper_spec.rb +0 -15
  140. data/spec/helpers/platforms_helper_spec.rb +0 -15
  141. data/spec/models/entity_spec.rb +0 -14
  142. data/spec/models/platform_spec.rb +0 -14
  143. data/spec/requests/entities_spec.rb +0 -11
  144. data/spec/requests/platforms_spec.rb +0 -11
  145. data/spec/routing/entities_routing_spec.rb +0 -35
  146. data/spec/routing/platforms_routing_spec.rb +0 -35
  147. data/spec/views/entities/edit.html.erb_spec.rb +0 -15
  148. data/spec/views/entities/index.html.erb_spec.rb +0 -14
  149. data/spec/views/entities/new.html.erb_spec.rb +0 -15
  150. data/spec/views/entities/show.html.erb_spec.rb +0 -11
  151. data/spec/views/platforms/edit.html.erb_spec.rb +0 -15
  152. data/spec/views/platforms/index.html.erb_spec.rb +0 -14
  153. data/spec/views/platforms/new.html.erb_spec.rb +0 -15
  154. data/spec/views/platforms/show.html.erb_spec.rb +0 -11
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails'
2
4
  require 'paper_trail'
3
5
 
@@ -7,66 +9,59 @@ rescue LoadError
7
9
  begin
8
10
  require 'kaminari'
9
11
  rescue LoadError
10
- raise LoadError.new('will_paginate or kaminari must be in Gemfile or load_path')
12
+ raise LoadError, 'will_paginate or kaminari must be in Gemfile or load_path'
11
13
  end
12
14
  end
13
15
 
14
16
  class PaperTrailManager < Rails::Engine
15
- initializer "paper_trail_manager.pagination" do
16
- if defined?(WillPaginate)
17
- ::ActionView::Base.send(:alias_method, :paginate, :will_paginate)
18
- end
17
+ initializer 'paper_trail_manager.pagination' do
18
+ ::ActionView::Base.send(:alias_method, :paginate, :will_paginate) if defined?(WillPaginate)
19
19
  end
20
20
 
21
21
  @@whodunnit_name_method = :name
22
- cattr_accessor :whodunnit_class, :whodunnit_name_method, :route_helpers, :layout, :base_controller
22
+ cattr_accessor :whodunnit_class, :whodunnit_name_method, :route_helpers,
23
+ :layout, :base_controller, :user_path_method, :item_name_method
23
24
 
24
- self.base_controller = "ApplicationController"
25
+ self.base_controller = 'ApplicationController'
26
+ self.user_path_method = :user_path
25
27
 
26
28
  (Pathname(__FILE__).dirname + '..').tap do |base|
27
- paths["app/controller"] = base + 'app/controllers'
28
- paths["app/view"] = base + 'app/views'
29
- end
30
-
31
- def self._allow_set(action, block)
32
- send(:class_variable_set, "@@allow_#{action}_block", block)
29
+ paths['app/controller'] = base + 'app/controllers'
30
+ paths['app/view'] = base + 'app/views'
33
31
  end
34
32
 
35
- def self._allow_check(action, *args)
36
- begin
37
- block = send(:class_variable_get, "@@allow_#{action}_block")
38
- rescue NameError => e
39
- return true
40
- end
33
+ cattr_accessor :allow_index_block, :allow_show_block, :allow_revert_block
41
34
 
42
- return block.call(*args)
43
- end
35
+ block = proc { true }
36
+ self.allow_index_block = block
37
+ self.allow_show_block = block
38
+ self.allow_revert_block = block
44
39
 
45
40
  def self.allow_index_when(&block)
46
- _allow_set(:index, block)
41
+ self.allow_index_block = block
47
42
  end
48
43
 
49
44
  def self.allow_index?(controller)
50
- _allow_check(:index, controller)
45
+ allow_index_block.call controller
51
46
  end
52
47
 
53
48
  def self.allow_show_when(&block)
54
- _allow_set(:show, block)
49
+ self.allow_show_block = block
55
50
  end
56
51
 
57
52
  def self.allow_show?(controller, version)
58
- _allow_check(:index, controller, version)
53
+ allow_index_block.call controller, version
59
54
  end
60
55
 
61
56
  # Describe when to allow reverts. Call this with a block that accepts
62
57
  # arguments for +controller+ and +version+.
63
58
  def self.allow_revert_when(&block)
64
- _allow_set(:revert, block)
59
+ self.allow_revert_block = block
65
60
  end
66
61
 
67
62
  # Allow revert given the +controller+ and +version+? If no
68
63
  # ::allow_revert_when was specified, always return +true+.
69
64
  def self.allow_revert?(controller, version)
70
- _allow_check(:revert, controller, version)
65
+ allow_revert_block.call controller, version
71
66
  end
72
67
  end
@@ -1,31 +1,32 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
 
5
6
  Gem::Specification.new do |spec|
6
- spec.name = "paper_trail_manager"
7
- spec.version = "0.5.0"
8
- spec.authors = ["Igal Koshevoy", "Reid Beels"]
9
- spec.authors = ["mail@reidbeels.com"]
10
- spec.summary = "A user interface for `paper_trail` versioning data in Ruby on Rails 3 applications."
11
- spec.description = "Browse, subscribe, view and revert changes to records when using Ruby on Rails 3 and the `paper_trail` gem."
12
- spec.homepage = "https://github.com/fusion94/paper_trail_manager"
13
- spec.license = "MIT"
7
+ spec.name = 'paper_trail_manager'
8
+ spec.version = '0.7.0'
9
+ spec.authors = ['Igal Koshevoy', 'Reid Beels']
10
+ spec.authors = ['mail@reidbeels.com']
11
+ spec.summary = 'A user interface for `paper_trail` versioning data in Rails applications.'
12
+ spec.description = 'Browse, subscribe, view and revert changes to records when using Rails and the `paper_trail` gem.'
13
+ spec.homepage = 'https://github.com/fusion94/paper_trail_manager'
14
+ spec.license = 'MIT'
14
15
 
15
16
  spec.files = `git ls-files -z`.split("\x0")
16
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
19
20
 
20
- spec.add_dependency "rails", [">= 3.0", "< 5.0"]
21
- spec.add_dependency "paper_trail", "~> 3.0"
21
+ spec.add_dependency 'paper_trail', ['>= 3.0']
22
+ spec.add_dependency 'rails', ['>= 3.0', '< 7.0']
22
23
 
23
- spec.add_development_dependency "rake", "~> 10.4"
24
- spec.add_development_dependency "sqlite3", "~> 1.3"
25
- spec.add_development_dependency "factory_girl_rails", "~> 4.0"
26
- spec.add_development_dependency "rspec-rails", "~> 3.0"
27
- spec.add_development_dependency "rspec-activemodel-mocks", "~> 1.0"
28
- spec.add_development_dependency "rspec-its", "~> 1.0"
29
- spec.add_development_dependency "appraisal", "~> 1.0"
24
+ spec.add_development_dependency 'appraisal', '~> 1.0'
25
+ spec.add_development_dependency 'factory_girl_rails', '~> 4.0'
26
+ spec.add_development_dependency 'rake', '~> 10.4'
27
+ spec.add_development_dependency 'rspec-activemodel-mocks', '~> 1.0'
28
+ spec.add_development_dependency 'rspec-html-matchers', '~> 0.9.2'
29
+ spec.add_development_dependency 'rspec-its', '~> 1.0'
30
+ spec.add_development_dependency 'rspec-rails', '~> 3.0'
31
+ spec.add_development_dependency 'sqlite3', '>= 1.3.6'
30
32
  end
31
-
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ gem 'paper_trail_manager', path: __FILE__ + '/../../../'
4
+
5
+ unless File.exist?('app/assets/config/manifest.js')
6
+ create_file 'app/assets/config/manifest.js'
7
+ append_to_file 'app/assets/config/manifest.js', "//= link application.css\n"
8
+ append_to_file 'app/assets/config/manifest.js', "//= link application.js\n"
9
+ end
10
+
11
+ generate 'paper_trail:install'
12
+ generate 'resource', 'entity name:string status:string --no-controller-specs --no-helper-specs'
13
+ generate 'resource', 'platform name:string status:string --no-controller-specs --no-helper-specs'
14
+
15
+ remove_file 'spec/models/entity_spec.rb'
16
+ remove_file 'spec/models/platform_spec.rb'
17
+
18
+ model_body = <<-MODEL
19
+ has_paper_trail
20
+
21
+ validates_presence_of :name
22
+ validates_presence_of :status
23
+ MODEL
24
+
25
+ inject_into_class 'app/models/entity.rb', 'Entity', model_body
26
+ inject_into_class 'app/models/platform.rb', 'Platform', model_body
27
+
28
+ route "resources :changes, :controller => 'paper_trail_manager/changes'"
29
+
30
+ rake 'db:migrate db:test:prepare'
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe "Navigation" do
4
- it "should be a valid app" do
5
+ describe 'Navigation' do
6
+ it 'is a valid app' do
5
7
  ::Rails.application.should be_a_kind_of(Rails::Application)
6
8
  end
7
9
  end
@@ -1,72 +1,55 @@
1
- require 'spec_helper'
2
-
3
- describe PaperTrailManager, :versioning => true do
4
- def version
5
- return assigns[:version]
6
- end
7
-
8
- def versions
9
- return assigns[:versions]
10
- end
11
-
12
- def item_types
13
- return versions.map(&:item_type).uniq.sort
14
- end
15
-
16
- def populate
17
- @reimu = FactoryGirl.create(:entity, :name => "Miko Hakurei Reimu", :status => "Highly Responsive to Prayers")
18
- @reimu.update_attributes(:name => "Hakurei Reimu", :status => "Phantasmagoria of Dimensional Dream")
19
- @reimu.update_attributes(:status => "Perfect Cherry Blossom")
1
+ # frozen_string_literal: true
20
2
 
21
- @sakuya = FactoryGirl.create(:entity, :name => "Sakuya Izayoi", :status => "Flowering Night")
22
-
23
- @flanchan = FactoryGirl.create(:entity, :name => "Flandre Scarlet", :status => "The Embodiment of Scarlet Devil")
24
- @flanchan.destroy
25
-
26
- @kyuu_hachi = FactoryGirl.create(:platform, :name => "PC-9801", :status => "SUGOI!!1!")
27
- @kyuu_hachi.update_attributes(:status => "Kimochi warui.")
28
- @kyuu_hachi.destroy
29
-
30
- @uinodouzu = FactoryGirl.create(:platform, :name => "Mikorusofto Uinodouzu", :status => 'o-O')
31
- end
3
+ require 'spec_helper'
32
4
 
33
- context "without changes" do
34
- context "index" do
35
- it "should have no changes by default" do
36
- get "/changes"
5
+ describe PaperTrailManager, versioning: true do
6
+ context 'without changes' do
7
+ context 'when fetching the index' do
8
+ it 'has no changes by default' do
9
+ get '/changes'
37
10
 
38
- assigns[:versions].should be_empty
11
+ expect(response.body).to include('No changes found')
39
12
  end
40
13
  end
41
14
  end
42
15
 
43
- context "with changes" do
44
- before do
45
- populate
46
- end
16
+ context 'with changes' do
17
+ let(:reimu) { FactoryGirl.create(:entity, name: 'Miko Hakurei Reimu', status: 'Highly Responsive to Prayers') }
18
+ let(:flanchan) { FactoryGirl.create(:entity, name: 'Flandre Scarlet', status: 'The Embodiment of Scarlet Devil') }
19
+ let(:sakuya) { FactoryGirl.create(:entity, name: 'Sakuya Izayoi', status: 'Flowering Night') }
20
+ let(:kyuu_hachi) { FactoryGirl.create(:platform, name: 'PC-9801', status: 'SUGOI!!1!') }
21
+ let!(:uinodouzu) { FactoryGirl.create(:platform, name: 'Mikorusofto Uinodouzu', status: 'o-O') }
22
+
23
+ let!(:flanchan_id) { flanchan.id }
47
24
 
48
- after do
49
- Entity.destroy_all
50
- Platform.destroy_all
51
- PaperTrail::Version.destroy_all
25
+ before do
26
+ sakuya
27
+ reimu.update(name: 'Hakurei Reimu', status: 'Phantasmagoria of Dimensional Dream')
28
+ reimu.update(status: 'Perfect Cherry Blossom')
29
+ flanchan.destroy
30
+ kyuu_hachi.update(status: 'Kimochi warui.')
31
+ kyuu_hachi.destroy
32
+ uinodouzu
52
33
  end
53
34
 
54
- context "index" do
55
- context "when getting all changes" do
56
- context "and authorized" do
57
- context "and getting default index" do
35
+ describe 'index' do
36
+ context 'when getting all changes' do
37
+ context 'with authorization' do
38
+ context 'when getting default index' do
58
39
  before { get changes_path }
59
40
 
60
- it "should have all changes" do
61
- versions.size.should == 10
41
+ it 'has all changes' do
42
+ expect(response.body).to have_tag('.change_row', count: 10)
62
43
  end
63
44
 
64
- it "should have changes for all changed item types" do
65
- item_types.should == ["Entity", "Platform"]
45
+ it 'has changes for all changed item types' do
46
+ expect(response.body).to have_tag('.change_item', text: /Entity/)
47
+ expect(response.body).to have_tag('.change_item', text: /Platform/)
66
48
  end
67
49
 
68
- it "should order changes with newest and highest id at the top" do
69
- versions.map(&:id).should == versions.sort_by { |o| [o.created_at, o.id] }.reverse.map(&:id)
50
+ it 'orders changes with newest and highest id at the top' do
51
+ ids = response.body.scan(/Change #(\d+)/).flatten.map(&:to_i)
52
+ expect(ids).to eq ids.sort.reverse
70
53
  end
71
54
  end
72
55
  end
@@ -77,16 +60,17 @@ describe PaperTrailManager, :versioning => true do
77
60
  # end
78
61
  end
79
62
 
80
- context "when getting changes for a specific type" do
81
- context "that exists" do
82
- before { get changes_path(:type => "Entity") }
63
+ context 'when getting changes for a specific type' do
64
+ context 'when changes exist' do
65
+ before { get changes_path(type: 'Entity') }
83
66
 
84
- it "should show a subset of the changes" do
85
- versions.size.should == 6
67
+ it 'shows a subset of the changes' do
68
+ expect(response.body).to have_tag('.change_row', count: 6)
86
69
  end
87
70
 
88
- it "should have changes only for that type" do
89
- item_types.should == ["Entity"]
71
+ it 'has changes only for that type' do
72
+ expect(response.body).to have_tag('.change_item', text: /Entity/)
73
+ expect(response.body).not_to have_tag('.change_item', text: /Platform/)
90
74
  end
91
75
  end
92
76
 
@@ -96,20 +80,21 @@ describe PaperTrailManager, :versioning => true do
96
80
  # end
97
81
  end
98
82
 
99
- context "when getting changes for a specific record" do
100
- context "that exists" do
101
- before { get changes_path(:type => "Entity", :id => @reimu.id) }
83
+ context 'when getting changes for a specific record' do
84
+ context 'when changes exist' do
85
+ before { get changes_path(type: 'Entity', id: reimu.id) }
102
86
 
103
- it "should show a subset of the changes" do
104
- versions.size.should == 3
87
+ it 'shows a subset of the changes' do
88
+ expect(response.body).to have_tag('.change_row', count: 3)
105
89
  end
106
90
 
107
- it "should have changes only for that type" do
108
- item_types.should == ["Entity"]
91
+ it 'has changes only for that type' do
92
+ expect(response.body).to have_tag('.change_item', text: /Entity/)
93
+ expect(response.body).not_to have_tag('.change_item', text: /Platform/)
109
94
  end
110
95
 
111
- it "should have changes only for that record" do
112
- versions.map(&:item_id).uniq.should == [@reimu.id]
96
+ it 'has changes only for that record' do
97
+ expect(response.body.scan(%r{/entities/(#{reimu.id})}).flatten.uniq).to eq [reimu.id.to_s]
113
98
  end
114
99
  end
115
100
 
@@ -120,24 +105,25 @@ describe PaperTrailManager, :versioning => true do
120
105
  end
121
106
  end
122
107
 
123
- context "show a change" do
124
- context "that exists" do
125
- context "when authorized" do
108
+ describe 'showing a change' do
109
+ context 'when the change exists' do
110
+ context 'when authorized' do
111
+ let(:version) { reimu.versions.last }
112
+
126
113
  before do
127
- @version = @reimu.versions.last
128
- get change_path(@version)
114
+ get change_path(version)
129
115
  end
130
116
 
131
- it "should show the requested change" do
132
- version.should == @version
117
+ it 'shows the requested change' do
118
+ expect(response.body).to have_tag('.change_id', text: "Change ##{version.id}")
133
119
  end
134
120
 
135
- it "should show a change with the right event" do
136
- version.event.should == "update"
121
+ it 'shows a change with the right event' do
122
+ expect(response.body).to have_tag('.change_event_update')
137
123
  end
138
124
 
139
- it "should be associated with the expected record" do
140
- version.item.should == @reimu
125
+ it 'is associated with the expected record' do
126
+ expect(response.body).to have_tag('.change_item', text: "Entity #{reimu.id}")
141
127
  end
142
128
  end
143
129
 
@@ -152,50 +138,48 @@ describe PaperTrailManager, :versioning => true do
152
138
  # it "should display an error that the change doesn't exist"
153
139
  # end
154
140
  end
155
- end
156
-
157
- context "when rolling back changes" do
158
- context "that that exist" do
159
- before(:each) { populate }
160
141
 
161
- context "when authorized" do
162
- it "should rollback a newly-created record by deleting it" do
163
- Entity.exists?(@reimu.id).should be_truthy
142
+ describe 'rolling back changes' do
143
+ context 'when changes exist' do
144
+ context 'when authorized' do
145
+ it 'rollbacks a newly-created record by deleting it' do
146
+ expect(Entity).to exist(reimu.id)
164
147
 
165
- put change_path(@reimu.versions.first)
148
+ put change_path(reimu.versions.first)
166
149
 
167
- Entity.exists?(@reimu.id).should be_falsey
168
- end
150
+ expect(Entity).not_to exist(reimu.id)
151
+ end
169
152
 
170
- it "should rollback an edit by reverting to the previous state" do
171
- @reimu.reload
172
- @reimu.status.should == "Perfect Cherry Blossom"
153
+ it 'rollbacks an edit by reverting to the previous state' do
154
+ reimu.reload
155
+ expect(reimu.status).to eq 'Perfect Cherry Blossom'
173
156
 
174
- put change_path(@reimu.versions.last)
157
+ put change_path(reimu.versions.last)
175
158
 
176
- @reimu.reload
177
- @reimu.status.should == "Phantasmagoria of Dimensional Dream"
178
- end
159
+ reimu.reload
160
+ expect(reimu.status).to eq 'Phantasmagoria of Dimensional Dream'
161
+ end
179
162
 
180
- it "should rollback a delete by restoring the record" do
181
- Entity.exists?(@flanchan.id).should be_falsey
163
+ it 'rollbacks a delete by restoring the record' do
164
+ Entity.exists?(flanchan_id).should be_falsey
182
165
 
183
- put change_path(PaperTrail::Version.where(:item_id => @flanchan.id, :item_type => "Entity").last)
166
+ put change_path(PaperTrail::Version.where(item_id: flanchan_id, item_type: 'Entity').last)
184
167
 
185
- flanchan = Entity.find(@flanchan.id)
186
- flanchan.status.should == "The Embodiment of Scarlet Devil"
168
+ found = Entity.find(flanchan_id)
169
+ expect(found.status).to eq 'The Embodiment of Scarlet Devil'
170
+ end
187
171
  end
172
+
173
+ # TODO
174
+ # context "when not authorized" do
175
+ # it "should display an error if user is not allowed to revert that change"
176
+ # end
188
177
  end
189
178
 
190
179
  # TODO
191
- # context "when not authorized" do
192
- # it "should display an error if user is not allowed to revert that change"
180
+ # context "that don't exist" do
181
+ # it "should display an error that the change doesn't exist"
193
182
  # end
194
183
  end
195
-
196
- # TODO
197
- # context "that don't exist" do
198
- # it "should display an error that the change doesn't exist"
199
- # end
200
184
  end
201
185
  end
data/spec/rails_helper.rb CHANGED
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is copied to spec/ when you run 'rails generate rspec:install'
2
- ENV["RAILS_ENV"] ||= 'test'
3
- require File.expand_path("../dummy/config/environment", __FILE__)
4
- require "rspec/rails"
5
- require "rspec/active_model/mocks"
4
+ ENV['RAILS_ENV'] ||= 'test'
5
+ require File.expand_path('dummy/config/environment', __dir__)
6
+ require 'rspec/rails'
7
+ require 'rspec/active_model/mocks'
6
8
 
7
9
  RSpec.configure do |config|
8
10
  # If you're not using ActiveRecord, or you'd prefer not to run each of your
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
- require "rails_helper"
2
- require "rspec/its"
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+ require 'rspec/its'
3
5
 
4
6
  # This file was generated by the `rails generate rspec:install` command. Conventionally, all
5
7
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@@ -25,7 +27,7 @@ require "rspec/its"
25
27
  # run twice. It is recommended that you do not name files matching this glob to
26
28
  # end with _spec.rb. You can configure this pattern with with the --pattern
27
29
  # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
28
- Dir["spec/support/**/*.rb"].each { |f| require File.expand_path(f) }
30
+ Dir['spec/support/**/*.rb'].each { |f| require File.expand_path(f) }
29
31
 
30
32
  RSpec.configure do |config|
31
33
  # config.include(Capybara::Webkit::RspecMatchers, :type => :feature)
@@ -71,7 +73,7 @@ RSpec.configure do |config|
71
73
  # Enable only the newer, non-monkey-patching expect syntax.
72
74
  # For more details, see:
73
75
  # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
74
- expectations.syntax = [:should, :expect]
76
+ expectations.syntax = %i[should expect]
75
77
  end
76
78
 
77
79
  # rspec-mocks config goes here. You can use an alternate test double
@@ -80,7 +82,7 @@ RSpec.configure do |config|
80
82
  # Enable only the newer, non-monkey-patching expect syntax.
81
83
  # For more details, see:
82
84
  # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
83
- mocks.syntax = [:should, :expect]
85
+ mocks.syntax = %i[should expect]
84
86
 
85
87
  # Prevents you from mocking or stubbing a method that does not exist on
86
88
  # a real object. This is generally recommended.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'factory_girl_rails'
2
4
 
3
5
  FactoryGirl.define do
@@ -11,4 +13,3 @@ FactoryGirl.define do
11
13
  sequence(:status) { |n| "status_#{n}" }
12
14
  end
13
15
  end
14
-
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec-html-matchers'
4
+
5
+ RSpec.configure do |config|
6
+ config.include RSpecHtmlMatchers
7
+ end