FIX: Regression where a topic rollback would not properly report errors to the client.

This commit is contained in:
Robin Ward 2013-06-07 12:36:37 -04:00
parent 3ae72259a6
commit 1b5ec42173
2 changed files with 21 additions and 2 deletions

View File

@ -131,8 +131,15 @@ class PostCreator
def setup_topic
if @opts[:topic_id].blank?
topic_creator = TopicCreator.new(@user, guardian, @opts)
topic = topic_creator.create
@errors = topic_creator.errors
begin
topic = topic_creator.create
@errors = topic_creator.errors
rescue ActiveRecord::Rollback => ex
# In the event of a rollback, grab the errors from the topic
@errors = topic_creator.errors
raise ex
end
@new_topic = true
else

View File

@ -26,6 +26,18 @@ describe PostCreator do
lambda { creator.create }.should raise_error(Discourse::InvalidAccess)
end
context "invalid title" do
let(:creator_invalid_title) { PostCreator.new(user, basic_topic_params.merge(title: 'a')) }
it "has errors" do
creator_invalid_title.create
expect(creator_invalid_title.errors).to be_present
end
end
context 'success' do
it "doesn't return true for spam" do