Syntax and code improvements

This commit is contained in:
Alfredo Sumaran 2016-04-12 12:49:34 -05:00
parent 7f263ca1de
commit 5ba79f49a4
2 changed files with 18 additions and 15 deletions

View file

@ -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

View file

@ -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