From 9b937c489d8ae7c215108c431f30de64393794ea Mon Sep 17 00:00:00 2001 From: Michael Roudnitski Date: Thu, 1 Feb 2024 18:38:19 -0500 Subject: [PATCH] feat: add extra_params option (#36) * feat: add extra_params option * Upgrade gem version * Upgrade to ruby 3.3 * Upgrade gem to 1.2.0 * Try older ruby * Try again * try try again until you succeed * Updates * Try rspec again * Syntax * Specs passing --- .github/workflows/lint.yml | 4 +- .github/workflows/rspec-tests.yml | 4 +- .tool-versions | 1 + Gemfile.lock | 329 ++++++++++-------- .../sn_filterable/main_component.html.erb | 3 + .../sn_filterable/main_component.rb | 4 +- lib/sn_filterable/version.rb | 2 +- sn_filterable.gemspec | 6 +- spec/dummy/.ruby-version | 1 - spec/dummy/config/application.rb | 4 +- spec/dummy/config/environments/development.rb | 8 - spec/dummy/config/initializers/assets.rb | 12 - spec/factories/filterables.rb | 2 +- spec/models/concerns/filterable_spec.rb | 14 +- spec/models/filtered_spec.rb | 78 ++--- 15 files changed, 251 insertions(+), 221 deletions(-) create mode 100644 .tool-versions delete mode 100644 spec/dummy/.ruby-version delete mode 100644 spec/dummy/config/initializers/assets.rb diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4b3e509..c3f6911 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,10 +6,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7.7 + ruby-version: 3.2 - name: rubocop uses: reviewdog/action-rubocop@v2 with: diff --git a/.github/workflows/rspec-tests.yml b/.github/workflows/rspec-tests.yml index 50fb473..bc85562 100644 --- a/.github/workflows/rspec-tests.yml +++ b/.github/workflows/rspec-tests.yml @@ -18,12 +18,12 @@ jobs: POSTGRES_DB: sn_filterable_test steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: + ruby-version: 3.2 bundler-cache: true - ruby-version: 2.7.7 - name: Setup Database env: RAILS_ENV: test diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..a3ec5a4 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +3.2 diff --git a/Gemfile.lock b/Gemfile.lock index 3db2056..04545e5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - sn_filterable (1.1.1) + sn_filterable (1.2.0) heroicon (~> 1) kaminari (~> 1) pg (~> 1) @@ -13,86 +13,110 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (6.1.7) - actionpack (= 6.1.7) - activesupport (= 6.1.7) + actioncable (7.1.3) + actionpack (= 7.1.3) + activesupport (= 7.1.3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.7) - actionpack (= 6.1.7) - activejob (= 6.1.7) - activerecord (= 6.1.7) - activestorage (= 6.1.7) - activesupport (= 6.1.7) + zeitwerk (~> 2.6) + actionmailbox (7.1.3) + actionpack (= 7.1.3) + activejob (= 7.1.3) + activerecord (= 7.1.3) + activestorage (= 7.1.3) + activesupport (= 7.1.3) mail (>= 2.7.1) - actionmailer (6.1.7) - actionpack (= 6.1.7) - actionview (= 6.1.7) - activejob (= 6.1.7) - activesupport (= 6.1.7) + net-imap + net-pop + net-smtp + actionmailer (7.1.3) + actionpack (= 7.1.3) + actionview (= 7.1.3) + activejob (= 7.1.3) + activesupport (= 7.1.3) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (6.1.7) - actionview (= 6.1.7) - activesupport (= 6.1.7) - rack (~> 2.0, >= 2.0.9) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.2) + actionpack (7.1.3) + actionview (= 7.1.3) + activesupport (= 7.1.3) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.7) - actionpack (= 6.1.7) - activerecord (= 6.1.7) - activestorage (= 6.1.7) - activesupport (= 6.1.7) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.3) + actionpack (= 7.1.3) + activerecord (= 7.1.3) + activestorage (= 7.1.3) + activesupport (= 7.1.3) + globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (6.1.7) - activesupport (= 6.1.7) + actionview (7.1.3) + activesupport (= 7.1.3) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.7) - activesupport (= 6.1.7) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.3) + activesupport (= 7.1.3) globalid (>= 0.3.6) - activemodel (6.1.7) - activesupport (= 6.1.7) - activerecord (6.1.7) - activemodel (= 6.1.7) - activesupport (= 6.1.7) - activestorage (6.1.7) - actionpack (= 6.1.7) - activejob (= 6.1.7) - activerecord (= 6.1.7) - activesupport (= 6.1.7) + activemodel (7.1.3) + activesupport (= 7.1.3) + activerecord (7.1.3) + activemodel (= 7.1.3) + activesupport (= 7.1.3) + timeout (>= 0.4.0) + activestorage (7.1.3) + actionpack (= 7.1.3) + activejob (= 7.1.3) + activerecord (= 7.1.3) + activesupport (= 7.1.3) marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (6.1.7) + activesupport (7.1.3) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) - zeitwerk (~> 2.3) ast (2.4.2) + base64 (0.2.0) + bigdecimal (3.1.6) builder (3.2.4) - concurrent-ruby (1.1.10) + concurrent-ruby (1.2.3) + connection_pool (2.4.1) crass (1.0.6) - date (3.3.3) + date (3.3.4) diff-lcs (1.5.0) - erubi (1.11.0) - factory_bot (6.2.1) + drb (2.2.0) + ruby2_keywords + erubi (1.12.0) + factory_bot (6.4.5) activesupport (>= 5.0.0) - factory_bot_rails (6.2.0) - factory_bot (~> 6.2.0) + factory_bot_rails (6.4.3) + factory_bot (~> 6.4) railties (>= 5.0.0) - faker (3.0.0) + faker (3.2.3) i18n (>= 1.8.11, < 2) - globalid (1.1.0) - activesupport (>= 5.0) + globalid (1.2.1) + activesupport (>= 6.1) heroicon (1.0.0) rails (>= 5.2) - i18n (1.12.0) + i18n (1.14.1) concurrent-ruby (~> 1.0) - json (2.6.3) + io-console (0.7.2) + irb (1.11.1) + rdoc + reline (>= 0.4.2) + json (2.7.1) kaminari (1.2.2) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.2) @@ -105,9 +129,10 @@ GEM activerecord kaminari-core (= 1.2.2) kaminari-core (1.2.2) - loofah (2.19.1) + language_server-protocol (3.17.0.3) + loofah (2.22.0) crass (~> 1.0.2) - nokogiri (>= 1.5.9) + nokogiri (>= 1.12.0) mail (2.8.1) mini_mime (>= 0.1.1) net-imap @@ -115,134 +140,154 @@ GEM net-smtp marcel (1.0.2) method_source (1.0.0) - mini_mime (1.1.2) - mini_portile2 (2.8.0) - minitest (5.16.3) - net-imap (0.3.6) + mini_mime (1.1.5) + mini_portile2 (2.8.5) + minitest (5.21.2) + mutex_m (0.2.0) + net-imap (0.4.9.1) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout - net-smtp (0.3.3) + net-smtp (0.4.0.1) net-protocol - nio4r (2.5.9) - nokogiri (1.13.10) - mini_portile2 (~> 2.8.0) + nio4r (2.7.0) + nokogiri (1.16.0) + mini_portile2 (~> 2.8.2) racc (~> 1.4) - parallel (1.22.1) - parser (3.1.3.0) + parallel (1.24.0) + parser (3.3.0.5) ast (~> 2.4.1) - pg (1.5.3) + racc + pg (1.5.4) pg_search (2.3.6) activerecord (>= 5.2) activesupport (>= 5.2) - racc (1.6.1) - rack (2.2.4) - rack-test (2.0.2) + psych (5.1.2) + stringio + racc (1.7.3) + rack (3.0.8) + rack-session (2.0.0) + rack (>= 3.0.0) + rack-test (2.1.0) rack (>= 1.3) - rails (6.1.7) - actioncable (= 6.1.7) - actionmailbox (= 6.1.7) - actionmailer (= 6.1.7) - actionpack (= 6.1.7) - actiontext (= 6.1.7) - actionview (= 6.1.7) - activejob (= 6.1.7) - activemodel (= 6.1.7) - activerecord (= 6.1.7) - activestorage (= 6.1.7) - activesupport (= 6.1.7) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.1.3) + actioncable (= 7.1.3) + actionmailbox (= 7.1.3) + actionmailer (= 7.1.3) + actionpack (= 7.1.3) + actiontext (= 7.1.3) + actionview (= 7.1.3) + activejob (= 7.1.3) + activemodel (= 7.1.3) + activerecord (= 7.1.3) + activestorage (= 7.1.3) + activesupport (= 7.1.3) bundler (>= 1.15.0) - railties (= 6.1.7) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + railties (= 7.1.3) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.4.4) - loofah (~> 2.19, >= 2.19.1) - railties (6.1.7) - actionpack (= 6.1.7) - activesupport (= 6.1.7) - method_source + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (7.1.3) + actionpack (= 7.1.3) + activesupport (= 7.1.3) + irb + rackup (>= 1.0.0) rake (>= 12.2) - thor (~> 1.0) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) rainbow (3.1.1) - rake (13.0.6) - regexp_parser (2.6.1) - rexml (3.2.5) - rspec-core (3.12.0) + rake (13.1.0) + rdoc (6.6.2) + psych (>= 4.0.0) + regexp_parser (2.9.0) + reline (0.4.2) + io-console (~> 0.5) + rexml (3.2.6) + rspec-core (3.12.2) rspec-support (~> 3.12.0) - rspec-expectations (3.12.0) + rspec-expectations (3.12.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-mocks (3.12.0) + rspec-mocks (3.12.6) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-rails (6.0.1) + rspec-rails (6.1.0) actionpack (>= 6.1) activesupport (>= 6.1) railties (>= 6.1) - rspec-core (~> 3.11) - rspec-expectations (~> 3.11) - rspec-mocks (~> 3.11) - rspec-support (~> 3.11) - rspec-support (3.12.0) - rubocop (1.39.0) + rspec-core (~> 3.12) + rspec-expectations (~> 3.12) + rspec-mocks (~> 3.12) + rspec-support (~> 3.12) + rspec-support (3.12.1) + rubocop (1.60.1) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.1.2.1) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.23.0, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.24.0) - parser (>= 3.1.1.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-capybara (2.20.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.25.1) + rubocop (~> 1.41) rubocop-github (0.20.0) rubocop (>= 1.37) rubocop-performance (>= 1.15) rubocop-rails (>= 2.17) - rubocop-performance (1.15.1) - rubocop (>= 1.7.0, < 2.0) - rubocop-ast (>= 0.4.0) - rubocop-rails (2.17.3) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-rails (2.23.1) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) - rubocop-rspec (2.15.0) - rubocop (~> 1.33) - ruby-progressbar (1.11.0) - sprockets (4.2.0) - concurrent-ruby (~> 1.0) - rack (>= 2.2.4, < 4) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - sprockets (>= 3.0.0) - tailwindcss-rails (2.0.29) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-rspec (2.26.1) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) + stringio (3.1.0) + tailwindcss-rails (2.3.0) railties (>= 6.0.0) - thor (1.2.1) - timeout (0.3.2) - turbo-rails (1.4.0) + thor (1.3.0) + timeout (0.4.1) + turbo-rails (1.5.0) actionpack (>= 6.0.0) activejob (>= 6.0.0) railties (>= 6.0.0) - tzinfo (2.0.5) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.3.0) - view_component (2.82.0) + unicode-display_width (2.5.0) + view_component (2.83.0) activesupport (>= 5.2.0, < 8.0) concurrent-ruby (~> 1.0) method_source (~> 1.0) - websocket-driver (0.7.5) + webrick (1.8.1) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - with_model (2.1.6) - activerecord (>= 5.2) - zeitwerk (2.6.6) + with_model (2.1.7) + activerecord (>= 6.0) + zeitwerk (2.6.12) PLATFORMS ruby @@ -260,4 +305,4 @@ DEPENDENCIES with_model (~> 2) BUNDLED WITH - 2.3.11 + 2.5.3 diff --git a/app/components/sn_filterable/main_component.html.erb b/app/components/sn_filterable/main_component.html.erb index 90fcf57..ad35cae 100644 --- a/app/components/sn_filterable/main_component.html.erb +++ b/app/components/sn_filterable/main_component.html.erb @@ -7,6 +7,9 @@ "data-turbo-frame": @frame_id, "class": "relative", "@submit": "filtersLoading = true" do %> + <% @extra_params.each do |k, v| %> + <%= content_tag :input, "", class: "hidden", type: "hidden", value: v, name: k %> + <% end %>
diff --git a/app/components/sn_filterable/main_component.rb b/app/components/sn_filterable/main_component.rb index 5b04d36..fff1735 100644 --- a/app/components/sn_filterable/main_component.rb +++ b/app/components/sn_filterable/main_component.rb @@ -24,7 +24,8 @@ class MainComponent < ViewComponent::Base # @param [String, nil] search_filter_name Optional, enable's and set's the search filter, specified by the filter's parameter name # @param [Boolean] show_sidebar If true, will show the sidebar with the filters. # @param [Boolean] update_url_on_submit If true, will update the URL in the user's browser on form submission. - def initialize(frame_id:, filtered:, filters:, url: nil, search_filter_name: nil, show_sidebar: true, update_url_on_submit: true) + # @param [Hash] extra_params Optional, allows for custom form values to be supplied. Useful if you need to retain non-filterable query params + def initialize(frame_id:, filtered:, filters:, url: nil, search_filter_name: nil, show_sidebar: true, update_url_on_submit: true, extra_params: {}) @frame_id = frame_id @filtered = filtered @filters = filters @@ -32,6 +33,7 @@ def initialize(frame_id:, filtered:, filters:, url: nil, search_filter_name: nil @search_filter_name = search_filter_name @show_sidebar = show_sidebar @update_url_on_submit = update_url_on_submit + @extra_params = extra_params end def search_field diff --git a/lib/sn_filterable/version.rb b/lib/sn_filterable/version.rb index f69afe6..c997043 100644 --- a/lib/sn_filterable/version.rb +++ b/lib/sn_filterable/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module SnFilterable - VERSION = "1.1.1" + VERSION = "1.2.0" end diff --git a/sn_filterable.gemspec b/sn_filterable.gemspec index f6da0af..c0c9c7b 100644 --- a/sn_filterable.gemspec +++ b/sn_filterable.gemspec @@ -5,14 +5,14 @@ require_relative "lib/sn_filterable/version" Gem::Specification.new do |spec| spec.name = "sn_filterable" spec.version = SnFilterable::VERSION - spec.authors = ["Chase McDougall"] - spec.email = ["chasemcdougall@hotmail.com"] + spec.authors = ["IBM Skills Network"] + spec.email = ["Skills.Network@ibm.com"] spec.summary = "Skills Network - Item filtering component" spec.description = "This gem adds a ViewComponent powered filtering component for searching and filtering your PostgreSQL data." spec.homepage = "https://github.com/ibm-skills-network/sn_filterable" spec.license = "MIT" - spec.required_ruby_version = ">= 2.7.0" + spec.required_ruby_version = ">= 3.2.0" spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = "https://github.com/ibm-skills-network/sn_filterable" diff --git a/spec/dummy/.ruby-version b/spec/dummy/.ruby-version deleted file mode 100644 index 338a5b5..0000000 --- a/spec/dummy/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -2.6.6 diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 48639f1..07e16f1 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -12,7 +12,7 @@ # require "action_text/engine" require "action_view/railtie" # require "action_cable/engine" -require "sprockets/railtie" +# require "sprockets/railtie" # require "rails/test_unit/railtie" # Require the gems listed in Gemfile, including any gems @@ -22,7 +22,7 @@ module Dummy class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 6.1 + config.load_defaults 7.0 # Configuration for the application, engines, and railties goes here. # diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb index 4ee5678..4eb6e68 100644 --- a/spec/dummy/config/environments/development.rb +++ b/spec/dummy/config/environments/development.rb @@ -45,14 +45,6 @@ # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true - # Debug mode disables concatenation and preprocessing of assets. - # This option may cause significant delays in view rendering with a large - # number of complex assets. - config.assets.debug = true - - # Suppress logger output for asset requests. - config.assets.quiet = true - # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true diff --git a/spec/dummy/config/initializers/assets.rb b/spec/dummy/config/initializers/assets.rb deleted file mode 100644 index 2eeef96..0000000 --- a/spec/dummy/config/initializers/assets.rb +++ /dev/null @@ -1,12 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Version of your assets, change this if you want to expire all your assets. -Rails.application.config.assets.version = "1.0" - -# Add additional assets to the asset load path. -# Rails.application.config.assets.paths << Emoji.images_path - -# Precompile additional assets. -# application.js, application.css, and all non-JS/CSS in the app/assets -# folder are already added. -# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/spec/factories/filterables.rb b/spec/factories/filterables.rb index 7e12e69..537891c 100644 --- a/spec/factories/filterables.rb +++ b/spec/factories/filterables.rb @@ -21,7 +21,7 @@ favorite_number { Faker::Number.unique.between(from: 0, to: 100_000) } end - factory :sort_with_explicit_reversed_filterable_test_model do + factory :sort_reversed_filterable_test do name { Faker::Name.unique.name } favorite_number { Faker::Number.unique.between(from: 0, to: 100_000) } end diff --git a/spec/models/concerns/filterable_spec.rb b/spec/models/concerns/filterable_spec.rb index 8b45d6a..28de450 100644 --- a/spec/models/concerns/filterable_spec.rb +++ b/spec/models/concerns/filterable_spec.rb @@ -300,7 +300,7 @@ end context "with an explicitly declared reversed sort" do - with_model :SortWithExplicitReversedFilterableTestModel, scope: :all do + with_model :SortReversedFilterableTest, scope: :all do table do |t| t.string :name t.integer :favorite_number @@ -309,7 +309,7 @@ model do include SnFilterable::Filterable - SortWithExplicitReversedFilterableTestModel::SORT_SCOPE_MAPPINGS = { # rubocop:disable RSpec/LeakyConstantDeclaration + SortReversedFilterableTest::SORT_SCOPE_MAPPINGS = { # rubocop:disable RSpec/LeakyConstantDeclaration "name": :sort_by_name }.freeze @@ -319,21 +319,21 @@ end before do - create_list(:sort_with_explicit_reversed_filterable_test_model, 10) + create_list(:sort_reversed_filterable_test, 10) end it "can sort" do - expected_items = SortWithExplicitReversedFilterableTestModel.order("name ASC").map(&:name) + expected_items = SortReversedFilterableTest.order("name ASC").map(&:name) - filtered = SortWithExplicitReversedFilterableTestModel.filter(params: ActionController::Parameters.new({ sort: "name", order: "asc" })) + filtered = SortReversedFilterableTest.filter(params: ActionController::Parameters.new({ sort: "name", order: "asc" })) expect(filtered.items.map(&:name)).to eq(expected_items) end it "can reverse sort" do - expected_items = SortWithExplicitReversedFilterableTestModel.order("favorite_number ASC").map(&:favorite_number) + expected_items = SortReversedFilterableTest.order("favorite_number ASC").map(&:favorite_number) - filtered = SortWithExplicitReversedFilterableTestModel.filter(params: ActionController::Parameters.new({ sort: "name", order: "desc" })) + filtered = SortReversedFilterableTest.filter(params: ActionController::Parameters.new({ sort: "name", order: "desc" })) expect(filtered.items.map(&:favorite_number)).to eq(expected_items) end diff --git a/spec/models/filtered_spec.rb b/spec/models/filtered_spec.rb index f4381eb..c53c651 100644 --- a/spec/models/filtered_spec.rb +++ b/spec/models/filtered_spec.rb @@ -46,29 +46,29 @@ describe "#set_filter_url" do it "creates a valid url when it has no parameters" do - expected_url = "/?filter[name]=test" + expected_url = "/?filter%5Bname%5D=test" actual_url = filtered.set_filter_url("/", "name", "test") expect(actual_url).to eq(expected_url) end it "creates a valid url when there is a conflicting filter" do - expected_url = "/?filter[name]=test" - actual_url = filtered.set_filter_url("/?filter[name]=123", "name", "test") + expected_url = "/?filter%5Bname%5D=test" + actual_url = filtered.set_filter_url("/?filter%5Bname%5D=123", "name", "test") expect(actual_url).to eq(expected_url) end it "creates a valid url when there is one filter" do - expected_url = "/?filter[name]=test" - actual_url = filtered.set_filter_url("/?filter[favorite_number]=123", "name", "test") + expected_url = "/?filter%5Bname%5D=test" + actual_url = filtered.set_filter_url("/?filter%5Bfavorite_number%5D=123", "name", "test") expect(actual_url).to eq(expected_url) end it "creates a valid url when there are multiple filters" do - expected_url = "/?filter[name]=test" - actual_url = filtered.set_filter_url("/?filter[favorite_number]=123&filter[created_at]=897", "name", "test") + expected_url = "/?filter%5Bname%5D=test" + actual_url = filtered.set_filter_url("/?filter%5Bfavorite_number%5D=123&filter%5Bcreated_at%5D=897", "name", "test") expect(actual_url).to eq(expected_url) end @@ -76,31 +76,31 @@ describe "#add_filter_url" do it "creates a valid url when there are no filters" do - expected_url = "/?filter[name]=test" + expected_url = "/?filter%5Bname%5D=test" actual_url = filtered.add_filter_url("/", "name", "test") expect(actual_url).to eq(expected_url) end it "creates a valid url when there is a conflicting filter" do - actual_url = filtered.add_filter_url("/?filter[name]=123", "name", "test") + actual_url = filtered.add_filter_url("/?filter%5Bname%5D=123", "name", "test") - expect(actual_url).to include("filter[name]=test") + expect(actual_url).to include("filter%5Bname%5D=test") end it "creates a valid url when there is one filter" do # rubocop:disable RSpec/MultipleExpectations - actual_url = filtered.add_filter_url("/?filter[favorite_number]=123", "name", "test") + actual_url = filtered.add_filter_url("/?filter%5Bfavorite_number%5D=123", "name", "test") - expect(actual_url).to include("filter[favorite_number]=123") - expect(actual_url).to include("filter[name]=test") + expect(actual_url).to include("filter%5Bfavorite_number%5D=123") + expect(actual_url).to include("filter%5Bname%5D=test") end it "creates a valid url when there are multiple filters" do # rubocop:disable RSpec/MultipleExpectations - actual_url = filtered.add_filter_url("/?filter[favorite_number]=123&filter[created_at]=897", "name", "test") + actual_url = filtered.add_filter_url("/?filter%5Bfavorite_number%5D=123&filter%5Bcreated_at%5D=897", "name", "test") - expect(actual_url).to include("filter[favorite_number]=123") - expect(actual_url).to include("filter[created_at]=897") - expect(actual_url).to include("filter[name]=test") + expect(actual_url).to include("filter%5Bfavorite_number%5D=123") + expect(actual_url).to include("filter%5Bcreated_at%5D=897") + expect(actual_url).to include("filter%5Bname%5D=test") end end @@ -114,24 +114,24 @@ it "creates a valid url when there is a matching filter" do expected_url = "/" - actual_url = filtered.remove_filter_url("/?filter[name]=123", "name") + actual_url = filtered.remove_filter_url("/?filter%5Bname%5D=123", "name") expect(actual_url).to eq(expected_url) end it "creates a valid url when there are no matching filters" do - expected_url = "/?filter[favorite_number]=123" - actual_url = filtered.remove_filter_url("/?filter[favorite_number]=123", "name") + expected_url = "/?filter%5Bfavorite_number%5D=123" + actual_url = filtered.remove_filter_url("/?filter%5Bfavorite_number%5D=123", "name") expect(actual_url).to eq(expected_url) end it "creates a valid url when there is a matching and multiple filters" do # rubocop:disable RSpec/MultipleExpectations - actual_url = filtered.remove_filter_url("/?filter[name]=123&filter[favorite_number]=123&filter[created_at]=897", "name") + actual_url = filtered.remove_filter_url("/?filter%5Bname%5D=123&filter%5Bfavorite_number%5D=123&filter%5Bcreated_at%5D=897", "name") - expect(actual_url).to include("filter[favorite_number]=123") - expect(actual_url).to include("filter[created_at]=897") - expect(actual_url).not_to include("filter[name]=test") + expect(actual_url).to include("filter%5Bfavorite_number%5D=123") + expect(actual_url).to include("filter%5Bcreated_at%5D=897") + expect(actual_url).not_to include("filter%5Bname%5D=test") end end @@ -145,24 +145,24 @@ it "creates a valid url when there is a matching filter" do expected_url = "/" - actual_url = filtered.remove_sub_filter_url("/?filter[name][]=123", "name", "123") + actual_url = filtered.remove_sub_filter_url("/?filter%5Bname%5D%5B%5D=123", "name", "123") expect(actual_url).to eq(expected_url) end it "creates a valid url when there are no matching filters" do - expected_url = "/?filter[favorite_number][]=123" - actual_url = filtered.remove_sub_filter_url("/?filter[favorite_number][]=123", "favorite_number", "456") + expected_url = "/?filter%5Bfavorite_number%5D%5B%5D=123" + actual_url = filtered.remove_sub_filter_url("/?filter%5Bfavorite_number%5D%5B%5D=123", "favorite_number", "456") expect(actual_url).to eq(expected_url) end it "creates a valid url when there is a matching and multiple filters" do # rubocop:disable RSpec/MultipleExpectations - actual_url = filtered.remove_sub_filter_url("/?filter[name][]=abc&filter[name][]=def&filter[name][]=ghi", "name", "abc") + actual_url = filtered.remove_sub_filter_url("/?filter%5Bname%5D%5B%5D=abc&filter%5Bname%5D%5B%5D=def&filter%5Bname%5D%5B%5D=ghi", "name", "abc") - expect(actual_url).not_to include("filter[name][]=abc") - expect(actual_url).to include("filter[name][]=def") - expect(actual_url).to include("filter[name][]=ghi") + expect(actual_url).not_to include("filter%5Bname%5D%5B%5D=abc") + expect(actual_url).to include("filter%5Bname%5D%5B%5D=def") + expect(actual_url).to include("filter%5Bname%5D%5B%5D=ghi") end end @@ -176,7 +176,7 @@ it "creates a valid url when there are filters" do expected_url = "/" - actual_url = filtered.clear_filter_url("/?filter[name]=test&filter[abc]=123") + actual_url = filtered.clear_filter_url("/?filter%5Bname%5D=test&filter%5Babc%5D=123") expect(actual_url).to eq(expected_url) end @@ -190,7 +190,7 @@ it "creates a valid url when there is sorting and filters" do expected_url = "/?sort=name&order=desc" - actual_url = filtered.clear_filter_url("/?filter[name]=test&filter[abc]=123&sort=name&order=desc") + actual_url = filtered.clear_filter_url("/?filter%5Bname%5D=test&filter%5Babc%5D=123&sort=name&order=desc") expect(actual_url).to eq(expected_url) end @@ -212,15 +212,15 @@ end it "creates a valid url when there are filters" do - expected_url = "/?filter[name]=test&filter[abc]=123" - actual_url = filtered.clear_sort_url("/?filter[name]=test&filter[abc]=123") + expected_url = "/?filter%5Bname%5D=test&filter%5Babc%5D=123" + actual_url = filtered.clear_sort_url("/?filter%5Bname%5D=test&filter%5Babc%5D=123") expect(actual_url).to eq(expected_url) end it "creates a valid url when there is sorting and filters" do - expected_url = "/?filter[name]=test&filter[abc]=123" - actual_url = filtered.clear_sort_url("/?filter[name]=test&filter[abc]=123&sort=name&order=desc") + expected_url = "/?filter%5Bname%5D=test&filter%5Babc%5D=123" + actual_url = filtered.clear_sort_url("/?filter%5Bname%5D=test&filter%5Babc%5D=123&sort=name&order=desc") expect(actual_url).to eq(expected_url) end @@ -243,14 +243,14 @@ it "creates an empty url when there are filters" do expected_url = "/" - actual_url = filtered.clear_all_url("/?filter[name]=test&filter[abc]=123") + actual_url = filtered.clear_all_url("/?filter%5Bname%5D=test&filter%5Babc%5D=123") expect(actual_url).to eq(expected_url) end it "creates an empty url when there is sorting and filters" do expected_url = "/" - actual_url = filtered.clear_all_url("/?filter[name]=test&filter[abc]=123&sort=name&order=desc") + actual_url = filtered.clear_all_url("/?filter%5Bname%5D=test&filter%5Babc%5D=123&sort=name&order=desc") expect(actual_url).to eq(expected_url) end