diff --git a/app/controllers/eligibilities_controller.rb b/app/controllers/eligibilities_controller.rb index 762c4c1e..93551280 100644 --- a/app/controllers/eligibilities_controller.rb +++ b/app/controllers/eligibilities_controller.rb @@ -4,6 +4,9 @@ class EligibilitiesController < ApplicationController :load_restrictions, :load_eligibilities def new # TODO: refactor + return redirect_to account_upgrade_path(@recipient) unless + @proposal.checked_fund?(@fund) || @proposal.show_fund?(@fund) + @org_criteria = find_or_initialize_eligibilities(@recipient, 'Organisation') @proposal_criteria = find_or_initialize_eligibilities(@proposal, 'Proposal') diff --git a/app/controllers/funds_controller.rb b/app/controllers/funds_controller.rb index 6de4dfcc..e22545ee 100644 --- a/app/controllers/funds_controller.rb +++ b/app/controllers/funds_controller.rb @@ -4,8 +4,9 @@ class FundsController < ApplicationController def show @fund = Fund.includes(:funder).find_by(slug: params[:id]) - redirect_to request.referer || root_path, alert: 'Fund not found' unless - @fund + return redirect_to request.referer || root_path, alert: 'Fund not found' unless @fund + redirect_to account_upgrade_path(@recipient) unless + @proposal.show_fund?(@fund) end def recommended diff --git a/app/helpers/recipients_helper.rb b/app/helpers/recipients_helper.rb index 0ccc816a..53c129dd 100644 --- a/app/helpers/recipients_helper.rb +++ b/app/helpers/recipients_helper.rb @@ -13,6 +13,17 @@ def fund_card_eligibility_text(fund) end end + def redacted_fund_card_eligibility_text(fund) + case @proposal.eligibility_for(fund) + when 0 + link_to('Ineligible', account_upgrade_path(@recipient), class: 'very-poor') + when 1 + link_to('Eligible', account_upgrade_path(@recipient), class: 'excellent') + else + link_to('Check', account_upgrade_path(@recipient), class: 'primary') + end + end + def fund_card_cta_button_copy(fund) classes = 'uk-width-1-1 uk-button uk-button-primary uk-button-large' case @proposal.eligibility_for(fund) diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 44077393..9ce09e24 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -267,7 +267,8 @@ def recommendation(fund) def show_fund?(fund) recipient.subscribed? || - recommended_funds.take(Recipient::RECOMMENDATION_LIMIT).include?(fund.id) + (recommended_funds - ineligible_fund_ids) + .take(Recipient::RECOMMENDATION_LIMIT).include?(fund.id) end def check_eligibility! diff --git a/app/views/funds/_summary_redacted.html.haml b/app/views/funds/_summary_redacted.html.haml index fd02ab46..ad292409 100644 --- a/app/views/funds/_summary_redacted.html.haml +++ b/app/views/funds/_summary_redacted.html.haml @@ -14,8 +14,11 @@ %th Match %tbody %tr - %td Eligibility - %td= scramble_recommendations + %td + Eligibility + %td + %strong + = redacted_fund_card_eligibility_text(fund) %tr %td Organisation type %td= scramble_recommendations @@ -39,18 +42,25 @@ .uk-width-medium-2-3 %h3.uk-margin-top - -# TODO: refactor - - if @current_user.feedbacks.count.positive? - = link_to (@tag.present? ? scramble_name(fund.name) : fund.name), proposal_fund_path(@proposal, fund), class: (@tag.present? ? 'yellow redacted large': 'yellow') - - else - = link_to (@tag.present? ? scramble_name(fund.name) : fund.name), account_upgrade_path(@recipient), class: (@tag.present? ? 'yellow redacted large': 'yellow') + = link_to scramble_name(fund.name), account_upgrade_path(@recipient), class: 'yellow redacted large' %span.year.muted %span.redacted= scramble_name(fund.funder.name) %p.redacted.muted= scramble_name(raw(fund.description)) %ul.insights - - 5.times do |i| + - unless @proposal.eligibility_for(fund).negative? + %li{ class: (@proposal.eligible?(fund) ? 'eligible' : 'ineligible')} + - if @proposal.eligible?(fund) + %a.badge{ href: eligible_proposal_funds_path(@proposal) } Eligible + You are eligible for funding. + %a.action{ href: account_upgrade_path(@recipient) } See criteria + - else + %a.badge{ href: ineligible_proposal_funds_path(@proposal) } Ineligible + You are ineligible for funding. + %a.action{ href: account_upgrade_path(@recipient) } Find out why + + - (3..5).to_a.sample.times do |i| %li .action.redacted.muted= redacted_insights - if i < 2 diff --git a/app/views/funds/all.html.haml b/app/views/funds/all.html.haml index bfc5eab6..9561be9a 100644 --- a/app/views/funds/all.html.haml +++ b/app/views/funds/all.html.haml @@ -13,7 +13,10 @@ - @funds.each_with_index do |fund, i| - = render partial: 'summary', locals: { fund: fund } + - if @proposal.show_fund?(fund) + = render partial: 'summary', locals: { fund: fund } + - else + = render partial: 'summary_redacted', locals: { fund: fund } - if i == 5 .cta.wide diff --git a/app/views/funds/eligible.html.haml b/app/views/funds/eligible.html.haml index b5eefa4f..e3be817c 100644 --- a/app/views/funds/eligible.html.haml +++ b/app/views/funds/eligible.html.haml @@ -30,6 +30,11 @@ = link_to 'Find a fund', recommended_proposal_funds_path(@proposal), class: 'uk-button uk-button-large uk-button-primary invert' - @funds.each_with_index do |fund, i| - = render partial: 'summary', locals: { fund: fund } + + - if @proposal.show_fund?(fund) + = render partial: 'summary', locals: { fund: fund } + - else + = render partial: 'summary_redacted', locals: { fund: fund } + - unless i == @funds.count - 1 %hr.thick diff --git a/app/views/funds/ineligible.html.haml b/app/views/funds/ineligible.html.haml index 33cd5689..65c05409 100644 --- a/app/views/funds/ineligible.html.haml +++ b/app/views/funds/ineligible.html.haml @@ -30,6 +30,11 @@ = link_to 'Find a fund', recommended_proposal_funds_path(@proposal), class: 'uk-button uk-button-large uk-button-primary invert' - @funds.each_with_index do |fund, i| - = render partial: 'summary', locals: { fund: fund } + + - if @proposal.show_fund?(fund) + = render partial: 'summary', locals: { fund: fund } + - else + = render partial: 'summary_redacted', locals: { fund: fund } + - unless i == @funds.count - 1 %hr.thick diff --git a/spec/features/browse_spec.rb b/spec/features/browse_spec.rb index 8014d090..71edffff 100644 --- a/spec/features/browse_spec.rb +++ b/spec/features/browse_spec.rb @@ -27,6 +27,7 @@ @unsuitable_fund = Fund.first @low_fund = Fund.find_by(name: 'Awards for All 2') @top_fund = Fund.last + @recipient = @db[:recipient] @app.sign_in visit root_path end @@ -103,6 +104,53 @@ expect(current_path).to eq recommended_proposal_funds_path(@proposal) end + def subscribe_and_visit(path) + @recipient.subscribe! + visit path + expect(current_path).to eq path + end + + scenario 'can only view proposal_fund_path for recommended funds ' \ + 'unless subscribed' do + visit proposal_fund_path(@proposal, Fund.first) + expect(current_path).to eq account_upgrade_path(@recipient) + + subscribe_and_visit proposal_fund_path(@proposal, Fund.first) + end + + scenario 'can only view eligibility_proposal_fund_path for ' \ + 'recommended funds unless subscribed' do + visit eligibility_proposal_fund_path(@proposal, Fund.first) + expect(current_path).to eq account_upgrade_path(@recipient) + + subscribe_and_visit eligibility_proposal_fund_path(@proposal, Fund.first) + end + + scenario 'only recommended funds shown unless subscribed' do + visit all_proposal_funds_path(@proposal) + expect(page).to have_css '.yellow.redacted.large', count: 1 + + subscribe_and_visit all_proposal_funds_path(@proposal) + end + + scenario 'only recommended funds shown unless subscribed' do + data = { Fund.first.slug => { eligible: true, count_failing: 0 } } + @proposal.update!(eligibility: data) + visit eligible_proposal_funds_path(@proposal) + expect(page).to have_css '.yellow.redacted.large', count: 1 + + subscribe_and_visit eligible_proposal_funds_path(@proposal) + end + + scenario 'only recommended funds shown unless subscribed' do + data = { Fund.first.slug => { eligible: false, count_failing: 1 } } + @proposal.update!(eligibility: data) + visit ineligible_proposal_funds_path(@proposal) + expect(page).to have_css '.yellow.redacted.large', count: 1 + + subscribe_and_visit ineligible_proposal_funds_path(@proposal) + end + context 'all_funds_path' do before(:each) do click_link 'All' @@ -111,9 +159,9 @@ scenario "When I find a recommended fund I'm interested in, I want to view more details, so I can decide if I want to apply" do - click_link @unsuitable_fund.name + click_link @top_fund.name expect(current_path).to eq proposal_fund_path( - @proposal, @unsuitable_fund + @proposal, @top_fund ) end @@ -122,12 +170,6 @@ so I can see which ones I already and the value of the site" do expect(current_path).to eq all_proposal_funds_path(@proposal) end - - scenario "When I'm browsing 'All' funds and can only see tags for - recommended funds, I want more information, - so I understand why I can't see some information" do - expect(page).to have_css '.redacted', count: 6 - end end context 'When I view fund a with open data' do