Skip to content

Instantly share code, notes, and snippets.

@benvds
Created January 12, 2011 13:08
Show Gist options
  • Save benvds/776145 to your computer and use it in GitHub Desktop.
Save benvds/776145 to your computer and use it in GitHub Desktop.
→ rspec spec/models/profile_match_spec.rb
F*
Pending:
ProfileMatch.match matches all motives
# cant spec query chain
# ./spec/models/profile_match_spec.rb:46
Failures:
1) ProfileMatch.match matches against all companies
Failure/Error: Company.should_receive(:all) # dont work
(<Company(id: integer, name: string, created_at: datetime, updated_at: datetime, cached_slug: string, intro_text: text, thank_you_text: text, show_company_results: boolean, show_personal_results: boolean, exclude_results: boolean, allow_anonymous_questionaires: boolean) (class)>).all(any args)
expected: 1 time
received: 0 times
# ./spec/models/profile_match_spec.rb:42:in `block (3 levels) in <top (required)>'
Finished in 0.10268 seconds
2 examples, 1 failure, 1 pending
class ProfileMatch
# for testing purposes
TEST_USER_RESULTS = [
{"motive_name" => "confac", "score" => 0.39457119067443797},
{"motive_name" => "leerfac", "score" => 0.14557119067443797},
{"motive_name" => "resulfac", "score" => 0.27557119067443797},
{"motive_name" => "orgfac", "score" => 0.84557119067443797},
{"motive_name" => "beslisfac", "score" => 0.64557119067443797},
{"motive_name" => "tradfac", "score" => 0.59457119067443797}
]
def self.result(user_results = TEST_USER_RESULTS)
@companies = Company.includes(:company_average_results => :motive).all
company_matches = []
@companies.each do |company|
difference = company.company_average_results.inject(0) do |total_difference, company_average_result|
corresponding_user_result = user_results.detect { |user_result| user_result["motive_name"] == company_average_result.motive.name }
total_difference + (company_average_result.score - corresponding_user_result["score"]).abs
end
company_matches << { :id => company.id, :name => company.name, :difference => difference }
end
# sort desc by difference, only top 5
company_matches.sort{ |a,b| b[:difference] <=> a[:difference] }.slice(0,5)
end
end
require 'spec_helper'
describe ProfileMatch do
describe ".result" do
before(:all) do
@user_results = [
{"motive_name" => "confac", "score" => 0.39457119067443797},
{"motive_name" => "leerfac", "score" => 0.14557119067443797},
{"motive_name" => "resulfac", "score" => 0.27557119067443797},
{"motive_name" => "orgfac", "score" => 0.84557119067443797},
{"motive_name" => "beslisfac", "score" => 0.64557119067443797},
{"motive_name" => "tradfac", "score" => 0.59457119067443797}
]
end
#let(:company) { mock_model(Company).as_null_object }
it "matches against all companies" do
pending "cant spec query chain"
Company.should_receive(:all) # dont work
ProfileMatch.result(@user_results)
end
it "matches all motives"
#it "returns matches"
#it "returns the motive_id for each match"
#it "returns the difference for each match"
#it "returns 5 matches at most"
#it "returns matches in descending order by difference"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment