From 5c4a2bff91e7ad02a675e5d0ce1c27a36bc4bee6 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Wed, 6 Jul 2016 11:48:06 -0500 Subject: [PATCH 1/3] Link to the user's profile in the abuse reports and add a link to the admin area view if the user viewing the profile is an admin --- app/views/admin/abuse_reports/_abuse_report.html.haml | 4 ++-- app/views/users/show.html.haml | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/views/admin/abuse_reports/_abuse_report.html.haml b/app/views/admin/abuse_reports/_abuse_report.html.haml index 862b86d9d4a..dd2e7ebd030 100644 --- a/app/views/admin/abuse_reports/_abuse_report.html.haml +++ b/app/views/admin/abuse_reports/_abuse_report.html.haml @@ -3,14 +3,14 @@ %tr %td - if user - = link_to user.name, [:admin, user] + = link_to user.name, user .light.small Joined #{time_ago_with_tooltip(user.created_at)} - else (removed) %td - if reporter - = link_to reporter.name, [:admin, reporter] + = link_to reporter.name, reporter - else (removed) .light.small diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 68665858c3e..db2b4885861 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -29,6 +29,11 @@   = link_to user_path(@user, :atom, { private_token: current_user.private_token }), class: 'btn btn-gray' do = icon('rss') + - if current_user.admin? +   + = link_to [:admin, @user], class: 'btn btn-gray', title: 'View user in admin area', + data: {toggle: 'tooltip', placement: 'bottom', container: 'body'} do + = icon('users') .avatar-holder = link_to avatar_icon(@user, 400), target: '_blank' do From 1867d0d505baf518fe92d3c306fddfb56e68a810 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Wed, 6 Jul 2016 16:17:20 -0500 Subject: [PATCH 2/3] Added specs to check for the correct links. --- .../abuse_reports/_abuse_report.html.haml | 2 +- app/views/users/show.html.haml | 2 +- .../admin/admin_abuse_reports_spec.rb | 31 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 spec/features/admin/admin_abuse_reports_spec.rb diff --git a/app/views/admin/abuse_reports/_abuse_report.html.haml b/app/views/admin/abuse_reports/_abuse_report.html.haml index dd2e7ebd030..b54ca059a61 100644 --- a/app/views/admin/abuse_reports/_abuse_report.html.haml +++ b/app/views/admin/abuse_reports/_abuse_report.html.haml @@ -3,7 +3,7 @@ %tr %td - if user - = link_to user.name, user + = link_to user.name, user, id: 'abuser_profile_path' .light.small Joined #{time_ago_with_tooltip(user.created_at)} - else diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index db2b4885861..520f76eb062 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -31,7 +31,7 @@ = icon('rss') - if current_user.admin?   - = link_to [:admin, @user], class: 'btn btn-gray', title: 'View user in admin area', + = link_to [:admin, @user], id: 'admin_user_path', class: 'btn btn-gray', title: 'View user in admin area', data: {toggle: 'tooltip', placement: 'bottom', container: 'body'} do = icon('users') diff --git a/spec/features/admin/admin_abuse_reports_spec.rb b/spec/features/admin/admin_abuse_reports_spec.rb new file mode 100644 index 00000000000..2ff02a1c9a8 --- /dev/null +++ b/spec/features/admin/admin_abuse_reports_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe "Admin::AbuseReports", feature: true, js: true do + let(:user) { create(:user) } + + context 'as an admin' do + describe 'if a user has been reported for abuse' do + before do + admin = create(:admin) + create(:abuse_report, user: user) + login_as admin + end + + describe 'in the abuse report view' do + it "should present a link to the user's profile" do + visit admin_abuse_reports_path + + expect(page).to have_selector '#abuser_profile_path' + end + end + + describe 'in the profile page of the user' do + it 'should show a link to the admin view of the user' do + visit user_path(user) + + expect(page).to have_selector '#admin_user_path' + end + end + end + end +end From be6c4fef40a937757a0e95ba758bf1b6da0155d7 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Thu, 7 Jul 2016 18:39:45 -0500 Subject: [PATCH 3/3] Removed unnecessary `id` from links and corrected tests to use the proper matcher. --- app/views/admin/abuse_reports/_abuse_report.html.haml | 2 +- app/views/users/show.html.haml | 2 +- spec/features/admin/admin_abuse_reports_spec.rb | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/views/admin/abuse_reports/_abuse_report.html.haml b/app/views/admin/abuse_reports/_abuse_report.html.haml index b54ca059a61..dd2e7ebd030 100644 --- a/app/views/admin/abuse_reports/_abuse_report.html.haml +++ b/app/views/admin/abuse_reports/_abuse_report.html.haml @@ -3,7 +3,7 @@ %tr %td - if user - = link_to user.name, user, id: 'abuser_profile_path' + = link_to user.name, user .light.small Joined #{time_ago_with_tooltip(user.created_at)} - else diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 520f76eb062..db2b4885861 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -31,7 +31,7 @@ = icon('rss') - if current_user.admin?   - = link_to [:admin, @user], id: 'admin_user_path', class: 'btn btn-gray', title: 'View user in admin area', + = link_to [:admin, @user], class: 'btn btn-gray', title: 'View user in admin area', data: {toggle: 'tooltip', placement: 'bottom', container: 'body'} do = icon('users') diff --git a/spec/features/admin/admin_abuse_reports_spec.rb b/spec/features/admin/admin_abuse_reports_spec.rb index 2ff02a1c9a8..16baf7e9516 100644 --- a/spec/features/admin/admin_abuse_reports_spec.rb +++ b/spec/features/admin/admin_abuse_reports_spec.rb @@ -6,16 +6,15 @@ describe "Admin::AbuseReports", feature: true, js: true do context 'as an admin' do describe 'if a user has been reported for abuse' do before do - admin = create(:admin) create(:abuse_report, user: user) - login_as admin + login_as :admin end describe 'in the abuse report view' do it "should present a link to the user's profile" do visit admin_abuse_reports_path - expect(page).to have_selector '#abuser_profile_path' + expect(page).to have_link user.name, href: user_path(user) end end @@ -23,7 +22,7 @@ describe "Admin::AbuseReports", feature: true, js: true do it 'should show a link to the admin view of the user' do visit user_path(user) - expect(page).to have_selector '#admin_user_path' + expect(page).to have_link '', href: admin_user_path(user) end end end