Permalink
Browse files

Make evaluation methods return true on success

  • Loading branch information...
1 parent 373e665 commit b85c94e696768c8073fc0108c14ea01cbde165b7 Katsuya Noguchi committed Jul 15, 2012
Showing with 29 additions and 25 deletions.
  1. +2 −0 History
  2. +4 −2 lib/models/rs_reputation.rb
  3. +23 −23 spec/reputation_system/evaluation_spec.rb
View
@@ -1,3 +1,5 @@
+ * Make evaluation methods return true on success.
+
== 1.2.1
* Fix index names to be able to db:rollback the migrations.
@@ -65,9 +65,10 @@ def self.update_reputation_value_with_new_source(rep, source, weight, process)
else
raise ArgumentError, "#{process} process is not supported yet"
end
- rep.save!
+ save_succeeded = rep.save
RSReputationMessage.add_reputation_message_if_not_exist(source, rep)
propagate_updated_reputation_value(rep, valueBeforeUpdate) if rep.target
+ save_succeeded
end
def self.update_reputation_value_with_updated_source(rep, source, oldValue, weight, process)
@@ -85,8 +86,9 @@ def self.update_reputation_value_with_updated_source(rep, source, oldValue, weig
else
raise ArgumentError, "#{process} process is not supported yet"
end
- rep.save!
+ save_succeeded = rep.save
propagate_updated_reputation_value(rep, valueBeforeUpdate) if rep.target
+ save_succeeded
end
def normalized_value
@@ -28,7 +28,7 @@
context "Primary Reputation" do
describe "#add_evaluation" do
it "should create evaluation in case of valid input" do
- @question.add_evaluation(:total_votes, 1, @user)
+ @question.add_evaluation(:total_votes, 1, @user).should be_true
@question.reputation_value_for(:total_votes).should == 1
end
@@ -48,8 +48,8 @@
context "With Scopes" do
it "should add evaluation on appropriate scope" do
- @phrase.add_evaluation(:difficulty_with_scope, 1, @user, :s1)
- @phrase.add_evaluation(:difficulty_with_scope, 2, @user, :s2)
+ @phrase.add_evaluation(:difficulty_with_scope, 1, @user, :s1).should be_true
+ @phrase.add_evaluation(:difficulty_with_scope, 2, @user, :s2).should be_true
@phrase.reputation_value_for(:difficulty_with_scope, :s1).should == 1
@phrase.reputation_value_for(:difficulty_with_scope, :s2).should == 2
@phrase.reputation_value_for(:difficulty_with_scope, :s3).should == 0
@@ -67,30 +67,30 @@
describe "#add_or_update_evaluation" do
it "should create evaluation if it does not exist" do
- @question.add_or_update_evaluation(:total_votes, 1, @user)
+ @question.add_or_update_evaluation(:total_votes, 1, @user).should be_true
@question.reputation_value_for(:total_votes).should == 1
end
it "should update evaluation if it exists already" do
@question.add_evaluation(:total_votes, 1, @user)
- @question.add_or_update_evaluation(:total_votes, 2, @user)
+ @question.add_or_update_evaluation(:total_votes, 2, @user).should be_true
@question.reputation_value_for(:total_votes).should == 2
end
context "With Scopes" do
it "should add evaluation on appropriate scope if it does not exist" do
- @phrase.add_or_update_evaluation(:difficulty_with_scope, 1, @user, :s1)
- @phrase.add_or_update_evaluation(:difficulty_with_scope, 2, @user, :s2)
+ @phrase.add_or_update_evaluation(:difficulty_with_scope, 1, @user, :s1).should be_true
+ @phrase.add_or_update_evaluation(:difficulty_with_scope, 2, @user, :s2).should be_true
@phrase.reputation_value_for(:difficulty_with_scope, :s1).should == 1
@phrase.reputation_value_for(:difficulty_with_scope, :s2).should == 2
@phrase.reputation_value_for(:difficulty_with_scope, :s3).should == 0
end
it "should update evaluation on appropriate scope if it exists already" do
- @phrase.add_evaluation(:difficulty_with_scope, 1, @user, :s1)
- @phrase.add_evaluation(:difficulty_with_scope, 2, @user, :s2)
- @phrase.add_or_update_evaluation(:difficulty_with_scope, 3, @user, :s1)
- @phrase.add_or_update_evaluation(:difficulty_with_scope, 5, @user, :s2)
+ @phrase.add_evaluation(:difficulty_with_scope, 1, @user, :s1).should be_true
+ @phrase.add_evaluation(:difficulty_with_scope, 2, @user, :s2).should be_true
+ @phrase.add_or_update_evaluation(:difficulty_with_scope, 3, @user, :s1).should be_true
+ @phrase.add_or_update_evaluation(:difficulty_with_scope, 5, @user, :s2).should be_true
@phrase.reputation_value_for(:difficulty_with_scope, :s1).should == 3
@phrase.reputation_value_for(:difficulty_with_scope, :s2).should == 5
@phrase.reputation_value_for(:difficulty_with_scope, :s3).should == 0
@@ -104,7 +104,7 @@
end
it "should update evaluation in case of valid input" do
- @question.update_evaluation(:total_votes, 2, @user)
+ @question.update_evaluation(:total_votes, 2, @user).should be_true
@question.reputation_value_for(:total_votes).should == 2
end
@@ -122,11 +122,11 @@
context "With Scopes" do
before :each do
- @phrase.add_evaluation(:difficulty_with_scope, 2, @user, :s2)
+ @phrase.add_evaluation(:difficulty_with_scope, 2, @user, :s2).should be_true
end
it "should update evaluation on appropriate scope" do
- @phrase.update_evaluation(:difficulty_with_scope, 5, @user, :s2)
+ @phrase.update_evaluation(:difficulty_with_scope, 5, @user, :s2).should be_true
@phrase.reputation_value_for(:difficulty_with_scope, :s1).should == 0
@phrase.reputation_value_for(:difficulty_with_scope, :s2).should == 5
@phrase.reputation_value_for(:difficulty_with_scope, :s3).should == 0
@@ -192,7 +192,7 @@
end
it "should delete evaluation in case of valid input" do
- @question.delete_evaluation(:total_votes, @user)
+ @question.delete_evaluation(:total_votes, @user).should be_true
@question.reputation_value_for(:total_votes).should == 0
end
@@ -210,7 +210,7 @@
end
it "should delete evaluation on appropriate scope" do
- @phrase.delete_evaluation(:difficulty_with_scope, @user, :s2)
+ @phrase.delete_evaluation(:difficulty_with_scope, @user, :s2).should be_true
@phrase.reputation_value_for(:difficulty_with_scope, :s1).should == 0
@phrase.reputation_value_for(:difficulty_with_scope, :s2).should == 0
@phrase.reputation_value_for(:difficulty_with_scope, :s3).should == 0
@@ -228,13 +228,13 @@
describe "#increase_evaluation" do
it "should add evaluation if it does not exist" do
- @question.increase_evaluation(:total_votes, 2, @user)
+ @question.increase_evaluation(:total_votes, 2, @user).should be_true
@question.reputation_value_for(:total_votes).should == 2
end
it "should increase evaluation if it exists already" do
@question.add_evaluation(:total_votes, 1, @user)
- @question.increase_evaluation(:total_votes, 2, @user)
+ @question.increase_evaluation(:total_votes, 2, @user).should be_true
@question.reputation_value_for(:total_votes).should == 3
end
@@ -244,7 +244,7 @@
end
it "should increase evaluation on appropriate scope" do
- @phrase.increase_evaluation(:difficulty_with_scope, 5, @user, :s2)
+ @phrase.increase_evaluation(:difficulty_with_scope, 5, @user, :s2).should be_true
@phrase.reputation_value_for(:difficulty_with_scope, :s1).should == 0
@phrase.reputation_value_for(:difficulty_with_scope, :s2).should == 7
@phrase.reputation_value_for(:difficulty_with_scope, :s3).should == 0
@@ -254,13 +254,13 @@
describe "#decrease_evaluation" do
it "should add evaluation if it does not exist" do
- @question.decrease_evaluation(:total_votes, 2, @user)
+ @question.decrease_evaluation(:total_votes, 2, @user).should be_true
@question.reputation_value_for(:total_votes).should == -2
end
it "should increase evaluation if it exists already" do
@question.add_evaluation(:total_votes, 1, @user)
- @question.decrease_evaluation(:total_votes, 2, @user)
+ @question.decrease_evaluation(:total_votes, 2, @user).should be_true
@question.reputation_value_for(:total_votes).should == -1
end
@@ -269,8 +269,8 @@
@phrase.add_evaluation(:difficulty_with_scope, 2, @user, :s2)
end
- it "should increase evaluation on appropriate scope" do
- @phrase.decrease_evaluation(:difficulty_with_scope, 5, @user, :s2)
+ it "should decrease evaluation on appropriate scope" do
+ @phrase.decrease_evaluation(:difficulty_with_scope, 5, @user, :s2).should be_true
@phrase.reputation_value_for(:difficulty_with_scope, :s1).should == 0
@phrase.reputation_value_for(:difficulty_with_scope, :s2).should == -3
@phrase.reputation_value_for(:difficulty_with_scope, :s3).should == 0

0 comments on commit b85c94e

Please sign in to comment.