This commit is contained in:
r888888888
2013-08-02 16:55:30 -07:00
parent ac487e5fab
commit df9c087e85
2 changed files with 26 additions and 11 deletions

View File

@@ -3,10 +3,13 @@ require 'test_helper'
class PostFlagTest < ActiveSupport::TestCase
context "In all cases" do
setup do
@alice = FactoryGirl.create(:user)
Timecop.travel(2.weeks.ago) do
@alice = FactoryGirl.create(:gold_user)
end
CurrentUser.user = @alice
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@post = FactoryGirl.create(:post, :tag_string => "aaa")
end
teardown do
@@ -14,11 +17,25 @@ class PostFlagTest < ActiveSupport::TestCase
CurrentUser.ip_addr = nil
end
context "a user" do
context "a basic user" do
setup do
@post = FactoryGirl.create(:post, :tag_string => "aaa")
Timecop.travel(2.weeks.ago) do
@bob = FactoryGirl.create(:user)
end
CurrentUser.user = @bob
end
should "not be able to flag more than 1 post in 24 hours" do
@post_flag = PostFlag.new(:post => @post, :reason => "aaa", :is_resolved => false)
@post_flag.expects(:flag_count_for_creator).returns(1)
assert_difference("PostFlag.count", 0) do
@post_flag.save
end
assert_equal(["You can flag 1 post a day"], @post_flag.errors.full_messages)
end
end
context "a gold user" do
should "not be able to flag a post more than twice" do
assert_difference("PostFlag.count", 1) do
@post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)