mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 04:19:28 +08:00
Add specs for topic create with auto_close_time. Just ignore auto_close_time from users who are not authorized to use it instead of raising an error.
This commit is contained in:
parent
617a605ca2
commit
1cc72d564f
|
@ -339,7 +339,7 @@ Discourse.Utilities = {
|
||||||
return t.add('days', 1).toJSON();
|
return t.add('days', 1).toJSON();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return arg;
|
return (arg === '' ? null : arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -443,7 +443,6 @@ Discourse.Composer = Discourse.Model.extend({
|
||||||
postStream = this.get('topic.postStream'),
|
postStream = this.get('topic.postStream'),
|
||||||
addedToStream = false;
|
addedToStream = false;
|
||||||
|
|
||||||
|
|
||||||
// Build the post object
|
// Build the post object
|
||||||
var createdPost = Discourse.Post.create({
|
var createdPost = Discourse.Post.create({
|
||||||
raw: this.get('reply'),
|
raw: this.get('reply'),
|
||||||
|
|
|
@ -55,7 +55,7 @@ class TopicCreator
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_auto_close_time
|
def setup_auto_close_time
|
||||||
@guardian.ensure_can_moderate!(@topic)
|
return unless @guardian.can_moderate?(@topic)
|
||||||
@topic.set_auto_close(@opts[:auto_close_time], @user)
|
@topic.set_auto_close(@opts[:auto_close_time], @user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -187,11 +187,10 @@ describe PostCreator do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when auto-close param is given' do
|
context 'when auto-close param is given' do
|
||||||
it 'ensures the user can auto-close the topic' do
|
it 'ensures the user can auto-close the topic, but ignores auto-close param silently' do
|
||||||
Guardian.any_instance.stubs(:can_moderate?).returns(false)
|
Guardian.any_instance.stubs(:can_moderate?).returns(false)
|
||||||
expect {
|
post = PostCreator.new(user, basic_topic_params.merge(auto_close_time: 2)).create
|
||||||
PostCreator.new(user, basic_topic_params.merge(auto_close_time: 2)).create
|
post.topic.auto_close_at.should be_nil
|
||||||
}.to raise_error(Discourse::InvalidAccess)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
47
spec/components/topic_creator_spec.rb
Normal file
47
spec/components/topic_creator_spec.rb
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe TopicCreator do
|
||||||
|
|
||||||
|
let(:user) { Fabricate(:user) }
|
||||||
|
let(:moderator) { Fabricate(:moderator) }
|
||||||
|
let(:admin) { Fabricate(:admin) }
|
||||||
|
|
||||||
|
let(:valid_attrs) { Fabricate.attributes_for(:topic) }
|
||||||
|
|
||||||
|
describe '#create' do
|
||||||
|
context 'success cases' do
|
||||||
|
before do
|
||||||
|
TopicCreator.any_instance.expects(:save_topic).returns(true)
|
||||||
|
TopicCreator.any_instance.expects(:watch_topic).returns(true)
|
||||||
|
SiteSetting.stubs(:allow_duplicate_topic_titles?).returns(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be possible for an admin to create a topic" do
|
||||||
|
TopicCreator.create(admin, Guardian.new(admin), valid_attrs).should be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be possible for a moderator to create a topic" do
|
||||||
|
TopicCreator.create(moderator, Guardian.new(moderator), valid_attrs).should be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'regular user' do
|
||||||
|
before { SiteSetting.stubs(:min_trust_to_create_topic).returns(TrustLevel.levels[:newuser]) }
|
||||||
|
|
||||||
|
it "should be possible for a regular user to create a topic" do
|
||||||
|
TopicCreator.create(user, Guardian.new(user), valid_attrs).should be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be possible for a regular user to create a topic with blank auto_close_time" do
|
||||||
|
TopicCreator.create(user, Guardian.new(user), valid_attrs.merge(auto_close_time: '')).should be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "ignores auto_close_time without raising an error" do
|
||||||
|
topic = TopicCreator.create(user, Guardian.new(user), valid_attrs.merge(auto_close_time: '24'))
|
||||||
|
topic.should be_valid
|
||||||
|
topic.auto_close_at.should be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user