From f3165cd9ddf90ccae72817faa1d6911364dfab2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jachymczyk?= Date: Fri, 26 Aug 2016 18:46:19 +0200 Subject: [PATCH 01/20] Fix handling view arguments. --- app/helpers/smart_listing/helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/smart_listing/helper.rb b/app/helpers/smart_listing/helper.rb index 4266f7f..8886548 100644 --- a/app/helpers/smart_listing/helper.rb +++ b/app/helpers/smart_listing/helper.rb @@ -230,7 +230,7 @@ def smart_listing_for name, *args, &block end def smart_listing_render name = controller_name, *args - options = args.extract_options! + options = args.dup.extract_options! smart_listing_for(name, *args) do |smart_listing| concat(smart_listing.render_list(options[:locals])) end From 58e7924e730c2530b9bce85a9600efd20e0ae855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jachymczyk?= Date: Mon, 29 Aug 2016 15:18:14 +0200 Subject: [PATCH 02/20] Version bump to 1.2.0 --- Changes.md | 4 ++++ lib/smart_listing/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Changes.md b/Changes.md index cb4fdd8..3ed01b3 100644 --- a/Changes.md +++ b/Changes.md @@ -1,3 +1,6 @@ +1.2.0 +----------- + - Rails 5 support and Kaminari update [akostadinov] - Better handling of nested controls params - Fix controls not fading out list. Related to #51 @@ -6,6 +9,7 @@ 1.1.2 ----------- + - Some bugfixing: #20, #46, #58 1.1.0 diff --git a/lib/smart_listing/version.rb b/lib/smart_listing/version.rb index 8b37f25..1b3116a 100644 --- a/lib/smart_listing/version.rb +++ b/lib/smart_listing/version.rb @@ -1,3 +1,3 @@ module SmartListing - VERSION = "1.1.2" + VERSION = "1.2.0" end From 6d728f81281f5f3736aacfa4e5b927464d597fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jachymczyk?= Date: Mon, 29 Aug 2016 15:23:50 +0200 Subject: [PATCH 03/20] Update Gemfile.lock --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index bf9b436..ee369ee 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - smart_listing (1.1.2) + smart_listing (1.2.0) coffee-rails jquery-rails kaminari (~> 0.17) From 4deac17d405dc3ef15b6920a63c3a89c70c9d1cf Mon Sep 17 00:00:00 2001 From: Brandon Valentine Date: Tue, 4 Oct 2016 14:44:00 -0500 Subject: [PATCH 04/20] Allow to render outside of controllers. Closes #106 --- Changes.md | 2 ++ app/helpers/smart_listing/helper.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/Changes.md b/Changes.md index 3ed01b3..be33338 100644 --- a/Changes.md +++ b/Changes.md @@ -1,3 +1,5 @@ +- Allow to render outside of controllers [bval] + 1.2.0 ----------- diff --git a/app/helpers/smart_listing/helper.rb b/app/helpers/smart_listing/helper.rb index 8886548..f437b49 100644 --- a/app/helpers/smart_listing/helper.rb +++ b/app/helpers/smart_listing/helper.rb @@ -11,6 +11,7 @@ def smart_listing_create *args name = (args[0] || options[:name] || controller_name).to_sym collection = args[1] || options[:collection] || smart_listing_collection + view_context = self.respond_to?(:controller) ? controller.view_context : self.view_context options = {:config_profile => view_context.smart_listing_config_profile}.merge(options) list = SmartListing::Base.new(name, collection, options) From cdc248edac10afbcf4c66cfd451e9888eadfeacf Mon Sep 17 00:00:00 2001 From: Christian Segura Date: Mon, 17 Oct 2016 17:05:09 -0700 Subject: [PATCH 05/20] Fixing documentation for filter search icon to be displayed correctly. --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 0eeed43..dcfba79 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ smart_listing_render(:users) - unless smart_listing.empty? %table %thead - %tr + %tr %th User name %th Email %tbody @@ -82,7 +82,7 @@ smart_listing_render(:users) %td= user.name %td= user.email - = smart_listing.paginate + = smart_listing.paginate - else %p.warning No records! ``` @@ -112,7 +112,7 @@ SmartListing supports two modes of sorting: implicit and explicit. Implicit mode - unless smart_listing.empty? %table %thead - %tr + %tr %th= smart_listing.sortable "User name", :name %th= smart_listing.sortable "Email", :email %tbody @@ -121,12 +121,12 @@ SmartListing supports two modes of sorting: implicit and explicit. Implicit mode %td= user.name %td= user.email - = smart_listing.paginate + = smart_listing.paginate - else %p.warning No records! ``` -In this case `:name` and `:email` are sorting column names. `Builder#sortable` renders special link containing column name and sort order (either `asc`, `desc`, or empty value). +In this case `:name` and `:email` are sorting column names. `Builder#sortable` renders special link containing column name and sort order (either `asc`, `desc`, or empty value). You can also specify default sort order in the controller: @@ -136,7 +136,7 @@ You can also specify default sort order in the controller: Implicit mode is convenient with simple data sets. In case you want to sort by joined column names, we advise you to use explicit sorting: ```ruby -@users = smart_listing_create :users, User.active.joins(:stats), partial: "users/listing", +@users = smart_listing_create :users, User.active.joins(:stats), partial: "users/listing", sort_attributes: [[:last_signin, "stats.last_signin_at"]], default_sort: {last_signin: "desc"} ``` @@ -153,7 +153,7 @@ In order to allow managing and editing list items, we need to reorganize our vie - unless smart_listing.empty? %table %thead - %tr + %tr %th= smart_listing.sortable "User name", "name" %th= smart_listing.sortable "Email", "email" %th @@ -161,9 +161,9 @@ In order to allow managing and editing list items, we need to reorganize our vie - smart_listing.collection.each do |user| %tr.editable{data: {id: user.id}} = smart_listing.render partial: 'users/user', locals: {user: user} - = smart_listing.item_new colspan: 3, link: new_user_path + = smart_listing.item_new colspan: 3, link: new_user_path - = smart_listing.paginate + = smart_listing.paginate - else %p.warning No records! ``` @@ -174,7 +174,7 @@ In order to allow managing and editing list items, we need to reorganize our vie <%= smart_listing_item :users, :new, @new_user, "users/form" %> ``` -Note that `new` action does not need to create SmartListing (via `smart_listing_create`). It just initializes `@new_user` and renders JS view. +Note that `new` action does not need to create SmartListing (via `smart_listing_create`). It just initializes `@new_user` and renders JS view. New partial for user (`users/user`) may look like this: ```haml @@ -204,10 +204,10 @@ Partial name supplied to `smart_listing_item` (`users/form`) references `@user` = form_for object, url: object.new_record? ? users_path : user_path(object), remote: true do |f| %p - Name: + Name: = f.text_field :name %p - Email: + Email: = f.text_field :email %p= f.submit "Save" ``` @@ -228,7 +228,7 @@ SmartListing controls allow you to change somehow presented data. This is typica .filter.input-append = text_field_tag :filter, '', class: "search", placeholder: "Type name here", autocomplete: "off" %button.btn.disabled{type: "submit"} - %i.icon.icon-search + %span.glyphicon.glyphicon-search ``` This gives you nice Bootstrap-enabled filter field with keychange handler. Of course you can use any other form fields in controls too. @@ -262,7 +262,7 @@ SmartListing.configure(:awesome_profile) do |config| end ``` -In order to use this profile, create helper method named `smart_listing_config_profile` returning profile name and put into your JS `SmartListing.config.merge()` function call. `merge()` function expects parameter with config attributes hash or reads body data-attribute named `smart-listing-config`. Hash of config attributes can be obtained by using helper method `SmartListing.config(:awesome_profile).to_json`. +In order to use this profile, create helper method named `smart_listing_config_profile` returning profile name and put into your JS `SmartListing.config.merge()` function call. `merge()` function expects parameter with config attributes hash or reads body data-attribute named `smart-listing-config`. Hash of config attributes can be obtained by using helper method `SmartListing.config(:awesome_profile).to_json`. ## Not enough? From 0e98a1a91d0c5fc7dd8347c1d89f29511fa7110e Mon Sep 17 00:00:00 2001 From: sevgibson Date: Thu, 5 Jan 2017 21:19:44 -0500 Subject: [PATCH 06/20] Use id.to_json so integers and uuids will both work. Closes #113 --- Changes.md | 2 ++ app/views/smart_listing/item/_create.js.erb | 2 +- app/views/smart_listing/item/_create_continue.js.erb | 2 +- app/views/smart_listing/item/_destroy.js.erb | 2 +- app/views/smart_listing/item/_edit.js.erb | 2 +- app/views/smart_listing/item/_remove.js.erb | 2 +- app/views/smart_listing/item/_update.js.erb | 2 +- 7 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Changes.md b/Changes.md index be33338..46f48ce 100644 --- a/Changes.md +++ b/Changes.md @@ -1,4 +1,6 @@ - Allow to render outside of controllers [bval] +- Documentation fixes [blackcofla] +- Use id.to_json so integers and uuids will both work [sevgibson] 1.2.0 ----------- diff --git a/app/views/smart_listing/item/_create.js.erb b/app/views/smart_listing/item/_create.js.erb index b54101e..55addf2 100644 --- a/app/views/smart_listing/item/_create.js.erb +++ b/app/views/smart_listing/item/_create.js.erb @@ -1,3 +1,3 @@ var smart_listing = $('#<%= name %>').smart_listing(); smart_listing.setAutoshow(false); -smart_listing.create(<%= id || 0 %>, <%= object.persisted? %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>"); +smart_listing.create(<%= (id || 0).to_json.html_safe %>, <%= object.persisted? %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>"); diff --git a/app/views/smart_listing/item/_create_continue.js.erb b/app/views/smart_listing/item/_create_continue.js.erb index 4d520cf..cc787b5 100644 --- a/app/views/smart_listing/item/_create_continue.js.erb +++ b/app/views/smart_listing/item/_create_continue.js.erb @@ -1,6 +1,6 @@ var smart_listing = $('#<%= name %>').smart_listing(); smart_listing.setAutoshow(true); -smart_listing.create(<%= id || 0 %>, <%= object.persisted? %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>"); +smart_listing.create(<%= (id || 0).to_json.html_safe %>, <%= object.persisted? %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>"); <% if object.persisted? %> smart_listing.new_item("<%= escape_javascript(render(:partial => new.last, :locals => {object_key => new.first})) %>"); <% end %> diff --git a/app/views/smart_listing/item/_destroy.js.erb b/app/views/smart_listing/item/_destroy.js.erb index 31c601e..5caace4 100644 --- a/app/views/smart_listing/item/_destroy.js.erb +++ b/app/views/smart_listing/item/_destroy.js.erb @@ -1,2 +1,2 @@ var smart_listing = $('#<%= name.to_s %>').smart_listing(); -smart_listing.destroy(<%= id %>, <%= object.destroyed? %>); +smart_listing.destroy(<%= id.to_json.html_safe %>, <%= object.destroyed? %>); diff --git a/app/views/smart_listing/item/_edit.js.erb b/app/views/smart_listing/item/_edit.js.erb index 00b0625..c2873a3 100644 --- a/app/views/smart_listing/item/_edit.js.erb +++ b/app/views/smart_listing/item/_edit.js.erb @@ -1,2 +1,2 @@ var smart_listing = $('#<%= name %>').smart_listing(); -smart_listing.edit(<%= id %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>"); +smart_listing.edit(<%= id.to_json.html_safe %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>"); diff --git a/app/views/smart_listing/item/_remove.js.erb b/app/views/smart_listing/item/_remove.js.erb index 7263d19..d876559 100644 --- a/app/views/smart_listing/item/_remove.js.erb +++ b/app/views/smart_listing/item/_remove.js.erb @@ -1,2 +1,2 @@ var smart_listing = $('#<%= name %>').smart_listing(); -smart_listing.remove(<%= id %>); +smart_listing.remove(<%= id.to_json.html_safe %>); diff --git a/app/views/smart_listing/item/_update.js.erb b/app/views/smart_listing/item/_update.js.erb index 69780d6..c8a678c 100644 --- a/app/views/smart_listing/item/_update.js.erb +++ b/app/views/smart_listing/item/_update.js.erb @@ -1,2 +1,2 @@ var smart_listing = $('#<%= name %>').smart_listing(); -smart_listing.update(<%= id %>, <%= valid.nil? ? object.valid? : valid %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>"); +smart_listing.update(<%= id.to_json.html_safe %>, <%= valid.nil? ? object.valid? : valid %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>"); From c4d4874f0e7152667e1275265df2a194e9d872b1 Mon Sep 17 00:00:00 2001 From: sevgibson Date: Thu, 5 Jan 2017 23:13:30 -0500 Subject: [PATCH 07/20] Allow boostrap 4 compatibility. Closes #114 --- Changes.md | 1 + app/assets/javascripts/smart_listing.coffee.erb | 11 +++++++---- lib/generators/smart_listing/templates/initializer.rb | 4 ++++ lib/smart_listing/config.rb | 3 +++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Changes.md b/Changes.md index 46f48ce..e0badb3 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,7 @@ - Allow to render outside of controllers [bval] - Documentation fixes [blackcofla] - Use id.to_json so integers and uuids will both work [sevgibson] +- Fix popover in bootstrap 4 [sevgibson] 1.2.0 ----------- diff --git a/app/assets/javascripts/smart_listing.coffee.erb b/app/assets/javascripts/smart_listing.coffee.erb index 040a8dc..db8de25 100644 --- a/app/assets/javascripts/smart_listing.coffee.erb +++ b/app/assets/javascripts/smart_listing.coffee.erb @@ -24,6 +24,9 @@ class window.SmartListing @element_template: (name)-> @options["constants"]["element_templates"][name] + @bootstrap_commands: (name)-> + @options["constants"]["bootstrap_commands"][name] + @config: Config @@ -319,8 +322,8 @@ $.fn.smart_listing.observeField = (field, opts = {}) -> , 400) $.fn.smart_listing.showPopover = (elem, body) -> - elem.popover("destroy") - elem.popover(content: body, html: true, trigger: "manual", title: null) + elem.popover(SmartListing.config.bootstrap_commands("popover_destroy")) + elem.popover(content: body, html: true, trigger: "manual") elem.popover("show") $.fn.smart_listing.showConfirmation = (confirmation_elem, msg, confirm_callback) -> @@ -333,12 +336,12 @@ $.fn.smart_listing.showConfirmation = (confirmation_elem, msg, confirm_callback) editable = $(event.currentTarget).closest(SmartListing.config.class_name("editable")) confirm_callback(confirmation_elem) $(confirmation_elem).click() - $(confirmation_elem).popover("destroy") + $(confirmation_elem).popover(SmartListing.config.bootstrap_commands("popover_destroy")) ) .append(" ") .append($(" +<% end %> + <%= smart_listing_render %> diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb index 053f5b6..82ca386 100644 --- a/spec/dummy/config/environments/test.rb +++ b/spec/dummy/config/environments/test.rb @@ -5,7 +5,7 @@ # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! - config.cache_classes = true + config.cache_classes = false # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that diff --git a/spec/dummy/config/initializers/smart_listing.rb b/spec/dummy/config/initializers/smart_listing.rb index da8b46b..c5bff54 100644 --- a/spec/dummy/config/initializers/smart_listing.rb +++ b/spec/dummy/config/initializers/smart_listing.rb @@ -10,7 +10,7 @@ #:unlimited_per_page => false, # allow infinite page size #:paginate => true, # allow pagination #:memorize_per_page => false, # save per page settings in the cookie - #:page_sizes => DEFAULT_PAGE_SIZES, # set available page sizes array + :page_sizes => [3, 10], # set available page sizes array #:kaminari_options => {:theme => "smart_listing"}, # Kaminari's paginate helper options #:sort_dirs => [nil, "asc", "desc"], # Default sorting directions cycle of sortables }) diff --git a/spec/dummy/db/migrate/20141028214800_user.rb b/spec/dummy/db/migrate/20141028214800_user.rb deleted file mode 100644 index 895bd36..0000000 --- a/spec/dummy/db/migrate/20141028214800_user.rb +++ /dev/null @@ -1,4 +0,0 @@ -class User < ActiveRecord::Migration - def change - end -end diff --git a/spec/dummy/db/migrate/20180126065408_create_user.rb b/spec/dummy/db/migrate/20180126065408_create_user.rb new file mode 100644 index 0000000..1832a64 --- /dev/null +++ b/spec/dummy/db/migrate/20180126065408_create_user.rb @@ -0,0 +1,9 @@ +class CreateUser < ActiveRecord::Migration[5.1] + def change + create_table :users do |t| + t.string :name + t.string :email + t.boolean :boolean + end + end +end diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index 30d31d6..187761d 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -11,11 +10,12 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20141028214800) do +ActiveRecord::Schema.define(version: 20180126065408) do - create_table "users", force: true do |t| + create_table "users", force: :cascade do |t| t.string "name" t.string "email" + t.boolean "boolean" end end diff --git a/spec/dummy/db/seeds.rb b/spec/dummy/db/seeds.rb new file mode 100644 index 0000000..e632b37 --- /dev/null +++ b/spec/dummy/db/seeds.rb @@ -0,0 +1,8 @@ +User.find_or_create_by(id: 1, name: "Betty", email: "betty@email.com", boolean: false) +User.find_or_create_by(id: 2, name: "Aaron", email: "aaron@email.com", boolean: true) +User.find_or_create_by(id: 3, name: "Jane", email: "jane@test.eu", boolean: false) +User.find_or_create_by(id: 4, name: "Edward", email: "edward@test.eu", boolean: true) +User.find_or_create_by(id: 5, name: "Nicholas", email: "salohcin@email.com", boolean: false) +User.find_or_create_by(id: 6, name: "Lisa", email: "asil@email.com", boolean: true) +User.find_or_create_by(id: 7, name: "Sara", email: "aras@test.eu", boolean: false) +User.find_or_create_by(id: 8, name: "Robin", email: "nibor@test.eu", boolean: true) diff --git a/spec/dummy/fixtures/users.yml b/spec/dummy/fixtures/users.yml new file mode 100644 index 0000000..d332125 --- /dev/null +++ b/spec/dummy/fixtures/users.yml @@ -0,0 +1,40 @@ +user1: + id: 1 + name: "Betty" + email: "betty@email.com" + boolean: false +user2: + id: 2 + name: "Aaron" + email: "aaron@email.com" + boolean: true +user3: + id: 3 + name: "Jane" + email: "jane@test.eu" + boolean: false +user4: + id: 4 + name: "Edward" + email: "edward@test.eu" + boolean: true +user5: + id: 5 + name: "Nicholas" + email: "salohcin@email.com" + boolean: false +user6: + id: 6 + name: "Lisa" + email: "asil@email.com" + boolean: true +user7: + id: 7 + name: "Sara" + email: "aras@test.eu" + boolean: false +user8: + id: 8 + name: "Robin" + email: "nibor@test.eu" + boolean: true diff --git a/spec/features/custom_filters_spec.rb b/spec/features/custom_filters_spec.rb new file mode 100644 index 0000000..d54e041 --- /dev/null +++ b/spec/features/custom_filters_spec.rb @@ -0,0 +1,69 @@ +require 'rails_helper' + +feature 'Combine custom filtering' do + fixtures :users + + scenario 'The user search user, change pagination and change page', js: true do + + visit admin_users_path + #page_sizes => [3, 10] + within(".pagination-per-page") { click_on "10" } + expect(page).to have_selector('tr.editable', count: 8) + fill_in "filter", with: "test" + expect(page).to have_selector('tr.editable', count: 4) + within(".pagination-per-page") { click_on "3" } + within(".pagination") { click_on "2" } + expect(page).to have_selector('tr.editable', count: 1) + + end + + scenario 'The user sort users and change page', js: true do + + visit admin_users_path + find('.name a.sortable').click + expect(page).to have_content("Aaron") + expect(page).to_not have_content("Jane") + within(".pagination") { click_on "2" } + expect(page).to have_content("Jane") + expect(page).to_not have_content("Aaron") + + end + + scenario 'The user combine filters', js: true do + + visit admin_users_path + fill_in "filter", with: "email" + find('input#boolean').click + expect(page).to have_selector('tr.editable', count: 2) + + end + + scenario 'The user combine filters and sort users', js: true do + + visit admin_users_path + fill_in "filter", with: "test" + find('input#boolean').click + wait_for_ajax + expect(page).to have_selector('tr.editable', count: 2) + click_link 'Name' + expect(page).to have_selector('tr.editable', count: 2) + expect(page.find(:css, "tbody > tr:nth-child(1)")).to have_content("Edward") + expect(page.find(:css, "tbody > tr:nth-child(2)")).to have_content("Robin") + + end + + scenario 'The user combine filters, sort and change page', js: true do + + visit admin_users_path + check 'boolean' + wait_for_ajax + expect(find(:css, '.email a.sortable')[:href]).to include("boolean") + click_link 'Email' + expect(page.find(:css, "tbody > tr:nth-child(2)")).to have_content("Lisa") + within(".pagination") { click_on "2" } + expect(page.find(:css, "tbody > tr:nth-child(1)")).to have_content("Robin") + expect(page.find(:css, '.count')).to have_content("4") + + end + +end diff --git a/spec/features/manage_items_spec.rb b/spec/features/manage_items_spec.rb index 1fea7ae..3607173 100644 --- a/spec/features/manage_items_spec.rb +++ b/spec/features/manage_items_spec.rb @@ -41,6 +41,6 @@ visit admin_users_path find('.change_name').click - expect(page).to_not have_content("Changed Name") + expect(page).to have_content("Changed Name") end end diff --git a/spec/features/view_items_spec.rb b/spec/features/view_items_spec.rb index c0b4442..00e2fb4 100644 --- a/spec/features/view_items_spec.rb +++ b/spec/features/view_items_spec.rb @@ -1,49 +1,44 @@ require 'rails_helper' feature 'View a list of items' do + fixtures :users scenario 'The user navigate through users', js: true do - 11.times { |i| User.create!(name: "Name#{i}", email: "Email#{i}") } visit root_path - - expect(page).to have_content("Name0") - expect(page).to_not have_content("Name10") + #page_sizes => [3, 10] + expect(page).to have_content("Betty") + expect(page).to_not have_content("Edward") within(".pagination") { click_on "2" } - expect(page).to have_content("Name10") - expect(page).to_not have_content("Name0") + expect(page).to have_content("Edward") + expect(page).to_not have_content("Betty") end scenario "The user sort users", js: true do - User.create(name: "aaaName", email: "bbbEmail") - User.create(name: "bbbName", email: "aaaEmail") visit sortable_users_path - expect(find(:xpath, "//table/tbody/tr[1]")).to have_content("bbbName") - expect(find(:xpath, "//table/tbody/tr[2]")).to have_content("aaaName") - find('.name a').click + expect(find(:xpath, "//table/tbody/tr[1]")).to have_content("Aaron") + expect(find(:xpath, "//table/tbody/tr[2]")).to have_content("Betty") - expect(find(:xpath, "//table/tbody/tr[1]")).to have_content("aaaName") - expect(find(:xpath, "//table/tbody/tr[2]")).to have_content("bbbName") + find('.name a').click + expect(find(:xpath, "//table/tbody/tr[1]")).to have_content("Sara") + expect(find(:xpath, "//table/tbody/tr[2]")).to have_content("Robin") end scenario "The user search user", js: true do - User.create(name: "Name1", email: "Email1") - User.create(name: "Name2", email: "Email2") - - visit searchable_users_path + visit admin_users_path - fill_in "filter", with: "1" + fill_in "filter", with: "ja" - expect(page).to have_content("Name1") - expect(page).to_not have_content("Name2") + expect(page).to have_content("Jane") + expect(page).to_not have_content("Aaron") - fill_in "filter", with: "3" + fill_in "filter", with: "ni" - expect(page).to_not have_content("Name1") - expect(page).to_not have_content("Name2") + expect(page).to_not have_content("Nicholas") + expect(page).to_not have_content("Jane") end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 4c69e00..11a1850 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -12,7 +12,8 @@ # run twice. It is recommended that you do not name files matching this glob to # end with _spec.rb. You can configure this pattern with the --pattern # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. -Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } + +Dir[Rails.root.join("../support/**/*.rb")].each { |f| require f } # Checks for pending migrations before tests are run. # If you are not using ActiveRecord, you can remove this line. @@ -20,7 +21,7 @@ RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{::Rails.root}/spec/fixtures" + config.fixture_path = "#{::Rails.root}/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false @@ -42,6 +43,8 @@ # https://relishapp.com/rspec/rspec-rails/docs config.infer_spec_type_from_file_location! + config.include WaitForAjax, type: :feature + config.before :each do DatabaseCleaner.start end diff --git a/spec/support/capybara/wait_for_ajax.rb b/spec/support/capybara/wait_for_ajax.rb new file mode 100644 index 0000000..b90fc11 --- /dev/null +++ b/spec/support/capybara/wait_for_ajax.rb @@ -0,0 +1,11 @@ +module WaitForAjax + def wait_for_ajax + Timeout.timeout(Capybara.default_max_wait_time) do + loop until finished_all_ajax_requests? + end + end + + def finished_all_ajax_requests? + page.evaluate_script('jQuery.active').zero? + end +end From a087e33ce4ee049235895dfafab82a0c794ce43b Mon Sep 17 00:00:00 2001 From: AakLak <30278646+AakLak@users.noreply.github.com> Date: Thu, 15 Feb 2018 00:40:01 -0800 Subject: [PATCH 18/20] Replace deprecated .any? with .present?. Closes #143 "DEPRECATION WARNING: Method any? is deprecated and will be removed in Rails 5.1, as ActionController::Parameters no longer inherits from hash. Using this deprecated behavior exposes potential security problems. If you continue to use this method you may be creating a security vulnerability in your app that can be exploited. Instead, consider using one of these documented methods which are not deprecated: http://api.rubyonrails.org/v5.0.0.rc1/classes/ActionController/Parameters.html" --- Changes.md | 1 + app/helpers/smart_listing/helper.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Changes.md b/Changes.md index a3e0d24..a05df8c 100644 --- a/Changes.md +++ b/Changes.md @@ -1,3 +1,4 @@ +- Replace deprecated .any? with .present? #143 [AakLak] - Development environment update #140 [mizinsky] - Fix sanitize_params method #137 [mizinsky] - Enable to configure global remote option and it to affects sortable helper #131 [kitabatake] diff --git a/app/helpers/smart_listing/helper.rb b/app/helpers/smart_listing/helper.rb index 8de25ee..707554a 100644 --- a/app/helpers/smart_listing/helper.rb +++ b/app/helpers/smart_listing/helper.rb @@ -312,7 +312,7 @@ def smart_listing_update *args smart_listing = @smart_listings[name] # don't update list if params are missing (prevents interfering with other lists) - if params.keys.select{|k| k.include?("smart_listing")}.any? && !params[smart_listing.base_param] + if params.keys.select{|k| k.include?("smart_listing")}.present? && !params[smart_listing.base_param] return unless options[:force] end From cce03033059980adcc5137f26fb2611071e74ed2 Mon Sep 17 00:00:00 2001 From: Nicolas Filzi Date: Sat, 10 Mar 2018 22:45:50 +0100 Subject: [PATCH 19/20] Remove duplicated href key from config template. Closes #146 --- Changes.md | 1 + lib/generators/smart_listing/templates/initializer.rb | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Changes.md b/Changes.md index a05df8c..df5b76d 100644 --- a/Changes.md +++ b/Changes.md @@ -1,3 +1,4 @@ +- Remove duplicated href key from config template #146 [nfilzi] - Replace deprecated .any? with .present? #143 [AakLak] - Development environment update #140 [mizinsky] - Fix sanitize_params method #137 [mizinsky] diff --git a/lib/generators/smart_listing/templates/initializer.rb b/lib/generators/smart_listing/templates/initializer.rb index 2665b0d..a2ba229 100644 --- a/lib/generators/smart_listing/templates/initializer.rb +++ b/lib/generators/smart_listing/templates/initializer.rb @@ -65,7 +65,6 @@ #:inline_edit_backup => "smart-listing-edit-backup", #:params => "params", #:observed => "observed", - #:href => "href", #:autoshow => "autoshow", #:popover => "slpopover", } From 4dbc51606505f0c64ce115d8c83f5b194559cef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jachymczyk?= Date: Sun, 11 Mar 2018 17:22:10 +0100 Subject: [PATCH 20/20] Version bump. --- Changes.md | 3 +++ lib/smart_listing/version.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changes.md b/Changes.md index df5b76d..b7af0c1 100644 --- a/Changes.md +++ b/Changes.md @@ -1,3 +1,6 @@ +1.2.2 +----------- + - Remove duplicated href key from config template #146 [nfilzi] - Replace deprecated .any? with .present? #143 [AakLak] - Development environment update #140 [mizinsky] diff --git a/lib/smart_listing/version.rb b/lib/smart_listing/version.rb index 11a0c93..058af58 100644 --- a/lib/smart_listing/version.rb +++ b/lib/smart_listing/version.rb @@ -1,3 +1,3 @@ module SmartListing - VERSION = "1.2.1" + VERSION = "1.2.2" end