Retrospring/spec/lib/use_case/reaction/create_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
852 B
Ruby
Raw Normal View History

2023-10-28 08:16:17 -07:00
# frozen_string_literal: true
require "rails_helper"
describe UseCase::Reaction::Create do
shared_examples_for "valid target type" do
it "creates a reaction" do
expect { subject }.to change { target.smile_count }.by(1)
end
end
subject { UseCase::Reaction::Create.call(source_user: user, target:) }
let(:user) { FactoryBot.create(:user) }
context "target is an Answer" do
let(:target) { FactoryBot.create(:answer, user:) }
include_examples "valid target type"
end
context "target is a Comment" do
let(:target) { FactoryBot.create(:comment, user:, answer: FactoryBot.create(:answer, user:)) }
include_examples "valid target type"
end
context "target is a Question" do
let(:target) { FactoryBot.create(:question) }
include_examples "raises an error", Dry::Types::ConstraintError
end
end