base_editing_bootstrap 0.9.0 → 0.10.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: 678f9ed5e165bf715f6e9523c7b9a29cd2d06ee4da800723a76b1efa61a5d747
4
- data.tar.gz: 9a7e3297a6e03130d8cb2d1b769b91a37d20010a070fdab81dd0a029ddadfc65
3
+ metadata.gz: ae3826e47810ce15c5ddb8c1e4abacb4af039cec40b2f2b835170691250357d0
4
+ data.tar.gz: '03069a335d73eaa8d449635c544315a154a66e18758f5d3e774f804e8fbf7d9b'
5
5
  SHA512:
6
- metadata.gz: 86c848f6f307910302465e1a7840f0046ab855ee60f7545f9ac68f004041d4176cff5370e02dd32d02b253a754756f0d2416de2783a1b47395d6d3ebac8cbc24
7
- data.tar.gz: 7259712a03b75b24489ef7b459ac137eb7101d7e045e4bec175640b24509bcf875bc979a9bb91e23e7ecb1f977dfce14b40c6779be2fda2f39ebca587a14d328
6
+ metadata.gz: 036470dfdaab3d46b054539d3a958bfed2138f443248f245917a1c258f420cf2a63174ff945ff164df62a001ad343814c48f87cf31c9cab696a9995b34d0b8ee
7
+ data.tar.gz: 2845c50faabf84b474f57c0144876e35661c22e38b042a4386f5c9f2eef01ba4f47b516cf6fff39cd051047920a1ac0de9da26978a5d0227952f8d201601a461
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
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.10.0 - 2024-06-26
6
+ #### Features
7
+ - Add sort configuration per controller - (0cca665) - Marino Bonetti
8
+ #### Miscellaneous Chores
9
+ - Add ignore to assets - (aff4ac6) - Marino Bonetti
10
+
11
+ - - -
12
+
13
+ ## 0.9.1 - 2024-06-17
14
+ #### Bug Fixes
15
+ - Change http status check from symbol to number - (1ecd63d) - Marino Bonetti
16
+
17
+ - - -
18
+
5
19
  ## 0.9.0 - 2024-06-16
6
20
  #### Features
7
21
  - Change default and docs for show - (f320698) - Marino Bonetti
data/README.md CHANGED
@@ -86,6 +86,9 @@ Utilizzo per modello base, in questo esempio prendiamo come modello Post come es
86
86
  - Creare Controller:
87
87
  ```ruby
88
88
  class PostsController < BaseEditingController
89
+ ##
90
+ # Set default sort order for ransack
91
+ # self.default_sort= ["id"]
89
92
  end
90
93
  ```
91
94
  - Aggiungere la rotta: `resources :posts`
@@ -9,12 +9,19 @@ class BaseEditingController < RestrictedAreaController
9
9
  :new_custom_polymorphic_path,
10
10
  :show_custom_polymorphic_path
11
11
 
12
+ ##
13
+ # Configure default sort in the index query.
14
+ # Works like documented in https://activerecord-hackery.github.io/ransack/getting-started/sorting/#sorting-in-the-controller
15
+ class_attribute :default_sorts, default: ["id"]
16
+
12
17
  def index
13
18
  authorize base_class
14
19
 
15
20
  q = policy_scope(base_scope)
16
-
17
- @search_instance = search_class.new(q, current_user, params: params.permit(:page, :q => {})) # FIXME trovare modo per essere più "STRONG"
21
+ @search_instance = search_class.new(q, current_user,
22
+ params: params.permit(:page, :q => {}), # FIXME trovare modo per essere più "STRONG"
23
+ sorts: default_sorts
24
+ )
18
25
  @search_instance = yield(@search_instance) if block_given?
19
26
  end
20
27
 
@@ -1 +1 @@
1
- 0.9.0
1
+ 0.10.0
@@ -7,24 +7,26 @@ module BaseEditingBootstrap::Searches
7
7
  include ActiveModel::Naming
8
8
  include ActiveModel::Conversion
9
9
 
10
- attr_reader :model_klass, :user, :params, :scope
10
+ attr_reader :model_klass, :user, :params, :scope, :sorts
11
11
 
12
12
  # @param [User] user
13
13
  # @param [ActiveRecord::Associations::CollectionProxy] scope
14
- def initialize(scope, user, params: {page: nil})
14
+ # @param [Array<String (frozen)>] sort
15
+ def initialize(scope, user, params: {page: nil}, sorts: ["id"])
15
16
  @model_klass = scope.klass
16
17
  @user = user
17
18
  @scope = scope
18
19
  @params = params
20
+ @sorts = sorts
19
21
  end
20
22
 
21
23
  ##
22
24
  # Risultato della ricerca, fa da pipeline verso ransack
25
+ # Impostando il sort nel caso in cui non sia già stato impostato da ransack
23
26
  def results
24
- ransack_query
25
- .result(distinct: true)
26
- .order(:id)
27
- .page(params[:page])
27
+ ransack_query.tap { |r|
28
+ r.sorts = @sorts if r.sorts.empty?
29
+ }.result(distinct: true).page(params[:page])
28
30
  end
29
31
 
30
32
  def ransack_query
@@ -22,7 +22,7 @@ module BaseEditingBootstrap
22
22
  opts = ["--no-helper", "--parent=BaseEditingController"]
23
23
  opts << "--force" if options.force?
24
24
  generate "controller", controller_class_name, *opts
25
-
25
+ # TODO usare i template ed aggiungere l'esempio della ricerca
26
26
  route "resources :#{plural_name}"
27
27
 
28
28
  template "spec/request.rb", File.join("spec/requests", "#{plural_file_name}_spec.rb")
@@ -88,7 +88,7 @@ RSpec.shared_examples "base editing controller" do |factory: nil, only: [], exce
88
88
  it "response" do
89
89
  params = {q: {"foo_eq": "foo"}}
90
90
  get url_for_index, params: params
91
- expect(response).to have_http_status(:ok)
91
+ expect(response).to have_http_status(200)
92
92
  expect(assigns[:search_instance]).to be_an_instance_of(BaseEditingBootstrap::Searches::Base).and(have_attributes(
93
93
  user: user,
94
94
  params: ActionController::Parameters.new(params).permit!
@@ -101,7 +101,7 @@ RSpec.shared_examples "base editing controller" do |factory: nil, only: [], exce
101
101
  describe "new" do
102
102
  it "response" do
103
103
  get url_for_new
104
- expect(response).to have_http_status(:ok)
104
+ expect(response).to have_http_status(200)
105
105
  expect(assigns[:object]).to be_an_instance_of(model)
106
106
  end
107
107
  end
@@ -111,7 +111,7 @@ RSpec.shared_examples "base editing controller" do |factory: nil, only: [], exce
111
111
  describe "edit" do
112
112
  it "response" do
113
113
  get url_for_edit.call
114
- expect(response).to have_http_status(:ok)
114
+ expect(response).to have_http_status(200)
115
115
  expect(assigns[:object]).to be_an_instance_of(model)
116
116
  end
117
117
  end
@@ -122,7 +122,7 @@ RSpec.shared_examples "base editing controller" do |factory: nil, only: [], exce
122
122
  it "response" do
123
123
  put url_for_update, params: {param_key => valid_attributes}
124
124
  expect(assigns[:object]).to be_an_instance_of(model)
125
- expect(response).to have_http_status(:see_other)
125
+ expect(response).to have_http_status(303)
126
126
  case BaseEditingBootstrap.after_success_update_redirect
127
127
  when :index
128
128
  expect(response).to redirect_to(url_for_index)
@@ -135,7 +135,7 @@ RSpec.shared_examples "base editing controller" do |factory: nil, only: [], exce
135
135
  unless skip_invalid_checks
136
136
  it "not valid" do
137
137
  put url_for_update, params: {param_key => invalid_attributes}
138
- expect(response).to have_http_status(:unprocessable_entity)
138
+ expect(response).to have_http_status(422)
139
139
  end
140
140
  end
141
141
  end
@@ -146,7 +146,7 @@ RSpec.shared_examples "base editing controller" do |factory: nil, only: [], exce
146
146
  it "response" do
147
147
  post url_for_create, params: {param_key => valid_attributes}
148
148
  expect(assigns[:object]).to be_an_instance_of(model)
149
- expect(response).to have_http_status(:see_other)
149
+ expect(response).to have_http_status(303)
150
150
  case BaseEditingBootstrap.after_success_create_redirect
151
151
  when :index
152
152
  expect(response).to redirect_to(url_for_index)
@@ -159,7 +159,7 @@ RSpec.shared_examples "base editing controller" do |factory: nil, only: [], exce
159
159
  unless skip_invalid_checks
160
160
  it "not valid" do
161
161
  post url_for_create, params: {param_key => invalid_attributes}
162
- expect(response).to have_http_status(:unprocessable_entity)
162
+ expect(response).to have_http_status(422)
163
163
  end
164
164
  end
165
165
  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: 0.9.0
4
+ version: 0.10.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-06-16 00:00:00.000000000 Z
11
+ date: 2024-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails