Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Only show donation button to non pros
  • Loading branch information
gbp committed Dec 7, 2017
1 parent 5a0a754 commit 66ecd1c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/helpers/donation_helper.rb
@@ -1,4 +1,9 @@
module DonationHelper
def show_donation_button?
AlaveteliConfiguration::donation_url.present? &&
!(feature_enabled?(:alaveteli_pro) && current_user && current_user.is_pro?)
end

def donate_now_link(content, options = {})
link_to _('Donate Now'),
donation_url(:utm_content => CGI::escape(content)),
Expand Down
2 changes: 1 addition & 1 deletion lib/views/request/_request_sent.html.erb
Expand Up @@ -68,7 +68,7 @@
</div>

<div class="request-sent-message__column-2">
<% if AlaveteliConfiguration::donation_url.present? %>
<% if show_donation_button? %>
<div class="what-next donate">
<h2 class="what-next__heading"><%= _("We work to defend the right to FOI for everyone") %></h2>
<p class="what-next__para"><%= _("Help us protect your right to hold public authorities to account. Donate and support our work.
Expand Down
3 changes: 1 addition & 2 deletions lib/views/request/_sidebar.html.erb
@@ -1,6 +1,5 @@
<div id="right_column" class="sidebar right_column" role="complementary">
<% unless flash[:request_sent] || \
(feature_enabled?(:alaveteli_pro) && current_user && current_user.is_pro?) %>
<% if show_donation_button? && !flash[:request_sent] %>
<div class="sidebar__donate-cta">
<h2 class="sidebar__donate-cta__header"><%= _('We work to defend the right to FOI for everyone') %></h2>
<p class="sidebar__donate-cta__para"><%= _('Help us protect your right to hold public authorities to account. Donate and support our work.') %></p>
Expand Down
2 changes: 1 addition & 1 deletion lib/views/request/describe_notices/_successful.html.erb
Expand Up @@ -46,7 +46,7 @@

</div>
<div class="request-sent-message__column-2">
<% if AlaveteliConfiguration::donation_url.present? %>
<% if show_donation_button? %>
<div class="what-next donate">
<h2 class="what-next__heading"><%= _("Help keep this site running") %></h2>
<p class="what-next__para"><%= _("Your donations help us make " \
Expand Down
42 changes: 42 additions & 0 deletions spec/donation_helper_spec.rb
Expand Up @@ -5,6 +5,48 @@
describe DonationHelper, type: :helper do
include DonationHelper

describe '#show_donation_button?' do
subject { show_donation_button? }

context 'without donation URL' do
it { is_expected.to eq false }
end

context 'with donation URL' do
before do
allow(AlaveteliConfiguration).to receive(:donation_url).
and_return('http://example.com')
end

context 'Pro not enabled' do
it { is_expected.to eq true }
end

context 'with pro enabled' do
before(:each) do
allow(AlaveteliFeatures.backend).
to receive(:enabled?).with(:alaveteli_pro).and_return(true)
end

context 'no current user' do
let(:current_user) { nil }
it { is_expected.to eq true }
end

context 'current user is not a Pro' do
let(:current_user) { FactoryGirl.create(:user) }
it { is_expected.to eq true }
end

context 'current user is a Pro' do
let(:current_user) { FactoryGirl.create(:pro_user) }
it { is_expected.to eq false }
end
end
end

end

describe '#donate_now_link' do
before do
allow(AlaveteliConfiguration).to receive(:donation_url).
Expand Down

0 comments on commit 66ecd1c

Please sign in to comment.