paper_trail_viewer 1.0.0 → 1.1.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.
@@ -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.0
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: 2022-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: kaminari
@@ -174,12 +174,11 @@ dependencies:
174
174
  description: Browse, view and revert changes to records when using Ruby on Rails and
175
175
  the `paper_trail` gem.
176
176
  email:
177
- executables:
178
- - setup
177
+ executables: []
179
178
  extensions: []
180
179
  extra_rdoc_files: []
181
180
  files:
182
- - ".github/workflows/test.yml"
181
+ - ".github/workflows/tests.yml"
183
182
  - ".gitignore"
184
183
  - Appraisals
185
184
  - CHANGELOG.md
@@ -200,18 +199,23 @@ files:
200
199
  - javascript/src/app.tsx
201
200
  - javascript/src/components/change_diff.tsx
202
201
  - javascript/src/components/config_modal.tsx
202
+ - javascript/src/components/context_menu.tsx
203
203
  - javascript/src/components/controls.tsx
204
204
  - javascript/src/components/full_object_modal.tsx
205
205
  - javascript/src/components/index.ts
206
206
  - javascript/src/components/modal.tsx
207
207
  - javascript/src/components/pagination.tsx
208
+ - javascript/src/components/version_context_menu.tsx
208
209
  - javascript/src/components/versions_list.tsx
209
210
  - javascript/src/index.ts
210
211
  - javascript/src/types.ts
211
212
  - lib/paper_trail_viewer.rb
212
213
  - lib/paper_trail_viewer/data_source/active_record.rb
214
+ - lib/paper_trail_viewer/data_source/base.rb
213
215
  - lib/paper_trail_viewer/data_source/bigquery.rb
214
216
  - lib/paper_trail_viewer/engine.rb
217
+ - lib/paper_trail_viewer/query.rb
218
+ - lib/paper_trail_viewer/rollback.rb
215
219
  - lib/paper_trail_viewer/version.rb
216
220
  - package.json
217
221
  - paper_trail_viewer.gemspec