2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
describe PostReply do
|
2016-07-13 11:34:21 -04:00
|
|
|
let(:topic) { Fabricate(:topic) }
|
|
|
|
let(:post) { Fabricate(:post, topic: topic) }
|
|
|
|
let(:other_post) { Fabricate(:post, topic: topic) }
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
it { is_expected.to belong_to :post }
|
|
|
|
it { is_expected.to belong_to :reply }
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2016-07-13 11:34:21 -04:00
|
|
|
context "validation" do
|
|
|
|
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 03:32:25 -04:00
|
|
|
other_post.update!(topic_id: other_topic.id)
|
2016-07-13 11:34:21 -04: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(
|
|
|
|
I18n.t("activerecord.errors.models.post_reply.base.different_topic")
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|