diff --git a/Gemfile b/Gemfile
index 8aaed5c..26fa95c 100644
--- a/Gemfile
+++ b/Gemfile
@@ -63,7 +63,6 @@ gem 'rubocop-packaging'
gem 'rubocop-performance'
gem 'rubocop-rails'
gem 'rubocop-rspec'
-gem 'rubocop-rspec_rails'
# Tools
gem 'pry-rails'
diff --git a/Makefile b/Makefile
index 6bca540..c99bb10 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@ bundle_install:
db_reset:
@rm -f spec/dummy/db/*.sqlite3
- @docker compose -f extra/docker-compose.yml run --rm app bin/rails db:create db:migrate db:test:prepare
+ @docker compose -f extra/docker-compose.yml run --rm app bin/rails db:create db:migrate db:seed db:test:prepare
up: build bundle_install db_reset
@docker compose -f extra/docker-compose.yml up
@@ -34,16 +34,13 @@ down:
# App commands
-seed:
- @docker compose -f extra/docker-compose.yml exec app bin/rails db:seed
-
-console: seed
+console:
@docker compose -f extra/docker-compose.yml exec app bin/rails console
lint:
@docker compose -f extra/docker-compose.yml exec app bin/rubocop
-server: seed
+server:
@rm -f spec/dummy/tmp/pids/server.pid
@docker compose -f extra/docker-compose.yml exec app bin/rails server -b 0.0.0.0 -p ${SERVER_PORT}
diff --git a/app/views/administrate_ransack/_filters.erb b/app/views/administrate_ransack/_filters.erb
new file mode 100644
index 0000000..f38cf0e
--- /dev/null
+++ b/app/views/administrate_ransack/_filters.erb
@@ -0,0 +1,51 @@
+<% content_for(:stylesheet) do %>
+
+<% end %>
+
+<% render 'administrate_ransack/javascript' %>
+
+
+ <% form_path = [namespace, @ransack_results] %>
+ <%= search_form_for(form_path, html: { 'data-administrate-ransack-filters': '1' }) do |f| %>
+ <% @fields.each do |field, data| %>
+ <% type = data.delete(:type) %>
+ <% attrs = { form: f, model: @model, field: field, type: type, options: data[:options] } %>
+ <%= render "administrate_ransack/components/field_#{type}", attrs %>
+ <% end %>
+
+ <%= render 'administrate_ransack/components/filter_buttons', form: f %>
+ <% end %>
+
diff --git a/app/views/administrate_ransack/_filters.html.erb b/app/views/administrate_ransack/_filters.html.erb
deleted file mode 100644
index ca53b9f..0000000
--- a/app/views/administrate_ransack/_filters.html.erb
+++ /dev/null
@@ -1,36 +0,0 @@
-<%
- attribute_labels ||= {}
- attribute_types ||= @dashboard.attribute_types.select { |key, _value| @dashboard.collection_attributes.include?(key) }
- options ||= {}
- form_options = { html: { 'data-administrate-ransack-filters': '1' } }
- namespace = local_assigns[:namespace] || :admin
- if local_assigns.has_key?(:search_path)
- form_path = @ransack_results
- form_options[:url] = search_path
- clear_filters_path = search_path
- else
- form_path = [namespace, @ransack_results]
- clear_filters_path = url_for(url_for([namespace, @ransack_results.klass]))
- end
-%>
-
-<% render 'administrate_ransack/javascript' %>
-
-<%= search_form_for form_path, form_options do |f| %>
-
- <% attribute_types.each do |field, type| %>
- <% next if field == :id %>
-
- <% label = attribute_labels.include?(field) ? attribute_labels[field] : field %>
- <% model = @ransack_results.klass %>
- <% input_type = type.is_a?(Administrate::Field::Deferred) ? type.deferred_class.to_s : type.to_s %>
- <% component = AdministrateRansack::FILTERS[input_type] || 'field_other' %>
-
-
- <%= render "administrate_ransack/components/#{component}", form: f, model: model, field: field, label: label, type: type, options: options[field] %>
-
- <% end %>
-
-
- <%= render 'administrate_ransack/components/filter_buttons', form: f, clear_filters_path: clear_filters_path %>
-<% end %>
diff --git a/app/views/administrate_ransack/_javascript.html.erb b/app/views/administrate_ransack/_javascript.html.erb
index cbe8f4e..02fe761 100644
--- a/app/views/administrate_ransack/_javascript.html.erb
+++ b/app/views/administrate_ransack/_javascript.html.erb
@@ -1,5 +1,8 @@
<% content_for :javascript do %>
+
diff --git a/app/views/administrate_ransack/components/_field_belongs_to.html.erb b/app/views/administrate_ransack/components/_field_belongs_to.html.erb
index 0fa4001..fe9f61a 100644
--- a/app/views/administrate_ransack/components/_field_belongs_to.html.erb
+++ b/app/views/administrate_ransack/components/_field_belongs_to.html.erb
@@ -1,9 +1,10 @@
<% association = model.reflections[field.to_s] %>
<% if association %>
- <% field_key = model.ransackable_scopes.include?(field) ? field : "#{field}_id_eq" %>
- <% desc = association.klass.method_defined?(:admin_label) ? :admin_label : :to_s %>
- <% collection = association.klass.send(association.klass.respond_to?(:admin_scope) ? :admin_scope : :all) %>
+
+ <% desc = association.klass.method_defined?(:admin_label) ? :admin_label : :to_s %>
+ <% collection = association.klass.send(association.klass.respond_to?(:admin_scope) ? :admin_scope : :all) %>
- <%= form.label(label, class: 'filter-label') %>
- <%= form.collection_select(field_key, collection, :id, desc, include_blank: true) %>
+ <%= form.label(options[:label], class: 'filter-label') %>
+ <%= form.collection_select(options[:param], collection, :id, desc, include_blank: true) %>
+
<% end %>
diff --git a/app/views/administrate_ransack/components/_field_boolean.html.erb b/app/views/administrate_ransack/components/_field_boolean.html.erb
index 66c0e66..cc156cd 100644
--- a/app/views/administrate_ransack/components/_field_boolean.html.erb
+++ b/app/views/administrate_ransack/components/_field_boolean.html.erb
@@ -1,5 +1,5 @@
-<% field_key = model.ransackable_scopes.include?(field) ? field : "#{field}_eq" %>
<% values = [[t('administrate_ransack.filters.no'), false], [t('administrate_ransack.filters.yes'), true]] %>
-
-<%= form.label(label, class: 'filter-label') %>
-<%= form.select(field_key, values, include_blank: true) %>
+
+ <%= form.label(options[:label], class: 'filter-label') %>
+ <%= form.select(options[:param], values, include_blank: true) %>
+
diff --git a/app/views/administrate_ransack/components/_field_date.html.erb b/app/views/administrate_ransack/components/_field_date.html.erb
index 3a3edef..30a6fd5 100644
--- a/app/views/administrate_ransack/components/_field_date.html.erb
+++ b/app/views/administrate_ransack/components/_field_date.html.erb
@@ -1,7 +1,9 @@
-<%= form.label(label, class: 'filter-label') %>
-<% if model.ransackable_scopes.include?(field) %>
- <%= form.date_field(field, value: form.object.send(field)) %>
-<% else %>
- <%= form.date_field("#{field}_gteq") %>
- <%= form.date_field("#{field}_lteq") %>
-<% end %>
+
+ <%= form.label(options[:label], class: 'filter-label') %>
+ <% if options[:range] %>
+ <%= form.date_field("#{field}_gteq") %>
+ <%= form.date_field("#{field}_lteq") %>
+ <% else %>
+ <%= form.date_field(options[:param], value: form.object.send(field)) %>
+ <% end %>
+
diff --git a/app/views/administrate_ransack/components/_field_datetime.html.erb b/app/views/administrate_ransack/components/_field_datetime.html.erb
index 3966cb3..b5860f7 100644
--- a/app/views/administrate_ransack/components/_field_datetime.html.erb
+++ b/app/views/administrate_ransack/components/_field_datetime.html.erb
@@ -1,7 +1,9 @@
-<%= form.label(label, class: 'filter-label') %>
-<% if model.ransackable_scopes.include?(field) %>
- <%= form.datetime_field(field, value: form.object.send(field)) %>
-<% else %>
- <%= form.datetime_field("#{field}_gteq") %>
- <%= form.datetime_field("#{field}_lteq") %>
-<% end %>
+
+ <%= form.label(options[:label], class: 'filter-label') %>
+ <% if options[:range] %>
+ <%= form.datetime_field("#{field}_gteq") %>
+ <%= form.datetime_field("#{field}_lteq") %>
+ <% else %>
+ <%= form.datetime_field(options[:param], value: form.object.send(field)) %>
+ <% end %>
+
diff --git a/app/views/administrate_ransack/components/_field_has_many.html.erb b/app/views/administrate_ransack/components/_field_has_many.html.erb
index a60dc12..34594d0 100644
--- a/app/views/administrate_ransack/components/_field_has_many.html.erb
+++ b/app/views/administrate_ransack/components/_field_has_many.html.erb
@@ -1,20 +1,22 @@
<% association = model.reflections[field.to_s] %>
<% if association %>
- <% field_key = model.ransackable_scopes.include?(field) ? field : "#{field}_id_in" %>
- <% desc = association.klass.method_defined?(:admin_label) ? :admin_label : :to_s %>
- <% collection = association.klass.send(association.klass.respond_to?(:admin_scope) ? :admin_scope : :all) %>
+
+ <%# field_key = model.ransackable_scopes.include?(field) ? field : "#{field}_id_in" %>
+ <% desc = association.klass.method_defined?(:admin_label) ? :admin_label : :to_s %>
+ <% collection = association.klass.send(association.klass.respond_to?(:admin_scope) ? :admin_scope : :all) %>
- <%= form.label(label, class: 'filter-label') %>
- <% if options&.include? 'select' %>
- <%= form.select(field_key, nil, {}, multiple: true) do %>
- <%= options_from_collection_for_select(collection, :id, desc) %>
- <% end %>
- <% else %>
- <%= form.collection_check_boxes(field_key, collection, :id, desc) do |b| %>
- <%= b.label do %>
- <%= b.check_box %>
- <%= b.object.send(desc) %>
+ <%= form.label(options[:label], class: 'filter-label') %>
+ <% if options[:select] %>
+ <%= form.select(options[:param], nil, {}, multiple: true) do %>
+ <%= options_from_collection_for_select(collection, :id, desc) %>
+ <% end %>
+ <% else %>
+ <%= form.collection_check_boxes(options[:param], collection, :id, desc) do |b| %>
+ <%= b.label do %>
+ <%= b.check_box %>
+ <%= b.object.send(desc) %>
+ <% end %>
<% end %>
<% end %>
- <% end %>
+
<% end %>
diff --git a/app/views/administrate_ransack/components/_field_number.html.erb b/app/views/administrate_ransack/components/_field_number.html.erb
index 4a732cd..8d42001 100644
--- a/app/views/administrate_ransack/components/_field_number.html.erb
+++ b/app/views/administrate_ransack/components/_field_number.html.erb
@@ -1,4 +1,4 @@
-<% field_key = model.ransackable_scopes.include?(field) ? field : "#{field}_eq" %>
-
-<%= form.label(label, class: 'filter-label') %>
-<%= form.number_field(field_key) %>
+
+ <%= form.label(options[:label], class: 'filter-label') %>
+ <%= form.number_field(options[:param]) %>
+
diff --git a/app/views/administrate_ransack/components/_field_other.html.erb b/app/views/administrate_ransack/components/_field_other.html.erb
index bac210d..6173d50 100644
--- a/app/views/administrate_ransack/components/_field_other.html.erb
+++ b/app/views/administrate_ransack/components/_field_other.html.erb
@@ -1,6 +1,7 @@
-<%= form.label(label, class: 'filter-label') %>
-<%= form.search_field(field) %>
-
+
+ <%= form.label(options[:label], class: 'filter-label') %>
+ <%= form.search_field(options[:param]) %>
+
<%# unsupported Field::HasOne %>
<%# unsupported Field::Polymorphic %>
<%# unsupported Field::Password %>
diff --git a/app/views/administrate_ransack/components/_field_select.html.erb b/app/views/administrate_ransack/components/_field_select.html.erb
index 5698415..8e1f2e5 100644
--- a/app/views/administrate_ransack/components/_field_select.html.erb
+++ b/app/views/administrate_ransack/components/_field_select.html.erb
@@ -1,5 +1,5 @@
-<% field_key = model.ransackable_scopes.include?(field) ? field : "#{field}_eq" %>
-<% collection = (type.respond_to?(:options) ? type.options[:collection] : []) || [] %>
-
-<%= form.label(label, class: 'filter-label') %>
-<%= form.select(field_key, collection, include_blank: true) %>
+
+ <% collection = options[:collection]&.respond_to?(:call) ? options[:collection].call : options[:collection] %>
+ <%= form.label(options[:label], class: 'filter-label') %>
+ <%= form.select(options[:param], collection || [], include_blank: true) %>
+
diff --git a/app/views/administrate_ransack/components/_field_string.html.erb b/app/views/administrate_ransack/components/_field_string.html.erb
index 4630c61..ea86d19 100644
--- a/app/views/administrate_ransack/components/_field_string.html.erb
+++ b/app/views/administrate_ransack/components/_field_string.html.erb
@@ -1,4 +1,4 @@
-<% field_key = model.ransackable_scopes.include?(field) ? field : "#{field}_cont" %>
-
-<%= form.label(label, class: 'filter-label') %>
-<%= form.search_field(field_key) %>
+
+ <%= form.label(options[:label], class: 'filter-label') %>
+ <%= form.search_field(options[:param]) %>
+
diff --git a/app/views/administrate_ransack/components/_filter_buttons.html.erb b/app/views/administrate_ransack/components/_filter_buttons.html.erb
index 79d7a37..01aaddd 100644
--- a/app/views/administrate_ransack/components/_filter_buttons.html.erb
+++ b/app/views/administrate_ransack/components/_filter_buttons.html.erb
@@ -1,4 +1,4 @@
- <%= form.submit t('administrate_ransack.filters.search'), name: nil %>
- <%= link_to t('administrate_ransack.filters.clear_filters'), clear_filters_path, class: 'btn-clear-filters' %>
+ <%= form.button t('administrate_ransack.filters.search'), name: nil, type: 'submit', class: 'btn-submit button--alt' %>
+ <%= link_to t('administrate_ransack.filters.clear_filters'), request.path, class: 'btn-clear-filters' %>
diff --git a/lib/administrate_ransack/filters.rb b/lib/administrate_ransack/filters.rb
index 9c7ac86..d1320e9 100644
--- a/lib/administrate_ransack/filters.rb
+++ b/lib/administrate_ransack/filters.rb
@@ -2,15 +2,15 @@
module AdministrateRansack
FILTERS = {
- 'Administrate::Field::BelongsTo' => 'field_belongs_to',
- 'Administrate::Field::Boolean' => 'field_boolean',
- 'Administrate::Field::Date' => 'field_date',
- 'Administrate::Field::DateTime' => 'field_date',
- 'Administrate::Field::Email' => 'field_string',
- 'Administrate::Field::HasMany' => 'field_has_many',
- 'Administrate::Field::Number' => 'field_number',
- 'Administrate::Field::Select' => 'field_select',
- 'Administrate::Field::String' => 'field_string',
- 'Administrate::Field::Text' => 'field_string'
+ 'Administrate::Field::BelongsTo' => :belongs_to,
+ 'Administrate::Field::Boolean' => :boolean,
+ 'Administrate::Field::Date' => :date,
+ 'Administrate::Field::DateTime' => :date,
+ 'Administrate::Field::Email' => :string,
+ 'Administrate::Field::HasMany' => :has_many,
+ 'Administrate::Field::Number' => :number,
+ 'Administrate::Field::Select' => :select,
+ 'Administrate::Field::String' => :string,
+ 'Administrate::Field::Text' => :string
}.freeze
end
diff --git a/lib/administrate_ransack/searchable.rb b/lib/administrate_ransack/searchable.rb
index 8c54147..bf0c0bd 100644
--- a/lib/administrate_ransack/searchable.rb
+++ b/lib/administrate_ransack/searchable.rb
@@ -4,11 +4,11 @@
module AdministrateRansack
module Searchable
- def scoped_resource
- options = respond_to?(:ransack_options, true) ? ransack_options : {}
- distinct = respond_to?(:ransack_result_distinct, true) ? ransack_result_distinct : true
- @ransack_results = prepare_search(resource_collection: super, query_params: params[:q], options: options)
- @ransack_results.result(distinct: distinct)
+ def filter_resources(resources, search_term:)
+ query = params[:q] || parse_search_term(search_term, model: resources.klass)
+ @ransack_results = prepare_search(resource_collection: resources, query_params: query)
+ setup_view_attrs(dashboard: dashboard, model: resources.klass)
+ prepare_result(@ransack_results)
end
# ref => https://github.com/thoughtbot/administrate/blob/v0.18.0/app/helpers/administrate/application_helper.rb#L72-L78
@@ -17,7 +17,7 @@ def sanitized_order_params(page, current_field_name)
association_params = collection_names.map do |assoc_name|
{ assoc_name => %i[order direction page per_page] }
end
- params.permit(:search, :id, :page, :per_page, association_params, q: {})
+ params.permit(:search, :id, :page, :per_page, :utf8, :_page, association_params, q: {})
end
class << self
@@ -28,7 +28,18 @@ def prepended(base)
private
- def prepare_search(resource_collection:, query_params:, options:)
+ def parse_search_term(search_term, model:)
+ return {} if search_term.blank?
+
+ terms_regex = /(\w+):"([^"]+)"|(\w+):'([^']+)'|(\w+):(\w+)/
+ terms = search_term.scan(terms_regex).map(&:compact)
+ terms.to_h.transform_keys do |key|
+ model.ransackable_attributes.include?(key) ? "#{key}_cont" : key
+ end
+ end
+
+ def prepare_search(resource_collection:, query_params:)
+ options = respond_to?(:ransack_options, true) ? ransack_options : {}
resource_collection.ransack(query_params, **options)
rescue ArgumentError => e
if defined?(Ransack::InvalidSearchError) && e.is_a?(Ransack::InvalidSearchError) # rubocop:disable Style/GuardClause
@@ -46,5 +57,50 @@ def ransack_invalid_search_error(error)
flash.now[:alert] = I18n.t('administrate_ransack.errors.invalid_search', default: error.message)
end
end
+
+ def setup_view_attrs(dashboard:, model:)
+ @model = model
+ @fields = prepare_fields_for(dashboard: dashboard)
+ end
+
+ def prepare_fields_for(dashboard:)
+ dashboard_class = dashboard.class
+ fields = defined?(dashboard_class::RANSACK_SEARCH) ? dashboard_class::RANSACK_SEARCH : {}
+ fields.to_h do |field, conf|
+ [field, eval_type(dashboard: dashboard, field: field, conf: conf)]
+ end
+ end
+
+ def eval_type(dashboard:, field:, conf:)
+ options = conf.is_a?(Hash) ? conf.dup : {}
+ options[:label] ||= field.to_s
+
+ type =
+ if conf.blank?
+ field_type = dashboard.attribute_type_for(field).to_s
+ AdministrateRansack::FILTERS[field_type]
+ elsif conf.is_a?(Hash)
+ (conf[:type] || :string).to_sym
+ else
+ conf.to_sym
+ end
+
+ options[:range] = true if %i[date datetime].include?(type) && !options.key?(:range)
+ options[:param] = field.to_s if options[:scope] && options[:param].blank?
+ options[:param] ||=
+ case type
+ when :belongs_to then "#{field}_id_eq"
+ when :has_many then "#{field}_id_in"
+ when :string then "#{field}_cont"
+ else "#{field}_eq"
+ end
+
+ { type: type, options: options }
+ end
+
+ def prepare_result(ransack_results)
+ distinct = respond_to?(:ransack_result_distinct, true) ? ransack_result_distinct : true
+ ransack_results.result(distinct: distinct)
+ end
end
end
diff --git a/spec/dummy/app/dashboards/post_dashboard.rb b/spec/dummy/app/dashboards/post_dashboard.rb
index 8845657..239dd2c 100644
--- a/spec/dummy/app/dashboards/post_dashboard.rb
+++ b/spec/dummy/app/dashboards/post_dashboard.rb
@@ -99,4 +99,40 @@ class PostDashboard < Administrate::BaseDashboard
# def display_resource(post)
# "Post ##{post.id}"
# end
+
+ RANSACK_SEARCH = {
+ author: {
+ type: :belongs_to,
+ label: "Author"
+ },
+ category: {
+ type: :select,
+ collection: -> { Post.categories }
+ # collection: Post.categories
+ },
+ title: {
+ type: :string,
+ # param: :title_eq,
+ # label: "Some title"
+ },
+ title2: {
+ type: :string,
+ param: :title_eq,
+ label: "Strict title"
+ },
+ published: :boolean,
+ position: :number,
+ by_category: {
+ type: :string,
+ scope: true
+ },
+ dt: :date,
+ tags: {
+ type: :has_many,
+ label: "Tags",
+ select: true
+ }
+ }.freeze
+
+ # RANSACK_SEARCH = %i[title published dt].freeze
end
diff --git a/spec/dummy/app/dashboards/tag_dashboard.rb b/spec/dummy/app/dashboards/tag_dashboard.rb
index 1b2af4c..045cf91 100644
--- a/spec/dummy/app/dashboards/tag_dashboard.rb
+++ b/spec/dummy/app/dashboards/tag_dashboard.rb
@@ -24,6 +24,8 @@ class TagDashboard < Administrate::BaseDashboard
COLLECTION_ATTRIBUTES = %i[
id
name
+ created_at
+ updated_at
posts
].freeze
# post_tags
@@ -66,4 +68,15 @@ class TagDashboard < Administrate::BaseDashboard
# def display_resource(tag)
# "Tag ##{tag.id}"
# end
+
+ RANSACK_SEARCH = {
+ posts: :has_many,
+ created_at: {
+ type: :date
+ },
+ updated_at: {
+ type: :date,
+ range: false
+ }
+ }
end
diff --git a/spec/dummy/app/views/admin/application/_javascript.html.erb b/spec/dummy/app/views/admin/application/_javascript.html.erb
deleted file mode 100644
index 6be6a9c..0000000
--- a/spec/dummy/app/views/admin/application/_javascript.html.erb
+++ /dev/null
@@ -1,23 +0,0 @@
-<%#
-# Javascript Partial
-
-This partial imports the necessary javascript on each page.
-By default, it includes the application JS,
-but each page can define additional JS sources
-by providing a `content_for(:javascript)` block.
-%>
-
-<% Administrate::Engine.javascripts.each do |js_path| %>
- <%= javascript_include_tag js_path %>
-<% end %>
-
-
-
-<%= yield :javascript %>
-
-<% if Rails.env.test? %>
- <%= javascript_tag do %>
- $.fx.off = true;
- $.ajaxSetup({ async: false });
- <% end %>
-<% end %>
diff --git a/spec/dummy/app/views/admin/application/_stylesheet.html.erb b/spec/dummy/app/views/admin/application/_stylesheet.html.erb
deleted file mode 100644
index 214d50e..0000000
--- a/spec/dummy/app/views/admin/application/_stylesheet.html.erb
+++ /dev/null
@@ -1,16 +0,0 @@
-<%#
-# Stylesheet Partial
-
-This partial imports the necessary stylesheets on each page.
-By default, it includes the application CSS,
-but each page can define additional CSS sources
-by providing a `content_for(:stylesheet)` block.
-%>
-
-<% Administrate::Engine.stylesheets.each do |css_path| %>
- <%= stylesheet_link_tag css_path %>
-<% end %>
-
-
-
-<%= yield :stylesheet %>
diff --git a/spec/dummy/app/views/admin/posts/index.html.erb b/spec/dummy/app/views/admin/posts/index.html.erb
deleted file mode 100644
index 7b798a6..0000000
--- a/spec/dummy/app/views/admin/posts/index.html.erb
+++ /dev/null
@@ -1,63 +0,0 @@
-<% content_for :stylesheet do %>
-
-<% end %>
-
-
- <%= render(
- "collection",
- collection_presenter: page,
- collection_field_name: resource_name,
- page: page,
- resources: resources,
- table_title: "page-title"
- ) %>
-
- <%= paginate resources, param_name: '_page' %>
-
-
-<% attribute_types = {
- author: Administrate::Field::BelongsTo,
- title: Administrate::Field::String,
- category: Administrate::Field::Select.with_options(collection: Post.categories.to_a),
- published: Administrate::Field::Boolean,
- position: Administrate::Field::Number,
- tags: Administrate::Field::HasMany,
- dt: Administrate::Field::Date,
- created_at: Administrate::Field::DateTime,
- recents: Administrate::Field::DateTime,
- by_category: Administrate::Field::String
-} %>
-
-<%= render(
- 'administrate_ransack/filters',
- attribute_types: attribute_types,
- options: { tags: 'select' }
-) %>
diff --git a/spec/dummy/app/views/admin/tags/index.html.erb b/spec/dummy/app/views/admin/tags/index.html.erb
deleted file mode 100644
index bb965ca..0000000
--- a/spec/dummy/app/views/admin/tags/index.html.erb
+++ /dev/null
@@ -1,25 +0,0 @@
-<% content_for :stylesheet do %>
-
-<% end %>
-
-
- <%= render(
- "collection",
- collection_presenter: page,
- collection_field_name: resource_name,
- page: page,
- resources: resources,
- table_title: "page-title"
- ) %>
-
- <%= paginate resources, param_name: '_page' %>
-
-
-<%= render('administrate_ransack/filters') %>
diff --git a/spec/dummy/app/views/administrate/application/_search.html.erb b/spec/dummy/app/views/administrate/application/_search.html.erb
new file mode 100644
index 0000000..a6c9c46
--- /dev/null
+++ b/spec/dummy/app/views/administrate/application/_search.html.erb
@@ -0,0 +1,30 @@
+<% if defined?(@ransack_results) %>
+ <%= render 'administrate_ransack/filters' %>
+<% else %>
+ <%# original _search.html.erb content %>
+
+<% end %>
diff --git a/spec/dummy/app/views/layouts/application.html.erb b/spec/dummy/app/views/layouts/application.html.erb
deleted file mode 100644
index 24307d3..0000000
--- a/spec/dummy/app/views/layouts/application.html.erb
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
- Dummy
- <%= csrf_meta_tags %>
- <%= csp_meta_tag %>
-
- <%= stylesheet_link_tag 'application', media: 'all' %>
-
-
-
- <%= yield %>
-
-
diff --git a/spec/dummy/app/views/layouts/mailer.html.erb b/spec/dummy/app/views/layouts/mailer.html.erb
deleted file mode 100644
index cbd34d2..0000000
--- a/spec/dummy/app/views/layouts/mailer.html.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
- <%= yield %>
-
-
diff --git a/spec/dummy/app/views/layouts/mailer.text.erb b/spec/dummy/app/views/layouts/mailer.text.erb
deleted file mode 100644
index 37f0bdd..0000000
--- a/spec/dummy/app/views/layouts/mailer.text.erb
+++ /dev/null
@@ -1 +0,0 @@
-<%= yield %>
diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb
index 121f474..592c360 100644
--- a/spec/support/capybara.rb
+++ b/spec/support/capybara.rb
@@ -5,16 +5,18 @@
Capybara.register_driver(:capybara_cuprite) do |app|
browser_options = {}.tap do |opts|
opts['no-sandbox'] = nil if ENV['DEVEL']
+ opts['log-level'] = 1
end
Capybara::Cuprite::Driver.new(
app,
- window_size: [1600, 1024],
browser_options: browser_options,
+ headless: !ENV['CUPRITE_HEADLESS'].in?(%w[n 0 no false]),
+ # logger: $stderr,
+ js_errors: true,
process_timeout: 30,
timeout: 30,
- inspector: true,
- headless: !ENV['CUPRITE_HEADLESS'].in?(%w[n 0 no false])
+ window_size: [1600, 1024]
)
end
diff --git a/spec/system/belongs_to_filter_spec.rb b/spec/system/belongs_to_filter_spec.rb
index 37c9704..d01efec 100644
--- a/spec/system/belongs_to_filter_spec.rb
+++ b/spec/system/belongs_to_filter_spec.rb
@@ -13,7 +13,9 @@
find('.filter-author .selectize-input').click
find(".filter-author .option[data-value='#{author.id}']").click
- find('input[type="submit"]').click
+ within('.filters-buttons') do
+ click_on('Search')
+ end
expected_param = CGI.escape("q[author_id_eq]")
expect(page).to have_current_path %r{/admin/posts\?.*#{expected_param}=#{author.id}}
diff --git a/spec/system/boolean_filter_spec.rb b/spec/system/boolean_filter_spec.rb
index 5f3d661..87e55e3 100644
--- a/spec/system/boolean_filter_spec.rb
+++ b/spec/system/boolean_filter_spec.rb
@@ -10,7 +10,9 @@
find('.filter-published .selectize-input').click
find('.filter-published .option[data-value="true"]').click
- find('input[type="submit"]').click
+ within('.filters-buttons') do
+ click_on('Search')
+ end
expect(page).to have_current_path %r{/admin/posts\?.+q%5Bpublished_eq%5D=true.*}
expect(page).to have_css('a.action-show', text: "A post")
diff --git a/spec/system/date_filter_spec.rb b/spec/system/date_filter_spec.rb
index f7b0d43..9b30f50 100644
--- a/spec/system/date_filter_spec.rb
+++ b/spec/system/date_filter_spec.rb
@@ -10,7 +10,9 @@
date = Date.tomorrow
fill_in('q[dt_gteq]', with: date)
- find('input[type="submit"]').click
+ within('.filters-buttons') do
+ click_on('Search')
+ end
expect(page).to have_current_path %r{/admin/posts\?.+q%5Bdt_gteq%5D=#{date}.*}
expect(page).to have_css('.js-table-row', count: 1)
diff --git a/spec/system/has_many_filter_spec.rb b/spec/system/has_many_filter_spec.rb
index 7d6f71e..e4048a1 100644
--- a/spec/system/has_many_filter_spec.rb
+++ b/spec/system/has_many_filter_spec.rb
@@ -12,7 +12,9 @@
find('.filter-tags .selectize-input').click
find(".filter-tags .option[data-value='#{tag.id}']").click
- find('input[type="submit"]').click
+ within('.filters-buttons') do
+ click_on('Search')
+ end
expected_param = CGI.escape("q[tags_id_in][]")
expect(page).to have_current_path %r{/admin/posts\?.+#{expected_param}=#{tag.id}}
@@ -25,7 +27,9 @@
post = Post.find_by!(title: "Another post")
find("#q_posts_id_in_#{post.id}").set(true)
- find('input[type="submit"]').click
+ within('.filters-buttons') do
+ click_on('Search')
+ end
expect(page).to have_css('.js-table-row', count: 1)
expect(page).to have_css('.js-table-row a.action-show', text: tag.name)
diff --git a/spec/system/number_filter_spec.rb b/spec/system/number_filter_spec.rb
index d0b5a2d..8141c11 100644
--- a/spec/system/number_filter_spec.rb
+++ b/spec/system/number_filter_spec.rb
@@ -9,7 +9,9 @@
visit admin_posts_path
fill_in('q[position_eq]', with: '234')
- find('input[type="submit"]').click
+ within('.filters-buttons') do
+ click_on('Search')
+ end
expect(page).to have_current_path %r{/admin/posts\?.+q%5Bposition_eq%5D=234.*}
expect(page).to have_css('.js-table-row', count: 1)
diff --git a/spec/system/scope_filter_spec.rb b/spec/system/scope_filter_spec.rb
index be06de4..5a64bb1 100644
--- a/spec/system/scope_filter_spec.rb
+++ b/spec/system/scope_filter_spec.rb
@@ -11,7 +11,9 @@
visit admin_posts_path
fill_in('q[by_category]', with: 'news')
- find('input[type="submit"]').click
+ within('.filters-buttons') do
+ click_on('Search')
+ end
expect(page).to have_current_path %r{/admin/posts\?.+q%5Bby_category%5D=news.*}
expect(posts.count).to be_positive
diff --git a/spec/system/select_filter_spec.rb b/spec/system/select_filter_spec.rb
index f7c908a..6813c0b 100644
--- a/spec/system/select_filter_spec.rb
+++ b/spec/system/select_filter_spec.rb
@@ -10,7 +10,9 @@
find('.filter-category .selectize-input').click
find('.filter-category .option[data-value="story"]').click
- find('input[type="submit"]').click
+ within('.filters-buttons') do
+ click_on('Search')
+ end
expect(page).to have_current_path %r{/admin/posts\?.+q%5Bcategory_eq%5D=story.*}
expect(page).to have_css('.js-table-row', count: 1)
diff --git a/spec/system/string_filter_spec.rb b/spec/system/string_filter_spec.rb
index b1cc2c0..c82961b 100644
--- a/spec/system/string_filter_spec.rb
+++ b/spec/system/string_filter_spec.rb
@@ -9,7 +9,9 @@
visit admin_posts_path
fill_in('q[title_cont]', with: 'another')
- find('input[type="submit"]').click
+ within('.filters-buttons') do
+ click_on('Search')
+ end
expect(page).to have_current_path %r{/admin/posts?.*q%5Btitle_cont%5D=another}
expect(page).to have_css('.js-table-row', count: 1)