require "rails_helper"

RSpec.describe TagsController, type: :controller do
  let(:current_user) { create(:user) }
  let(:releasable) { create(:appearance_release) }

  before do
    sign_in current_user
  end

  describe "#new" do
    it "responds successfully" do
      get :new, xhr: true, params: { "#{releasable.model_name.singular}_id" => releasable }
    end
  end

  describe "#create" do
    it "responds successfully" do
      post :create, xhr: true, params: { "#{releasable.model_name.singular}_id" => releasable, acts_as_taggable_on_tag: tag_params }

      expect(response).to be_successful
    end

    it "creates a new tag" do
      expect {
        post :create, xhr: true, params: { "#{releasable.model_name.singular}_id" => releasable, acts_as_taggable_on_tag: tag_params }
      }.to change(releasable.taggings, :count).by(1)
    end
  end

  private

  def tag_params
    { name: "Fresh" }
  end
end
