From 5ba79f49a45041f5a805de00a1f737ade5ac5832 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Tue, 12 Apr 2016 12:49:34 -0500 Subject: [PATCH] Syntax and code improvements --- app/helpers/diff_helper.rb | 26 ++++++++++--------- .../toggle_whitespace_changes.rb | 7 ++--- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index 06e5b95297e..5c7317bdd40 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -129,18 +129,6 @@ module DiffHelper end end - def hide_whitespace? - params[:w] == '1' - end - - def params_with_whitespace - hide_whitespace? ? request.query_parameters.except(:w) : request.query_parameters.merge(w: 1) - end - - def toggle_whitespace_link(url) - link_to "#{hide_whitespace? ? 'Show' : 'Hide'} whitespace changes", url, class: "btn btn-default" - end - def commit_diff_whitespace_link(project, commit) url = namespace_project_commit_path(project.namespace, project, commit.id, params_with_whitespace) toggle_whitespace_link(url) @@ -150,4 +138,18 @@ module DiffHelper url = diffs_namespace_project_merge_request_path(project.namespace, project, merge_request, params_with_whitespace) toggle_whitespace_link(url) end + + private + + def hide_whitespace? + params[:w] == '1' + end + + def params_with_whitespace + hide_whitespace? ? request.query_parameters.except(:w) : request.query_parameters.merge(w: 1) + end + + def toggle_whitespace_link(url) + link_to "#{hide_whitespace? ? 'Show' : 'Hide'} whitespace changes", url, class: 'btn btn-default' + end end diff --git a/spec/features/merge_requests/toggle_whitespace_changes.rb b/spec/features/merge_requests/toggle_whitespace_changes.rb index bf4fd5289d1..0f98737b700 100644 --- a/spec/features/merge_requests/toggle_whitespace_changes.rb +++ b/spec/features/merge_requests/toggle_whitespace_changes.rb @@ -9,13 +9,14 @@ feature 'Toggle Whitespace Changes', js: true, feature: true do end it 'has a button to toggle whitespace changes' do - expect(page).to have_content "Hide whitespace changes" + expect(page).to have_content 'Hide whitespace changes' end describe 'clicking "Hide whitespace changes" button' do it 'toggles the "Hide whitespace changes" button' do - click_link "Hide whitespace changes" - expect(page).to have_content "Show whitespace changes" + click_link 'Hide whitespace changes' + + expect(page).to have_content 'Show whitespace changes' end end end