Permalink
Browse files

Add reputation_for and normalized_reputation_for methods

  • Loading branch information...
Katsuya Noguchi
Katsuya Noguchi committed Sep 15, 2012
1 parent a444b47 commit 6dbe5cb6594d6a20a788d8c7c7b6d56cd6842ee9
View
@@ -1,6 +1,8 @@
+* Add `reputation_for` and `normalized_reputation_for` methods that are shorten name of `reputation_value_for` and `normalized_reputation_value_for` methods.
+
## ActiveRecordReputationSystem 1.4.0 ##
-* Add `with_normalized_reputation` and `with_normalized_reputation_only`
+* Add `with_normalized_reputation` and `with_normalized_reputation_only`.
* Add `with_reputation` and `with_reputation_only` methods.
@@ -17,10 +17,20 @@
module ReputationSystem
module Reputation
def reputation_value_for(reputation_name, *args)
+ warn "[DEPRECATION] `reputation_value_for` will be deprecated in version 2.0.0. Please use `reputation_for` instead."
+ reputation_for(reputation_name, *args)
+ end
+
+ def reputation_for(reputation_name, *args)
find_reputation(reputation_name, args.first).value
end
def normalized_reputation_value_for(reputation_name, *args)
+ warn "[DEPRECATION] `normalized_reputation_value_for` will be deprecated in version 2.0.0. Please use `normalized_reputation_for` instead."
+ normalized_reputation_for(reputation_name, *args)
+ end
+
+ def normalized_reputation_for(reputation_name, *args)
find_reputation(reputation_name, args.first).normalized_value
end
@@ -45,7 +55,7 @@ def reputations_activated?(reputation_name)
def rank_for(reputation_name, *args)
scope = args.first
- my_value = self.reputation_value_for(reputation_name, scope)
+ my_value = self.reputation_for(reputation_name, scope)
self.class.count_with_reputation(reputation_name, scope, :all,
:conditions => ["rs_reputations.value > ?", my_value]
) + 1
@@ -36,14 +36,14 @@
@user.respond_to?(:add_evaluation).should == false
end
- it "should add 'reputation_value_for' method to a model with reputation" do
- @user.respond_to?(:reputation_value_for).should == true
- @question.respond_to?(:reputation_value_for).should == true
+ it "should add 'reputation_for' method to a model with reputation" do
+ @user.respond_to?(:reputation_for).should == true
+ @question.respond_to?(:reputation_for).should == true
end
- it "should add 'normalized_reputation_value_for' method to a model with reputation" do
- @user.respond_to?(:normalized_reputation_value_for).should == true
- @question.respond_to?(:normalized_reputation_value_for).should == true
+ it "should add 'normalized_reputation_for' method to a model with reputation" do
+ @user.respond_to?(:normalized_reputation_for).should == true
+ @question.respond_to?(:normalized_reputation_for).should == true
end
it "should delete reputations if target is deleted" do
@@ -56,12 +56,12 @@
end
it "should have declared default value if any" do
- @answer.reputation_value_for(:avg_rating).should == 1
+ @answer.reputation_for(:avg_rating).should == 1
end
it "should overwrite reputation definitions if the same reputation name is declared" do
Answer.has_reputation(:avg_rating, :source => :user, :aggregated_by => :average, :init_value => 2)
- Answer.new.reputation_value_for(:avg_rating).should == 2
+ Answer.new.reputation_for(:avg_rating).should == 2
end
end
end
@@ -75,7 +75,7 @@
describe "#add_evaluation" do
it "should create evaluation in case of valid input" do
@question.add_evaluation(:total_votes, 1, @user).should be_true
- @question.reputation_value_for(:total_votes).should == 1
+ @question.reputation_for(:total_votes).should == 1
end
it "should raise exception if invalid reputation name is given" do
@@ -96,9 +96,9 @@
it "should add evaluation on appropriate scope" do
@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
+ @phrase.reputation_for(:difficulty_with_scope, :s1).should == 1
+ @phrase.reputation_for(:difficulty_with_scope, :s2).should == 2
+ @phrase.reputation_for(:difficulty_with_scope, :s3).should == 0
end
it "should raise exception if invalid scope is given" do
@@ -114,32 +114,32 @@
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).should be_true
- @question.reputation_value_for(:total_votes).should == 1
+ @question.reputation_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).should be_true
- @question.reputation_value_for(:total_votes).should == 2
+ @question.reputation_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).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
+ @phrase.reputation_for(:difficulty_with_scope, :s1).should == 1
+ @phrase.reputation_for(:difficulty_with_scope, :s2).should == 2
+ @phrase.reputation_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).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
+ @phrase.reputation_for(:difficulty_with_scope, :s1).should == 3
+ @phrase.reputation_for(:difficulty_with_scope, :s2).should == 5
+ @phrase.reputation_for(:difficulty_with_scope, :s3).should == 0
end
end
end
@@ -151,7 +151,7 @@
it "should update evaluation in case of valid input" do
@question.update_evaluation(:total_votes, 2, @user).should be_true
- @question.reputation_value_for(:total_votes).should == 2
+ @question.reputation_for(:total_votes).should == 2
end
it "should raise exception if invalid reputation name is given" do
@@ -173,9 +173,9 @@
it "should update evaluation on appropriate scope" do
@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
+ @phrase.reputation_for(:difficulty_with_scope, :s1).should == 0
+ @phrase.reputation_for(:difficulty_with_scope, :s2).should == 5
+ @phrase.reputation_for(:difficulty_with_scope, :s3).should == 0
end
it "should raise exception if invalid scope is given" do
@@ -195,7 +195,7 @@
it "should delete evaluation in case of valid input" do
@question.delete_evaluation!(:total_votes, @user)
- @question.reputation_value_for(:total_votes).should == 0
+ @question.reputation_for(:total_votes).should == 0
end
it "should raise exception if invalid reputation name is given" do
@@ -217,9 +217,9 @@
it "should delete evaluation on appropriate scope" do
@phrase.delete_evaluation!(:difficulty_with_scope, @user, :s2)
- @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
+ @phrase.reputation_for(:difficulty_with_scope, :s1).should == 0
+ @phrase.reputation_for(:difficulty_with_scope, :s2).should == 0
+ @phrase.reputation_for(:difficulty_with_scope, :s3).should == 0
end
it "should raise exception if invalid scope is given" do
@@ -239,7 +239,7 @@
it "should delete evaluation in case of valid input" do
@question.delete_evaluation(:total_votes, @user).should be_true
- @question.reputation_value_for(:total_votes).should == 0
+ @question.reputation_for(:total_votes).should == 0
end
it "should raise exception if invalid reputation name is given" do
@@ -257,9 +257,9 @@
it "should delete evaluation on appropriate scope" do
@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
+ @phrase.reputation_for(:difficulty_with_scope, :s1).should == 0
+ @phrase.reputation_for(:difficulty_with_scope, :s2).should == 0
+ @phrase.reputation_for(:difficulty_with_scope, :s3).should == 0
end
it "should raise exception if invalid scope is given" do
@@ -275,13 +275,13 @@
describe "#increase_evaluation" do
it "should add evaluation if it does not exist" do
@question.increase_evaluation(:total_votes, 2, @user).should be_true
- @question.reputation_value_for(:total_votes).should == 2
+ @question.reputation_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).should be_true
- @question.reputation_value_for(:total_votes).should == 3
+ @question.reputation_for(:total_votes).should == 3
end
context "With Scopes" do
@@ -291,23 +291,23 @@
it "should increase evaluation on appropriate scope" do
@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
+ @phrase.reputation_for(:difficulty_with_scope, :s1).should == 0
+ @phrase.reputation_for(:difficulty_with_scope, :s2).should == 7
+ @phrase.reputation_for(:difficulty_with_scope, :s3).should == 0
end
end
end
describe "#decrease_evaluation" do
it "should add evaluation if it does not exist" do
@question.decrease_evaluation(:total_votes, 2, @user).should be_true
- @question.reputation_value_for(:total_votes).should == -2
+ @question.reputation_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).should be_true
- @question.reputation_value_for(:total_votes).should == -1
+ @question.reputation_for(:total_votes).should == -1
end
context "With Scopes" do
@@ -317,9 +317,9 @@
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
+ @phrase.reputation_for(:difficulty_with_scope, :s1).should == 0
+ @phrase.reputation_for(:difficulty_with_scope, :s2).should == -3
+ @phrase.reputation_for(:difficulty_with_scope, :s3).should == 0
end
end
end
@@ -336,8 +336,8 @@
it "should affect only reputations with relevant scope" do
@trans_ja.add_evaluation(:votes, 1, @user)
@trans_fr.add_evaluation(:votes, 2, @user)
- @phrase.reputation_value_for(:maturity, :ja).should == 1
- @phrase.reputation_value_for(:maturity, :fr).should == 2
+ @phrase.reputation_for(:maturity, :ja).should == 1
+ @phrase.reputation_for(:maturity, :fr).should == 2
end
end
@@ -348,8 +348,8 @@
it "should affect only reputations with relevant scope" do
@trans_ja.update_evaluation(:votes, 3, @user)
- @phrase.reputation_value_for(:maturity, :ja).should == 3
- @phrase.reputation_value_for(:maturity, :fr).should == 0
+ @phrase.reputation_for(:maturity, :ja).should == 3
+ @phrase.reputation_for(:maturity, :fr).should == 0
end
end
@@ -360,8 +360,8 @@
it "should affect only reputations with relevant scope" do
@trans_ja.delete_evaluation!(:votes, @user)
- @phrase.reputation_value_for(:maturity, :ja).should == 0
- @phrase.reputation_value_for(:maturity, :fr).should == 0
+ @phrase.reputation_for(:maturity, :ja).should == 0
+ @phrase.reputation_for(:maturity, :fr).should == 0
end
end
end
@@ -378,14 +378,14 @@
describe "#add_evaluation" do
it "should affect only reputations with relevant scope" do
@trans_ja.add_evaluation(:votes, 1, @user)
- @phrase.reputation_value_for(:maturity_all).should == 1
+ @phrase.reputation_for(:maturity_all).should == 1
@trans_fr.add_evaluation(:votes, 2, @user)
- @phrase.reputation_value_for(:maturity_all).should == 3
+ @phrase.reputation_for(:maturity_all).should == 3
@trans_de.add_evaluation(:votes, 3, @user)
- @phrase.reputation_value_for(:maturity_all).should == 3
- @phrase.reputation_value_for(:maturity, :ja).should == 1
- @phrase.reputation_value_for(:maturity, :fr).should == 2
- @phrase.reputation_value_for(:maturity, :de).should == 3
+ @phrase.reputation_for(:maturity_all).should == 3
+ @phrase.reputation_for(:maturity, :ja).should == 1
+ @phrase.reputation_for(:maturity, :fr).should == 2
+ @phrase.reputation_for(:maturity, :de).should == 3
end
end
@@ -398,7 +398,7 @@
it "should affect only reputations with relevant scope" do
@trans_ja.update_evaluation(:votes, 3, @user)
@trans_de.update_evaluation(:votes, 2, @user)
- @phrase.reputation_value_for(:maturity_all).should == 3
+ @phrase.reputation_for(:maturity_all).should == 3
end
end
@@ -410,9 +410,9 @@
it "should affect only reputations with relevant scope" do
@trans_de.delete_evaluation!(:votes, @user)
- @phrase.reputation_value_for(:maturity_all).should == 1
+ @phrase.reputation_for(:maturity_all).should == 1
@trans_ja.delete_evaluation!(:votes, @user)
- @phrase.reputation_value_for(:maturity_all).should == 0
+ @phrase.reputation_for(:maturity_all).should == 0
end
end
end
Oops, something went wrong.

0 comments on commit 6dbe5cb

Please sign in to comment.