2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 21:27:38 -05:00
|
|
|
RSpec.describe PostReply do
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:topic) { Fabricate(:topic) }
|
|
|
|
fab!(:post) { Fabricate(:post, topic: topic) }
|
|
|
|
fab!(:other_post) { Fabricate(:post, topic: topic) }
|
2013-02-05 13:16:51 -06:00
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
describe "Validations" do
|
2016-07-13 10:34:21 -05:00
|
|
|
it "should ensure that the posts belong in the same topic" do
|
|
|
|
expect(PostReply.new(post: post, reply: other_post)).to be_valid
|
|
|
|
|
|
|
|
other_topic = Fabricate(:topic)
|
2019-04-29 02:32:25 -05:00
|
|
|
other_post.update!(topic_id: other_topic.id)
|
2016-07-13 10:34:21 -05:00
|
|
|
other_post.reload
|
|
|
|
|
|
|
|
post_reply = PostReply.new(post: post, reply: other_post)
|
|
|
|
expect(post_reply).to_not be_valid
|
|
|
|
|
|
|
|
expect(post_reply.errors[:base]).to include(
|
2023-01-09 05:18:21 -06:00
|
|
|
I18n.t("activerecord.errors.models.post_reply.base.different_topic"),
|
2016-07-13 10:34:21 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|