From 09540192c96d2ed35accf0b34f3acd9d04170727 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 14 Apr 2017 21:09:55 -0400 Subject: [PATCH] Rename admin/accounts_helper to admin/filter_helper (#1816) - Add some spec coverage for both methods - Add explicit constant call-outs for where the params are from --- .../{accounts_helper.rb => filter_helper.rb} | 13 ++++++++---- spec/helpers/admin/accounts_helper_spec.rb | 5 ----- spec/helpers/admin/filter_helper_spec.rb | 20 +++++++++++++++++++ 3 files changed, 29 insertions(+), 9 deletions(-) rename app/helpers/admin/{accounts_helper.rb => filter_helper.rb} (70%) delete mode 100644 spec/helpers/admin/accounts_helper_spec.rb create mode 100644 spec/helpers/admin/filter_helper_spec.rb diff --git a/app/helpers/admin/accounts_helper.rb b/app/helpers/admin/filter_helper.rb similarity index 70% rename from app/helpers/admin/accounts_helper.rb rename to app/helpers/admin/filter_helper.rb index 497abf80db..591056dd78 100644 --- a/app/helpers/admin/accounts_helper.rb +++ b/app/helpers/admin/filter_helper.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true -module Admin::AccountsHelper - def filter_params(more_params) - params.permit(:local, :remote, :by_domain, :silenced, :suspended, :recent, :resolved).merge(more_params) - end +module Admin::FilterHelper + ACCOUNT_FILTERS = %i[local remote by_domain silenced suspended recent].freeze + REPORT_FILTERS = %i[resolved].freeze + + FILTERS = ACCOUNT_FILTERS + REPORT_FILTERS def filter_link_to(text, more_params) new_url = filtered_url_for(more_params) @@ -16,6 +17,10 @@ module Admin::AccountsHelper private + def filter_params(more_params) + params.permit(FILTERS).merge(more_params) + end + def filter_link_class(new_url) filtered_url_for(params) == new_url ? 'selected' : '' end diff --git a/spec/helpers/admin/accounts_helper_spec.rb b/spec/helpers/admin/accounts_helper_spec.rb deleted file mode 100644 index b91f258b3a..0000000000 --- a/spec/helpers/admin/accounts_helper_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Admin::AccountsHelper, type: :helper do - -end diff --git a/spec/helpers/admin/filter_helper_spec.rb b/spec/helpers/admin/filter_helper_spec.rb new file mode 100644 index 0000000000..9d4ea28294 --- /dev/null +++ b/spec/helpers/admin/filter_helper_spec.rb @@ -0,0 +1,20 @@ +require 'rails_helper' + +describe Admin::FilterHelper do + it 'Uses filter_link_to to create filter links' do + params = ActionController::Parameters.new( + { test: 'test' } + ) + allow(helper).to receive(:params).and_return(params) + allow(helper).to receive(:url_for).and_return('/test') + result = helper.filter_link_to('text', { resolved: true }) + + expect(result).to match(/text/) + end + + it 'Uses table_link_to to create icon links' do + result = helper.table_link_to 'icon', 'text', 'path' + + expect(result).to match(/text/) + end +end