From 53809d526cc7e1441666b8aca79667f642a1f3df Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Thu, 5 May 2016 18:28:25 +0530 Subject: [PATCH] FIX: show proper error message when no user selected for private message --- lib/has_errors.rb | 2 +- lib/post_creator.rb | 3 +-- spec/components/has_errors_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/has_errors.rb b/lib/has_errors.rb index 9aae07e05c0..ddf213e4869 100644 --- a/lib/has_errors.rb +++ b/lib/has_errors.rb @@ -13,7 +13,7 @@ module HasErrors end def rollback_with!(obj, error) - obj.errors[:base] << error + obj.errors.add(:base, error) rollback_from_errors!(obj) end diff --git a/lib/post_creator.rb b/lib/post_creator.rb index bd0d67295a7..414202e0045 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -317,8 +317,7 @@ class PostCreator topic_creator = TopicCreator.new(@user, guardian, @opts) @topic = topic_creator.create rescue ActiveRecord::Rollback - add_errors_from(topic_creator) - return + rollback_from_errors!(topic_creator) end @post.topic_id = @topic.id @post.topic = @topic diff --git a/spec/components/has_errors_spec.rb b/spec/components/has_errors_spec.rb index f9b6876501c..1ae0eaef14e 100644 --- a/spec/components/has_errors_spec.rb +++ b/spec/components/has_errors_spec.rb @@ -45,10 +45,10 @@ describe HasErrors do it "triggers a rollback" do expect(-> { - error_test.rollback_with!(invalid_topic, :custom_error) + error_test.rollback_with!(invalid_topic, :too_many_users) }).to raise_error(ActiveRecord::Rollback) expect(error_test.errors).to be_present - expect(error_test.errors[:base]).to include(:custom_error) + expect(error_test.errors[:base]).to include("You can only send warnings to one user at a time.") end end