2013-11-28 11:06:04 -05:00
|
|
|
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
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(TopicCreator.create(admin, Guardian.new(admin), valid_attrs)).to be_valid
|
2013-11-28 11:06:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be possible for a moderator to create a topic" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(TopicCreator.create(moderator, Guardian.new(moderator), valid_attrs)).to be_valid
|
2013-11-28 11:06:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'regular user' do
|
2014-09-05 01:20:39 -04:00
|
|
|
before { SiteSetting.stubs(:min_trust_to_create_topic).returns(TrustLevel[0]) }
|
2013-11-28 11:06:04 -05:00
|
|
|
|
|
|
|
it "should be possible for a regular user to create a topic" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(TopicCreator.create(user, Guardian.new(user), valid_attrs)).to be_valid
|
2013-11-28 11:06:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be possible for a regular user to create a topic with blank auto_close_time" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(TopicCreator.create(user, Guardian.new(user), valid_attrs.merge(auto_close_time: ''))).to be_valid
|
2013-11-28 11:06:04 -05:00
|
|
|
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'))
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(topic).to be_valid
|
|
|
|
expect(topic.auto_close_at).to eq(nil)
|
2013-11-28 11:06:04 -05:00
|
|
|
end
|
2014-08-18 11:07:32 -04:00
|
|
|
|
|
|
|
it "category name is case insensitive" do
|
|
|
|
category = Fabricate(:category, name: "Neil's Blog")
|
|
|
|
topic = TopicCreator.create(user, Guardian.new(user), valid_attrs.merge(category: "neil's blog"))
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(topic).to be_valid
|
|
|
|
expect(topic.category).to eq(category)
|
2014-08-18 11:07:32 -04:00
|
|
|
end
|
2013-11-28 11:06:04 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|