base_editing_bootstrap 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 +4 -4
- data/CHANGELOG.md +24 -0
- data/README.md +44 -0
- data/app/views/base_editing/_form_field.html.erb +2 -2
- data/lib/base_editing_bootstrap/VERSION +1 -1
- data/lib/generators/base_editing_bootstrap/cell_override/cell_override_generator.rb +38 -0
- data/lib/generators/base_editing_bootstrap/field_override/field_override_generator.rb +38 -0
- data/lib/generators/base_editing_bootstrap/install/install_generator.rb +1 -0
- data/spec/support/external_shared/base_editing_controller_helpers.rb +6 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f49f0f2c12bba569f7cc1d5dae8c7539939b2f98214800c405566fc20a2b8597
|
4
|
+
data.tar.gz: 2f5c46bad766c8212f9d8684cb951c8156d6c26a279d411c5cc61e9e117abb54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '058cca4f47850ca85f902e591f0c48df33ac520d47a593ef0c1f307fb838c911aa8100330fbe8b0391c7d4f9ef3d1551666c4ad18e760ab0959bdb70f7478997'
|
7
|
+
data.tar.gz: 6f05b31efdf2862ff1e7ff5f90ccf9b98645493223f801245e2e7efed0794718c9e57fa79bb851c0edb6cebd13a3c51a0cc595c4ec28ced82eb3bd8fcd082cb8
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,30 @@
|
|
2
2
|
All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.
|
3
3
|
|
4
4
|
- - -
|
5
|
+
## 0.7.0 - 2024-05-30
|
6
|
+
#### Bug Fixes
|
7
|
+
- Generators with enum - (7f25cac) - Marino Bonetti
|
8
|
+
#### Features
|
9
|
+
- Add Generator for cell field - (ab0210b) - Marino Bonetti
|
10
|
+
- Add generator for form field override - (118b998) - Marino Bonetti
|
11
|
+
- Add distinguishable classes per field - (2e5e797) - Marino Bonetti
|
12
|
+
#### Tests
|
13
|
+
- Add Tests to generator - (cd3f40a) - Marino Bonetti
|
14
|
+
|
15
|
+
- - -
|
16
|
+
|
17
|
+
## 0.6.0 - 2024-05-29
|
18
|
+
#### Bug Fixes
|
19
|
+
- Add dependency in generator - (b911b1a) - Marino Bonetti
|
20
|
+
#### Documentation
|
21
|
+
- Add documentation for specs - (42a88ca) - Marino Bonetti
|
22
|
+
#### Features
|
23
|
+
- Add Capacity to skip un-authorization - (c83c51c) - Marino Bonetti
|
24
|
+
#### Tests
|
25
|
+
- Add spec for test env - (b8611d7) - Marino Bonetti
|
26
|
+
|
27
|
+
- - -
|
28
|
+
|
5
29
|
## 0.5.0 - 2024-05-22
|
6
30
|
#### Bug Fixes
|
7
31
|
- Correct initializer commented examples - (ba90fba) - Marino Bonetti
|
data/README.md
CHANGED
@@ -170,6 +170,50 @@ Utilizzo per modello base, in questo esempio prendiamo come modello Post come es
|
|
170
170
|
#...
|
171
171
|
```
|
172
172
|
|
173
|
+
## Testing helpers
|
174
|
+
|
175
|
+
### Requirements(installed with generators)
|
176
|
+
```ruby
|
177
|
+
group :test do
|
178
|
+
gem 'rails-controller-testing'
|
179
|
+
end
|
180
|
+
```
|
181
|
+
### Usage
|
182
|
+
Controllers:
|
183
|
+
```ruby
|
184
|
+
require 'rails_helper'
|
185
|
+
RSpec.describe "ServiceControllers", type: :request do
|
186
|
+
it_behaves_like "as logged in user" do
|
187
|
+
it_behaves_like "base editing controller", factory: :service
|
188
|
+
end
|
189
|
+
end
|
190
|
+
```
|
191
|
+
Model:
|
192
|
+
```ruby
|
193
|
+
require 'rails_helper'
|
194
|
+
RSpec.describe Service, type: :model do
|
195
|
+
it_behaves_like "a base model",
|
196
|
+
ransack_permitted_attributes: %w[created_at id last_status name stack_id updated_at],
|
197
|
+
ransack_permitted_associations: []
|
198
|
+
end
|
199
|
+
```
|
200
|
+
Policy
|
201
|
+
```ruby
|
202
|
+
require 'rails_helper'
|
203
|
+
##
|
204
|
+
# - check_default_responses default false, to check default responses
|
205
|
+
# TODO should be configurable
|
206
|
+
# [:show?, false],
|
207
|
+
# [:destroy?, true],
|
208
|
+
# [:update?, true],
|
209
|
+
# [:create?, true],
|
210
|
+
# [:index?, true],
|
211
|
+
#
|
212
|
+
RSpec.describe ServicePolicy, type: :policy do
|
213
|
+
it_behaves_like "a standard base model policy", :service, check_default_responses: false
|
214
|
+
end
|
215
|
+
```
|
216
|
+
|
173
217
|
|
174
218
|
## Contributing
|
175
219
|
Contribution directions go here.
|
@@ -1,5 +1,5 @@
|
|
1
|
-
<%= form.label(form_field, class:
|
2
|
-
<div class="input-group mb-2 <%= form.object.validated? ? "has-validation" : "" %>">
|
1
|
+
<%= form.label(form_field, class: ["form-label","form-#{form_field}-label"]) %>
|
2
|
+
<div class="input-group mb-2 <%= form.object.validated? ? "has-validation" : "" %><%= "form-#{form_field}-input-group" %>">
|
3
3
|
<%= render partial: "editing_form_measure_unit", locals: {object: form.object, field: form_field} %>
|
4
4
|
<%= form_print_field(form, form_field) %>
|
5
5
|
<%= error_messages_for(form.object, form_field) %>
|
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BaseEditingBootstrap
|
4
|
+
module Generators
|
5
|
+
class CellOverrideGenerator < ::Rails::Generators::Base
|
6
|
+
source_root File.expand_path("../../../../app/views/base_editing", __dir__)
|
7
|
+
argument :name, type: :string, banner: "Post", required: true
|
8
|
+
argument :attributes, type: :array, default: [], banner: "field field:type"
|
9
|
+
|
10
|
+
TYPES = [:base,:timestamps].freeze
|
11
|
+
|
12
|
+
desc <<-DESCRIPTION.strip_heredoc
|
13
|
+
Description:
|
14
|
+
Copy partial files for a defined cell,
|
15
|
+
the possible types are #{TYPES}
|
16
|
+
Default to base
|
17
|
+
DESCRIPTION
|
18
|
+
|
19
|
+
def copy_form_partials
|
20
|
+
if attributes.empty?
|
21
|
+
say "Need one field"
|
22
|
+
else
|
23
|
+
singular_name = name.underscore.downcase.singularize
|
24
|
+
plural_name = singular_name.pluralize
|
25
|
+
attributes.each do |a|
|
26
|
+
attr_name, type = a.split(":")
|
27
|
+
|
28
|
+
type = :base if type.nil?
|
29
|
+
type = type.to_sym
|
30
|
+
raise "Type #{type} not found in #{TYPES}" unless TYPES.include?(type)
|
31
|
+
copy_file "cell_field/_#{type}.html.erb", File.join("app/views", plural_name, singular_name, 'cell_field', "_#{attr_name}.html.erb")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BaseEditingBootstrap
|
4
|
+
module Generators
|
5
|
+
class FieldOverrideGenerator < ::Rails::Generators::Base
|
6
|
+
source_root File.expand_path("../../../../app/views/base_editing", __dir__)
|
7
|
+
argument :name, type: :string, banner: "Post", required: true
|
8
|
+
argument :attributes, type: :array, default: [], banner: "field field:type"
|
9
|
+
|
10
|
+
TYPES = %i[base date datetime decimal integer enum]
|
11
|
+
|
12
|
+
desc <<-DESCRIPTION.strip_heredoc
|
13
|
+
Description:
|
14
|
+
Copy partial files for a defined fields,
|
15
|
+
the possible types are #{TYPES}
|
16
|
+
Default to base
|
17
|
+
DESCRIPTION
|
18
|
+
|
19
|
+
def copy_form_partials
|
20
|
+
if attributes.empty?
|
21
|
+
say "Need one field"
|
22
|
+
else
|
23
|
+
singular_name = name.underscore.downcase.singularize
|
24
|
+
plural_name = singular_name.pluralize
|
25
|
+
attributes.each do |a|
|
26
|
+
attr_name, type = a.split(":")
|
27
|
+
|
28
|
+
type = :base if type.nil?
|
29
|
+
type = type.to_sym
|
30
|
+
raise "Type #{type} not found in #{TYPES}" unless TYPES.include?(type)
|
31
|
+
copy_file "form_field/_#{type}.html.erb", File.join("app/views", plural_name, singular_name, 'form_field', "_#{attr_name}.html.erb")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -18,6 +18,7 @@ module BaseEditingBootstrap
|
|
18
18
|
|
19
19
|
def prepare_test_environment
|
20
20
|
gem "factory_bot_rails", group: :test, version: '~> 6.4', comment: "Necessary for spec"
|
21
|
+
gem 'rails-controller-testing',group: :test,comment:"Required if used with controllers spec"
|
21
22
|
inject_into_class "config/application.rb", "Application", <<~RUBY
|
22
23
|
config.generators do |g|
|
23
24
|
g.test_framework :rspec
|
@@ -20,6 +20,7 @@ end
|
|
20
20
|
# - index
|
21
21
|
# @!attribute expect [Array[Symbol]] -> nome delle action da non controllare
|
22
22
|
# @!attribute skip_invalid_checks [Boolean] -> se serve saltare il check delle azioni con dati non validi
|
23
|
+
# @!attribute skip_authorization_check [Boolean] -> se skippare controllo delle autorizzazioni nel caso non siano azioni non autorizzabili
|
23
24
|
#
|
24
25
|
# Sono poi disponibili diversi let per poter fare l'override arbitrario degli url,
|
25
26
|
# tutti abbastanza auto-descrittivi
|
@@ -36,7 +37,7 @@ end
|
|
36
37
|
# :url_for_update
|
37
38
|
#
|
38
39
|
#
|
39
|
-
RSpec.shared_examples "base editing controller" do |factory: nil, only: [], except: [], skip_invalid_checks: false|
|
40
|
+
RSpec.shared_examples "base editing controller" do |factory: nil, only: [], except: [], skip_invalid_checks: false, skip_authorization_check: false|
|
40
41
|
if factory
|
41
42
|
let(:inside_factory) { factory }
|
42
43
|
else
|
@@ -78,7 +79,9 @@ RSpec.shared_examples "base editing controller" do |factory: nil, only: [], exce
|
|
78
79
|
nested_attributes_for(inside_factory)
|
79
80
|
}
|
80
81
|
|
81
|
-
|
82
|
+
unless skip_authorization_check
|
83
|
+
it_behaves_like "fail with unauthorized", request: -> { get url_for(url_for_unauthorized) }
|
84
|
+
end
|
82
85
|
|
83
86
|
if check_if_should_execute(only, except, :index)
|
84
87
|
describe "index" do
|
@@ -186,7 +189,7 @@ end
|
|
186
189
|
default_unathorized_failure = -> { raise "TODO - passare proc con richiesta che dovrà fallire" }
|
187
190
|
|
188
191
|
RSpec.shared_examples "fail with unauthorized" do |request: default_unathorized_failure|
|
189
|
-
it "
|
192
|
+
it "is expected to redirect to root" do
|
190
193
|
expect(Pundit).to receive(:authorize).with(user, any_args).and_raise(Pundit::NotAuthorizedError)
|
191
194
|
instance_exec(&request)
|
192
195
|
expect(response).to redirect_to(root_path)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: base_editing_bootstrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marino Bonetti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -354,6 +354,8 @@ files:
|
|
354
354
|
- lib/base_editing_bootstrap/searches/base.rb
|
355
355
|
- lib/base_editing_bootstrap/searches/field.rb
|
356
356
|
- lib/base_editing_bootstrap/version.rb
|
357
|
+
- lib/generators/base_editing_bootstrap/cell_override/cell_override_generator.rb
|
358
|
+
- lib/generators/base_editing_bootstrap/field_override/field_override_generator.rb
|
357
359
|
- lib/generators/base_editing_bootstrap/install/USAGE
|
358
360
|
- lib/generators/base_editing_bootstrap/install/install_generator.rb
|
359
361
|
- lib/generators/base_editing_bootstrap/install/templates/initializer.rb
|