activerecord-reputation-system 1.5.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +29 -198
- data/lib/activerecord-reputation-system.rb +1 -0
- data/lib/reputation_system.rb +6 -6
- data/lib/reputation_system/base.rb +16 -6
- data/lib/reputation_system/{evaluation.rb → evaluation_methods.rb} +32 -13
- data/lib/reputation_system/models/evaluation.rb +73 -0
- data/lib/reputation_system/models/reputation.rb +211 -0
- data/lib/reputation_system/models/reputation_message.rb +49 -0
- data/lib/reputation_system/network.rb +2 -0
- data/lib/reputation_system/query_builder.rb +4 -4
- data/lib/reputation_system/{reputation.rb → reputation_methods.rb} +5 -15
- data/lib/reputation_system/{scope.rb → scope_methods.rb} +2 -2
- data/lib/reputation_system/version.rb +1 -1
- data/spec/reputation_system/base_spec.rb +46 -6
- data/spec/reputation_system/{evaluation_spec.rb → evaluation_methods_spec.rb} +52 -9
- data/spec/{models/rs_evaluation_spec.rb → reputation_system/models/evaluation_spec.rb} +8 -8
- data/spec/{models/rs_reputation_message_spec.rb → reputation_system/models/reputation_message_spec.rb} +10 -10
- data/spec/reputation_system/models/reputation_spec.rb +136 -0
- data/spec/reputation_system/{reputation_spec.rb → reputation_methods_spec.rb} +2 -2
- data/spec/reputation_system/{scope_spec.rb → scope_methods_spec.rb} +0 -0
- data/spec/spec_helper.rb +2 -4
- metadata +15 -14
- data/lib/models/rs_evaluation.rb +0 -69
- data/lib/models/rs_reputation.rb +0 -204
- data/lib/models/rs_reputation_message.rb +0 -46
- data/spec/models/rs_reputation_spec.rb +0 -119
@@ -48,15 +48,55 @@ describe ActiveRecord::Base do
|
|
48
48
|
|
49
49
|
it "should delete reputations if target is deleted" do
|
50
50
|
@question.add_evaluation(:total_votes, 5, @user)
|
51
|
-
reputation_count =
|
52
|
-
message_count =
|
51
|
+
reputation_count = ReputationSystem::Reputation.count
|
52
|
+
message_count = ReputationSystem::ReputationMessage.count
|
53
53
|
@question.destroy
|
54
|
-
|
55
|
-
|
54
|
+
ReputationSystem::Reputation.count.should < reputation_count
|
55
|
+
ReputationSystem::ReputationMessage.count.should < message_count
|
56
56
|
end
|
57
|
+
end
|
58
|
+
end
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
+
context "Association" do
|
61
|
+
describe "#reputations" do
|
62
|
+
it "should define reputations association" do
|
63
|
+
@question.respond_to?(:reputations).should == true
|
64
|
+
end
|
65
|
+
it "should return all reputations for the target" do
|
66
|
+
@question.add_evaluation(:total_votes, 2, @user)
|
67
|
+
@question.add_evaluation(:difficulty, 2, @user)
|
68
|
+
@question.reputations.count.should == 2
|
69
|
+
end
|
70
|
+
describe "#for" do
|
71
|
+
it "should return empty array if there is no reputation for the target" do
|
72
|
+
@question.reputations.for(:total_votes).should == []
|
73
|
+
end
|
74
|
+
it "should return all reputations of the given type for the target" do
|
75
|
+
@question.add_evaluation(:total_votes, 2, @user)
|
76
|
+
@question.add_evaluation(:difficulty, 2, @user)
|
77
|
+
@question.reputations.for(:total_votes).count.should == 1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#evaluations" do
|
83
|
+
it "should define evaluations association" do
|
84
|
+
@question.respond_to?(:evaluations).should == true
|
85
|
+
end
|
86
|
+
it "should return all evaluations for the target" do
|
87
|
+
@question.add_evaluation(:total_votes, 2, @user)
|
88
|
+
@question.add_evaluation(:difficulty, 2, @user)
|
89
|
+
@question.evaluations.count.should == 2
|
90
|
+
end
|
91
|
+
describe "#for" do
|
92
|
+
it "should return empty array if there is no evaluation for the target" do
|
93
|
+
@question.evaluations.for(:total_votes).should == []
|
94
|
+
end
|
95
|
+
it "should return all evaluations of the given type for the target" do
|
96
|
+
@question.add_evaluation(:total_votes, 2, @user)
|
97
|
+
@question.add_evaluation(:difficulty, 2, @user)
|
98
|
+
@question.evaluations.for(:total_votes).count.should == 1
|
99
|
+
end
|
60
100
|
end
|
61
101
|
end
|
62
102
|
end
|
@@ -26,11 +26,33 @@ describe ActiveRecord::Base do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
context "Primary Reputation" do
|
29
|
+
describe "#has_evaluation?" do
|
30
|
+
it "should return false if it has not already been evaluated by a given source" do
|
31
|
+
user = User.create! :name => 'katsuya'
|
32
|
+
@question.add_evaluation(:total_votes, 3, user)
|
33
|
+
@question.has_evaluation?(:total_votes, @user).should be_false
|
34
|
+
end
|
35
|
+
it "should return true if it has been evaluated by a given source" do
|
36
|
+
@question.add_evaluation(:total_votes, 3, @user)
|
37
|
+
@question.has_evaluation?(:total_votes, @user).should be_true
|
38
|
+
end
|
39
|
+
context "With Scopes" do
|
40
|
+
it "should return false if it has not already been evaluated by a given source" do
|
41
|
+
@phrase.add_evaluation(:difficulty_with_scope, 3, @user, :s1)
|
42
|
+
@phrase.has_evaluation?(:difficulty_with_scope, @user, :s2).should be_false
|
43
|
+
end
|
44
|
+
it "should return true if it has been evaluated by a given source" do
|
45
|
+
@phrase.add_evaluation(:difficulty_with_scope, 3, @user, :s1)
|
46
|
+
@phrase.has_evaluation?(:difficulty_with_scope, @user, :s1).should be_true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
29
51
|
describe "#evaluated_by" do
|
30
|
-
it "should return an empty array if it is not
|
52
|
+
it "should return an empty array if it is not evaluated by a given source" do
|
31
53
|
Question.evaluated_by(:total_votes, @user).should == []
|
32
54
|
end
|
33
|
-
|
55
|
+
|
34
56
|
it "should return an array of targets evaluated by a given source" do
|
35
57
|
user2 = User.create!(:name => 'katsuya')
|
36
58
|
question2 = Question.create!(:text => 'Question 2', :author_id => @user.id)
|
@@ -61,13 +83,34 @@ describe ActiveRecord::Base do
|
|
61
83
|
Phrase.evaluated_by(:difficulty_with_scope, @user, :s3).should == [phrase2]
|
62
84
|
Phrase.evaluated_by(:difficulty_with_scope, user2, :s3).should == [@phrase]
|
63
85
|
end
|
86
|
+
end
|
87
|
+
end
|
64
88
|
|
65
|
-
|
66
|
-
|
67
|
-
|
89
|
+
describe "#evaluators_for" do
|
90
|
+
it "should return an empty array if it is not evaluated for a given reputation" do
|
91
|
+
@question.evaluators_for(:total_votes).should == []
|
92
|
+
end
|
68
93
|
|
69
|
-
|
70
|
-
|
94
|
+
it "should return an array of sources evaluated the target" do
|
95
|
+
user2 = User.create!(:name => 'katsuya')
|
96
|
+
question2 = Question.create!(:text => 'Question 2', :author_id => @user.id)
|
97
|
+
@question.add_evaluation(:total_votes, 1, @user).should be_true
|
98
|
+
question2.add_evaluation(:total_votes, 1, @user).should be_true
|
99
|
+
question2.add_evaluation(:total_votes, 2, user2).should be_true
|
100
|
+
@question.evaluators_for(:total_votes).should == [@user]
|
101
|
+
question2.evaluators_for(:total_votes).should == [@user, user2]
|
102
|
+
end
|
103
|
+
|
104
|
+
context "With Scopes" do
|
105
|
+
it "should return an array of targets evaluated by a given source on appropriate scope" do
|
106
|
+
user2 = User.create!(:name => 'katsuya')
|
107
|
+
@phrase.add_evaluation(:difficulty_with_scope, 1, @user, :s1).should be_true
|
108
|
+
@phrase.add_evaluation(:difficulty_with_scope, 2, @user, :s2).should be_true
|
109
|
+
@phrase.add_evaluation(:difficulty_with_scope, 3, user2, :s2).should be_true
|
110
|
+
@phrase.add_evaluation(:difficulty_with_scope, 4, user2, :s3).should be_true
|
111
|
+
@phrase.evaluators_for(:difficulty_with_scope, :s1).should == [@user]
|
112
|
+
@phrase.evaluators_for(:difficulty_with_scope, :s2).should == [@user, user2]
|
113
|
+
@phrase.evaluators_for(:difficulty_with_scope, :s3).should == [user2]
|
71
114
|
end
|
72
115
|
end
|
73
116
|
end
|
@@ -251,8 +294,8 @@ describe ActiveRecord::Base do
|
|
251
294
|
lambda { @question.delete_evaluation(:invalid, @user) }.should raise_error(ArgumentError)
|
252
295
|
end
|
253
296
|
|
254
|
-
it "should return
|
255
|
-
@answer.delete_evaluation(:avg_rating, @user).should
|
297
|
+
it "should return false if evaluation does not exist" do
|
298
|
+
@answer.delete_evaluation(:avg_rating, @user).should be_false
|
256
299
|
end
|
257
300
|
|
258
301
|
context "With Scopes" do
|
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
require 'spec_helper'
|
18
18
|
|
19
|
-
describe
|
19
|
+
describe ReputationSystem::Evaluation do
|
20
20
|
before(:each) do
|
21
21
|
@user = User.create!(:name => 'jack')
|
22
22
|
@question = Question.create!(:text => 'What is Twitter?', :author_id => @user.id)
|
@@ -27,8 +27,8 @@ describe RSEvaluation do
|
|
27
27
|
@attributes = {:reputation_name => 'total_votes', :source => @user, :target => @question, :value => 1}
|
28
28
|
end
|
29
29
|
it "should not be able to create an evaluation from given source if it has already evaluated the same reputation of the target" do
|
30
|
-
|
31
|
-
lambda {
|
30
|
+
ReputationSystem::Evaluation.create!(@attributes)
|
31
|
+
lambda {ReputationSystem::Evaluation.create!(@attributes)}.should raise_error
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -37,14 +37,14 @@ describe RSEvaluation do
|
|
37
37
|
it "should assign source class name as source type if not STI" do
|
38
38
|
question = Question.create!(:text => 'Does this work?', :author_id => @user.id)
|
39
39
|
question.add_evaluation(:total_votes, 5, @user)
|
40
|
-
evaluation =
|
40
|
+
evaluation = ReputationSystem::Evaluation.find_by_reputation_name_and_source_and_target(:total_votes, @user, question)
|
41
41
|
evaluation.source_type.should == @user.class.name
|
42
42
|
end
|
43
43
|
it "should assign source's ancestors class name where reputation is declared if STI" do
|
44
44
|
designer = Designer.create! :name => 'hiro'
|
45
45
|
programmer = Programmer.create! :name => 'katsuya'
|
46
46
|
programmer.add_evaluation(:leadership, 1, designer)
|
47
|
-
evaluation =
|
47
|
+
evaluation = ReputationSystem::Evaluation.find_by_reputation_name_and_source_and_target(:leadership, designer, programmer)
|
48
48
|
evaluation.source_type.should == Person.name
|
49
49
|
end
|
50
50
|
end
|
@@ -53,10 +53,10 @@ describe RSEvaluation do
|
|
53
53
|
context "Association" do
|
54
54
|
it "should delete associated reputation message" do
|
55
55
|
@question.add_evaluation(:total_votes, 5, @user)
|
56
|
-
evaluation =
|
57
|
-
|
56
|
+
evaluation = ReputationSystem::Evaluation.find_by_reputation_name_and_source_and_target(:total_votes, @user, @question)
|
57
|
+
ReputationSystem::ReputationMessage.find_by_sender_id_and_sender_type(evaluation.id, evaluation.class.name).should_not be_nil
|
58
58
|
@question.delete_evaluation(:total_votes, @user)
|
59
|
-
|
59
|
+
ReputationSystem::ReputationMessage.find_by_sender_id_and_sender_type(evaluation.id, evaluation.class.name).should be_nil
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -16,21 +16,21 @@
|
|
16
16
|
|
17
17
|
require 'spec_helper'
|
18
18
|
|
19
|
-
describe
|
19
|
+
describe ReputationSystem::ReputationMessage do
|
20
20
|
before(:each) do
|
21
21
|
@user = User.create!(:name => 'jack')
|
22
|
-
@rep1 =
|
23
|
-
@rep2 =
|
22
|
+
@rep1 = ReputationSystem::Reputation.create!(:reputation_name => "karma1", :target_id => @user.id, :target_type => @user.class.to_s, :aggregated_by => 'sum')
|
23
|
+
@rep2 = ReputationSystem::Reputation.create!(:reputation_name => "karma2", :target_id => @user.id, :target_type => @user.class.to_s, :aggregated_by => 'sum')
|
24
24
|
end
|
25
25
|
|
26
26
|
context "Validation" do
|
27
27
|
it "should not be able to create a message from given sender if it has already sent one to the same receiver" do
|
28
|
-
|
29
|
-
|
28
|
+
ReputationSystem::ReputationMessage.create(:sender => @rep1, :receiver => @rep2).should be_valid
|
29
|
+
ReputationSystem::ReputationMessage.create(:sender => @rep1, :receiver => @rep2).should_not be_valid
|
30
30
|
end
|
31
31
|
|
32
|
-
it "should have raise error if sender is neither
|
33
|
-
|
32
|
+
it "should have raise error if sender is neither ReputationSystem::Evaluation and ReputationSystem::Reputation" do
|
33
|
+
ReputationSystem::ReputationMessage.create(:sender => @user, :receiver => @rep2).errors[:sender].should_not be_nil
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -38,10 +38,10 @@ describe RSReputationMessage do
|
|
38
38
|
it "should delete associated sender if it is evaluation" do
|
39
39
|
question = Question.create!(:text => 'What is Twitter?', :author_id => @user.id)
|
40
40
|
question.add_evaluation(:total_votes, 5, @user)
|
41
|
-
evaluation =
|
42
|
-
m =
|
41
|
+
evaluation = ReputationSystem::Evaluation.find_by_reputation_name_and_source_and_target(:total_votes, @user, question)
|
42
|
+
m = ReputationSystem::ReputationMessage.find_by_sender_id_and_sender_type(evaluation.id, evaluation.class.name)
|
43
43
|
m.destroy
|
44
44
|
lambda { evaluation.reload }.should raise_error ActiveRecord::RecordNotFound
|
45
45
|
end
|
46
46
|
end
|
47
|
-
end
|
47
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
##
|
2
|
+
# Copyright 2012 Twitter, Inc
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
##
|
16
|
+
|
17
|
+
require 'spec_helper'
|
18
|
+
|
19
|
+
describe ReputationSystem::Reputation do
|
20
|
+
before(:each) do
|
21
|
+
@user = User.create!(:name => 'jack')
|
22
|
+
end
|
23
|
+
|
24
|
+
context "Validation" do
|
25
|
+
it "should have value 0 by default in case of non product process" do
|
26
|
+
r = ReputationSystem::Reputation.create!(:reputation_name => "karma", :target_id => @user.id, :target_type => @user.class.to_s, :aggregated_by => 'sum')
|
27
|
+
r.value.should == 0
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be able to change value to 0 if process is not product process" do
|
31
|
+
r = ReputationSystem::Reputation.create!(:reputation_name => "karma", :target_id => @user.id, :target_type => @user.class.to_s, :aggregated_by => 'sum', :value => 10)
|
32
|
+
r.value = 0
|
33
|
+
r.save!
|
34
|
+
r.reload
|
35
|
+
r.value.should == 0
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should have value 1 by default in case of product process" do
|
39
|
+
r = ReputationSystem::Reputation.create!(:reputation_name => "karma", :target_id => @user.id, :target_type => @user.class.to_s, :aggregated_by => 'product')
|
40
|
+
r.value.should == 1
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should be able to create reputation with process 'sum', 'average' and 'product'" do
|
44
|
+
ReputationSystem::Reputation.create(:reputation_name => "karma1", :target_id => @user.id, :target_type => @user.class.to_s, :aggregated_by => 'sum').should be_valid
|
45
|
+
ReputationSystem::Reputation.create(:reputation_name => "karma2", :target_id => @user.id, :target_type => @user.class.to_s, :aggregated_by => 'average').should be_valid
|
46
|
+
ReputationSystem::Reputation.create(:reputation_name => "karma3", :target_id => @user.id, :target_type => @user.class.to_s, :aggregated_by => 'product').should be_valid
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should not be able to create reputation with process other than 'sum', 'average' and 'product'" do
|
50
|
+
ReputationSystem::Reputation.create(:reputation_name => "karma", :target_id => @user.id, :target_type => @user.class.to_s, :aggregated_by => 'invalid').should_not be_valid
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should not be able to create reputation of the same name for the same target" do
|
54
|
+
ReputationSystem::Reputation.create(:reputation_name => "karma", :target_id => @user.id, :target_type => @user.class.to_s, :aggregated_by => 'sum').should be_valid
|
55
|
+
ReputationSystem::Reputation.create(:reputation_name => "karma", :target_id => @user.id, :target_type => @user.class.to_s, :aggregated_by => 'sum').should_not be_valid
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "Callback" do
|
60
|
+
describe "#set_target_type_for_sti" do
|
61
|
+
it "should assign target class name as target type if not STI" do
|
62
|
+
question = Question.create!(:text => 'Does this work?', :author_id => @user.id)
|
63
|
+
question.add_evaluation(:total_votes, 5, @user)
|
64
|
+
rep = ReputationSystem::Reputation.find_by_reputation_name_and_target(:total_votes, question)
|
65
|
+
rep.target_type.should == question.class.name
|
66
|
+
end
|
67
|
+
it "should assign target's ancestors class name where reputation is declared if STI" do
|
68
|
+
designer = Designer.create! :name => 'hiro'
|
69
|
+
programmer = Programmer.create! :name => 'katsuya'
|
70
|
+
programmer.add_evaluation(:leadership, 1, designer)
|
71
|
+
rep = ReputationSystem::Reputation.find_by_reputation_name_and_target(:leadership, programmer)
|
72
|
+
rep.target_type.should == Person.name
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "Association" do
|
78
|
+
before :each do
|
79
|
+
@question = Question.create!(:text => 'What is Twitter?', :author_id => @user.id)
|
80
|
+
@question.add_evaluation(:total_votes, 5, @user)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should delete associated received messages" do
|
84
|
+
rep = ReputationSystem::Reputation.find_by_target_id_and_target_type(@question.id, 'Question')
|
85
|
+
ReputationSystem::ReputationMessage.find_by_receiver_id(rep.id).should_not be_nil
|
86
|
+
rep.destroy
|
87
|
+
ReputationSystem::ReputationMessage.find_by_receiver_id(rep.id).should be_nil
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should delete associated sent messages" do
|
91
|
+
rep = ReputationSystem::Reputation.find_by_target_id_and_target_type(@user.id, 'User')
|
92
|
+
ReputationSystem::ReputationMessage.find_by_sender_id_and_sender_type(rep.id, rep.class.name).should_not be_nil
|
93
|
+
rep.destroy
|
94
|
+
ReputationSystem::ReputationMessage.find_by_sender_id_and_sender_type(rep.id, rep.class.name).should be_nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#normalized_value" do
|
99
|
+
before :each do
|
100
|
+
@user2 = User.create!(:name => 'dick')
|
101
|
+
@user3 = User.create!(:name => 'foo')
|
102
|
+
question = Question.new(:text => "Does this work?", :author_id => @user.id)
|
103
|
+
@r1 = ReputationSystem::Reputation.create!(:reputation_name => "karma", :value => 2, :target_id => @user.id, :target_type => @user.class.to_s, :aggregated_by => 'sum')
|
104
|
+
@r2 = ReputationSystem::Reputation.create!(:reputation_name => "karma", :value => 6, :target_id => @user2.id, :target_type => @user2.class.to_s, :aggregated_by => 'sum')
|
105
|
+
@r3 = ReputationSystem::Reputation.create!(:reputation_name => "karma", :value => 10, :target_id => @user3.id, :target_type => @user3.class.to_s, :aggregated_by => 'sum')
|
106
|
+
@r4 = ReputationSystem::Reputation.create!(:reputation_name => "karma", :value => 10, :target_id => question.id, :target_type => question.class.to_s, :aggregated_by => 'sum')
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should return correct normalized value" do
|
110
|
+
@r1.normalized_value.should be_within(DELTA).of(0)
|
111
|
+
@r2.normalized_value.should be_within(DELTA).of(0.5)
|
112
|
+
@r3.normalized_value.should be_within(DELTA).of(1)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should return 0 if max and min are the same" do
|
116
|
+
@r4.normalized_value.should be_within(DELTA).of(0)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "value propagation with average process" do
|
121
|
+
it "should calculate average reputation even after evaluation is deleted" do
|
122
|
+
user1 = User.create! :name => 'dick'
|
123
|
+
user2 = User.create! :name => 'katsuya'
|
124
|
+
answer = Answer.create!
|
125
|
+
answer.add_evaluation(:avg_rating, 3, user1)
|
126
|
+
answer.add_evaluation(:avg_rating, 2, user2)
|
127
|
+
answer.reputation_for(:avg_rating).should be_within(DELTA).of(2.5)
|
128
|
+
answer.delete_evaluation(:avg_rating, user1)
|
129
|
+
answer.reputation_for(:avg_rating).should be_within(DELTA).of(2)
|
130
|
+
answer.delete_evaluation(:avg_rating, user2)
|
131
|
+
answer.reputation_for(:avg_rating).should be_within(DELTA).of(0)
|
132
|
+
answer.add_evaluation(:avg_rating, 3, user1)
|
133
|
+
answer.reputation_for(:avg_rating).should be_within(DELTA).of(3)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -153,9 +153,9 @@ describe ActiveRecord::Base do
|
|
153
153
|
@question2.add_evaluation(:total_votes, 70, @user)
|
154
154
|
@question.add_evaluation(:total_votes, 100, @user)
|
155
155
|
@question.deactivate_all_reputations
|
156
|
-
|
156
|
+
ReputationSystem::Reputation.maximum(:value, :conditions => {:reputation_name => 'total_votes', :active => true}).should == 70
|
157
157
|
@question.activate_all_reputations
|
158
|
-
|
158
|
+
ReputationSystem::Reputation.maximum(:value, :conditions => {:reputation_name => 'total_votes', :active => true}).should == 100
|
159
159
|
end
|
160
160
|
end
|
161
161
|
end
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -135,7 +135,6 @@ class Question < ActiveRecord::Base
|
|
135
135
|
|
136
136
|
has_reputation :total_votes,
|
137
137
|
:source => :user,
|
138
|
-
:aggregated_by => :sum,
|
139
138
|
:source_of => { :reputation => :question_karma, :of => :author }
|
140
139
|
|
141
140
|
has_reputation :difficulty,
|
@@ -156,8 +155,7 @@ class Answer < ActiveRecord::Base
|
|
156
155
|
|
157
156
|
has_reputation :avg_rating,
|
158
157
|
:source => :user,
|
159
|
-
:aggregated_by => :average
|
160
|
-
:init_value => 1
|
158
|
+
:aggregated_by => :average
|
161
159
|
end
|
162
160
|
|
163
161
|
class Phrase < ActiveRecord::Base
|
@@ -192,7 +190,7 @@ class Translation < ActiveRecord::Base
|
|
192
190
|
has_reputation :votes,
|
193
191
|
:source => :user,
|
194
192
|
:aggregated_by => :sum,
|
195
|
-
:source_of => { :reputation => :maturity, :of => :phrase, :scope => :locale}
|
193
|
+
:source_of => { :reputation => :maturity, :of => :phrase, :scope => :locale}
|
196
194
|
end
|
197
195
|
|
198
196
|
class Person < ActiveRecord::Base
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: activerecord-reputation-system
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version:
|
5
|
+
version: 2.0.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Katsuya Noguchi
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-10-
|
13
|
+
date: 2012-10-05 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- LICENSE
|
92
92
|
- README.md
|
93
93
|
- Rakefile
|
94
|
+
- lib/activerecord-reputation-system.rb
|
94
95
|
- lib/generators/reputation_system/reputation_system_generator.rb
|
95
96
|
- lib/generators/reputation_system/templates/add_evaluations_index.rb
|
96
97
|
- lib/generators/reputation_system/templates/add_reputation_messages_index.rb
|
@@ -99,28 +100,28 @@ files:
|
|
99
100
|
- lib/generators/reputation_system/templates/change_reputation_messages_index_to_unique.rb
|
100
101
|
- lib/generators/reputation_system/templates/change_reputations_index_to_unique.rb
|
101
102
|
- lib/generators/reputation_system/templates/create_reputation_system.rb
|
102
|
-
- lib/models/rs_evaluation.rb
|
103
|
-
- lib/models/rs_reputation.rb
|
104
|
-
- lib/models/rs_reputation_message.rb
|
105
103
|
- lib/reputation_system/base.rb
|
106
|
-
- lib/reputation_system/
|
104
|
+
- lib/reputation_system/evaluation_methods.rb
|
107
105
|
- lib/reputation_system/finder_methods.rb
|
106
|
+
- lib/reputation_system/models/evaluation.rb
|
107
|
+
- lib/reputation_system/models/reputation.rb
|
108
|
+
- lib/reputation_system/models/reputation_message.rb
|
108
109
|
- lib/reputation_system/network.rb
|
109
110
|
- lib/reputation_system/query_builder.rb
|
110
111
|
- lib/reputation_system/query_methods.rb
|
111
|
-
- lib/reputation_system/
|
112
|
-
- lib/reputation_system/
|
112
|
+
- lib/reputation_system/reputation_methods.rb
|
113
|
+
- lib/reputation_system/scope_methods.rb
|
113
114
|
- lib/reputation_system/version.rb
|
114
115
|
- lib/reputation_system.rb
|
115
|
-
- spec/models/rs_evaluation_spec.rb
|
116
|
-
- spec/models/rs_reputation_message_spec.rb
|
117
|
-
- spec/models/rs_reputation_spec.rb
|
118
116
|
- spec/reputation_system/base_spec.rb
|
119
|
-
- spec/reputation_system/
|
117
|
+
- spec/reputation_system/evaluation_methods_spec.rb
|
120
118
|
- spec/reputation_system/finder_methods_spec.rb
|
119
|
+
- spec/reputation_system/models/evaluation_spec.rb
|
120
|
+
- spec/reputation_system/models/reputation_message_spec.rb
|
121
|
+
- spec/reputation_system/models/reputation_spec.rb
|
121
122
|
- spec/reputation_system/query_methods_spec.rb
|
122
|
-
- spec/reputation_system/
|
123
|
-
- spec/reputation_system/
|
123
|
+
- spec/reputation_system/reputation_methods_spec.rb
|
124
|
+
- spec/reputation_system/scope_methods_spec.rb
|
124
125
|
- spec/spec_helper.rb
|
125
126
|
homepage: https://github.com/twitter/activerecord-reputation-system
|
126
127
|
licenses: []
|