mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08:00
Merge pull request #1230 from ZogStriP/add-newuser-max-attachments-setting
add newuser-max-attachments setting
This commit is contained in:
@ -184,6 +184,54 @@ describe Post do
|
||||
|
||||
end
|
||||
|
||||
describe "maximum attachments" do
|
||||
let(:newuser) { Fabricate(:user, trust_level: TrustLevel.levels[:newuser]) }
|
||||
let(:post_no_attachments) { Fabricate.build(:post, post_args.merge(user: newuser)) }
|
||||
let(:post_one_attachment) { post_with_body('<a class="attachment" href="/uploads/default/1/2082985.txt">file.txt</a>', newuser) }
|
||||
let(:post_two_attachments) { post_with_body('<a class="attachment" href="/uploads/default/2/20947092.log">errors.log</a> <a class="attachment" href="/uploads/default/3/283572385.3ds">model.3ds</a>', newuser) }
|
||||
|
||||
it "returns 0 attachments for an empty post" do
|
||||
Fabricate.build(:post).attachment_count.should == 0
|
||||
end
|
||||
|
||||
it "finds attachments from HTML" do
|
||||
post_two_attachments.attachment_count.should == 2
|
||||
end
|
||||
|
||||
context "validation" do
|
||||
|
||||
before do
|
||||
SiteSetting.stubs(:newuser_max_attachments).returns(1)
|
||||
end
|
||||
|
||||
context 'newuser' do
|
||||
it "allows a new user to post below the limit" do
|
||||
post_one_attachment.should be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow more than the maximum" do
|
||||
post_two_attachments.should_not be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow a new user to edit their post to insert an attachment" do
|
||||
post_no_attachments.user.trust_level = TrustLevel.levels[:new]
|
||||
post_no_attachments.save
|
||||
-> {
|
||||
post_no_attachments.revise(post_no_attachments.user, post_two_attachments.raw)
|
||||
post_no_attachments.reload
|
||||
}.should_not change(post_no_attachments, :raw)
|
||||
end
|
||||
end
|
||||
|
||||
it "allows more attachments from a not-new account" do
|
||||
post_two_attachments.user.trust_level = TrustLevel.levels[:basic]
|
||||
post_two_attachments.should be_valid
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "links" do
|
||||
let(:newuser) { Fabricate(:user, trust_level: TrustLevel.levels[:newuser]) }
|
||||
let(:no_links) { post_with_body("hello world my name is evil trout", newuser) }
|
||||
|
Reference in New Issue
Block a user