From f0dd1f0d679cfba871417e13bd541009666aeabb Mon Sep 17 00:00:00 2001 From: "Michael J. Giarlo" Date: Thu, 9 Jul 2015 10:31:49 -0700 Subject: [PATCH] Check to make sure Zotero integration is enabled before asking user instances if they have a Zotero user ID. Fixes #1235 --- app/views/users/_user_info.html.erb | 2 +- spec/views/users/_user_info.html.erb_spec.rb | 29 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 spec/views/users/_user_info.html.erb_spec.rb diff --git a/app/views/users/_user_info.html.erb b/app/views/users/_user_info.html.erb index 3a4db894eb..e9f6c33d5c 100644 --- a/app/views/users/_user_info.html.erb +++ b/app/views/users/_user_info.html.erb @@ -5,7 +5,7 @@
<%= link_to user.orcid, user.orcid, { target: '_blank' } %>
<% end %> -<% if user.zotero_userid.present? %> +<% if Sufia.config.arkivo_api && user.zotero_userid.present? %>
<%= zotero_label(html_class: 'profile') %>
<%= link_to zotero_profile_url(user.zotero_userid), zotero_profile_url(user.zotero_userid), { target: '_blank' } %>
<% end %> diff --git a/spec/views/users/_user_info.html.erb_spec.rb b/spec/views/users/_user_info.html.erb_spec.rb new file mode 100644 index 0000000000..30dd3b39a1 --- /dev/null +++ b/spec/views/users/_user_info.html.erb_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe 'users/_user_info.html.erb', type: :view do + let(:user) { stub_model(User, user_key: 'jdoe42') } + + context 'with Zotero disabled' do + before do + allow(Sufia.config).to receive(:arkivo_api) { false } + allow(user).to receive(:zotero_userid).and_raise(NoMethodError) + render "users/user_info", user: user + end + + it 'does not display a Zotero profile link' do + expect(rendered).not_to match(/Zotero Profile/) + end + end + + context 'with Zotero enabled' do + before do + allow(Sufia.config).to receive(:arkivo_api) { true } + allow(user).to receive(:zotero_userid) { 'jdoe42zotero' } + render "users/user_info", user: user + end + + it 'displays a Zotero profile link' do + expect(rendered).to match(/Zotero Profile/) + end + end +end