-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from blocknotes/scopes
Scopes
- Loading branch information
Showing
14 changed files
with
91 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
app/views/administrate_ransack/components/_field_belongs_to.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<% 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) %> | ||
<%= form.label(label) %> | ||
<%= form.collection_select "#{field}_id_eq", collection, :id, desc, include_blank: true %> | ||
<%= form.collection_select(field_key, collection, :id, desc, include_blank: true) %> | ||
<% end %> |
3 changes: 2 additions & 1 deletion
3
app/views/administrate_ransack/components/_field_boolean.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<% 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) %> | ||
<%= form.select "#{field}_eq", values, include_blank: true %> | ||
<%= form.select(field_key, values, include_blank: true) %> |
8 changes: 6 additions & 2 deletions
8
app/views/administrate_ransack/components/_field_date.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
<%= form.label(label) %> | ||
<%= form.date_field "#{field}_gteq" %> | ||
<%= form.date_field "#{field}_lteq" %> | ||
<% if model.ransackable_scopes.include?(field) %> | ||
<%= form.date_field(field) %> | ||
<% else %> | ||
<%= form.date_field("#{field}_gteq") %> | ||
<%= form.date_field("#{field}_lteq") %> | ||
<% end %> |
8 changes: 6 additions & 2 deletions
8
app/views/administrate_ransack/components/_field_datetime.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
<%= form.label(label) %> | ||
<%= form.datetime_field "#{field}_gteq" %> | ||
<%= form.datetime_field "#{field}_lteq" %> | ||
<% if model.ransackable_scopes.include?(field) %> | ||
<%= form.datetime_field(field) %> | ||
<% else %> | ||
<%= form.datetime_field("#{field}_gteq") %> | ||
<%= form.datetime_field("#{field}_lteq") %> | ||
<% end %> |
3 changes: 2 additions & 1 deletion
3
app/views/administrate_ransack/components/_field_has_many.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
app/views/administrate_ransack/components/_field_number.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
<% field_key = model.ransackable_scopes.include?(field) ? field : "#{field}_eq" %> | ||
<%= form.label(label) %> | ||
<%= form.number_field "#{field}_eq" %> | ||
<%= form.number_field(field_key) %> |
3 changes: 2 additions & 1 deletion
3
app/views/administrate_ransack/components/_field_select.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
<% field_key = model.ransackable_scopes.include?(field) ? field : "#{field}_eq" %> | ||
<%= form.label(label) %> | ||
<%= form.select "#{field}_eq", type.options[:collection] || [], include_blank: true %> | ||
<%= form.select(field_key, type.options[:collection] || [], include_blank: true) %> |
3 changes: 2 additions & 1 deletion
3
app/views/administrate_ransack/components/_field_string.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
<% field_key = model.ransackable_scopes.include?(field) ? field : "#{field}_cont" %> | ||
<%= form.label(label) %> | ||
<%= form.search_field("#{field}_cont") %> | ||
<%= form.search_field(field_key) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe 'Scope filter', type: :system do | ||
let(:posts) { Post.where(category: 'news') } | ||
|
||
it 'filters the posts by category (using the scope)' do | ||
visit '/admin/posts' | ||
|
||
fill_in('q[by_category]', with: 'news') | ||
find('input[type="submit"]').click | ||
|
||
expect(page).to have_current_path %r{/admin/posts\?.+q%5Bby_category%5D=news.*} | ||
expect(posts.count).to be_positive | ||
expect(page).to have_css('.js-table-row', count: posts.count) | ||
posts.each do |post| | ||
expect(page).to have_css('.js-table-row a.action-show', text: post.title) | ||
end | ||
end | ||
end |