base_editing_bootstrap 1.2.0 → 1.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8975be7d400651326b997d9d7650bd12c9145233c753e326ddb945c8a84816a
4
- data.tar.gz: 97a6eaaa243d8d3320c3093fdc5a650c6d9cc5b20641680cb91f7985bf50f8fe
3
+ metadata.gz: 5a6226c6077cf2467b75341e9a1a8cdd8829e06faac291de10cf2e6f3686a4bc
4
+ data.tar.gz: 82eaf0b64cf498b708aea0eadd96c674a6c06b2ecf3b2d38d4450dfd249e6e3d
5
5
  SHA512:
6
- metadata.gz: 48733c1f94d354afb34528998fce967e9b22d1bdf2b418eb8fb4444fea4bac157d4a0a79168c365675e3ca864d23eba0b046b54bbc8babb397f42e449e69f736
7
- data.tar.gz: 5de0164ea3ae7de687816ec721117b66bde4c309ac3806ce1e812e266eb847a61c859dd185bf0755a496bf42e76b5b820c936e76b39849321b75481d8009e3f5
6
+ metadata.gz: 442b7a0c1a90eefcb4fe707fb10559dfbce75a1595a6eaed04d35529e324d57635c2b9d07d991f7ed7820404d483d5bf82dedf1883b6e048ac878e5ecb1e0590
7
+ data.tar.gz: 528f5e47faeaba5312d6aa8620de661c1503cd86fe7b52a7cb6b30bbca944078df7e7d50c65ef2d64754f1561e488aa808a05104731097c0f84a84ead9d94db2
data/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
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
+ ## 1.3.1 - 2025-01-10
6
+ #### Bug Fixes
7
+ - Better spec helpers - (0d16364) - Marino Bonetti
8
+
9
+ - - -
10
+
11
+ ## 1.3.0 - 2025-01-09
12
+ #### Documentation
13
+ - Aggiunta documentazione per override search field - (ba97155) - Marino Bonetti
14
+ #### Features
15
+ - Translated Namespaced button (#12) - (7e06c5f) - Marino Bonetti
16
+ #### Tests
17
+ - Add sub view for dummy posts - (0b25868) - Marino Bonetti
18
+
19
+ - - -
20
+
5
21
  ## 1.2.0 - 2025-01-09
6
22
  #### Features
7
23
  - Add new method to get label from search field - (ace5fa0) - Marino Bonetti
data/README.md CHANGED
@@ -173,6 +173,12 @@ Utilizzo per modello base, in questo esempio prendiamo come modello Post come es
173
173
  #...
174
174
  ```
175
175
 
176
+ ### Translations
177
+ Traduzioni disponibili:
178
+ Per i bottoni della index, è possibile eseguire l'override del testo presente nel bottone.
179
+ Leggere la documentazione nel file `app/helpers/base_editing_helper.rb#translate_with_controller_scoped`
180
+
181
+
176
182
  ## Testing helpers
177
183
 
178
184
  ### Requirements(installed with generators)
@@ -5,5 +5,42 @@ module BaseEditingHelper
5
5
  include Utilities::FormHelper
6
6
  include Utilities::IconHelper
7
7
 
8
+ ##
9
+ # Estrapola la traduzione, andando ad includere la path del controller nella ricerca della chiave
10
+ # Viene tenuto conto anche del namespace del controller assieme ai suoi namespace
11
+ # ES:
12
+ # In un caso in cui abbiamo un controller di questo tipo: Customer::PostsController < PostsController
13
+ # la ricerca della chiave .destroy partendo dal partial app/views/base_editing/_search_result_buttons.html.erb
14
+ # sarà così composta:
15
+ #
16
+ # it.customer/posts.index.base_editing.search_result_buttons.destroy => nil
17
+ # it.customer/posts.base_editing.search_result_buttons.destroy => nil
18
+ # it.posts.index.base_editing.search_result_buttons.destroy => nil
19
+ # it.posts.base_editing.search_result_buttons.destroy => nil
20
+ # it.base_editing.index.base_editing.search_result_buttons.destroy => nil
21
+ # it.base_editing.base_editing.search_result_buttons.destroy => nil
22
+ # it.restricted_area.index.base_editing.search_result_buttons.destroy => nil
23
+ # it.restricted_area.base_editing.search_result_buttons.destroy => nil
24
+ # it.authentication.index.base_editing.search_result_buttons.destroy => nil
25
+ # it.authentication.base_editing.search_result_buttons.destroy => nil
26
+ # it.base_editing.search_result_buttons.destroy => nil
27
+ #
28
+ def translate_with_controller_scoped(key, **options)
29
+ if key&.start_with?(".")
30
+ inner_key = scope_key_by_partial(key)
31
+ defaults = []
32
+ paths = controller.class.ancestors.select { |c| c < ApplicationController }.collect(&:controller_path).uniq
33
+ paths.each do |path|
34
+ defaults << [:"#{path}.#{action_name}.#{inner_key}", :"#{path}.#{inner_key}"]
35
+ end
36
+ defaults << inner_key.to_sym
37
+ defaults << options[:default] if options.key?(:default)
38
+ key = nil
39
+ options[:default] = defaults.flatten
40
+ end
41
+
42
+ # dobbiamo eliminare possibili duplicati nello scope delle chiavi
43
+ t(key, **options)
44
+ end
8
45
 
9
46
  end
@@ -1,3 +1,9 @@
1
+ <%
2
+ ##
3
+ # Il campo search_field è un BaseEditingBootstrap::Searches::Field.
4
+ # Per strutturare in modo differente il campo di ricerca si ha a disposizione
5
+ # l'helper BaseEditingBootstrap::Searches::Field#label che stampa il contenuto della label
6
+ %>
1
7
  <div class="form-group col-xs-6 col-sm-4 col-md-3">
2
8
  <%= ransack_form_builder.label(search_field.name) %>
3
9
  <%= ransack_form_builder.search_field(search_field.name, class: "form-control form-control-sm") %>
@@ -1,15 +1,14 @@
1
1
  <%# locals: (obj:) -%>
2
- <%= link_to(icon("pencil-square"),
2
+ <%= link_to(icon("pencil-square", translate_with_controller_scoped(".edit", default: [:edit,""])),
3
3
  edit_custom_polymorphic_path(obj),
4
4
  class: "btn btn-sm btn-primary me-1") if policy(obj).edit? %>
5
5
 
6
-
7
- <%= link_to(icon(:eye),
6
+ <%= link_to(icon(:eye, translate_with_controller_scoped(".show", default: [:show,""])),
8
7
  show_custom_polymorphic_path(obj),
9
8
  class: "btn btn-sm btn-primary me-1") if policy(obj).show? %>
10
9
 
11
10
 
12
- <%= link_to(icon(:trash),
11
+ <%= link_to(icon(:trash, translate_with_controller_scoped(".destroy", default: [:destroy,""])),
13
12
  destroy_custom_polymorphic_path(obj),
14
13
  data: {
15
14
  turbo_method: :delete,
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.3.1
@@ -1,6 +1,15 @@
1
1
  require 'rails_helper'
2
2
  RSpec.describe <%= class_name %>, type: :model do
3
3
  it_behaves_like "a base model",
4
- ransack_permitted_attributes: %w[<%= attributes_names.join(" ") %>],
5
- ransack_permitted_associations: []
4
+ ransack_permitted_attributes: %w[<%= attributes_names.join(" ") %>]
5
+
6
+ # it_behaves_like "a base model",
7
+ # ransack_permitted_attributes: %w[<%= attributes_names.join(" ") %>],
8
+ # ransack_permitted_associations: [] do
9
+ # let(:auth_object) { :auth_object } <- default
10
+ # let(:auth_object) { create(:user, :as_admin) } <- in caso di necessità di override
11
+ # let(:new_user_ransack_permitted_attributes) { ransack_permitted_attributes }
12
+ # let(:new_user_ransack_permitted_associations) { ransack_permitted_associations }
13
+ # end
14
+
6
15
  end
@@ -6,48 +6,39 @@ RSpec.shared_examples "a base model" do |ransack_permitted_attributes: [], ransa
6
6
  expect(described_class).to respond_to(:human_action_message)
7
7
  end
8
8
 
9
+ ##
10
+ # Oggetto solitamente di classe User che identifichi l'utente a cui eseguire il check dei permessi
11
+ let(:auth_object) { :auth_object }
12
+ let(:new_user_ransack_permitted_attributes) { ransack_permitted_attributes }
13
+ let(:new_user_ransack_permitted_associations) { ransack_permitted_associations }
14
+
9
15
  describe "with ransackables" do
10
- where(:base_model_method, :policy_method, :policy_output, :result) do
16
+ where(:base_model_method, :result, :new_user_result) do
11
17
  [
12
18
  [
13
- :ransackable_attributes, :permitted_attributes_for_ransack, ransack_permitted_attributes.map(&:to_s), ransack_permitted_attributes.map(&:to_s)
14
- ],
15
- [
16
- :ransackable_attributes, :permitted_attributes_for_ransack, ransack_permitted_attributes.map(&:to_sym), ransack_permitted_attributes.map(&:to_s)
19
+ :ransackable_attributes, ransack_permitted_attributes.map(&:to_s), lazy { new_user_ransack_permitted_attributes.map(&:to_s) }
17
20
  ],
18
21
  [
19
- :ransackable_associations, :permitted_associations_for_ransack,ransack_permitted_associations.map(&:to_s), ransack_permitted_associations.map(&:to_s)
22
+ :ransackable_associations, ransack_permitted_associations.map(&:to_s), lazy { new_user_ransack_permitted_associations.map(&:to_s) }
20
23
  ],
21
- [
22
- :ransackable_associations, :permitted_associations_for_ransack, ransack_permitted_associations.map(&:to_sym), ransack_permitted_associations.map(&:to_s)
23
- ]
24
24
  ]
25
25
  end
26
26
 
27
27
  with_them do
28
- subject { described_class.send(base_model_method, auth_object) }
28
+ subject { described_class.send(base_model_method, inner_auth_object) }
29
29
 
30
- let(:simulated_user_instance) { instance_double("User") }
31
- # before do
32
- # allow(User).to receive(:new).and_return(simulated_user_instance)
33
- # end
34
- let(:auth_object) { nil }
35
- let(:policy) {
36
- instance_double("BaseModelPolicy", policy_method => policy_output)
37
- }
30
+ let(:inner_auth_object) { nil }
38
31
  it "new user" do
39
32
  expect(Pundit).to receive(:policy).with(an_instance_of(User),
40
33
  an_instance_of(described_class)).and_call_original
41
- #.and_return(policy)
42
34
 
43
- is_expected.to match_array(result)
35
+ is_expected.to match_array(new_user_result)
44
36
  end
45
37
 
46
38
  context "with auth_object" do
47
- let(:auth_object) { :auth_object }
39
+ let(:inner_auth_object) { auth_object }
48
40
  it do
49
- expect(Pundit).to receive(:policy).with(auth_object, an_instance_of(described_class)).and_call_original
50
- # .and_return(policy)
41
+ expect(Pundit).to receive(:policy).with(inner_auth_object, an_instance_of(described_class)).and_call_original
51
42
 
52
43
  is_expected.to match_array(result)
53
44
  end
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: 1.2.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marino Bonetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-09 00:00:00.000000000 Z
11
+ date: 2025-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails