From cd3f1591c96488b6c97a2ac6beafb35c53fd2386 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Wed, 15 Jun 2022 00:08:58 +0200 Subject: [PATCH] Add test for creating anonymous blocks --- .../ajax/anonymous_block_controller_spec.rb | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 spec/controllers/ajax/anonymous_block_controller_spec.rb diff --git a/spec/controllers/ajax/anonymous_block_controller_spec.rb b/spec/controllers/ajax/anonymous_block_controller_spec.rb new file mode 100644 index 00000000..6471d072 --- /dev/null +++ b/spec/controllers/ajax/anonymous_block_controller_spec.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true +require "rails_helper" + +describe Ajax::AnonymousBlockController, :ajax_controller, type: :controller do + describe "#create" do + subject { post(:create, params: params) } + + context "user signed in" do + let(:user) { FactoryBot.create(:user) } + + before do + sign_in(user) + end + + context "when all parameters are given" do + let(:question) { FactoryBot.create(:question, author_identifier: "someidentifier") } + let!(:inbox) { FactoryBot.create(:inbox, user: user, question: question) } + let(:params) do + { question: question.id } + end + + let(:expected_response) do + { + "success" => true, + "status" => "okay", + "message" => anything + } + end + + it "creates an anonymous block" do + expect { subject }.to(change { AnonymousBlock.count }.by(1)) + end + + include_examples "returns the expected response" + end + + context "when parameters are missing" do + let(:params) { {} } + let(:expected_response) do + { + "success" => false, + "status" => "parameter_error", + "message" => anything + } + end + + it "does not create an anonymous block" do + expect { subject }.not_to(change { AnonymousBlock.count }) + end + + include_examples "returns the expected response" + end + end + end + + describe "#destroy" do + pending + end +end