diff --git a/Gemfile.lock b/Gemfile.lock index cab8805..188096f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,52 +10,86 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (5.1.4) - actionpack (= 5.1.4) + actioncable (7.2.0) + actionpack (= 7.2.0) + activesupport (= 7.2.0) nio4r (~> 2.0) - websocket-driver (~> 0.6.1) - actionmailer (5.1.4) - actionpack (= 5.1.4) - actionview (= 5.1.4) - activejob (= 5.1.4) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (5.1.4) - actionview (= 5.1.4) - activesupport (= 5.1.4) - rack (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (7.2.0) + actionpack (= 7.2.0) + activejob (= 7.2.0) + activerecord (= 7.2.0) + activestorage (= 7.2.0) + activesupport (= 7.2.0) + mail (>= 2.8.0) + actionmailer (7.2.0) + actionpack (= 7.2.0) + actionview (= 7.2.0) + activejob (= 7.2.0) + activesupport (= 7.2.0) + mail (>= 2.8.0) + rails-dom-testing (~> 2.2) + actionpack (7.2.0) + actionview (= 7.2.0) + activesupport (= 7.2.0) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4, < 3.2) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.4) - activesupport (= 5.1.4) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + useragent (~> 0.16) + actiontext (7.2.0) + actionpack (= 7.2.0) + activerecord (= 7.2.0) + activestorage (= 7.2.0) + activesupport (= 7.2.0) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.2.0) + activesupport (= 7.2.0) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.1.4) - activesupport (= 5.1.4) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.2.0) + activesupport (= 7.2.0) globalid (>= 0.3.6) - activemodel (5.1.4) - activesupport (= 5.1.4) - activerecord (5.1.4) - activemodel (= 5.1.4) - activesupport (= 5.1.4) - arel (~> 8.0) - activesupport (5.1.4) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) - minitest (~> 5.1) - tzinfo (~> 1.1) + activemodel (7.2.0) + activesupport (= 7.2.0) + activerecord (7.2.0) + activemodel (= 7.2.0) + activesupport (= 7.2.0) + timeout (>= 0.4.0) + activestorage (7.2.0) + actionpack (= 7.2.0) + activejob (= 7.2.0) + activerecord (= 7.2.0) + activesupport (= 7.2.0) + marcel (~> 1.0) + activesupport (7.2.0) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) - arel (8.0.0) - autoprefixer-rails (7.2.5) - execjs - bootstrap-sass (3.3.7) + autoprefixer-rails (10.4.19.0) + execjs (~> 2) + base64 (0.2.0) + bigdecimal (3.1.8) + bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) - sass (>= 3.3.4) - builder (3.2.3) + sassc (>= 2.0.0) + builder (3.3.0) byebug (9.1.0) capybara (2.13.0) addressable @@ -75,16 +109,19 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.0.5) - crass (1.0.3) + concurrent-ruby (1.3.4) + connection_pool (2.4.1) + crass (1.0.6) database_cleaner (1.6.2) + date (3.3.4) diff-lcs (1.3) - erubi (1.7.0) - execjs (2.7.0) - ffi (1.9.18) + drb (2.2.1) + erubi (1.13.0) + execjs (2.9.1) + ffi (1.17.0) formatador (0.2.5) - globalid (0.4.1) - activesupport (>= 4.2.0) + globalid (1.2.1) + activesupport (>= 6.1) guard (2.14.2) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) @@ -99,8 +136,12 @@ GEM guard (~> 2.1) guard-compat (~> 1.1) rspec (>= 2.99.0, < 4.0) - i18n (0.9.3) + i18n (1.14.5) concurrent-ruby (~> 1.0) + io-console (0.7.2) + irb (1.14.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) jquery-rails (4.3.3) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) @@ -122,60 +163,93 @@ GEM rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) ruby_dep (~> 1.2) - loofah (2.1.1) + logger (1.6.0) + loofah (2.22.0) crass (~> 1.0.2) - nokogiri (>= 1.5.9) + nokogiri (>= 1.12.0) lumberjack (1.0.12) - mail (2.7.0) + mail (2.8.1) mini_mime (>= 0.1.1) - method_source (0.9.0) + net-imap + net-pop + net-smtp + marcel (1.0.4) + method_source (0.9.2) mime-types (3.1) mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) - mini_mime (1.0.0) - mini_portile2 (2.3.0) - minitest (5.11.2) + mini_mime (1.1.5) + mini_portile2 (2.8.7) + minitest (5.25.1) nenv (0.3.0) - nio4r (2.3.1) - nokogiri (1.8.1) - mini_portile2 (~> 2.3.0) + net-imap (0.4.14) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.0) + net-protocol + nio4r (2.7.3) + nokogiri (1.16.7) + mini_portile2 (~> 2.8.2) + racc (~> 1.4) notiffany (0.1.1) nenv (~> 0.1) shellany (~> 0.0) pry (0.11.3) coderay (~> 1.1.0) method_source (~> 0.9.0) + psych (5.1.2) + stringio public_suffix (3.0.1) - rack (2.0.3) - rack-test (0.8.2) - rack (>= 1.0, < 3) - rails (5.1.4) - actioncable (= 5.1.4) - actionmailer (= 5.1.4) - actionpack (= 5.1.4) - actionview (= 5.1.4) - activejob (= 5.1.4) - activemodel (= 5.1.4) - activerecord (= 5.1.4) - activesupport (= 5.1.4) - bundler (>= 1.3.0) - railties (= 5.1.4) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + racc (1.8.1) + rack (3.1.7) + rack-session (2.0.0) + rack (>= 3.0.0) + rack-test (2.1.0) + rack (>= 1.3) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.2.0) + actioncable (= 7.2.0) + actionmailbox (= 7.2.0) + actionmailer (= 7.2.0) + actionpack (= 7.2.0) + actiontext (= 7.2.0) + actionview (= 7.2.0) + activejob (= 7.2.0) + activemodel (= 7.2.0) + activerecord (= 7.2.0) + activestorage (= 7.2.0) + activesupport (= 7.2.0) + bundler (>= 1.15.0) + railties (= 7.2.0) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - railties (5.1.4) - actionpack (= 5.1.4) - activesupport (= 5.1.4) - method_source - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (12.3.0) - rb-fsevent (0.10.2) - rb-inotify (0.9.10) - ffi (>= 0.5.0, < 2) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (7.2.0) + actionpack (= 7.2.0) + activesupport (= 7.2.0) + irb (~> 1.13) + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rake (13.2.1) + rb-fsevent (0.11.2) + rb-inotify (0.11.1) + ffi (~> 1.0) + rdoc (6.7.0) + psych (>= 4.0.0) + reline (0.5.9) + io-console (~> 0.5) rspec (3.7.0) rspec-core (~> 3.7.0) rspec-expectations (~> 3.7.0) @@ -198,29 +272,24 @@ GEM rspec-support (~> 3.7.0) rspec-support (3.7.0) ruby_dep (1.5.0) - sass (3.5.5) - sass-listen (~> 4.0.0) - sass-listen (4.0.0) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) + sassc (2.4.0) + ffi (~> 1.9) + securerandom (0.3.1) shellany (0.0.1) - sprockets (3.7.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) - sprockets (>= 3.0.0) sqlite3 (1.3.13) - thor (0.20.0) - thread_safe (0.3.6) - tzinfo (1.2.4) - thread_safe (~> 0.1) - websocket-driver (0.6.5) + stringio (3.1.1) + thor (1.3.1) + timeout (0.4.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + useragent (0.16.10) + webrick (1.8.1) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) + websocket-extensions (0.1.5) xpath (2.1.0) nokogiri (~> 1.3) + zeitwerk (2.6.17) PLATFORMS ruby diff --git a/app/helpers/smart_listing/helper.rb b/app/helpers/smart_listing/helper.rb index 707554a..b36810a 100644 --- a/app/helpers/smart_listing/helper.rb +++ b/app/helpers/smart_listing/helper.rb @@ -46,7 +46,7 @@ def name def paginate options = {} if @smart_listing.collection.respond_to? :current_page - @template.paginate @smart_listing.collection, {:remote => @smart_listing.remote?, :param_name => @smart_listing.param_name(:page)}.merge(@smart_listing.kaminari_options) + @template.paginate @smart_listing.collection, **{:remote => @smart_listing.remote?, :param_name => @smart_listing.param_name(:page)}.merge(@smart_listing.kaminari_options) end end diff --git a/lib/smart_listing.rb b/lib/smart_listing.rb index 329fd12..2534bcc 100644 --- a/lib/smart_listing.rb +++ b/lib/smart_listing.rb @@ -65,17 +65,6 @@ def setup params, cookies set_param(:per_page, @per_page, cookies) if @options[:memorize_per_page] - @count = @collection.size - @count = @count.length if @count.is_a?(Hash) - - # Reset @page if greater than total number of pages - if @per_page > 0 - no_pages = (@count.to_f / @per_page.to_f).ceil.to_i - if @page.to_i > no_pages - @page = no_pages - end - end - if @options[:array] if @sort && !@sort.empty? # when array we sort only by first attribute i = sort_keys.index{|x| x[0] == @sort.to_h.first[0]} @@ -109,7 +98,7 @@ def setup params, cookies else # let's sort by all attributes # - @collection = @collection.order(sort_keys.collect{|s| "#{s[1]} #{@sort[s[0]]}" if @sort[s[0]]}.compact) if @sort && !@sort.empty? + @collection = @collection.order(sort_keys.collect{|s| Arel.sql("#{s[1]} #{@sort[s[0]]}") if @sort[s[0]]}.compact) if @sort && !@sort.empty? if @options[:paginate] && @per_page > 0 @collection = @collection.page(@page).per(@per_page) diff --git a/spec/dummy/Gemfile.lock b/spec/dummy/Gemfile.lock index 7fa9a1e..ac83d51 100644 --- a/spec/dummy/Gemfile.lock +++ b/spec/dummy/Gemfile.lock @@ -4,7 +4,7 @@ PATH smart_listing (1.2.1) coffee-rails jquery-rails - kaminari (~> 0.17) + kaminari (>= 0.17) rails (>= 3.2) GEM @@ -50,11 +50,11 @@ GEM addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) arel (8.0.0) - autoprefixer-rails (7.2.5) - execjs - bootstrap-sass (3.3.7) + autoprefixer-rails (10.4.19.0) + execjs (~> 2) + bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) - sass (>= 3.3.4) + sassc (>= 2.0.0) builder (3.2.3) byebug (10.0.0) capybara (2.13.0) @@ -78,13 +78,14 @@ GEM concurrent-ruby (1.0.5) crass (1.0.3) database_cleaner (1.6.2) + date (3.3.4) diff-lcs (1.3) erubi (1.7.0) - execjs (2.7.0) - ffi (1.9.18) + execjs (2.9.1) + ffi (1.17.0) formatador (0.2.5) - globalid (0.4.1) - activesupport (>= 4.2.0) + globalid (1.1.0) + activesupport (>= 5.0) guard (2.14.2) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) @@ -101,14 +102,23 @@ GEM rspec (>= 2.99.0, < 4.0) i18n (0.9.3) concurrent-ruby (~> 1.0) - jquery-rails (4.3.1) + jquery-rails (4.6.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (2.1.0) - kaminari (0.17.0) - actionpack (>= 3.0.0) - activesupport (>= 3.0.0) + kaminari (1.2.2) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.2.2) + kaminari-activerecord (= 1.2.2) + kaminari-core (= 1.2.2) + kaminari-actionview (1.2.2) + actionview + kaminari-core (= 1.2.2) + kaminari-activerecord (1.2.2) + activerecord + kaminari-core (= 1.2.2) + kaminari-core (1.2.2) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -117,17 +127,29 @@ GEM crass (~> 1.0.2) nokogiri (>= 1.5.9) lumberjack (1.0.12) - mail (2.7.0) + mail (2.8.1) mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp method_source (0.9.0) mime-types (3.1) mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) - mini_mime (1.0.0) + mini_mime (1.1.5) mini_portile2 (2.3.0) minitest (5.11.1) nenv (0.3.0) - nio4r (2.2.0) + net-imap (0.4.14) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.0) + net-protocol + nio4r (2.7.3) nokogiri (1.8.1) mini_portile2 (~> 2.3.0) notiffany (0.1.1) @@ -164,9 +186,9 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (12.3.0) - rb-fsevent (0.10.2) - rb-inotify (0.9.10) - ffi (>= 0.5.0, < 2) + rb-fsevent (0.11.2) + rb-inotify (0.11.1) + ffi (~> 1.0) rspec (3.7.0) rspec-core (~> 3.7.0) rspec-expectations (~> 3.7.0) @@ -189,27 +211,25 @@ GEM rspec-support (~> 3.7.0) rspec-support (3.7.0) ruby_dep (1.5.0) - sass (3.5.5) - sass-listen (~> 4.0.0) - sass-listen (4.0.0) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) + sassc (2.4.0) + ffi (~> 1.9) shellany (0.0.1) - sprockets (3.7.1) + sprockets (4.1.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.1) + sprockets-rails (3.2.2) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.13) thor (0.20.0) thread_safe (0.3.6) + timeout (0.4.1) tzinfo (1.2.4) thread_safe (~> 0.1) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) + websocket-extensions (0.1.5) xpath (2.1.0) nokogiri (~> 1.3)