From 6b9d0208623ca59b682e1d434187c2b30b507a89 Mon Sep 17 00:00:00 2001 From: GeorgeGorbanev Date: Sat, 22 Jun 2019 00:02:02 +0300 Subject: [PATCH 1/9] add vacancies#index remote_filter html --- apps/web/templates/vacancies/index.html.slim | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/web/templates/vacancies/index.html.slim b/apps/web/templates/vacancies/index.html.slim index 8ffe92b..bb610ee 100644 --- a/apps/web/templates/vacancies/index.html.slim +++ b/apps/web/templates/vacancies/index.html.slim @@ -13,13 +13,22 @@ hr br -.row.mt-3.mb-3 +.row.mt-3 .col-sm-6 h4 Еженедельная рассылка новых вакансий p Подпишитесь на рассылку, что бы быть в курсе новых вакансий, появляющихся на сайте. .col-sm-6 = subscribe_form +.row.mb-3 + .col + .btn-group.btn-group-toggle data-toggle="buttons" + label.btn.btn-light.active + input type="radio" name="remote_filter" id="all" checked="all" Любые + label.btn.btn-light + input type="radio" name="remote_filter" id="only-remote" checked="only-remote" Удаленные + label.btn.btn-light + input type="radio" name="remote_filter" id="not-remote" checked="not-remote" В офисе /hr /.row.mt-3.mb-3 From 6b32e2d354c6d52619f356deac50884efaedcb84 Mon Sep 17 00:00:00 2001 From: GeorgeGorbanev Date: Sat, 22 Jun 2019 03:02:19 +0300 Subject: [PATCH 2/9] radiobutton link --- apps/web/controllers/vacancies/index.rb | 6 ++++++ apps/web/templates/vacancies/index.html.slim | 13 +++++-------- apps/web/views/vacancies/index.rb | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/apps/web/controllers/vacancies/index.rb b/apps/web/controllers/vacancies/index.rb index 4313484..0b3a026 100644 --- a/apps/web/controllers/vacancies/index.rb +++ b/apps/web/controllers/vacancies/index.rb @@ -16,10 +16,12 @@ class Index expose :vacancies expose :pager + expose :remote_filter_param params do optional(:page).filled optional(:query).filled + optional(:remote_filter).filled end def call(params) @@ -37,6 +39,10 @@ def call(params) def search_query params[:query] ? search_query_parser.call(params[:query]) : EMPTY_SEARCH_QUERY end + + def remote_filter_param + @remote_filter_param ||= (params[:remote_filter] || 'all') + end end end end diff --git a/apps/web/templates/vacancies/index.html.slim b/apps/web/templates/vacancies/index.html.slim index bb610ee..3904c39 100644 --- a/apps/web/templates/vacancies/index.html.slim +++ b/apps/web/templates/vacancies/index.html.slim @@ -13,7 +13,7 @@ hr br -.row.mt-3 +.row.mt-3.mb-3 .col-sm-6 h4 Еженедельная рассылка новых вакансий p Подпишитесь на рассылку, что бы быть в курсе новых вакансий, появляющихся на сайте. @@ -22,13 +22,10 @@ br .row.mb-3 .col - .btn-group.btn-group-toggle data-toggle="buttons" - label.btn.btn-light.active - input type="radio" name="remote_filter" id="all" checked="all" Любые - label.btn.btn-light - input type="radio" name="remote_filter" id="only-remote" checked="only-remote" Удаленные - label.btn.btn-light - input type="radio" name="remote_filter" id="not-remote" checked="not-remote" В офисе + .btn-group.btn-group-toggle + = remote_filter_button(text: 'Любые', filter: 'all') + = remote_filter_button(text: 'Удаленные', filter: 'only-remote') + = remote_filter_button(text: 'В офисе', filter: 'not-remote') /hr /.row.mt-3.mb-3 diff --git a/apps/web/views/vacancies/index.rb b/apps/web/views/vacancies/index.rb index eb81d95..4b12ae2 100644 --- a/apps/web/views/vacancies/index.rb +++ b/apps/web/views/vacancies/index.rb @@ -37,6 +37,22 @@ def subscribe_form # rubocop:disable Metrics/MethodLength end end end + + def remote_filter_button(text:, filter:) + link_params = {} + + if filter == remote_filter_param + link_params[:class] = "btn btn-light active" + else + link_params[:class] = "btn btn-light" + link_params[:href] = routes.root_path(remote_filter: filter) + end + + html.a(link_params) do + html.input(type: 'radio') + html.span { text } + end + end end end end From 98b66182b499f94362dfb51ea56511775e0f6e55 Mon Sep 17 00:00:00 2001 From: GeorgeGorbanev Date: Sat, 22 Jun 2019 03:25:17 +0300 Subject: [PATCH 3/9] query --- apps/web/controllers/vacancies/index.rb | 10 +++++++-- apps/web/templates/vacancies/index.html.slim | 2 +- lib/core/queries/vacancy.rb | 22 +++++++++++++------- lib/vacancies/operations/list.rb | 4 ++-- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/apps/web/controllers/vacancies/index.rb b/apps/web/controllers/vacancies/index.rb index 0b3a026..0ff991a 100644 --- a/apps/web/controllers/vacancies/index.rb +++ b/apps/web/controllers/vacancies/index.rb @@ -13,6 +13,7 @@ class Index ] EMPTY_SEARCH_QUERY = {}.freeze + REMOTE_FILTER_PARAMS = ['none', 'only-remote', 'not-remote'].freeze expose :vacancies expose :pager @@ -25,7 +26,7 @@ class Index end def call(params) - result = operation.call(search_query: search_query, page: params[:page]) + result = operation.call(search_query: search_query, page: params[:page], remote_filter: remote_filter_param) case result when Success @@ -41,7 +42,12 @@ def search_query end def remote_filter_param - @remote_filter_param ||= (params[:remote_filter] || 'all') + @remote_filter_param ||= + if REMOTE_FILTER_PARAMS.include?(params[:remote_filter]) + params[:remote_filter] + else + 'none' + end end end end diff --git a/apps/web/templates/vacancies/index.html.slim b/apps/web/templates/vacancies/index.html.slim index 3904c39..a699d5c 100644 --- a/apps/web/templates/vacancies/index.html.slim +++ b/apps/web/templates/vacancies/index.html.slim @@ -23,7 +23,7 @@ br .row.mb-3 .col .btn-group.btn-group-toggle - = remote_filter_button(text: 'Любые', filter: 'all') + = remote_filter_button(text: 'Любые', filter: 'none') = remote_filter_button(text: 'Удаленные', filter: 'only-remote') = remote_filter_button(text: 'В офисе', filter: 'not-remote') /hr diff --git a/lib/core/queries/vacancy.rb b/lib/core/queries/vacancy.rb index 7e58ace..c9e4d17 100644 --- a/lib/core/queries/vacancy.rb +++ b/lib/core/queries/vacancy.rb @@ -8,8 +8,8 @@ def initialize(repo = VacancyRepository.new) @repo = repo end - def all_with_contact(limit:, page:) - all_with_contact_relation(limit: limit, page: page).to_a + def all_with_contact(limit:, page:, remote_filter: '') + all_with_contact_relation(limit: limit, page: page, remote_filter: remote_filter).to_a end def pager_for_all_with_contact(limit:, page:) @@ -20,11 +20,19 @@ def pager_for_all_with_contact(limit:, page:) private - def all_with_contact_relation(limit:, page:) - repo.aggregate(:contact) - .where(published: true, archived: false, deleted_at: nil) - .map_to(::Vacancy).order { created_at.desc } - .per_page(limit).page(page || 1) + def all_with_contact_relation(limit:, page:, remote_filter:) + relation = repo.aggregate(:contact) + .where(published: true, archived: false, deleted_at: nil) + .map_to(::Vacancy).order { created_at.desc } + .per_page(limit).page(page || 1) + + if remote_filter == 'only-remote' + relation = relation.where(remote_available: true) + elsif remote_filter == 'not-remote' + relation = relation.where(remote_available: false) + end + + relation end end end diff --git a/lib/vacancies/operations/list.rb b/lib/vacancies/operations/list.rb index ff42984..507e210 100644 --- a/lib/vacancies/operations/list.rb +++ b/lib/vacancies/operations/list.rb @@ -9,9 +9,9 @@ class List < ::Libs::Operation PAGINATION_LIMIT = 10 - def call(search_query: {}, page: 1) # rubocop:disable Lint/UnusedMethodArgument + def call(search_query: {}, page: 1, remote_filter: '') # rubocop:disable Lint/UnusedMethodArgument pager = vacancy_query.pager_for_all_with_contact(limit: PAGINATION_LIMIT, page: page || 1) - result = vacancy_query.all_with_contact(limit: PAGINATION_LIMIT, page: page || 1) + result = vacancy_query.all_with_contact(limit: PAGINATION_LIMIT, page: page || 1, remote_filter: remote_filter) Success(result: result, pager: pager) end From a227dd9b12817b5bf5b407b2fb2a90b56b1c7e78 Mon Sep 17 00:00:00 2001 From: GeorgeGorbanev Date: Sat, 22 Jun 2019 03:31:58 +0300 Subject: [PATCH 4/9] remote available --- lib/core/queries/vacancy.rb | 20 +++++++++----------- lib/vacancies/operations/list.rb | 11 +++++++++-- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/core/queries/vacancy.rb b/lib/core/queries/vacancy.rb index c9e4d17..3a40e33 100644 --- a/lib/core/queries/vacancy.rb +++ b/lib/core/queries/vacancy.rb @@ -8,8 +8,8 @@ def initialize(repo = VacancyRepository.new) @repo = repo end - def all_with_contact(limit:, page:, remote_filter: '') - all_with_contact_relation(limit: limit, page: page, remote_filter: remote_filter).to_a + def all_with_contact(limit:, page:, remote_available: nil) + all_with_contact_relation(limit: limit, page: page, remote_available: remote_available).to_a end def pager_for_all_with_contact(limit:, page:) @@ -20,16 +20,14 @@ def pager_for_all_with_contact(limit:, page:) private - def all_with_contact_relation(limit:, page:, remote_filter:) + def all_with_contact_relation(limit:, page:, remote_available:) relation = repo.aggregate(:contact) - .where(published: true, archived: false, deleted_at: nil) - .map_to(::Vacancy).order { created_at.desc } - .per_page(limit).page(page || 1) - - if remote_filter == 'only-remote' - relation = relation.where(remote_available: true) - elsif remote_filter == 'not-remote' - relation = relation.where(remote_available: false) + .where(published: true, archived: false, deleted_at: nil) + .map_to(::Vacancy).order { created_at.desc } + .per_page(limit).page(page || 1) + + unless remote_available.nil? + relation = relation.where(remote_available: remote_available) end relation diff --git a/lib/vacancies/operations/list.rb b/lib/vacancies/operations/list.rb index 507e210..bbc464b 100644 --- a/lib/vacancies/operations/list.rb +++ b/lib/vacancies/operations/list.rb @@ -9,9 +9,16 @@ class List < ::Libs::Operation PAGINATION_LIMIT = 10 - def call(search_query: {}, page: 1, remote_filter: '') # rubocop:disable Lint/UnusedMethodArgument + def call(search_query: {}, page: 1, remote_filter: 'none') # rubocop:disable Lint/UnusedMethodArgument + remote_available = + case remote_filter + when 'only-remote' then true + when 'not-remote' then false + else nil + end + pager = vacancy_query.pager_for_all_with_contact(limit: PAGINATION_LIMIT, page: page || 1) - result = vacancy_query.all_with_contact(limit: PAGINATION_LIMIT, page: page || 1, remote_filter: remote_filter) + result = vacancy_query.all_with_contact(limit: PAGINATION_LIMIT, page: page || 1, remote_available: remote_available) Success(result: result, pager: pager) end From a10cc7c596398f7143694846ee84512bbe3e900f Mon Sep 17 00:00:00 2001 From: GeorgeGorbanev Date: Sat, 22 Jun 2019 03:35:00 +0300 Subject: [PATCH 5/9] pager --- lib/core/queries/vacancy.rb | 4 ++-- lib/vacancies/operations/list.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core/queries/vacancy.rb b/lib/core/queries/vacancy.rb index 3a40e33..00b1821 100644 --- a/lib/core/queries/vacancy.rb +++ b/lib/core/queries/vacancy.rb @@ -12,9 +12,9 @@ def all_with_contact(limit:, page:, remote_available: nil) all_with_contact_relation(limit: limit, page: page, remote_available: remote_available).to_a end - def pager_for_all_with_contact(limit:, page:) + def pager_for_all_with_contact(limit:, page:, remote_available: nil) Hanami::Pagination::Pager.new( - all_with_contact_relation(limit: limit, page: page).pager + all_with_contact_relation(limit: limit, page: page, remote_available: remote_available).pager ) end diff --git a/lib/vacancies/operations/list.rb b/lib/vacancies/operations/list.rb index bbc464b..64d5301 100644 --- a/lib/vacancies/operations/list.rb +++ b/lib/vacancies/operations/list.rb @@ -17,7 +17,7 @@ def call(search_query: {}, page: 1, remote_filter: 'none') # rubocop:disable Lin else nil end - pager = vacancy_query.pager_for_all_with_contact(limit: PAGINATION_LIMIT, page: page || 1) + pager = vacancy_query.pager_for_all_with_contact(limit: PAGINATION_LIMIT, page: page || 1, remote_available: remote_available) result = vacancy_query.all_with_contact(limit: PAGINATION_LIMIT, page: page || 1, remote_available: remote_available) Success(result: result, pager: pager) From 131b5e4fc5554a24941159c1d5764f59b2704fb8 Mon Sep 17 00:00:00 2001 From: GeorgeGorbanev Date: Sat, 22 Jun 2019 18:35:16 +0300 Subject: [PATCH 6/9] remote query --- apps/web/controllers/vacancies/index.rb | 15 ++------------- apps/web/templates/vacancies/index.html.slim | 6 +++--- apps/web/views/vacancies/index.rb | 19 ++++++++++--------- lib/vacancies/operations/list.rb | 10 ++-------- 4 files changed, 17 insertions(+), 33 deletions(-) diff --git a/apps/web/controllers/vacancies/index.rb b/apps/web/controllers/vacancies/index.rb index 0ff991a..a57a152 100644 --- a/apps/web/controllers/vacancies/index.rb +++ b/apps/web/controllers/vacancies/index.rb @@ -13,20 +13,18 @@ class Index ] EMPTY_SEARCH_QUERY = {}.freeze - REMOTE_FILTER_PARAMS = ['none', 'only-remote', 'not-remote'].freeze expose :vacancies expose :pager - expose :remote_filter_param params do optional(:page).filled optional(:query).filled - optional(:remote_filter).filled + optional(:remote).filled end def call(params) - result = operation.call(search_query: search_query, page: params[:page], remote_filter: remote_filter_param) + result = operation.call(search_query: search_query, page: params[:page], remote_query: params[:remote]) case result when Success @@ -40,15 +38,6 @@ def call(params) def search_query params[:query] ? search_query_parser.call(params[:query]) : EMPTY_SEARCH_QUERY end - - def remote_filter_param - @remote_filter_param ||= - if REMOTE_FILTER_PARAMS.include?(params[:remote_filter]) - params[:remote_filter] - else - 'none' - end - end end end end diff --git a/apps/web/templates/vacancies/index.html.slim b/apps/web/templates/vacancies/index.html.slim index a699d5c..edc11f0 100644 --- a/apps/web/templates/vacancies/index.html.slim +++ b/apps/web/templates/vacancies/index.html.slim @@ -23,9 +23,9 @@ br .row.mb-3 .col .btn-group.btn-group-toggle - = remote_filter_button(text: 'Любые', filter: 'none') - = remote_filter_button(text: 'Удаленные', filter: 'only-remote') - = remote_filter_button(text: 'В офисе', filter: 'not-remote') + = remote_filter_button(text: 'Любые', remote_value: nil) + = remote_filter_button(text: 'Удаленные', remote_value: 'true') + = remote_filter_button(text: 'В офисе', remote_value: 'false') /hr /.row.mt-3.mb-3 diff --git a/apps/web/views/vacancies/index.rb b/apps/web/views/vacancies/index.rb index 4b12ae2..da75d94 100644 --- a/apps/web/views/vacancies/index.rb +++ b/apps/web/views/vacancies/index.rb @@ -38,15 +38,16 @@ def subscribe_form # rubocop:disable Metrics/MethodLength end end - def remote_filter_button(text:, filter:) - link_params = {} - - if filter == remote_filter_param - link_params[:class] = "btn btn-light active" - else - link_params[:class] = "btn btn-light" - link_params[:href] = routes.root_path(remote_filter: filter) - end + def remote_filter_button(text:, remote_value:) + link_params = + if remote_value == params[:remote] + { class: 'btn btn-light active' } + else + { + class: 'btn btn-light', + href: routes.root_path(remote_value.nil? ? {} : { remote: remote_value }) + } + end html.a(link_params) do html.input(type: 'radio') diff --git a/lib/vacancies/operations/list.rb b/lib/vacancies/operations/list.rb index 64d5301..adb3de2 100644 --- a/lib/vacancies/operations/list.rb +++ b/lib/vacancies/operations/list.rb @@ -9,14 +9,8 @@ class List < ::Libs::Operation PAGINATION_LIMIT = 10 - def call(search_query: {}, page: 1, remote_filter: 'none') # rubocop:disable Lint/UnusedMethodArgument - remote_available = - case remote_filter - when 'only-remote' then true - when 'not-remote' then false - else nil - end - + def call(search_query: {}, page: 1, remote_query: nil) # rubocop:disable Lint/UnusedMethodArgument + remote_available = { 'true' => true, 'false' => false }[remote_query] pager = vacancy_query.pager_for_all_with_contact(limit: PAGINATION_LIMIT, page: page || 1, remote_available: remote_available) result = vacancy_query.all_with_contact(limit: PAGINATION_LIMIT, page: page || 1, remote_available: remote_available) From e11022c343c6b9e307bce215871d47fd3ec94273 Mon Sep 17 00:00:00 2001 From: GeorgeGorbanev Date: Sat, 22 Jun 2019 19:58:52 +0300 Subject: [PATCH 7/9] spec --- apps/web/views/vacancies/index.rb | 8 ++- spec/core/queries/vacancy_spec.rb | 11 +++- spec/vacancies/operations/list_spec.rb | 50 +++++++++++++++ spec/web/controllers/vacancies/index_spec.rb | 10 ++- spec/web/views/vacancies/index_spec.rb | 65 +++++++++++++++++++- 5 files changed, 137 insertions(+), 7 deletions(-) diff --git a/apps/web/views/vacancies/index.rb b/apps/web/views/vacancies/index.rb index da75d94..11d5a62 100644 --- a/apps/web/views/vacancies/index.rb +++ b/apps/web/views/vacancies/index.rb @@ -40,7 +40,7 @@ def subscribe_form # rubocop:disable Metrics/MethodLength def remote_filter_button(text:, remote_value:) link_params = - if remote_value == params[:remote] + if remote_value == current_remote_query { class: 'btn btn-light active' } else { @@ -54,6 +54,12 @@ def remote_filter_button(text:, remote_value:) html.span { text } end end + + private + + def current_remote_query + params[:remote] if ['true', 'false'].include?(params[:remote]) + end end end end diff --git a/spec/core/queries/vacancy_spec.rb b/spec/core/queries/vacancy_spec.rb index 72700a0..ea08730 100644 --- a/spec/core/queries/vacancy_spec.rb +++ b/spec/core/queries/vacancy_spec.rb @@ -4,9 +4,11 @@ let(:repo) { described_class.new } describe '#all_with_contact' do - subject { repo.all_with_contact(limit: 10, page: 1) } + subject { repo.all_with_contact(limit: 10, page: 1, remote_available: remote_available) } - before { Fabricate.create(:vacancy, published: published, archived: archived, deleted_at: deleted_at) } + let(:remote_available) { nil } + + before { Fabricate.create(:vacancy, published: published, archived: archived, deleted_at: deleted_at, remote_available: false) } context 'when vacancy published and not archived or deleted' do let(:published) { true } @@ -16,6 +18,11 @@ it { expect(subject.count).to eq(1) } it { expect(subject).to all(be_a(Vacancy)) } it { expect(subject.first.contact).to be_a(Contact) } + + context 'when remote_available is true' do + let(:remote_available) { true } + it { expect(subject).to eq([]) } + end end context 'when vacancy published and archived' do diff --git a/spec/vacancies/operations/list_spec.rb b/spec/vacancies/operations/list_spec.rb index 6d7414b..68d9845 100644 --- a/spec/vacancies/operations/list_spec.rb +++ b/spec/vacancies/operations/list_spec.rb @@ -25,6 +25,56 @@ it { expect(subject.value!).to eq(result: [], pager: pager) } end + context 'with remote query' do + let(:vacancies) { [] } + + subject { operation.call(remote_query: remote_query) } + + context 'when remote_query nil' do + let(:remote_query) { nil } + + it do + expect(vacancy_query) + .to receive(:all_with_contact) + .with(limit: 10, page: 1, remote_available: nil) + subject + end + end + + context 'when remote_query not true or false string' do + let(:remote_query) { 'not true or false string' } + + it do + expect(vacancy_query) + .to receive(:all_with_contact) + .with(limit: 10, page: 1, remote_available: nil) + subject + end + end + + context 'when remote_query true' do + let(:remote_query) { 'true' } + + it do + expect(vacancy_query) + .to receive(:all_with_contact) + .with(limit: 10, page: 1, remote_available: true) + subject + end + end + + context 'when remote_query false' do + let(:remote_query) { 'false' } + + it do + expect(vacancy_query) + .to receive(:all_with_contact) + .with(limit: 10, page: 1, remote_available: false) + subject + end + end + end + context 'with real dependencies' do subject { operation.call } diff --git a/spec/web/controllers/vacancies/index_spec.rb b/spec/web/controllers/vacancies/index_spec.rb index cb7b39e..290ecd3 100644 --- a/spec/web/controllers/vacancies/index_spec.rb +++ b/spec/web/controllers/vacancies/index_spec.rb @@ -18,13 +18,17 @@ expect(action.pager).to eq(pager) end - context 'when params inlcludes query param' do - let(:params) { { query: 'remote:true search text' } } + context 'when params includes query param' do + let(:params) { { query: 'remote:true search text', remote: 'remote_query' } } it { expect(subject).to be_success } it do - expect(operation).to receive(:call).with(page: nil, search_query: { remote: 'true', text: 'search text' }) + expect(operation).to receive(:call).with( + page: nil, + search_query: { remote: 'true', text: 'search text' }, + remote_query: 'remote_query' + ) subject end end diff --git a/spec/web/views/vacancies/index_spec.rb b/spec/web/views/vacancies/index_spec.rb index ad2b059..8343d6c 100644 --- a/spec/web/views/vacancies/index_spec.rb +++ b/spec/web/views/vacancies/index_spec.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true RSpec.describe Web::Views::Vacancies::Index, type: :view do - let(:exposures) { Hash[format: :html] } + let(:params) { Hash[] } + let(:exposures) { Hash[format: :html, flash: {}, vacancies: [], params: params] } let(:template) { Hanami::View::Template.new('apps/web/templates/vacancies/index.html.slim') } let(:view) { described_class.new(template, exposures) } let(:rendered) { view.render } @@ -9,4 +10,66 @@ it 'exposes #format' do expect(view.format).to eq exposures.fetch(:format) end + + describe 'remote radiobuttons' do + let(:rendered) { without_indentation(view.render) } + + before { allow(view).to receive(:pagination) } + + it do + expect(rendered).to include without_indentation <<~HTML + + HTML + end + + context 'when remote is true' do + let(:params) { Hash[remote: 'true'] } + + it do + expect(rendered).to include without_indentation <<~HTML + + HTML + end + end + + context 'when remote is false' do + let(:params) { Hash[remote: 'false'] } + + it do + expect(rendered).to include without_indentation <<~HTML + + HTML + end + end + + context 'when remote is not valid' do + let(:params) { Hash[remote: 'foo'] } + + it do + expect(rendered).to include without_indentation <<~HTML + + HTML + end + end + end + + def without_indentation(string) + string.strip.gsub("\n", '') + end end From f2e7cb02602349a06d21ca40b0faf5c3af0b117c Mon Sep 17 00:00:00 2001 From: GeorgeGorbanev Date: Sat, 22 Jun 2019 20:25:19 +0300 Subject: [PATCH 8/9] rubocop fix --- apps/web/views/vacancies/index.rb | 11 ++++++----- lib/vacancies/operations/list.rb | 8 ++++++-- spec/core/queries/vacancy_spec.rb | 6 +++++- spec/vacancies/operations/list_spec.rb | 4 ++-- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/web/views/vacancies/index.rb b/apps/web/views/vacancies/index.rb index 11d5a62..614a964 100644 --- a/apps/web/views/vacancies/index.rb +++ b/apps/web/views/vacancies/index.rb @@ -43,10 +43,7 @@ def remote_filter_button(text:, remote_value:) if remote_value == current_remote_query { class: 'btn btn-light active' } else - { - class: 'btn btn-light', - href: routes.root_path(remote_value.nil? ? {} : { remote: remote_value }) - } + { class: 'btn btn-light', href: remote_filter_button_href(remote_value) } end html.a(link_params) do @@ -58,7 +55,11 @@ def remote_filter_button(text:, remote_value:) private def current_remote_query - params[:remote] if ['true', 'false'].include?(params[:remote]) + params[:remote] if params[:remote] == 'true' || params[:remote] == 'false' + end + + def remote_filter_button_href(remote_value) + routes.root_path(remote_value.nil? ? {} : { remote: remote_value }) end end end diff --git a/lib/vacancies/operations/list.rb b/lib/vacancies/operations/list.rb index adb3de2..fdf7dd8 100644 --- a/lib/vacancies/operations/list.rb +++ b/lib/vacancies/operations/list.rb @@ -11,8 +11,12 @@ class List < ::Libs::Operation def call(search_query: {}, page: 1, remote_query: nil) # rubocop:disable Lint/UnusedMethodArgument remote_available = { 'true' => true, 'false' => false }[remote_query] - pager = vacancy_query.pager_for_all_with_contact(limit: PAGINATION_LIMIT, page: page || 1, remote_available: remote_available) - result = vacancy_query.all_with_contact(limit: PAGINATION_LIMIT, page: page || 1, remote_available: remote_available) + pager = vacancy_query.pager_for_all_with_contact(limit: PAGINATION_LIMIT, + page: page || 1, + remote_available: remote_available) + result = vacancy_query.all_with_contact(limit: PAGINATION_LIMIT, + page: page || 1, + remote_available: remote_available) Success(result: result, pager: pager) end diff --git a/spec/core/queries/vacancy_spec.rb b/spec/core/queries/vacancy_spec.rb index ea08730..4c2f401 100644 --- a/spec/core/queries/vacancy_spec.rb +++ b/spec/core/queries/vacancy_spec.rb @@ -8,7 +8,10 @@ let(:remote_available) { nil } - before { Fabricate.create(:vacancy, published: published, archived: archived, deleted_at: deleted_at, remote_available: false) } + before do + Fabricate.create(:vacancy, published: published, archived: archived, + deleted_at: deleted_at, remote_available: false) + end context 'when vacancy published and not archived or deleted' do let(:published) { true } @@ -21,6 +24,7 @@ context 'when remote_available is true' do let(:remote_available) { true } + it { expect(subject).to eq([]) } end end diff --git a/spec/vacancies/operations/list_spec.rb b/spec/vacancies/operations/list_spec.rb index 68d9845..4635538 100644 --- a/spec/vacancies/operations/list_spec.rb +++ b/spec/vacancies/operations/list_spec.rb @@ -26,10 +26,10 @@ end context 'with remote query' do - let(:vacancies) { [] } - subject { operation.call(remote_query: remote_query) } + let(:vacancies) { [] } + context 'when remote_query nil' do let(:remote_query) { nil } From ccebe36dbd4772aa3111a4fdfc3546252aafc1eb Mon Sep 17 00:00:00 2001 From: GeorgeGorbanev Date: Wed, 26 Jun 2019 00:58:33 +0300 Subject: [PATCH 9/9] use query param --- apps/web/controllers/vacancies/index.rb | 11 +++------- apps/web/views/vacancies/index.rb | 4 ++-- lib/vacancies/operations/list.rb | 4 ++-- spec/vacancies/operations/list_spec.rb | 2 +- spec/web/controllers/vacancies/index_spec.rb | 8 ++------ spec/web/views/vacancies/index_spec.rb | 21 ++++++++++---------- 6 files changed, 21 insertions(+), 29 deletions(-) diff --git a/apps/web/controllers/vacancies/index.rb b/apps/web/controllers/vacancies/index.rb index a57a152..834a7a0 100644 --- a/apps/web/controllers/vacancies/index.rb +++ b/apps/web/controllers/vacancies/index.rb @@ -16,15 +16,16 @@ class Index expose :vacancies expose :pager + expose :search_query params do optional(:page).filled optional(:query).filled - optional(:remote).filled end def call(params) - result = operation.call(search_query: search_query, page: params[:page], remote_query: params[:remote]) + @search_query = params[:query] ? search_query_parser.call(params[:query]) : EMPTY_SEARCH_QUERY + result = operation.call(search_query: @search_query, page: params[:page]) case result when Success @@ -32,12 +33,6 @@ def call(params) @vacancies = result.value![:result] end end - - private - - def search_query - params[:query] ? search_query_parser.call(params[:query]) : EMPTY_SEARCH_QUERY - end end end end diff --git a/apps/web/views/vacancies/index.rb b/apps/web/views/vacancies/index.rb index 614a964..800847c 100644 --- a/apps/web/views/vacancies/index.rb +++ b/apps/web/views/vacancies/index.rb @@ -55,11 +55,11 @@ def remote_filter_button(text:, remote_value:) private def current_remote_query - params[:remote] if params[:remote] == 'true' || params[:remote] == 'false' + search_query[:remote] if search_query[:remote] == 'true' || search_query[:remote] == 'false' end def remote_filter_button_href(remote_value) - routes.root_path(remote_value.nil? ? {} : { remote: remote_value }) + routes.root_path(remote_value.nil? ? {} : { query: "remote:#{remote_value}" }) end end end diff --git a/lib/vacancies/operations/list.rb b/lib/vacancies/operations/list.rb index fdf7dd8..00404c6 100644 --- a/lib/vacancies/operations/list.rb +++ b/lib/vacancies/operations/list.rb @@ -9,8 +9,8 @@ class List < ::Libs::Operation PAGINATION_LIMIT = 10 - def call(search_query: {}, page: 1, remote_query: nil) # rubocop:disable Lint/UnusedMethodArgument - remote_available = { 'true' => true, 'false' => false }[remote_query] + def call(search_query: {}, page: 1) # rubocop:disable Lint/UnusedMethodArgument + remote_available = { 'true' => true, 'false' => false }[search_query[:remote]] pager = vacancy_query.pager_for_all_with_contact(limit: PAGINATION_LIMIT, page: page || 1, remote_available: remote_available) diff --git a/spec/vacancies/operations/list_spec.rb b/spec/vacancies/operations/list_spec.rb index 4635538..9e8829d 100644 --- a/spec/vacancies/operations/list_spec.rb +++ b/spec/vacancies/operations/list_spec.rb @@ -26,7 +26,7 @@ end context 'with remote query' do - subject { operation.call(remote_query: remote_query) } + subject { operation.call(search_query: { remote: remote_query }) } let(:vacancies) { [] } diff --git a/spec/web/controllers/vacancies/index_spec.rb b/spec/web/controllers/vacancies/index_spec.rb index 290ecd3..3829bc0 100644 --- a/spec/web/controllers/vacancies/index_spec.rb +++ b/spec/web/controllers/vacancies/index_spec.rb @@ -19,16 +19,12 @@ end context 'when params includes query param' do - let(:params) { { query: 'remote:true search text', remote: 'remote_query' } } + let(:params) { { query: 'remote:true search text' } } it { expect(subject).to be_success } it do - expect(operation).to receive(:call).with( - page: nil, - search_query: { remote: 'true', text: 'search text' }, - remote_query: 'remote_query' - ) + expect(operation).to receive(:call).with(page: nil, search_query: { remote: 'true', text: 'search text' }) subject end end diff --git a/spec/web/views/vacancies/index_spec.rb b/spec/web/views/vacancies/index_spec.rb index 8343d6c..a0d60eb 100644 --- a/spec/web/views/vacancies/index_spec.rb +++ b/spec/web/views/vacancies/index_spec.rb @@ -2,7 +2,8 @@ RSpec.describe Web::Views::Vacancies::Index, type: :view do let(:params) { Hash[] } - let(:exposures) { Hash[format: :html, flash: {}, vacancies: [], params: params] } + let(:search_query) { Hash[] } + let(:exposures) { Hash[format: :html, flash: {}, params: params, vacancies: [], search_query: search_query] } let(:template) { Hanami::View::Template.new('apps/web/templates/vacancies/index.html.slim') } let(:view) { described_class.new(template, exposures) } let(:rendered) { view.render } @@ -20,34 +21,34 @@ expect(rendered).to include without_indentation <<~HTML HTML end context 'when remote is true' do - let(:params) { Hash[remote: 'true'] } + let(:search_query) { Hash[remote: 'true'] } it do expect(rendered).to include without_indentation <<~HTML HTML end end context 'when remote is false' do - let(:params) { Hash[remote: 'false'] } + let(:search_query) { Hash[remote: 'false'] } it do expect(rendered).to include without_indentation <<~HTML HTML @@ -55,14 +56,14 @@ end context 'when remote is not valid' do - let(:params) { Hash[remote: 'foo'] } + let(:search_query) { Hash[remote: 'foo'] } it do expect(rendered).to include without_indentation <<~HTML HTML end