-
-
Save just3ws/648916 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# clear; spec spec/models/user_spec.rb -f specdoc --colour | |
require 'spec/spec_helper' | |
describe User, "add reputation via voting" do | |
let(:user) {User.new} | |
context "when starting from a brand new user" do | |
it "gives a user one reputation for free" do | |
user.reputation.should equal 1 | |
end | |
it "increments the reputation by one" do | |
user.add_reputation(:voting) | |
user.reputation.should equal 2 | |
end | |
it "can't add rep more than 10 times per day" do | |
vote_twenty_times(user) | |
user.reputation.should equal 11 | |
end | |
end | |
context "when working with an existing user who has some history" do | |
before {user.last_vote_date = 3.days.ago } | |
it "limits the reputation to the daily limit" do | |
user.last_vote_date.utc < 1.day.ago | |
vote_twenty_times(user) | |
user.reputation.should equal 11 | |
end | |
context "when user already has some reputation" do | |
before {user.reputation = 5} | |
it "limits rep per day when last vote is a few days back and has some rep already" do | |
user.votes_per_day = 5 | |
vote_twenty_times(user) | |
user.reputation.should equal 15 | |
end | |
end | |
end | |
def vote_twenty_times(user) | |
20.times do | |
user.add_reputation(:voting) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment