diff --git a/lib/post_creator.rb b/lib/post_creator.rb index 6db17d5fb05..0f39dda50b6 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -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 diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index d57a5259fe4..ebcf723f95b 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -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