fixes #826
This commit is contained in:
@@ -61,21 +61,19 @@ class PostFlag < ActiveRecord::Base
|
|||||||
|
|
||||||
def validate_creator_is_not_limited
|
def validate_creator_is_not_limited
|
||||||
if CurrentUser.is_janitor?
|
if CurrentUser.is_janitor?
|
||||||
false
|
# do nothing
|
||||||
elsif flag_count_for_creator >= 10
|
elsif creator.created_at > 1.week.ago
|
||||||
|
errors[:creator] << "cannot flag within the first week of sign up"
|
||||||
|
elsif creator.is_gold? && flag_count_for_creator >= 10
|
||||||
errors[:creator] << "can flag 10 posts a day"
|
errors[:creator] << "can flag 10 posts a day"
|
||||||
false
|
elsif !creator.is_gold? && flag_count_for_creator >= 1
|
||||||
else
|
errors[:creator] << "can flag 1 post a day"
|
||||||
true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_post_is_active
|
def validate_post_is_active
|
||||||
if post.is_deleted?
|
if post.is_deleted?
|
||||||
errors[:post] << "is deleted"
|
errors[:post] << "is deleted"
|
||||||
false
|
|
||||||
else
|
|
||||||
true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,13 @@ require 'test_helper'
|
|||||||
class PostFlagTest < ActiveSupport::TestCase
|
class PostFlagTest < ActiveSupport::TestCase
|
||||||
context "In all cases" do
|
context "In all cases" do
|
||||||
setup do
|
setup do
|
||||||
@alice = FactoryGirl.create(:user)
|
Timecop.travel(2.weeks.ago) do
|
||||||
|
@alice = FactoryGirl.create(:gold_user)
|
||||||
|
end
|
||||||
CurrentUser.user = @alice
|
CurrentUser.user = @alice
|
||||||
CurrentUser.ip_addr = "127.0.0.1"
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
MEMCACHE.flush_all
|
MEMCACHE.flush_all
|
||||||
|
@post = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
@@ -14,11 +17,25 @@ class PostFlagTest < ActiveSupport::TestCase
|
|||||||
CurrentUser.ip_addr = nil
|
CurrentUser.ip_addr = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
context "a user" do
|
context "a basic user" do
|
||||||
setup 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
|
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
|
should "not be able to flag a post more than twice" do
|
||||||
assert_difference("PostFlag.count", 1) do
|
assert_difference("PostFlag.count", 1) do
|
||||||
@post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
|
@post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
|
||||||
|
|||||||
Reference in New Issue
Block a user