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.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +88 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +33 -0
- data/Appraisals +26 -34
- data/CHANGES.md +14 -2
- data/Gemfile +2 -1
- data/README.md +10 -1
- data/Rakefile +17 -5
- data/app/controllers/paper_trail_manager/changes_controller.rb +103 -100
- data/app/helpers/paper_trail_manager/changes_helper.rb +34 -51
- data/app/views/paper_trail_manager/changes/_version.html.erb +7 -3
- data/app/views/paper_trail_manager/changes/index.atom.builder +23 -19
- data/gemfiles/rails_4.2.2_paper_trail_3.0_kaminari.gemfile +13 -0
- data/gemfiles/rails_4.2.2_paper_trail_3.0_will_paginate.gemfile +13 -0
- data/gemfiles/rails_4.2.2_paper_trail_4.0_kaminari.gemfile +13 -0
- data/gemfiles/rails_4.2.2_paper_trail_4.0_will_paginate.gemfile +13 -0
- data/gemfiles/rails_4.2.2_paper_trail_5.0_kaminari.gemfile +13 -0
- data/gemfiles/rails_4.2.2_paper_trail_5.0_will_paginate.gemfile +13 -0
- data/gemfiles/rails_4.2.2_paper_trail_6.0_kaminari.gemfile +13 -0
- data/gemfiles/rails_4.2.2_paper_trail_6.0_will_paginate.gemfile +13 -0
- data/gemfiles/rails_4.2.2_paper_trail_7.0_kaminari.gemfile +13 -0
- data/gemfiles/rails_4.2.2_paper_trail_7.0_will_paginate.gemfile +13 -0
- data/gemfiles/rails_4.2.2_paper_trail_8.0_kaminari.gemfile +13 -0
- data/gemfiles/rails_4.2.2_paper_trail_8.0_will_paginate.gemfile +13 -0
- data/gemfiles/rails_5.0.0_paper_trail_5.0_kaminari.gemfile +13 -0
- data/gemfiles/rails_5.0.0_paper_trail_5.0_will_paginate.gemfile +13 -0
- data/gemfiles/rails_5.0.0_paper_trail_6.0_kaminari.gemfile +13 -0
- data/gemfiles/rails_5.0.0_paper_trail_6.0_will_paginate.gemfile +13 -0
- data/gemfiles/rails_5.0.0_paper_trail_7.0_kaminari.gemfile +13 -0
- data/gemfiles/rails_5.0.0_paper_trail_7.0_will_paginate.gemfile +13 -0
- data/gemfiles/rails_5.0.0_paper_trail_8.0_kaminari.gemfile +13 -0
- data/gemfiles/rails_5.0.0_paper_trail_8.0_will_paginate.gemfile +13 -0
- data/gemfiles/rails_5.1.0_paper_trail_10.0_kaminari.gemfile +13 -0
- data/gemfiles/rails_5.1.0_paper_trail_10.0_will_paginate.gemfile +13 -0
- data/gemfiles/rails_5.1.0_paper_trail_7.0_kaminari.gemfile +13 -0
- data/gemfiles/rails_5.1.0_paper_trail_7.0_will_paginate.gemfile +13 -0
- data/gemfiles/rails_5.1.0_paper_trail_8.0_kaminari.gemfile +13 -0
- data/gemfiles/rails_5.1.0_paper_trail_8.0_will_paginate.gemfile +13 -0
- data/gemfiles/rails_5.1.0_paper_trail_9.0_kaminari.gemfile +13 -0
- data/gemfiles/rails_5.1.0_paper_trail_9.0_will_paginate.gemfile +13 -0
- data/gemfiles/rails_5.2.0_paper_trail_10.0_kaminari.gemfile +13 -0
- data/gemfiles/rails_5.2.0_paper_trail_10.0_will_paginate.gemfile +13 -0
- data/gemfiles/rails_5.2.0_paper_trail_9.0_kaminari.gemfile +13 -0
- data/gemfiles/rails_5.2.0_paper_trail_9.0_will_paginate.gemfile +13 -0
- data/gemfiles/rails_6.0.0_paper_trail_10.0_kaminari.gemfile +14 -0
- data/gemfiles/rails_6.0.0_paper_trail_10.0_will_paginate.gemfile +15 -0
- data/lib/paper_trail_manager.rb +22 -27
- data/paper_trail_manager.gemspec +22 -21
- data/spec/app_template.rb +30 -0
- data/spec/integration/navigation_spec.rb +4 -2
- data/spec/integration/paper_trail_manager_spec.rb +94 -110
- data/spec/rails_helper.rb +6 -4
- data/spec/spec_helper.rb +7 -5
- data/spec/support/factories.rb +2 -1
- data/spec/support/rspec_html_matchers.rb +7 -0
- metadata +87 -224
- data/.travis.yml +0 -15
- data/gemfiles/rails_3.2_kaminari.gemfile +0 -8
- data/gemfiles/rails_3.2_will_paginate.gemfile +0 -8
- data/gemfiles/rails_4.0_kaminari.gemfile +0 -8
- data/gemfiles/rails_4.0_will_paginate.gemfile +0 -8
- data/gemfiles/rails_4.1_kaminari.gemfile +0 -8
- data/gemfiles/rails_4.1_will_paginate.gemfile +0 -8
- data/gemfiles/rails_4.2_kaminari.gemfile +0 -8
- data/gemfiles/rails_4.2_will_paginate.gemfile +0 -8
- data/spec/controllers/entities_controller_spec.rb +0 -125
- data/spec/controllers/platforms_controller_spec.rb +0 -125
- data/spec/dummy/.gitignore +0 -15
- data/spec/dummy/Gemfile +0 -9
- data/spec/dummy/README.rdoc +0 -261
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/assets/images/rails.png +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +0 -15
- data/spec/dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/dummy/app/controllers/application_controller.rb +0 -6
- data/spec/dummy/app/controllers/entities_controller.rb +0 -83
- data/spec/dummy/app/controllers/platforms_controller.rb +0 -83
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/helpers/entities_helper.rb +0 -2
- data/spec/dummy/app/helpers/platforms_helper.rb +0 -2
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/entity.rb +0 -6
- data/spec/dummy/app/models/platform.rb +0 -6
- data/spec/dummy/app/views/application/index.html.erb +0 -6
- data/spec/dummy/app/views/entities/_form.html.erb +0 -17
- data/spec/dummy/app/views/entities/edit.html.erb +0 -6
- data/spec/dummy/app/views/entities/index.html.erb +0 -21
- data/spec/dummy/app/views/entities/new.html.erb +0 -5
- data/spec/dummy/app/views/entities/show.html.erb +0 -5
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/app/views/platforms/_form.html.erb +0 -17
- data/spec/dummy/app/views/platforms/edit.html.erb +0 -6
- data/spec/dummy/app/views/platforms/index.html.erb +0 -21
- data/spec/dummy/app/views/platforms/new.html.erb +0 -5
- data/spec/dummy/app/views/platforms/show.html.erb +0 -5
- data/spec/dummy/config/application.rb +0 -64
- data/spec/dummy/config/boot.rb +0 -6
- data/spec/dummy/config/database.yml +0 -22
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -37
- data/spec/dummy/config/environments/production.rb +0 -67
- data/spec/dummy/config/environments/test.rb +0 -36
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/inflections.rb +0 -15
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -8
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/db/migrate/20110228091428_create_entities.rb +0 -14
- data/spec/dummy/db/migrate/20110228093241_create_platforms.rb +0 -14
- data/spec/dummy/db/migrate/20110228094444_create_versions.rb +0 -18
- data/spec/dummy/db/schema.rb +0 -41
- data/spec/dummy/db/seeds.rb +0 -7
- data/spec/dummy/doc/README_FOR_APP +0 -2
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/lib/tasks/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -25
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/index.html +0 -241
- data/spec/dummy/public/robots.txt +0 -5
- data/spec/dummy/script/rails +0 -6
- data/spec/dummy/test/fixtures/.gitkeep +0 -0
- data/spec/dummy/test/functional/.gitkeep +0 -0
- data/spec/dummy/test/integration/.gitkeep +0 -0
- data/spec/dummy/test/performance/browsing_test.rb +0 -12
- data/spec/dummy/test/test_helper.rb +0 -13
- data/spec/dummy/test/unit/.gitkeep +0 -0
- data/spec/dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/helpers/entities_helper_spec.rb +0 -15
- data/spec/helpers/platforms_helper_spec.rb +0 -15
- data/spec/models/entity_spec.rb +0 -14
- data/spec/models/platform_spec.rb +0 -14
- data/spec/requests/entities_spec.rb +0 -11
- data/spec/requests/platforms_spec.rb +0 -11
- data/spec/routing/entities_routing_spec.rb +0 -35
- data/spec/routing/platforms_routing_spec.rb +0 -35
- data/spec/views/entities/edit.html.erb_spec.rb +0 -15
- data/spec/views/entities/index.html.erb_spec.rb +0 -14
- data/spec/views/entities/new.html.erb_spec.rb +0 -15
- data/spec/views/entities/show.html.erb_spec.rb +0 -11
- data/spec/views/platforms/edit.html.erb_spec.rb +0 -15
- data/spec/views/platforms/index.html.erb_spec.rb +0 -14
- data/spec/views/platforms/new.html.erb_spec.rb +0 -15
- data/spec/views/platforms/show.html.erb_spec.rb +0 -11
data/lib/paper_trail_manager.rb
CHANGED
|
@@ -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
|
|
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
|
|
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,
|
|
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 =
|
|
25
|
+
self.base_controller = 'ApplicationController'
|
|
26
|
+
self.user_path_method = :user_path
|
|
25
27
|
|
|
26
28
|
(Pathname(__FILE__).dirname + '..').tap do |base|
|
|
27
|
-
paths[
|
|
28
|
-
paths[
|
|
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
|
-
|
|
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
|
-
|
|
43
|
-
|
|
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
|
-
|
|
41
|
+
self.allow_index_block = block
|
|
47
42
|
end
|
|
48
43
|
|
|
49
44
|
def self.allow_index?(controller)
|
|
50
|
-
|
|
45
|
+
allow_index_block.call controller
|
|
51
46
|
end
|
|
52
47
|
|
|
53
48
|
def self.allow_show_when(&block)
|
|
54
|
-
|
|
49
|
+
self.allow_show_block = block
|
|
55
50
|
end
|
|
56
51
|
|
|
57
52
|
def self.allow_show?(controller, version)
|
|
58
|
-
|
|
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
|
-
|
|
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
|
-
|
|
65
|
+
allow_revert_block.call controller, version
|
|
71
66
|
end
|
|
72
67
|
end
|
data/paper_trail_manager.gemspec
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
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 =
|
|
7
|
-
spec.version =
|
|
8
|
-
spec.authors = [
|
|
9
|
-
spec.authors = [
|
|
10
|
-
spec.summary =
|
|
11
|
-
spec.description =
|
|
12
|
-
spec.homepage =
|
|
13
|
-
spec.license =
|
|
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 = [
|
|
19
|
+
spec.require_paths = ['lib']
|
|
19
20
|
|
|
20
|
-
spec.add_dependency
|
|
21
|
-
spec.add_dependency
|
|
21
|
+
spec.add_dependency 'paper_trail', ['>= 3.0']
|
|
22
|
+
spec.add_dependency 'rails', ['>= 3.0', '< 7.0']
|
|
22
23
|
|
|
23
|
-
spec.add_development_dependency
|
|
24
|
-
spec.add_development_dependency
|
|
25
|
-
spec.add_development_dependency
|
|
26
|
-
spec.add_development_dependency
|
|
27
|
-
spec.add_development_dependency
|
|
28
|
-
spec.add_development_dependency
|
|
29
|
-
spec.add_development_dependency
|
|
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,72 +1,55 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
11
|
+
expect(response.body).to include('No changes found')
|
|
39
12
|
end
|
|
40
13
|
end
|
|
41
14
|
end
|
|
42
15
|
|
|
43
|
-
context
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
55
|
-
context
|
|
56
|
-
context
|
|
57
|
-
context
|
|
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
|
|
61
|
-
|
|
41
|
+
it 'has all changes' do
|
|
42
|
+
expect(response.body).to have_tag('.change_row', count: 10)
|
|
62
43
|
end
|
|
63
44
|
|
|
64
|
-
it
|
|
65
|
-
|
|
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
|
|
69
|
-
|
|
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
|
|
81
|
-
context
|
|
82
|
-
before { get changes_path(:
|
|
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
|
|
85
|
-
|
|
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
|
|
89
|
-
|
|
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
|
|
100
|
-
context
|
|
101
|
-
before { get changes_path(:
|
|
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
|
|
104
|
-
|
|
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
|
|
108
|
-
|
|
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
|
|
112
|
-
|
|
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
|
-
|
|
124
|
-
context
|
|
125
|
-
context
|
|
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
|
-
|
|
128
|
-
get change_path(@version)
|
|
114
|
+
get change_path(version)
|
|
129
115
|
end
|
|
130
116
|
|
|
131
|
-
it
|
|
132
|
-
|
|
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
|
|
136
|
-
|
|
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
|
|
140
|
-
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
148
|
+
put change_path(reimu.versions.first)
|
|
166
149
|
|
|
167
|
-
|
|
168
|
-
|
|
150
|
+
expect(Entity).not_to exist(reimu.id)
|
|
151
|
+
end
|
|
169
152
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
157
|
+
put change_path(reimu.versions.last)
|
|
175
158
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
159
|
+
reimu.reload
|
|
160
|
+
expect(reimu.status).to eq 'Phantasmagoria of Dimensional Dream'
|
|
161
|
+
end
|
|
179
162
|
|
|
180
|
-
|
|
181
|
-
|
|
163
|
+
it 'rollbacks a delete by restoring the record' do
|
|
164
|
+
Entity.exists?(flanchan_id).should be_falsey
|
|
182
165
|
|
|
183
|
-
|
|
166
|
+
put change_path(PaperTrail::Version.where(item_id: flanchan_id, item_type: 'Entity').last)
|
|
184
167
|
|
|
185
|
-
|
|
186
|
-
|
|
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 "
|
|
192
|
-
# it "should display an error
|
|
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[
|
|
3
|
-
require File.expand_path(
|
|
4
|
-
require
|
|
5
|
-
require
|
|
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
|
-
|
|
2
|
-
|
|
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[
|
|
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 = [
|
|
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 = [
|
|
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.
|
data/spec/support/factories.rb
CHANGED