FIX: show proper error message when no user selected for private message

This commit is contained in:
Arpit Jalan 2016-05-05 18:28:25 +05:30
parent 24a49daa71
commit 53809d526c
3 changed files with 4 additions and 5 deletions

View file

@ -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

View file

@ -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

View file

@ -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