# frozen_string_literal: true

require 'rails_helper'

describe ContractTemplates::DuplicatesController do
  let(:account) { build(:account) }
  let(:current_user) { create(:user, :manager, primary_account: account) }
  let(:project) { create(:project, members: [current_user], account: account) }

  before do
    sign_in(current_user)
  end

  describe '#create' do
    it "responds with redirect to the edit page for newly created duplicate" do
      contract_template = create(:contract_template, project: project)

      expect do
        post :create, params: { contract_template_id: contract_template }
      end.to change(ContractTemplate, :count).by(1)

      new_ct = ContractTemplate.last

      expect(new_ct.name).to eq t('contract_templates.duplicate.name_prefix', template_name: contract_template.name)
      expect(new_ct.release_type).to eq contract_template.release_type

      expect(response).to redirect_to [:edit, new_ct]
    end
  end
end
