change daily flag limit to 5/day

This commit is contained in:
r888888888
2017-03-16 14:32:04 -07:00
parent d9a26975ba
commit e7b3fae215
3 changed files with 36 additions and 8 deletions

View File

@@ -95,12 +95,10 @@ class PostFlag < ActiveRecord::Base
end
def validate_creator_is_not_limited
if CurrentUser.can_approve_posts?
# do nothing
elsif creator.created_at > 1.week.ago
if 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"
elsif creator.is_gold? && flag_count_for_creator >= 5
errors[:creator] << "can flag 5 posts a day"
elsif !creator.is_gold? && flag_count_for_creator >= 1
errors[:creator] << "can flag 1 post a day"
end

View File

@@ -48,13 +48,13 @@ class PostFlagTest < ActiveSupport::TestCase
assert_equal(["You have already flagged this post"], @post_flag.errors.full_messages)
end
should "not be able to flag more than 10 posts in 24 hours" do
should "not be able to flag more than 5 posts in 24 hours" do
@post_flag = PostFlag.new(:post => @post, :reason => "aaa", :is_resolved => false)
@post_flag.expects(:flag_count_for_creator).returns(10)
@post_flag.expects(:flag_count_for_creator).returns(5)
assert_difference("PostFlag.count", 0) do
@post_flag.save
end
assert_equal(["You can flag 10 posts a day"], @post_flag.errors.full_messages)
assert_equal(["You can flag 5 posts a day"], @post_flag.errors.full_messages)
end
should "not be able to flag a deleted post" do

View File

@@ -10,6 +10,36 @@ class SavedSearchTest < ActiveSupport::TestCase
mock_saved_search_service!
end
context ".labels_for" do
setup do
@user = FactoryGirl.create(:user)
FactoryGirl.create(:saved_search, user: @user, label_string: "blah", query: "blah")
FactoryGirl.create(:saved_search, user: @user, label_string: "zah", query: "blah")
end
should "fetch the labels used by a user" do
assert_equal(%w(blah zah), SavedSearch.labels_for(@user.id))
end
should "expire when a search is updated" do
Cache.expects(:delete).once
FactoryGirl.create(:saved_search, user: @user, query: "blah")
end
end
context ".queries_for" do
setup do
@user = FactoryGirl.create(:user)
FactoryGirl.create(:saved_search, user: @user, label_string: "blah", query: "aaa")
FactoryGirl.create(:saved_search, user: @user, label_string: "zah", query: "bbb")
end
should "fetch the queries used by a user for a label" do
assert_equal(%w(aaa), SavedSearch.queries_for(@user.id, "blah"))
assert_equal(%w(aaa bbb), SavedSearch.queries_for(@user.id))
end
end
context "Fetching the post ids for a search" do
setup do
MEMCACHE.expects(:get).returns(nil)