summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2018-02-22 13:54:19 +0100
committerJames Lopez <james@jameslopez.es>2018-02-23 14:02:40 +0100
commit0767861bcdc62cedf374c6a4b53d8526efb4ff58 (patch)
tree3e6d866497ba45ac0cafcbf3963cf7f6979b4dfd
parent228b757d29a141c4fda0e7c4be75784a6cefe427 (diff)
downloadgitlab-ce-0767861bcdc62cedf374c6a4b53d8526efb4ff58.tar.gz
refactor code based on feedback
-rw-r--r--app/helpers/blob_helper.rb22
-rw-r--r--app/views/projects/blob/_header.html.haml4
-rw-r--r--app/views/projects/diffs/_file.html.haml2
-rw-r--r--spec/helpers/blob_helper_spec.rb8
4 files changed, 18 insertions, 18 deletions
diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb
index 6322eb1b671..93e2a752547 100644
--- a/app/helpers/blob_helper.rb
+++ b/app/helpers/blob_helper.rb
@@ -16,13 +16,13 @@ module BlobHelper
options[:link_opts])
end
- def edit_blob_element(project = @project, ref = @ref, path = @path, options = {})
+ def edit_blob_button(project = @project, ref = @ref, path = @path, options = {})
return unless blob = readable_blob(options, path, project, ref)
common_classes = "btn js-edit-blob #{options[:extra_class]}"
if !on_top_of_branch?(project, ref)
- edit_button_tag(edit_text, common_classes)
+ edit_disabled_button_tag(edit_text, common_classes)
# This condition applies to anonymous or users who can edit directly
elsif !current_user || user_can_modify_blob?(blob, project, ref)
edit_link_tag(edit_text, edit_blob_path(project, ref, path, options), common_classes)
@@ -54,14 +54,14 @@ module BlobHelper
_('Web IDE')
end
- def ide_edit_element(project = @project, ref = @ref, path = @path, options = {})
+ def ide_edit_button(project = @project, ref = @ref, path = @path, options = {})
return unless show_new_ide?
return unless blob = readable_blob(options, path, project, ref)
common_classes = "btn js-edit-ide #{options[:extra_class]}"
if !on_top_of_branch?(project, ref)
- edit_button_tag(ide_edit_text, common_classes)
+ edit_disabled_button_tag(ide_edit_text, common_classes)
# This condition only applies to users who are logged in
# Web IDE (Beta) requires the user to have this feature enabled
elsif user_can_modify_blob?(blob, project, ref)
@@ -327,17 +327,17 @@ module BlobHelper
def edit_blob_fork_params(path)
{
- to: path,
- notice: edit_in_new_fork_notice,
- notice_now: edit_in_new_fork_notice_now
+ to: path,
+ notice: edit_in_new_fork_notice,
+ notice_now: edit_in_new_fork_notice_now
}
end
def edit_modify_file_fork_params(action)
{
- to: request.fullpath,
- notice: edit_in_new_fork_notice_action(action),
- notice_now: edit_in_new_fork_notice_now
+ to: request.fullpath,
+ notice: edit_in_new_fork_notice_action(action),
+ notice_now: edit_in_new_fork_notice_now
}
end
@@ -349,7 +349,7 @@ module BlobHelper
data: { action: action, fork_path: fork_path }
end
- def edit_button_tag(button_text, common_classes)
+ def edit_disabled_button_tag(button_text, common_classes)
button_tag(button_text, class: "#{common_classes} disabled has-tooltip", title: _('You can only edit files when you are on a branch'), data: { container: 'body' })
end
diff --git a/app/views/projects/blob/_header.html.haml b/app/views/projects/blob/_header.html.haml
index da0c0ed6cb4..1b150ec3e5c 100644
--- a/app/views/projects/blob/_header.html.haml
+++ b/app/views/projects/blob/_header.html.haml
@@ -11,8 +11,8 @@
= view_on_environment_button(@commit.sha, @path, @environment) if @environment
.btn-group{ role: "group" }<
- = edit_blob_element
- = ide_edit_element
+ = edit_blob_button
+ = ide_edit_button
- if current_user
= replace_blob_link
= delete_blob_link
diff --git a/app/views/projects/diffs/_file.html.haml b/app/views/projects/diffs/_file.html.haml
index 3e6001e6f30..47bfcb21cf4 100644
--- a/app/views/projects/diffs/_file.html.haml
+++ b/app/views/projects/diffs/_file.html.haml
@@ -17,7 +17,7 @@
\
- if editable_diff?(diff_file)
- link_opts = @merge_request.persisted? ? { from_merge_request_iid: @merge_request.iid } : {}
- = edit_blob_element(@merge_request.source_project, @merge_request.source_branch, diff_file.new_path,
+ = edit_blob_button(@merge_request.source_project, @merge_request.source_branch, diff_file.new_path,
blob: blob, link_opts: link_opts)
- if image_diff && image_replaced
diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb
index d1968eac3e3..0548e71c89d 100644
--- a/spec/helpers/blob_helper_spec.rb
+++ b/spec/helpers/blob_helper_spec.rb
@@ -86,7 +86,7 @@ describe BlobHelper do
it 'verifies blob is text' do
expect(helper).not_to receive(:blob_text_viewable?)
- button = edit_blob_element(project, 'refs/heads/master', 'README.md')
+ button = edit_blob_button(project, 'refs/heads/master', 'README.md')
expect(button).to start_with('<button')
end
@@ -96,17 +96,17 @@ describe BlobHelper do
expect(project.repository).not_to receive(:blob_at)
- edit_blob_element(project, 'refs/heads/master', 'README.md', blob: blob)
+ edit_blob_button(project, 'refs/heads/master', 'README.md', blob: blob)
end
it 'returns a link with the proper route' do
- link = edit_blob_element(project, 'master', 'README.md')
+ link = edit_blob_button(project, 'master', 'README.md')
expect(Capybara.string(link).find_link('Edit')[:href]).to eq("/#{project.full_path}/edit/master/README.md")
end
it 'returns a link with the passed link_opts on the expected route' do
- link = edit_blob_element(project, 'master', 'README.md', link_opts: { mr_id: 10 })
+ link = edit_blob_button(project, 'master', 'README.md', link_opts: { mr_id: 10 })
expect(Capybara.string(link).find_link('Edit')[:href]).to eq("/#{project.full_path}/edit/master/README.md?mr_id=10")
end