gestart-admino 1.0.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 (46) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +29 -0
  3. data/.gitignore +20 -0
  4. data/.tool-versions +1 -0
  5. data/CHANGELOG.md +91 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +716 -0
  9. data/Rakefile +6 -0
  10. data/gestart-admino.gemspec +36 -0
  11. data/lib/admino/action_view_extension.rb +35 -0
  12. data/lib/admino/query/base.rb +124 -0
  13. data/lib/admino/query/base_presenter.rb +27 -0
  14. data/lib/admino/query/builder.rb +24 -0
  15. data/lib/admino/query/configuration.rb +100 -0
  16. data/lib/admino/query/dsl.rb +38 -0
  17. data/lib/admino/query/filter_group.rb +73 -0
  18. data/lib/admino/query/filter_group_presenter.rb +85 -0
  19. data/lib/admino/query/scope_presenter.rb +17 -0
  20. data/lib/admino/query/search_field.rb +43 -0
  21. data/lib/admino/query/sorting.rb +74 -0
  22. data/lib/admino/query/sorting_presenter.rb +60 -0
  23. data/lib/admino/query.rb +15 -0
  24. data/lib/admino/table/head_row.rb +86 -0
  25. data/lib/admino/table/presenter.rb +122 -0
  26. data/lib/admino/table/resource_row.rb +145 -0
  27. data/lib/admino/table/row.rb +56 -0
  28. data/lib/admino/table.rb +7 -0
  29. data/lib/admino/version.rb +3 -0
  30. data/lib/admino.rb +14 -0
  31. data/lib/gestart-admino.rb +1 -0
  32. data/spec/admino/integration_spec.rb +63 -0
  33. data/spec/admino/query/base_presenter_spec.rb +59 -0
  34. data/spec/admino/query/base_spec.rb +192 -0
  35. data/spec/admino/query/dsl_spec.rb +52 -0
  36. data/spec/admino/query/filter_group_presenter_spec.rb +182 -0
  37. data/spec/admino/query/filter_group_spec.rb +133 -0
  38. data/spec/admino/query/search_field_spec.rb +66 -0
  39. data/spec/admino/query/sorting_presenter_spec.rb +206 -0
  40. data/spec/admino/query/sorting_spec.rb +137 -0
  41. data/spec/admino/table/head_row_spec.rb +158 -0
  42. data/spec/admino/table/presenter_spec.rb +180 -0
  43. data/spec/admino/table/resource_row_spec.rb +225 -0
  44. data/spec/admino/table/row_spec.rb +76 -0
  45. data/spec/spec_helper.rb +93 -0
  46. metadata +267 -0
@@ -0,0 +1,225 @@
1
+ require 'spec_helper'
2
+
3
+ module Admino
4
+ module Table
5
+ describe ResourceRow do
6
+ subject(:row) { ResourceRow.new(resource, view) }
7
+ let(:view) { RailsViewContext.new }
8
+ let(:resource) { Post.new('1') }
9
+
10
+ it 'takes a resource and a view context' do
11
+ expect(row.resource).to eq resource
12
+ expect(row.view_context).to eq view
13
+ end
14
+
15
+ describe '#column' do
16
+ subject { row.to_html }
17
+
18
+ context 'if block is present' do
19
+ before do
20
+ row.column { 'foo' }
21
+ end
22
+
23
+ it 'fills the cell with the block content' do
24
+ is_expected.to have_tag(:td, text: 'foo')
25
+ end
26
+ end
27
+
28
+ context 'if attribute is present' do
29
+ before { row.column(:title) }
30
+
31
+ it 'fills the cell with the attribute value' do
32
+ is_expected.to have_tag(:td, text: 'Post 1')
33
+ end
34
+ end
35
+
36
+ context 'if both attribute and block are missing' do
37
+ it 'raises an ArgumentError' do
38
+ expect { row.column('Title') }.to raise_error(ArgumentError)
39
+ end
40
+ end
41
+
42
+ context 'role attribute' do
43
+ before { row.column(:author_name) }
44
+
45
+ it 'generates a role attribute with the snake-cased name of the attribute' do
46
+ is_expected.to have_tag(:td, with: { role: 'author-name' })
47
+ end
48
+ end
49
+
50
+ context 'with HTML options param' do
51
+ before { row.column(:title, class: 'title') }
52
+
53
+ it 'uses it to build attributes' do
54
+ is_expected.to have_tag(:td, with: { class: 'title' })
55
+ end
56
+
57
+ context 'with a class that implements a <action_name>_html_options' do
58
+ let(:row) { row_subclass.new(resource, view) }
59
+ let(:row_subclass) do
60
+ Class.new(ResourceRow) do
61
+ def column_html_options(action_name)
62
+ { class: 'attribute' }
63
+ end
64
+ end
65
+ end
66
+
67
+ it 'renders them as attributes' do
68
+ is_expected.to have_tag(:td, with: { class: 'attribute title' })
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ describe '#actions' do
75
+ context 'block given' do
76
+ it 'yields the block' do
77
+ called = false
78
+ result = row.actions do
79
+ called = true
80
+ end
81
+
82
+ expect(called).to be_truthy
83
+ end
84
+ end
85
+
86
+ context 'no block' do
87
+ before do
88
+ allow(row).to receive(:action)
89
+ end
90
+
91
+ before do
92
+ row.actions(:show, :destroy)
93
+ end
94
+
95
+ it 'calls #action for each passed param' do
96
+ expect(row).to have_received(:action).with(:show)
97
+ expect(row).to have_received(:action).with(:destroy)
98
+ end
99
+ end
100
+ end
101
+
102
+ describe '#action' do
103
+ subject { row.to_html }
104
+
105
+ context 'URL' do
106
+ context 'with an explicit URL' do
107
+ before { row.action(:show, '/') }
108
+
109
+ it 'generates a link with the specified URL' do
110
+ is_expected.to have_tag(:a, with: { href: '/' })
111
+ end
112
+ end
113
+
114
+ context 'with no explicit URL' do
115
+ let(:row) { row_subclass.new(resource, view) }
116
+ let(:row_subclass) do
117
+ Class.new(ResourceRow) do
118
+ def show_action_url
119
+ "/posts/#{resource.to_param}"
120
+ end
121
+ end
122
+ end
123
+
124
+ before { row.action(:show) }
125
+
126
+ it 'uses a method to build the URL (ie. show_url)' do
127
+ is_expected.to have_tag(:a, with: { href: '/posts/1' })
128
+ end
129
+ end
130
+
131
+ context 'with no explicit URL and no action name' do
132
+ it 'raises an ArgumentError' do
133
+ expect { row.action(:show) }.to raise_error(ArgumentError)
134
+ end
135
+ end
136
+ end
137
+
138
+ context 'with no arguments' do
139
+ it 'raises an ArgumentError' do
140
+ expect { row.action }.to raise_error(ArgumentError)
141
+ end
142
+ end
143
+
144
+ context 'td cell' do
145
+ before { row.action(:show, '/') }
146
+
147
+ it 'generates a td cell with actions role' do
148
+ is_expected.to have_tag(:td, with: { role: 'actions' })
149
+ end
150
+ end
151
+
152
+ context 'link role' do
153
+ before { row.action(:show, '/') }
154
+
155
+ it 'generates a link with role' do
156
+ is_expected.to have_tag(:a, with: { role: 'show' })
157
+ end
158
+ end
159
+
160
+ context 'link text' do
161
+ context do
162
+ before { row.action(:show, '/') }
163
+
164
+ it 'generates a link with a titleized attribute' do
165
+ is_expected.to have_tag(:a, text: 'Show')
166
+ end
167
+ end
168
+
169
+ context 'if I18n is set up' do
170
+ before do
171
+ I18n.backend.store_translations(
172
+ :en,
173
+ table: { actions: { post: { show: 'Show post' } } }
174
+ )
175
+ end
176
+
177
+ before { row.action(:show, '/') }
178
+
179
+ it 'generates a I18n text' do
180
+ is_expected.to have_tag(:a, text: 'Show post')
181
+ end
182
+ end
183
+ end
184
+
185
+ context 'with html options' do
186
+ before { row.action(:show, '/', class: 'foo') }
187
+
188
+ it 'renders them as attributes' do
189
+ is_expected.to have_tag(:a, with: { class: 'foo' })
190
+ end
191
+
192
+ context 'with a class that implements a <action_name>_html_options' do
193
+ let(:row) { row_subclass.new(resource, view) }
194
+ let(:row_subclass) do
195
+ Class.new(ResourceRow) do
196
+ def action_html_options(action_name)
197
+ { class: 'button' }
198
+ end
199
+
200
+ def show_action_html_options
201
+ { class: 'show-button' }
202
+ end
203
+ end
204
+ end
205
+
206
+ it 'renders them as attributes' do
207
+ is_expected.to have_tag(:a, with: { class: 'foo show-button button' })
208
+ end
209
+ end
210
+ end
211
+
212
+ context 'with block' do
213
+ before do
214
+ row.action { 'Foo' }
215
+ end
216
+
217
+ it 'renders it' do
218
+ is_expected.to have_tag(:td, text: 'Foo')
219
+ end
220
+ end
221
+ end
222
+ end
223
+ end
224
+ end
225
+
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ module Admino
4
+ module Table
5
+ describe Row do
6
+ subject(:row) { Row.new(view) }
7
+ let(:view) { double('View Context') }
8
+
9
+ it 'takes view context' do
10
+ expect(row.view_context).to eq view
11
+ end
12
+
13
+ it 'aliases view_context to h' do
14
+ expect(row.h).to eq view
15
+ end
16
+
17
+ describe '#parse_column_args' do
18
+ subject do
19
+ row.parse_column_args(arguments)
20
+ end
21
+
22
+ context 'with a symbol param' do
23
+ let(:arguments) { [:title] }
24
+ it { is_expected.to eq [:title, nil, {}] }
25
+ end
26
+
27
+ context 'with a string param' do
28
+ let(:arguments) { ['Title'] }
29
+ it { is_expected.to eq [nil, 'Title', {}] }
30
+ end
31
+
32
+ context 'with a symbol and string param' do
33
+ let(:arguments) { [:title, 'Title'] }
34
+ it { is_expected.to eq [:title, 'Title', {}] }
35
+ end
36
+
37
+ context 'with two symbol params' do
38
+ let(:arguments) { [:title, :foo] }
39
+ it { is_expected.to eq [:title, :foo, {}] }
40
+ end
41
+
42
+ context 'with options' do
43
+ let(:arguments) { [{ foo: 'bar' }] }
44
+ it { is_expected.to eq [nil, nil, { foo: 'bar' }] }
45
+ end
46
+ end
47
+
48
+ describe '#parse_action_args' do
49
+ subject do
50
+ row.parse_action_args(arguments)
51
+ end
52
+
53
+ context 'with a symbol param' do
54
+ let(:arguments) { [:show] }
55
+ it { is_expected.to eq [:show, nil, nil, {}] }
56
+ end
57
+
58
+ context 'with a one string param' do
59
+ let(:arguments) { ['/'] }
60
+ it { is_expected.to eq [nil, '/', nil, {}] }
61
+ end
62
+
63
+ context 'with a two string params' do
64
+ let(:arguments) { ['/', 'Details'] }
65
+ it { is_expected.to eq [nil, '/', 'Details', {}] }
66
+ end
67
+
68
+ context 'with options' do
69
+ let(:arguments) { [{ foo: 'bar' }] }
70
+ it { is_expected.to eq [nil, nil, nil, { foo: 'bar' }] }
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+
@@ -0,0 +1,93 @@
1
+ require 'admino'
2
+ require 'rspec-html-matchers'
3
+ require 'ostruct'
4
+
5
+ I18n.enforce_available_locales = true
6
+ I18n.available_locales = [:en]
7
+ I18n.locale = :en
8
+
9
+ class ScopeMock
10
+ attr_reader :chain, :name
11
+
12
+ def initialize(name = nil, chain = [])
13
+ @name = name
14
+ @chain = chain
15
+ end
16
+
17
+ def method_missing(method_name, *args, &block)
18
+ ::ScopeMock.new(name, chain + [method_name, args])
19
+ end
20
+ end
21
+
22
+ class TestQuery < Admino::Query::Base
23
+ search_field :foo, default: 'bar'
24
+ search_field :starting_from
25
+
26
+ filter_by :bar, [:one, :two],
27
+ include_empty_scope: true,
28
+ default: :two
29
+
30
+ sorting :by_title, :by_date,
31
+ default_scope: :by_title,
32
+ default_direction: :desc
33
+
34
+ starting_scope { 'start' }
35
+ ending_scope { 'end' }
36
+ end
37
+
38
+ class Post < Struct.new(:key, :dom_id)
39
+ extend ActiveModel::Naming
40
+ extend ActiveModel::Translation
41
+
42
+ def title
43
+ "Post #{key}"
44
+ end
45
+
46
+ def author_name
47
+ "steffoz"
48
+ end
49
+
50
+ def to_param
51
+ key
52
+ end
53
+
54
+ def to_key
55
+ [key]
56
+ end
57
+ end
58
+
59
+ module Rails
60
+ def self.env
61
+ OpenStruct.new(development?: false)
62
+ end
63
+ end
64
+
65
+ require 'action_view'
66
+ require 'simple_form'
67
+
68
+ class RailsViewContext < ActionView::Base
69
+ include ActionView::Helpers::TagHelper
70
+ include SimpleForm::ActionViewExtensions::FormHelper
71
+ include Admino::ActionViewExtension
72
+
73
+ def initialize(*)
74
+ super(ActionView::LookupContext.new([]), {}, nil)
75
+ end
76
+
77
+ def request
78
+ OpenStruct.new(path: '/', fullpath: '/?p=1')
79
+ end
80
+
81
+ def polymorphic_path(*args)
82
+ '/'
83
+ end
84
+ end
85
+
86
+ RSpec.configure do |c|
87
+ c.include RSpecHtmlMatchers
88
+
89
+ c.before(:each) do
90
+ I18n.backend = I18n::Backend::Simple.new
91
+ end
92
+ end
93
+
metadata ADDED
@@ -0,0 +1,267 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gestart-admino
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Gestart Cloud S.r.l.
8
+ - Stefano Verna
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 1980-01-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: showcase
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activemodel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: i18n
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-html-matchers
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: actionpack
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: railties
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simple_form
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: ostruct
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: Fork Gestart di admino 0.0.22, potato di ciò che Gestart non usa
182
+ email:
183
+ - dev@gestart.net
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".github/workflows/ci.yml"
189
+ - ".gitignore"
190
+ - ".tool-versions"
191
+ - CHANGELOG.md
192
+ - Gemfile
193
+ - LICENSE.txt
194
+ - README.md
195
+ - Rakefile
196
+ - gestart-admino.gemspec
197
+ - lib/admino.rb
198
+ - lib/admino/action_view_extension.rb
199
+ - lib/admino/query.rb
200
+ - lib/admino/query/base.rb
201
+ - lib/admino/query/base_presenter.rb
202
+ - lib/admino/query/builder.rb
203
+ - lib/admino/query/configuration.rb
204
+ - lib/admino/query/dsl.rb
205
+ - lib/admino/query/filter_group.rb
206
+ - lib/admino/query/filter_group_presenter.rb
207
+ - lib/admino/query/scope_presenter.rb
208
+ - lib/admino/query/search_field.rb
209
+ - lib/admino/query/sorting.rb
210
+ - lib/admino/query/sorting_presenter.rb
211
+ - lib/admino/table.rb
212
+ - lib/admino/table/head_row.rb
213
+ - lib/admino/table/presenter.rb
214
+ - lib/admino/table/resource_row.rb
215
+ - lib/admino/table/row.rb
216
+ - lib/admino/version.rb
217
+ - lib/gestart-admino.rb
218
+ - spec/admino/integration_spec.rb
219
+ - spec/admino/query/base_presenter_spec.rb
220
+ - spec/admino/query/base_spec.rb
221
+ - spec/admino/query/dsl_spec.rb
222
+ - spec/admino/query/filter_group_presenter_spec.rb
223
+ - spec/admino/query/filter_group_spec.rb
224
+ - spec/admino/query/search_field_spec.rb
225
+ - spec/admino/query/sorting_presenter_spec.rb
226
+ - spec/admino/query/sorting_spec.rb
227
+ - spec/admino/table/head_row_spec.rb
228
+ - spec/admino/table/presenter_spec.rb
229
+ - spec/admino/table/resource_row_spec.rb
230
+ - spec/admino/table/row_spec.rb
231
+ - spec/spec_helper.rb
232
+ homepage: https://github.com/gestartcloudsrl/gestart-admino
233
+ licenses:
234
+ - MIT
235
+ metadata: {}
236
+ rdoc_options: []
237
+ require_paths:
238
+ - lib
239
+ required_ruby_version: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '3.1'
244
+ required_rubygems_version: !ruby/object:Gem::Requirement
245
+ requirements:
246
+ - - ">="
247
+ - !ruby/object:Gem::Version
248
+ version: '0'
249
+ requirements: []
250
+ rubygems_version: 3.6.9
251
+ specification_version: 4
252
+ summary: 'Fork Gestart di admino: query object e tabelle delle pagine indice'
253
+ test_files:
254
+ - spec/admino/integration_spec.rb
255
+ - spec/admino/query/base_presenter_spec.rb
256
+ - spec/admino/query/base_spec.rb
257
+ - spec/admino/query/dsl_spec.rb
258
+ - spec/admino/query/filter_group_presenter_spec.rb
259
+ - spec/admino/query/filter_group_spec.rb
260
+ - spec/admino/query/search_field_spec.rb
261
+ - spec/admino/query/sorting_presenter_spec.rb
262
+ - spec/admino/query/sorting_spec.rb
263
+ - spec/admino/table/head_row_spec.rb
264
+ - spec/admino/table/presenter_spec.rb
265
+ - spec/admino/table/resource_row_spec.rb
266
+ - spec/admino/table/row_spec.rb
267
+ - spec/spec_helper.rb