Skip to content
Browse files

Rename RockScore to CalculateScore

  • Loading branch information...
1 parent ff4915b commit 83d02a910048aae4447d25fd5c669b52ca386bc4 @hammerdr committed Apr 2, 2012
View
2 app/controllers/scores_controller.rb
@@ -2,7 +2,7 @@ class ScoresController < ApplicationController
def show
term = params[:term]
score = ScoreCache.for_term(term)
- score = nil if score == RockScore::NoScore
+ score = nil if score == CalculateScore::NoScore
render :json => {:term => term, :score => score}
end
end
View
4 app/models/cached_score.rb
@@ -3,14 +3,14 @@ class NoScore < RuntimeError
end
def self.save_score(term, score)
- score = nil if score == RockScore::NoScore
+ score = nil if score == CalculateScore::NoScore
create!(:term => term, :score => score)
end
def self.for_term(term)
cached_score = find_by_term(term) or raise NoScore
score = cached_score.score
- score.nil? ? RockScore::NoScore : score
+ score.nil? ? CalculateScore::NoScore : score
end
end
View
2 app/services/rock_score.rb → app/services/calculate_score.rb
@@ -1,4 +1,4 @@
-class RockScore
+class CalculateScore
NoScore = Class.new
def self.for_term(term)
View
2 app/services/score_cache.rb
@@ -7,7 +7,7 @@ def for_term(term)
end
def cache_new_score(term)
- score = RockScore.for_term(term)
+ score = CalculateScore.for_term(term)
CachedScore.save_score(term, score)
score
end
View
2 features/step_definitions/search_steps.rb
@@ -3,7 +3,7 @@
end
Given /^microsoft is cached with no score$/ do
- CachedScore.save_score("microsoft", RockScore::NoScore)
+ CachedScore.save_score("microsoft", CalculateScore::NoScore)
end
When /^I search for (.*)$/ do |term|
View
2 spec/controllers/scores_controller_spec.rb
@@ -8,7 +8,7 @@
end
it "returns nil for NoScore" do
- ScoreCache.stub(:for_term).with("microsoft") { RockScore::NoScore }
+ ScoreCache.stub(:for_term).with("microsoft") { CalculateScore::NoScore }
get :show, :term => "microsoft"
response.body.should == {:term => "microsoft", :score => nil}.to_json
end
View
4 spec/models/cached_score_spec.rb
@@ -13,8 +13,8 @@
end
it "round-trips NoScores to the database" do
- CachedScore.save_score("microsoft", RockScore::NoScore)
- CachedScore.for_term("microsoft").should == RockScore::NoScore
+ CachedScore.save_score("microsoft", CalculateScore::NoScore)
+ CachedScore.for_term("microsoft").should == CalculateScore::NoScore
end
end
View
12 spec/services/rock_score_spec.rb → spec/services/calculate_score_spec.rb
@@ -1,29 +1,29 @@
-require_relative "../../app/services/rock_score"
+require_relative "../../app/services/calculate_score"
require_relative "../../app/services/search_engine"
-describe RockScore do
+describe CalculateScore do
it "returns 0 for unpopular terms" do
SearchEngine.stub(:count_results).with(%{"apple rocks"}) { 0 }
SearchEngine.stub(:count_results).with(%{"apple sucks"}) { 1 }
- RockScore.for_term("apple").should == 0.0
+ CalculateScore.for_term("apple").should == 0.0
end
it "returns 10 for popular terms" do
SearchEngine.stub(:count_results).with(%{"apple rocks"}) { 1 }
SearchEngine.stub(:count_results).with(%{"apple sucks"}) { 0 }
- RockScore.for_term("apple").should == 10.0
+ CalculateScore.for_term("apple").should == 10.0
end
it "returns mediocre results for mediocre terms" do
SearchEngine.stub(:count_results).with(%{"apple rocks"}) { 9 }
SearchEngine.stub(:count_results).with(%{"apple sucks"}) { 11 }
- RockScore.for_term("apple").should == 4.5
+ CalculateScore.for_term("apple").should == 4.5
end
it "does not divide by zero" do
SearchEngine.stub(:count_results).with(%{"apple rocks"}) { 0 }
SearchEngine.stub(:count_results).with(%{"apple sucks"}) { 0 }
- RockScore.for_term("apple").should == RockScore::NoScore
+ CalculateScore.for_term("apple").should == CalculateScore::NoScore
end
end
View
4 spec/services/score_cache_spec.rb
@@ -1,5 +1,5 @@
require_relative "../../app/services/score_cache"
-require_relative "../../app/services/rock_score"
+require_relative "../../app/services/calculate_score"
class CachedScore
class NoScore < RuntimeError; end
@@ -13,7 +13,7 @@ class NoScore < RuntimeError; end
context "when the term is not cached" do
before do
- RockScore.stub(:for_term).with("microsoft") { 5.5 }
+ CalculateScore.stub(:for_term).with("microsoft") { 5.5 }
CachedScore.stub(:for_term).with("microsoft").
and_raise(CachedScore::NoScore)
CachedScore.stub(:save_score)

0 comments on commit 83d02a9

Please sign in to comment.
Something went wrong with that request. Please try again.