Skip to content

Commit

Permalink
Merge pull request #147 from TechforgoodCAST/develop
Browse files Browse the repository at this point in the history
Mystery fund when eligible
  • Loading branch information
suninthesky authored Apr 18, 2017
2 parents 50d4354 + e47006f commit c74c032
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 22 deletions.
3 changes: 3 additions & 0 deletions app/controllers/eligibilities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
5 changes: 3 additions & 2 deletions app/controllers/funds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions app/helpers/recipients_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion app/models/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
26 changes: 18 additions & 8 deletions app/views/funds/_summary_redacted.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion app/views/funds/all.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion app/views/funds/eligible.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion app/views/funds/ineligible.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
58 changes: 50 additions & 8 deletions spec/features/browse_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand 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

Expand All @@ -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
Expand Down

0 comments on commit c74c032

Please sign in to comment.