paper_trail_viewer 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,22 +13,13 @@ Gem::Specification.new do |spec|
13
13
  spec.license = 'MIT'
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0") + %w[javascript/compiled.js]
16
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
17
  spec.require_paths = ['lib']
19
18
 
20
- spec.required_ruby_version = '>= 2.7'
19
+ spec.required_ruby_version = '>= 3.0'
21
20
 
22
21
  spec.add_dependency 'kaminari'
22
+ spec.add_dependency 'ostruct'
23
23
  spec.add_dependency 'paper_trail', ['>= 11.1']
24
- spec.add_dependency 'rails', ['>= 6.0', '< 8.0']
25
-
26
- spec.add_development_dependency 'appraisal', '~> 1.0'
27
- spec.add_development_dependency 'capybara', '~> 3.0'
28
- spec.add_development_dependency 'factory_bot_rails', '~> 6.0'
29
- spec.add_development_dependency 'puma', '~> 5.0'
30
- spec.add_development_dependency 'rake', '~> 13.0'
31
- spec.add_development_dependency 'rspec-rails', '~> 5.0'
32
- spec.add_development_dependency 'sqlite3', '>= 1.3.6'
33
- spec.add_development_dependency 'webdrivers', '~> 5.0'
24
+ spec.add_dependency 'rails', ['>= 6.0', '< 9.0']
34
25
  end
data/spec/app_template.rb CHANGED
@@ -1,10 +1,12 @@
1
- gem 'paper_trail_viewer', path: __FILE__ + '/../../../'
1
+ gem 'paper_trail_viewer', path: __dir__ + '/../'
2
2
 
3
3
  generate 'paper_trail:install'
4
4
  generate 'resource', 'entity name:string status:string --no-test-framework'
5
5
  generate 'resource', 'platform name:string status:string --no-test-framework'
6
6
 
7
7
  model_body = <<-RUBY
8
+ ::ActiveRecord.try(:use_yaml_unsafe_load=, true)
9
+
8
10
  has_paper_trail
9
11
 
10
12
  validates_presence_of :name
data/spec/rails_helper.rb CHANGED
@@ -2,8 +2,8 @@ ENV['RAILS_ENV'] ||= 'test'
2
2
  require File.expand_path('dummy/config/environment', __dir__)
3
3
  require 'rspec/rails'
4
4
 
5
+ require 'capybara/rspec'
5
6
  require 'selenium/webdriver'
6
- require 'webdrivers/chromedriver'
7
7
 
8
8
  Capybara.server = :puma, { Silent: true }
9
9
 
@@ -13,6 +13,14 @@ RSpec.configure do |config|
13
13
  config.use_transactional_fixtures = true
14
14
  config.infer_spec_type_from_file_location!
15
15
  config.before(:each, type: :system) do
16
- driven_by :selenium_chrome_headless
16
+ driven_by :selenium, using: :headless_chrome, screen_size: [1600, 900] do |opts|
17
+ # https://github.com/SeleniumHQ/selenium/issues/14453
18
+ opts.add_argument('--disable-search-engine-choice-screen')
19
+ # various fixes for GH actions
20
+ opts.add_argument('--disable-dev-shm-usage')
21
+ opts.add_argument('--disable-extensions')
22
+ opts.add_argument('--disable-site-isolation-trials')
23
+ opts.add_argument('--remote-debugging-pipe')
24
+ end
17
25
  end
18
26
  end
@@ -14,101 +14,116 @@ describe PaperTrailViewer, versioning: true do
14
14
  end
15
15
 
16
16
  context 'with changes' do
17
- let(:reimu) { FactoryBot.create(:entity, name: 'Miko Hakurei Reimu', status: 'Highly Responsive to Prayers') }
18
- let(:flanchan) { FactoryBot.create(:entity, name: 'Flandre Scarlet', status: 'The Embodiment of Scarlet Devil') }
19
- let(:sakuya) { FactoryBot.create(:entity, name: 'Sakuya Izayoi', status: 'Flowering Night') }
20
- let(:kyuu_hachi) { FactoryBot.create(:platform, name: 'PC-9801', status: 'SUGOI!!1!') }
17
+ let!(:reimu) { FactoryBot.create(:entity, name: 'Miko Hakurei Reimu', status: 'Highly Responsive to Prayers') }
18
+ let!(:flanchan) { FactoryBot.create(:entity, name: 'Flandre Scarlet', status: 'The Embodiment of Scarlet Devil') }
19
+ let!(:sakuya) { FactoryBot.create(:entity, name: 'Sakuya Izayoi', status: 'Flowering Night') }
20
+ let!(:kyuu_hachi) { FactoryBot.create(:platform, name: 'PC-9801', status: 'SUGOI!!1!') }
21
21
  let!(:uinodouzu) { FactoryBot.create(:platform, name: 'Mikorusofto Uinodouzu', status: 'o-O') }
22
22
 
23
- let!(:flanchan_id) { flanchan.id }
24
-
25
23
  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
24
+ reimu.update!(name: 'Hakurei Reimu', status: 'Phantasmagoria of Dimensional Dream')
25
+ reimu.update!(status: 'Perfect Cherry Blossom')
26
+ flanchan.destroy!
27
+ kyuu_hachi.update!(status: 'Kimochi warui.')
28
+ kyuu_hachi.destroy!
33
29
  end
34
30
 
35
31
  describe 'index' do
36
- context 'when getting all changes' do
37
- context 'with authorization' do
38
- context 'when getting default index' do
39
- before { visit engine_urls.root_path }
40
-
41
- it 'has all changes' do
42
- expect(page).to have_selector('[data-ci-type="version-row"]', count: 10)
43
- end
44
-
45
- it 'has changes for all changed item types' do
46
- within('table') do
47
- expect(page).to have_content('Entity')
48
- expect(page).to have_content('Platform')
49
- end
50
- end
51
-
52
- it 'orders changes with newest and highest id at the top' do
53
- ids = PaperTrail::Version.pluck(:id)
54
- expect(page).to have_content(/#{ids.sort.reverse.join('.+')}/m)
55
- end
56
- end
32
+ before { visit engine_urls.root_path }
33
+
34
+ it 'has all changes' do
35
+ expect(page).to have_selector('[data-ci-type="version-row"]', count: 10)
36
+ end
37
+
38
+ it 'has changes for all changed item types' do
39
+ within('table') do
40
+ expect(page).to have_content('Entity')
41
+ expect(page).to have_content('Platform')
57
42
  end
58
43
  end
59
44
 
45
+ it 'orders changes with newest and highest id at the top' do
46
+ ids = PaperTrail::Version.pluck(:id)
47
+ expect(page).to have_content(/#{ids.sort.reverse.join('.+')}/m)
48
+ end
49
+
60
50
  context 'when getting changes for a specific type' do
61
- context 'when changes exist' do
62
- before { visit engine_urls.root_path(item_type: 'Entity') }
51
+ before { visit engine_urls.root_path(item_type: 'Entity') }
63
52
 
64
- it 'shows a subset of the changes' do
65
- expect(page).to have_selector('[data-ci-type="version-row"]', count: 6)
66
- end
53
+ it 'shows a subset of the changes' do
54
+ expect(page).to have_selector('[data-ci-type="version-row"]', count: 6)
67
55
  end
68
56
  end
69
57
 
70
58
  context 'when getting changes for a specific record' do
71
- context 'when changes exist' do
72
- before { visit engine_urls.root_path(item_type: 'Entity', item_id: reimu.id) }
59
+ before { visit engine_urls.root_path(item_type: 'Entity', item_id: reimu.id) }
73
60
 
74
- it 'shows a subset of the changes' do
75
- expect(page).to have_selector('[data-ci-type="version-row"]', count: 3)
76
- end
61
+ it 'shows a subset of the changes' do
62
+ expect(page).to have_selector('[data-ci-type="version-row"]', count: 3)
77
63
  end
78
64
  end
79
65
  end
80
66
 
67
+ describe 'tracking an item' do
68
+ it 'works' do
69
+ visit engine_urls.root_path
70
+ expect(page).to have_selector('[data-ci-type="version-row"]', count: 10)
71
+
72
+ open_reimu_actions_menu
73
+ click_on 'Track item'
74
+
75
+ expect(page).to have_selector('[data-ci-type="version-row"]', count: 3)
76
+ end
77
+ end
78
+
81
79
  describe 'rolling back changes' do
82
- context 'when changes exist' do
83
- context 'when authorized' do
84
- it 'rollbacks a newly-created record by deleting it' do
85
- expect(Entity).to exist(reimu.id)
80
+ it 'can be done via the UI' do
81
+ visit engine_urls.root_path(item_type: 'Entity', item_id: reimu.id)
86
82
 
87
- put engine_urls.version_path(reimu.versions.first)
83
+ open_reimu_actions_menu
88
84
 
89
- expect(Entity).not_to exist(reimu.id)
85
+ accept_confirm do # confirm that we really want to roll back
86
+ accept_alert do # accept alert saying that rollback happened
87
+ find('span', text: 'Roll back').click
90
88
  end
89
+ end
91
90
 
92
- it 'rollbacks an edit by reverting to the previous state' do
93
- reimu.reload
94
- expect(reimu.status).to eq 'Perfect Cherry Blossom'
91
+ expect(Entity.exists?(reimu.id)).to eq false
92
+ end
95
93
 
96
- put engine_urls.version_path(reimu.versions.last)
94
+ it 'rolls back a newly-created record by deleting it' do
95
+ expect(Entity).to exist(reimu.id)
97
96
 
98
- reimu.reload
99
- expect(reimu.status).to eq 'Phantasmagoria of Dimensional Dream'
100
- end
97
+ put engine_urls.version_path(reimu.versions.first)
101
98
 
102
- it 'rollbacks a delete by restoring the record' do
103
- expect(Entity.exists?(flanchan_id)).to eq false
99
+ expect(Entity).not_to exist(reimu.id)
100
+ end
104
101
 
105
- put engine_urls.version_path(PaperTrail::Version.where(item_id: flanchan_id, item_type: 'Entity').last)
102
+ it 'rolls back an edit by reverting to the previous state' do
103
+ reimu.reload
104
+ expect(reimu.status).to eq 'Perfect Cherry Blossom'
106
105
 
107
- found = Entity.find(flanchan_id)
108
- expect(found.status).to eq 'The Embodiment of Scarlet Devil'
109
- end
110
- end
106
+ put engine_urls.version_path(reimu.versions.last)
107
+
108
+ reimu.reload
109
+ expect(reimu.status).to eq 'Phantasmagoria of Dimensional Dream'
111
110
  end
111
+
112
+ it 'rolls back a delete by restoring the record' do
113
+ expect(Entity.exists?(flanchan.id)).to eq false
114
+
115
+ version = PaperTrail::Version.where(item_id: flanchan.id, item_type: 'Entity').last
116
+ put engine_urls.version_path(version)
117
+
118
+ found = Entity.find(flanchan.id)
119
+ expect(found.status).to eq 'The Embodiment of Scarlet Devil'
120
+ end
121
+ end
122
+ end
123
+
124
+ def open_reimu_actions_menu
125
+ within("tr[data-ci-id='#{reimu.versions.find_by!(event: :create).id}']") do
126
+ find('[data-ci-type="version-action-button"]').click
112
127
  end
113
128
  end
114
129
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_trail_viewer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janosch Müller
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-03-26 00:00:00.000000000 Z
12
+ date: 2024-09-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: kaminari
@@ -26,162 +26,62 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: paper_trail
29
+ name: ostruct
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '11.1'
34
+ version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '11.1'
41
+ version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: rails
43
+ name: paper_trail
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: '6.0'
49
- - - "<"
50
- - !ruby/object:Gem::Version
51
- version: '8.0'
48
+ version: '11.1'
52
49
  type: :runtime
53
50
  prerelease: false
54
51
  version_requirements: !ruby/object:Gem::Requirement
55
52
  requirements:
56
53
  - - ">="
57
54
  - !ruby/object:Gem::Version
58
- version: '6.0'
59
- - - "<"
60
- - !ruby/object:Gem::Version
61
- version: '8.0'
62
- - !ruby/object:Gem::Dependency
63
- name: appraisal
64
- requirement: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.0'
69
- type: :development
70
- prerelease: false
71
- version_requirements: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.0'
76
- - !ruby/object:Gem::Dependency
77
- name: capybara
78
- requirement: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.0'
83
- type: :development
84
- prerelease: false
85
- version_requirements: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '3.0'
55
+ version: '11.1'
90
56
  - !ruby/object:Gem::Dependency
91
- name: factory_bot_rails
57
+ name: rails
92
58
  requirement: !ruby/object:Gem::Requirement
93
59
  requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '6.0'
97
- type: :development
98
- prerelease: false
99
- version_requirements: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
60
+ - - ">="
102
61
  - !ruby/object:Gem::Version
103
62
  version: '6.0'
104
- - !ruby/object:Gem::Dependency
105
- name: puma
106
- requirement: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '5.0'
111
- type: :development
112
- prerelease: false
113
- version_requirements: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '5.0'
118
- - !ruby/object:Gem::Dependency
119
- name: rake
120
- requirement: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '13.0'
125
- type: :development
126
- prerelease: false
127
- version_requirements: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '13.0'
132
- - !ruby/object:Gem::Dependency
133
- name: rspec-rails
134
- requirement: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '5.0'
139
- type: :development
140
- prerelease: false
141
- version_requirements: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '5.0'
146
- - !ruby/object:Gem::Dependency
147
- name: sqlite3
148
- requirement: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
63
+ - - "<"
151
64
  - !ruby/object:Gem::Version
152
- version: 1.3.6
153
- type: :development
65
+ version: '9.0'
66
+ type: :runtime
154
67
  prerelease: false
155
68
  version_requirements: !ruby/object:Gem::Requirement
156
69
  requirements:
157
70
  - - ">="
158
71
  - !ruby/object:Gem::Version
159
- version: 1.3.6
160
- - !ruby/object:Gem::Dependency
161
- name: webdrivers
162
- requirement: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: '5.0'
167
- type: :development
168
- prerelease: false
169
- version_requirements: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
72
+ version: '6.0'
73
+ - - "<"
172
74
  - !ruby/object:Gem::Version
173
- version: '5.0'
75
+ version: '9.0'
174
76
  description: Browse, view and revert changes to records when using Ruby on Rails and
175
77
  the `paper_trail` gem.
176
78
  email:
177
- executables:
178
- - setup
79
+ executables: []
179
80
  extensions: []
180
81
  extra_rdoc_files: []
181
82
  files:
182
- - ".github/workflows/test.yml"
83
+ - ".github/workflows/tests.yml"
183
84
  - ".gitignore"
184
- - Appraisals
185
85
  - CHANGELOG.md
186
86
  - Gemfile
187
87
  - LICENSE.txt
@@ -193,25 +93,27 @@ files:
193
93
  - app/views/paper_trail_viewer/viewer/index.html.erb
194
94
  - bin/setup
195
95
  - config/routes.rb
196
- - gemfiles/rails_6.0_paper_trail_11.1.gemfile
197
- - gemfiles/rails_6.0_paper_trail_12.2.gemfile
198
- - gemfiles/rails_7.0_paper_trail_12.2.gemfile
199
96
  - javascript/compiled.js
200
97
  - javascript/src/app.tsx
201
98
  - javascript/src/components/change_diff.tsx
202
99
  - javascript/src/components/config_modal.tsx
100
+ - javascript/src/components/context_menu.tsx
203
101
  - javascript/src/components/controls.tsx
204
102
  - javascript/src/components/full_object_modal.tsx
205
103
  - javascript/src/components/index.ts
206
104
  - javascript/src/components/modal.tsx
207
105
  - javascript/src/components/pagination.tsx
106
+ - javascript/src/components/version_context_menu.tsx
208
107
  - javascript/src/components/versions_list.tsx
209
108
  - javascript/src/index.ts
210
109
  - javascript/src/types.ts
211
110
  - lib/paper_trail_viewer.rb
212
111
  - lib/paper_trail_viewer/data_source/active_record.rb
112
+ - lib/paper_trail_viewer/data_source/base.rb
213
113
  - lib/paper_trail_viewer/data_source/bigquery.rb
214
114
  - lib/paper_trail_viewer/engine.rb
115
+ - lib/paper_trail_viewer/query.rb
116
+ - lib/paper_trail_viewer/rollback.rb
215
117
  - lib/paper_trail_viewer/version.rb
216
118
  - package.json
217
119
  - paper_trail_viewer.gemspec
@@ -233,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
233
135
  requirements:
234
136
  - - ">="
235
137
  - !ruby/object:Gem::Version
236
- version: '2.7'
138
+ version: '3.0'
237
139
  required_rubygems_version: !ruby/object:Gem::Requirement
238
140
  requirements:
239
141
  - - ">="
data/Appraisals DELETED
@@ -1,13 +0,0 @@
1
- {
2
- '6.0' => %w[11.1 12.2],
3
- '7.0' => %w[12.2],
4
- }.each do |rails_version, paper_trail_versions|
5
- paper_trail_versions.each do |paper_trail_version|
6
- appraise "rails-#{rails_version}-paper_trail-#{paper_trail_version}" do
7
- gem 'rails', "~> #{rails_version}"
8
- gem 'sqlite3', '~> 1.4'
9
- gem 'paper_trail', "~> #{paper_trail_version}"
10
- gem 'kaminari'
11
- end
12
- end
13
- end
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 6.0"
6
- gem "sqlite3", "~> 1.4"
7
- gem "paper_trail", "~> 11.1"
8
- gem "kaminari"
9
-
10
- gemspec :path => "../"
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 6.0"
6
- gem "sqlite3", "~> 1.4"
7
- gem "paper_trail", "~> 12.2"
8
- gem "kaminari"
9
-
10
- gemspec :path => "../"
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 7.0"
6
- gem "sqlite3", "~> 1.4"
7
- gem "paper_trail", "~> 12.2"
8
- gem "kaminari"
9
-
10
- gemspec :path => "../"