administrate-field-jsontable 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +6 -0
- data/.rubocop.yml +96 -0
- data/Gemfile +9 -1
- data/Gemfile.lock +43 -17
- data/README.md +7 -0
- data/Rakefile +11 -0
- data/administrate-field-jsontable.gemspec +1 -1
- data/app/views/fields/jsontable/_index.html.erb +18 -0
- data/app/views/fields/jsontable/_json_table_field.html.erb +30 -0
- data/app/views/fields/jsontable/_show.html.erb +2 -29
- data/lib/administrate/field/jsontable.rb +2 -0
- data/spec/example_app/app/assets/config/manifest.js +2 -0
- data/spec/example_app/app/assets/javascripts/application.js +15 -0
- data/spec/example_app/app/assets/stylesheets/application.css +15 -0
- data/spec/example_app/app/controllers/application_controller.rb +7 -0
- data/spec/example_app/app/models/application_record.rb +5 -0
- data/spec/example_app/app/views/layouts/application.html.erb +31 -0
- data/spec/example_app/app/views/pages/.keep +0 -0
- data/spec/example_app/config.ru +6 -0
- data/spec/example_app/config/application.rb +39 -0
- data/spec/example_app/config/boot.rb +4 -0
- data/spec/example_app/config/database.yml +11 -0
- data/spec/example_app/config/environment.rb +7 -0
- data/spec/example_app/config/environments/development.rb +39 -0
- data/spec/example_app/config/environments/production.rb +78 -0
- data/spec/example_app/config/environments/staging.rb +3 -0
- data/spec/example_app/config/environments/test.rb +43 -0
- data/spec/example_app/config/initializers/assets.rb +13 -0
- data/spec/example_app/config/initializers/backtrace_silencers.rb +8 -0
- data/spec/example_app/config/initializers/cookies_serializer.rb +5 -0
- data/spec/example_app/config/initializers/disable_xml_params.rb +5 -0
- data/spec/example_app/config/initializers/errors.rb +20 -0
- data/spec/example_app/config/initializers/filter_parameter_logging.rb +6 -0
- data/spec/example_app/config/initializers/inflections.rb +18 -0
- data/spec/example_app/config/initializers/json_encoding.rb +3 -0
- data/spec/example_app/config/initializers/mime_types.rb +5 -0
- data/spec/example_app/config/initializers/session_store.rb +5 -0
- data/spec/example_app/config/initializers/wrap_parameters.rb +16 -0
- data/spec/example_app/config/routes.rb +4 -0
- data/spec/example_app/config/secrets.yml +15 -0
- data/spec/example_app/db/schema.rb +18 -0
- data/spec/example_app/db/seeds.rb +8 -0
- data/spec/example_app/public/robots.txt +5 -0
- data/spec/fixtures/jsontable/array_contains_hash.html +1 -0
- data/spec/fixtures/jsontable/hash_contains_array.html +31 -0
- data/spec/fixtures/jsontable/pure_hash.html +58 -0
- data/spec/lib/administrate/field/jsontable_index_spec.rb +95 -0
- data/spec/lib/administrate/field/jsontable_show_spec.rb +95 -0
- data/spec/lib/administrate/field/jsontable_spec.rb +16 -5
- data/spec/rails_helper.rb +6 -0
- data/spec/support/read_fixture.rb +7 -0
- metadata +84 -2
@@ -0,0 +1,58 @@
|
|
1
|
+
<table>
|
2
|
+
<tbody>
|
3
|
+
<tr>
|
4
|
+
<td>2019</td>
|
5
|
+
<td>
|
6
|
+
<table>
|
7
|
+
<tbody>
|
8
|
+
<tr>
|
9
|
+
<td>start_date</td>
|
10
|
+
<td>
|
11
|
+
2019-01-01
|
12
|
+
</td>
|
13
|
+
</tr>
|
14
|
+
<tr>
|
15
|
+
<td>end_date</td>
|
16
|
+
<td>
|
17
|
+
2019-12-31
|
18
|
+
</td>
|
19
|
+
</tr>
|
20
|
+
<tr>
|
21
|
+
<td>id</td>
|
22
|
+
<td>
|
23
|
+
123456_2019
|
24
|
+
</td>
|
25
|
+
</tr>
|
26
|
+
<tbody>
|
27
|
+
</table>
|
28
|
+
</td>
|
29
|
+
</tr>
|
30
|
+
<tr>
|
31
|
+
<td>2020</td>
|
32
|
+
<td>
|
33
|
+
<table>
|
34
|
+
<tbody>
|
35
|
+
<tr>
|
36
|
+
<td>start_date</td>
|
37
|
+
<td>
|
38
|
+
2020-01-01
|
39
|
+
</td>
|
40
|
+
</tr>
|
41
|
+
<tr>
|
42
|
+
<td>end_date</td>
|
43
|
+
<td>
|
44
|
+
2020-12-31
|
45
|
+
</td>
|
46
|
+
</tr>
|
47
|
+
<tr>
|
48
|
+
<td>id</td>
|
49
|
+
<td>
|
50
|
+
123456_2020
|
51
|
+
</td>
|
52
|
+
</tr>
|
53
|
+
<tbody>
|
54
|
+
</table>
|
55
|
+
</td>
|
56
|
+
</tr>
|
57
|
+
<tbody>
|
58
|
+
</table>
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'administrate/field/jsontable'
|
4
|
+
require File.expand_path('../../../support/read_fixture', __dir__)
|
5
|
+
require 'rails_helper'
|
6
|
+
|
7
|
+
describe 'fields/jsontable/_index', type: :view do
|
8
|
+
include ReadFixture
|
9
|
+
|
10
|
+
let(:pure_hash) do
|
11
|
+
instance_double(
|
12
|
+
'Administrate::Field::Jsontable',
|
13
|
+
data: {
|
14
|
+
"2019": {
|
15
|
+
"start_date": '2019-01-01',
|
16
|
+
"end_date": '2019-12-31',
|
17
|
+
"id": '123456_2019'
|
18
|
+
},
|
19
|
+
"2020": {
|
20
|
+
"start_date": '2020-01-01',
|
21
|
+
"end_date": '2020-12-31',
|
22
|
+
"id": '123456_2020'
|
23
|
+
}
|
24
|
+
}
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:pure_array) do
|
29
|
+
instance_double(
|
30
|
+
'Administrate::Field::Jsontable',
|
31
|
+
data: [1, 2, 3, 4]
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:hash_contains_array) do
|
36
|
+
instance_double(
|
37
|
+
'Administrate::Field::Jsontable',
|
38
|
+
data: {
|
39
|
+
"2019": {
|
40
|
+
"ids": [1, 2, 3, 4],
|
41
|
+
"end_date": '2019-12-31',
|
42
|
+
"id": '123456_2019'
|
43
|
+
}
|
44
|
+
}
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:array_contains_hash) do
|
49
|
+
instance_double(
|
50
|
+
'Administrate::Field::Jsontable',
|
51
|
+
data: [1, 2, 3, { "2019": {
|
52
|
+
"start_date": '2019-01-01',
|
53
|
+
"end_date": '2019-12-31',
|
54
|
+
"id": '123456_2019'
|
55
|
+
} }]
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'displays pure_hash' do
|
60
|
+
allow(view).to receive(:valid_action?).and_return(true)
|
61
|
+
render_jsontable_index(field: pure_hash)
|
62
|
+
|
63
|
+
expect(rendered.strip).to eq(read_fixture('pure_hash.html'))
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'displays pure_array' do
|
67
|
+
allow(view).to receive(:valid_action?).and_return(true)
|
68
|
+
render_jsontable_index(field: pure_array)
|
69
|
+
|
70
|
+
expect(rendered.strip).to eq('[1, 2, 3, 4]')
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'displays hash_contains_array' do
|
74
|
+
allow(view).to receive(:valid_action?).and_return(true)
|
75
|
+
render_jsontable_index(field: hash_contains_array)
|
76
|
+
|
77
|
+
expect(rendered.strip).to eq(read_fixture('hash_contains_array.html'))
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'displays array_contains_hash' do
|
81
|
+
allow(view).to receive(:valid_action?).and_return(true)
|
82
|
+
render_jsontable_index(field: array_contains_hash)
|
83
|
+
|
84
|
+
expect(rendered.strip).to eq(read_fixture('array_contains_hash.html'))
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def render_jsontable_index(field:)
|
90
|
+
render(
|
91
|
+
partial: 'fields/jsontable/index.html.erb',
|
92
|
+
locals: { field: field, namespace: 'admin' }
|
93
|
+
)
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'administrate/field/jsontable'
|
4
|
+
require File.expand_path('../../../support/read_fixture', __dir__)
|
5
|
+
require 'rails_helper'
|
6
|
+
|
7
|
+
describe 'fields/jsontable/_show', type: :view do
|
8
|
+
include ReadFixture
|
9
|
+
|
10
|
+
let(:pure_hash) do
|
11
|
+
instance_double(
|
12
|
+
'Administrate::Field::Jsontable',
|
13
|
+
data: {
|
14
|
+
"2019": {
|
15
|
+
"start_date": '2019-01-01',
|
16
|
+
"end_date": '2019-12-31',
|
17
|
+
"id": '123456_2019'
|
18
|
+
},
|
19
|
+
"2020": {
|
20
|
+
"start_date": '2020-01-01',
|
21
|
+
"end_date": '2020-12-31',
|
22
|
+
"id": '123456_2020'
|
23
|
+
}
|
24
|
+
}
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:pure_array) do
|
29
|
+
instance_double(
|
30
|
+
'Administrate::Field::Jsontable',
|
31
|
+
data: [1, 2, 3, 4]
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:hash_contains_array) do
|
36
|
+
instance_double(
|
37
|
+
'Administrate::Field::Jsontable',
|
38
|
+
data: {
|
39
|
+
"2019": {
|
40
|
+
"ids": [1, 2, 3, 4],
|
41
|
+
"end_date": '2019-12-31',
|
42
|
+
"id": '123456_2019'
|
43
|
+
}
|
44
|
+
}
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:array_contains_hash) do
|
49
|
+
instance_double(
|
50
|
+
'Administrate::Field::Jsontable',
|
51
|
+
data: [1, 2, 3, { "2019": {
|
52
|
+
"start_date": '2019-01-01',
|
53
|
+
"end_date": '2019-12-31',
|
54
|
+
"id": '123456_2019'
|
55
|
+
} }]
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'displays pure_hash' do
|
60
|
+
allow(view).to receive(:valid_action?).and_return(true)
|
61
|
+
render_jsontable_show(field: pure_hash)
|
62
|
+
|
63
|
+
expect(rendered.strip).to eq(read_fixture('pure_hash.html'))
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'displays pure_array' do
|
67
|
+
allow(view).to receive(:valid_action?).and_return(true)
|
68
|
+
render_jsontable_show(field: pure_array)
|
69
|
+
|
70
|
+
expect(rendered.strip).to eq('[1, 2, 3, 4]')
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'displays hash_contains_array' do
|
74
|
+
allow(view).to receive(:valid_action?).and_return(true)
|
75
|
+
render_jsontable_show(field: hash_contains_array)
|
76
|
+
|
77
|
+
expect(rendered.strip).to eq(read_fixture('hash_contains_array.html'))
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'displays array_contains_hash' do
|
81
|
+
allow(view).to receive(:valid_action?).and_return(true)
|
82
|
+
render_jsontable_show(field: array_contains_hash)
|
83
|
+
|
84
|
+
expect(rendered.strip).to eq(read_fixture('array_contains_hash.html'))
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def render_jsontable_show(field:)
|
90
|
+
render(
|
91
|
+
partial: 'fields/jsontable/show.html.erb',
|
92
|
+
locals: { field: field, namespace: 'admin' }
|
93
|
+
)
|
94
|
+
end
|
95
|
+
end
|
@@ -1,14 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'administrate/field/jsontable'
|
2
4
|
|
3
5
|
describe Administrate::Field::Jsontable do
|
4
6
|
describe '#to_partial_path' do
|
5
7
|
it 'returns a partial based on the page being rendered' do
|
6
|
-
page
|
7
|
-
|
8
|
-
|
9
|
-
path = field.to_partial_path
|
8
|
+
assert_partial_path(page: :show)
|
9
|
+
end
|
10
10
|
|
11
|
-
|
11
|
+
it 'returns a partial for index page' do
|
12
|
+
assert_partial_path(page: :index)
|
12
13
|
end
|
13
14
|
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def assert_partial_path(page:)
|
19
|
+
field = Administrate::Field::Jsontable.new(:status, 'status', page)
|
20
|
+
|
21
|
+
path = field.to_partial_path
|
22
|
+
|
23
|
+
expect(path).to eq("/fields/jsontable/#{page}")
|
24
|
+
end
|
14
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: administrate-field-jsontable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Rangel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-09-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: administrate
|
@@ -48,14 +48,57 @@ extensions: []
|
|
48
48
|
extra_rdoc_files: []
|
49
49
|
files:
|
50
50
|
- ".gitignore"
|
51
|
+
- ".rubocop.yml"
|
51
52
|
- Gemfile
|
52
53
|
- Gemfile.lock
|
53
54
|
- LICENSE.md
|
54
55
|
- README.md
|
56
|
+
- Rakefile
|
55
57
|
- administrate-field-jsontable.gemspec
|
58
|
+
- app/views/fields/jsontable/_index.html.erb
|
59
|
+
- app/views/fields/jsontable/_json_table_field.html.erb
|
56
60
|
- app/views/fields/jsontable/_show.html.erb
|
57
61
|
- lib/administrate/field/jsontable.rb
|
62
|
+
- spec/example_app/app/assets/config/manifest.js
|
63
|
+
- spec/example_app/app/assets/javascripts/application.js
|
64
|
+
- spec/example_app/app/assets/stylesheets/application.css
|
65
|
+
- spec/example_app/app/controllers/application_controller.rb
|
66
|
+
- spec/example_app/app/models/application_record.rb
|
67
|
+
- spec/example_app/app/views/layouts/application.html.erb
|
68
|
+
- spec/example_app/app/views/pages/.keep
|
69
|
+
- spec/example_app/config.ru
|
70
|
+
- spec/example_app/config/application.rb
|
71
|
+
- spec/example_app/config/boot.rb
|
72
|
+
- spec/example_app/config/database.yml
|
73
|
+
- spec/example_app/config/environment.rb
|
74
|
+
- spec/example_app/config/environments/development.rb
|
75
|
+
- spec/example_app/config/environments/production.rb
|
76
|
+
- spec/example_app/config/environments/staging.rb
|
77
|
+
- spec/example_app/config/environments/test.rb
|
78
|
+
- spec/example_app/config/initializers/assets.rb
|
79
|
+
- spec/example_app/config/initializers/backtrace_silencers.rb
|
80
|
+
- spec/example_app/config/initializers/cookies_serializer.rb
|
81
|
+
- spec/example_app/config/initializers/disable_xml_params.rb
|
82
|
+
- spec/example_app/config/initializers/errors.rb
|
83
|
+
- spec/example_app/config/initializers/filter_parameter_logging.rb
|
84
|
+
- spec/example_app/config/initializers/inflections.rb
|
85
|
+
- spec/example_app/config/initializers/json_encoding.rb
|
86
|
+
- spec/example_app/config/initializers/mime_types.rb
|
87
|
+
- spec/example_app/config/initializers/session_store.rb
|
88
|
+
- spec/example_app/config/initializers/wrap_parameters.rb
|
89
|
+
- spec/example_app/config/routes.rb
|
90
|
+
- spec/example_app/config/secrets.yml
|
91
|
+
- spec/example_app/db/schema.rb
|
92
|
+
- spec/example_app/db/seeds.rb
|
93
|
+
- spec/example_app/public/robots.txt
|
94
|
+
- spec/fixtures/jsontable/array_contains_hash.html
|
95
|
+
- spec/fixtures/jsontable/hash_contains_array.html
|
96
|
+
- spec/fixtures/jsontable/pure_hash.html
|
97
|
+
- spec/lib/administrate/field/jsontable_index_spec.rb
|
98
|
+
- spec/lib/administrate/field/jsontable_show_spec.rb
|
58
99
|
- spec/lib/administrate/field/jsontable_spec.rb
|
100
|
+
- spec/rails_helper.rb
|
101
|
+
- spec/support/read_fixture.rb
|
59
102
|
homepage: https://github.com/Valiot/administrate-field-jsontable
|
60
103
|
licenses:
|
61
104
|
- MIT
|
@@ -80,4 +123,43 @@ signing_key:
|
|
80
123
|
specification_version: 4
|
81
124
|
summary: JSON to table field plugin for Administrate
|
82
125
|
test_files:
|
126
|
+
- spec/example_app/app/assets/config/manifest.js
|
127
|
+
- spec/example_app/app/assets/javascripts/application.js
|
128
|
+
- spec/example_app/app/assets/stylesheets/application.css
|
129
|
+
- spec/example_app/app/controllers/application_controller.rb
|
130
|
+
- spec/example_app/app/models/application_record.rb
|
131
|
+
- spec/example_app/app/views/layouts/application.html.erb
|
132
|
+
- spec/example_app/app/views/pages/.keep
|
133
|
+
- spec/example_app/config.ru
|
134
|
+
- spec/example_app/config/application.rb
|
135
|
+
- spec/example_app/config/boot.rb
|
136
|
+
- spec/example_app/config/database.yml
|
137
|
+
- spec/example_app/config/environment.rb
|
138
|
+
- spec/example_app/config/environments/development.rb
|
139
|
+
- spec/example_app/config/environments/production.rb
|
140
|
+
- spec/example_app/config/environments/staging.rb
|
141
|
+
- spec/example_app/config/environments/test.rb
|
142
|
+
- spec/example_app/config/initializers/assets.rb
|
143
|
+
- spec/example_app/config/initializers/backtrace_silencers.rb
|
144
|
+
- spec/example_app/config/initializers/cookies_serializer.rb
|
145
|
+
- spec/example_app/config/initializers/disable_xml_params.rb
|
146
|
+
- spec/example_app/config/initializers/errors.rb
|
147
|
+
- spec/example_app/config/initializers/filter_parameter_logging.rb
|
148
|
+
- spec/example_app/config/initializers/inflections.rb
|
149
|
+
- spec/example_app/config/initializers/json_encoding.rb
|
150
|
+
- spec/example_app/config/initializers/mime_types.rb
|
151
|
+
- spec/example_app/config/initializers/session_store.rb
|
152
|
+
- spec/example_app/config/initializers/wrap_parameters.rb
|
153
|
+
- spec/example_app/config/routes.rb
|
154
|
+
- spec/example_app/config/secrets.yml
|
155
|
+
- spec/example_app/db/schema.rb
|
156
|
+
- spec/example_app/db/seeds.rb
|
157
|
+
- spec/example_app/public/robots.txt
|
158
|
+
- spec/fixtures/jsontable/array_contains_hash.html
|
159
|
+
- spec/fixtures/jsontable/hash_contains_array.html
|
160
|
+
- spec/fixtures/jsontable/pure_hash.html
|
161
|
+
- spec/lib/administrate/field/jsontable_index_spec.rb
|
162
|
+
- spec/lib/administrate/field/jsontable_show_spec.rb
|
83
163
|
- spec/lib/administrate/field/jsontable_spec.rb
|
164
|
+
- spec/rails_helper.rb
|
165
|
+
- spec/support/read_fixture.rb
|