Skip to content

Commit

Permalink
Merge pull request #364 from TechforgoodCAST/develop
Browse files Browse the repository at this point in the history
Patch Proposal#update_legacy_suitability
  • Loading branch information
suninthesky authored Aug 9, 2017
2 parents e130342 + 3435244 commit c35e96b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
7 changes: 3 additions & 4 deletions app/controllers/funds_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class FundsController < ApplicationController
before_action :ensure_logged_in,
:refine_recommendations # TODO: refactor
before_action :ensure_logged_in, :update_legacy_suitability

def show
@fund = Fund.includes(:funder).find_by(slug: params[:id])
Expand Down Expand Up @@ -30,7 +29,7 @@ def sources

private

def refine_recommendations # TODO: refactor
@proposal.refine_recommendations
def update_legacy_suitability
@proposal.update_legacy_suitability
end
end
6 changes: 2 additions & 4 deletions app/models/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,8 @@ def initial_recommendation
)
end

def refine_recommendations # TODO: refactor
return if updated_at > (Fund.order(:updated_at).last&.updated_at || Date.today)
touch
initial_recommendation
def update_legacy_suitability
initial_recommendation if suitability.all_values_for('total').empty?
end

def suitable_funds
Expand Down
25 changes: 20 additions & 5 deletions spec/models/proposal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,29 @@

context 'with funds' do
before(:each) do
@app.setup_funds(num: 2, open_data: true)
@app.setup_funds(open_data: true)
@initial_proposal.save
end

it '#refine_recommendations' do
@initial_proposal.updated_at = 1.day.ago
@initial_proposal.refine_recommendations
expect(@initial_proposal.updated_at.day).not_to eq 1.day.ago
it '#update_legacy_suitability' do
result = {
'acme-2-awards-for-all-1' => {
'amount' => { 'score' => 0.2 },
'duration' => { 'score' => 0.0 },
'location' => { 'score' => 1, 'reason' => 'anywhere' },
'org_type' => { 'score' => 0.41500000000000004 },
'theme' => { 'score' => 1.0 },
'total' => 2.615
}
}

@initial_proposal.suitability = {}
@initial_proposal.update_legacy_suitability
expect(@initial_proposal.suitability).to eq result

@initial_proposal.suitability = { 'key' => 'value' }
@initial_proposal.update_legacy_suitability
expect(@initial_proposal.suitability).to eq result
end
end

Expand Down

0 comments on commit c35e96b

Please sign in to comment.