discourse/spec/models/post_reply_spec.rb
Daniel Waterworth 6e161d3e75
DEV: Allow fab! without block (#24314)
The most common thing that we do with fab! is:

    fab!(:thing) { Fabricate(:thing) }

This commit adds a shorthand for this which is just simply:

    fab!(:thing)

i.e. If you omit the block, then, by default, you'll get a `Fabricate`d object using the fabricator of the same name.
2023-11-09 16:47:59 -06:00

25 lines
720 B
Ruby

# frozen_string_literal: true
RSpec.describe PostReply do
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic) }
fab!(:other_post) { Fabricate(:post, topic: topic) }
describe "Validations" 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