discourse/spec/models/post_reply_spec.rb
Sam Saffron 4ea21fa2d0 DEV: use #frozen_string_literal: true on all spec
This change both speeds up specs (less strings to allocate) and helps catch
cases where methods in Discourse are mutating inputs.

Overall we will be migrating everything to use #frozen_string_literal: true
it will take a while, but this is the first and safest move in this direction
2019-04-30 10:27:42 +10:00

30 lines
836 B
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe PostReply do
let(:topic) { Fabricate(:topic) }
let(:post) { Fabricate(:post, topic: topic) }
let(:other_post) { Fabricate(:post, topic: topic) }
it { is_expected.to belong_to :post }
it { is_expected.to belong_to :reply }
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)
other_post.update!(topic_id: other_topic.id)
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
end