base_editing_bootstrap 0.4.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77c13adc91ffb0336f044c8679f8594896f0488217c2a794440346f950cb13c1
4
- data.tar.gz: c41c9312226e37ff2f244612abe2168e3aecf9bd6cadc79015faa1939e3f7eeb
3
+ metadata.gz: 3f75c92251f46045d20902120b1796ad0804dbfd632b0ddd77669a6f4f7ab35c
4
+ data.tar.gz: 9e87df84d2fc30d8f981095cc3304479c1629b25cf0daa14746a78d83dba5245
5
5
  SHA512:
6
- metadata.gz: 4bda28795ec6bb33c7dcfc043f51da88c54b4055b014f223d0ccad0d2d5ba72423db87134f08317f2b6153da9bc0c5713ded3772a4949b0f165285c2aae3cf1b
7
- data.tar.gz: 6ef88c451560bf050e497c559f19bc1e96cf87b02e83b5fe6dd42010e3baea5e30f94e6ceac57963eb89d7ce16d21a2e88e6358a80bcf8237fe8e04558324e39
6
+ metadata.gz: 3ded9cc6fbff9ae4515f98530596a444f3b18760dc5677b0ae9f5c9b96056287d08500f5a691fb2bcf926709151e79d7af7d4da235dbcd129aa7db4d3d4f520d
7
+ data.tar.gz: 6d22f81c4ecf3db3a7413f0fa42ac35b01ffa1e36a570d9cbc412e5daa5a49c9abc3659f63613e7c194cac8b3a417b52de0e5dc2d243799b7faf9dfc5d255213
data/CHANGELOG.md CHANGED
@@ -2,6 +2,29 @@
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.6.0 - 2024-05-29
6
+ #### Bug Fixes
7
+ - Add dependency in generator - (b911b1a) - Marino Bonetti
8
+ #### Documentation
9
+ - Add documentation for specs - (42a88ca) - Marino Bonetti
10
+ #### Features
11
+ - Add Capacity to skip un-authorization - (c83c51c) - Marino Bonetti
12
+ #### Tests
13
+ - Add spec for test env - (b8611d7) - Marino Bonetti
14
+
15
+ - - -
16
+
17
+ ## 0.5.0 - 2024-05-22
18
+ #### Bug Fixes
19
+ - Correct initializer commented examples - (ba90fba) - Marino Bonetti
20
+ #### Features
21
+ - Action for Show enabled - (d364ed3) - Marino Bonetti
22
+ - Enums with Integer identified - (4fa9e87) - Marino Bonetti
23
+ #### Tests
24
+ - Save example_status_persistence_file_path - (235939d) - Marino Bonetti
25
+
26
+ - - -
27
+
5
28
  ## 0.4.2 - 2024-05-08
6
29
  #### Bug Fixes
7
30
  - Rename shared example for cluck with apps - (41638f8) - 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
1
  class BaseEditingController < RestrictedAreaController
2
- before_action :load_object, only: [:edit, :update, :destroy]
2
+ before_action :load_object, only: [:edit, :show, :update, :destroy]
3
3
  helper_method :base_class,
4
4
  :destroy_custom_polymorphic_path,
5
5
  :edit_custom_polymorphic_path,
@@ -32,6 +32,10 @@ class BaseEditingController < RestrictedAreaController
32
32
  @object = yield(@object) if block_given?
33
33
  end
34
34
 
35
+ def show
36
+ @object = yield(@object) if block_given?
37
+ end
38
+
35
39
  def update
36
40
  @object = yield(@object) if block_given?
37
41
  respond_to do |format|
@@ -18,23 +18,23 @@ module Utilities
18
18
  # @param [Symbol] field
19
19
  def form_print_field(form, field)
20
20
  locals = {form:, field:}
21
- type = form.object.class.type_for_attribute(field).type
22
- case type
23
- when :datetime
24
- generic_field = "datetime"
25
- when :date
26
- generic_field = "date"
27
- when :decimal
28
- locals[:scale] = form.object.class.type_for_attribute(field).scale || 2
29
- generic_field = "decimal"
30
- when :float
31
- locals[:scale] = 2 # usiamo il default dato che non abbiamo questa informazione negli attributes di rails
32
- generic_field = "decimal"
33
- when :integer
34
- generic_field = "integer"
21
+ if form.object.class.defined_enums.key?(field.to_s)
22
+ generic_field = "enum"
35
23
  else
36
- if form.object.class.defined_enums.key?(field.to_s)
37
- generic_field = "enum"
24
+ type = form.object.class.type_for_attribute(field).type
25
+ case type
26
+ when :datetime
27
+ generic_field = "datetime"
28
+ when :date
29
+ generic_field = "date"
30
+ when :decimal
31
+ locals[:scale] = form.object.class.type_for_attribute(field).scale || 2
32
+ generic_field = "decimal"
33
+ when :float
34
+ locals[:scale] = 2 # usiamo il default dato che non abbiamo questa informazione negli attributes di rails
35
+ generic_field = "decimal"
36
+ when :integer
37
+ generic_field = "integer"
38
38
  else
39
39
  generic_field = "base"
40
40
  end
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.6.0
@@ -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
@@ -5,18 +5,18 @@ BaseEditingBootstrap.configure do |config|
5
5
  # Controller da cui derivare poi il BaseEditingController da cui derivano
6
6
  # tutti i controller sottostanti
7
7
  # @default "ApplicationController"
8
- # config_accessor :inherited_controller, default: "ApplicationController"
8
+ # config.inherited_controller = "ApplicationController"
9
9
 
10
10
  ##
11
11
  # Configurazione per alterare lo standard di azione post aggiornamento record
12
12
  # il default è andare nella pagina di editing del record
13
13
  # possibili valori :edit , :index
14
- # config_accessor :after_success_update_redirect, default: :edit
14
+ # config.inherited_controller = :edit
15
15
 
16
16
  ##
17
17
  # Configurazione per alterare lo standard di azione post creazione record
18
18
  # il default è andare nella pagina di editing del record
19
19
  # possibili valori :edit , :index
20
- # config_accessor :after_success_create_redirect, default: :edit
20
+ # config.inherited_controller = :edit
21
21
 
22
22
  end
@@ -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
- it_behaves_like "fail with unauthorized", request: -> { get url_for(url_for_unauthorized) }
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 "expect to redirect to root" do
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.2
4
+ version: 0.6.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-08 00:00:00.000000000 Z
11
+ date: 2024-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails