Skip to content

Instantly share code, notes, and snippets.

@jakcharlton
Created October 26, 2010 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jakcharlton/646254 to your computer and use it in GitHub Desktop.
Save jakcharlton/646254 to your computer and use it in GitHub Desktop.
Can't quite get this looking cleaner by using "subject" and "specify"
require 'spec_helper'
describe User, ".add_reputation via voting" do
before(:each) do
@user = User.new
@user.reputation.should == 1
end
it "adds one rep" do
@user.add_reputation(:voting)
@user.reputation.should == 2
end
it "cant add rep more than 10 times per day" do
vote_twenty_times(@user)
@user.reputation.should == 11
end
it "limits rep for voting per day when last vote is a few days back" do
@user.last_vote_date = 3.days.ago
@user.last_vote_date.utc < 1.day.ago
vote_twenty_times(@user)
@user.reputation.should == 11
end
it "limits rep per day when last vote is a few days back and has some rep already" do
@user.last_vote_date = 3.days.ago
@user.votes_per_day = 5
@user.reputation = 5
vote_twenty_times(@user)
@user.reputation.should == 15
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