summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2017-03-23 09:43:34 +0100
committerToon Claes <toon@gitlab.com>2017-03-23 22:21:00 +0100
commit0759db802f053e2757d52a284fd29098a9473df2 (patch)
tree7a86a3d8fd10d7fda7f7581a194133d57970358d
parenta57890bcaa76d540aa675e0c89d50620c9d69018 (diff)
downloadgitlab-ce-0759db802f053e2757d52a284fd29098a9473df2.tar.gz
Move user_link to generic UsersHelper
Make the user_link helper more generic to be used for objects other than pipelines.
-rw-r--r--app/helpers/pipelines_helper.rb11
-rw-r--r--app/helpers/users_helper.rb7
-rw-r--r--app/views/projects/pipelines/_info.html.haml4
-rw-r--r--spec/helpers/avatars_helper_spec.rb21
-rw-r--r--spec/helpers/pipelines_helper_spec.rb35
-rw-r--r--spec/helpers/users_helper_spec.rb17
6 files changed, 47 insertions, 48 deletions
diff --git a/app/helpers/pipelines_helper.rb b/app/helpers/pipelines_helper.rb
deleted file mode 100644
index 23b9ff97521..00000000000
--- a/app/helpers/pipelines_helper.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-module PipelinesHelper
- def pipeline_user_avatar(pipeline)
- user_avatar(user: pipeline.user, size: 24)
- end
-
- def pipeline_user_link(pipeline)
- link_to(pipeline.user.name, user_path(pipeline.user),
- title: pipeline.user.email,
- class: 'has-tooltip commit-committer-link')
- end
-end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
new file mode 100644
index 00000000000..9c623c9ba7c
--- /dev/null
+++ b/app/helpers/users_helper.rb
@@ -0,0 +1,7 @@
+module UsersHelper
+ def user_link(user)
+ link_to(user.name, user_path(user),
+ title: user.email,
+ class: 'has-tooltip commit-committer-link')
+ end
+end
diff --git a/app/views/projects/pipelines/_info.html.haml b/app/views/projects/pipelines/_info.html.haml
index a280f5a62ab..4be9a1371ec 100644
--- a/app/views/projects/pipelines/_info.html.haml
+++ b/app/views/projects/pipelines/_info.html.haml
@@ -5,8 +5,8 @@
triggered #{time_ago_with_tooltip(@pipeline.created_at)}
- if @pipeline.user
by
- = pipeline_user_avatar(@pipeline)
- = pipeline_user_link(@pipeline)
+ = user_avatar(user: @pipeline.user, size: 24)
+ = user_link(@pipeline.user)
.header-action-buttons
- if can?(current_user, :update_pipeline, @pipeline.project)
- if @pipeline.retryable?
diff --git a/spec/helpers/avatars_helper_spec.rb b/spec/helpers/avatars_helper_spec.rb
new file mode 100644
index 00000000000..581726c1d0e
--- /dev/null
+++ b/spec/helpers/avatars_helper_spec.rb
@@ -0,0 +1,21 @@
+require 'rails_helper'
+
+describe AvatarsHelper do
+ let(:user) { create(:user) }
+
+ describe '#user_avatar' do
+ subject { helper.user_avatar(user: user) }
+
+ it "links to the user's profile" do
+ is_expected.to include("href=\"#{user_path(user)}\"")
+ end
+
+ it "has the user's name as title" do
+ is_expected.to include("title=\"#{user.name}\"")
+ end
+
+ it "contains the user's avatar image" do
+ is_expected.to include(CGI.escapeHTML(user.avatar_url(16)))
+ end
+ end
+end
diff --git a/spec/helpers/pipelines_helper_spec.rb b/spec/helpers/pipelines_helper_spec.rb
deleted file mode 100644
index 8101fb71ee8..00000000000
--- a/spec/helpers/pipelines_helper_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require 'rails_helper'
-
-describe PipelinesHelper do
- let(:user) { create(:user) }
- let(:project) { create(:project) }
- let(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id, user: user) }
-
- describe '#pipeline_user_avatar' do
- subject { helper.pipeline_user_avatar(pipeline) }
-
- it "links to the user's profile" do
- is_expected.to include("href=\"#{user_path(user)}\"")
- end
-
- it "has the user's name as title" do
- is_expected.to include("title=\"#{user.name}\"")
- end
-
- it "contains the user's avatar image" do
- is_expected.to include(CGI.escapeHTML(user.avatar_url(24)))
- end
- end
-
- describe '#pipeline_user_link' do
- subject { helper.pipeline_user_link(pipeline) }
-
- it "links to the user's profile" do
- is_expected.to include("href=\"#{user_path(user)}\"")
- end
-
- it "has the user's email as title" do
- is_expected.to include("title=\"#{user.email}\"")
- end
- end
-end
diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb
new file mode 100644
index 00000000000..03f78de8e91
--- /dev/null
+++ b/spec/helpers/users_helper_spec.rb
@@ -0,0 +1,17 @@
+require 'rails_helper'
+
+describe UsersHelper do
+ let(:user) { create(:user) }
+
+ describe '#user_link' do
+ subject { helper.user_link(user) }
+
+ it "links to the user's profile" do
+ is_expected.to include("href=\"#{user_path(user)}\"")
+ end
+
+ it "has the user's email as title" do
+ is_expected.to include("title=\"#{user.email}\"")
+ end
+ end
+end