diff --git a/config/locales/en.yml b/config/locales/en.yml index 3c54e28..aca610b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -700,6 +700,7 @@ en: update: Save Changes contract_template: create: Create Release Template + update: Save Changes directory: create: Create Folder new_file: Upload Files diff --git a/config/locales/es.yml b/config/locales/es.yml index d646e05..6ca5c01 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -317,6 +317,8 @@ es: broadcast: create: Create Live Stream (ES) update: Save Changes (ES) + contract_template: + update: Save changes (ES) create: 'Crear %{model}' medical_release: update: Approve (ES) diff --git a/spec/controllers/contract_templates/duplicates_controller.rb b/spec/controllers/contract_templates/duplicates_controller.rb new file mode 100644 index 0000000..2ee5fc4 --- /dev/null +++ b/spec/controllers/contract_templates/duplicates_controller.rb @@ -0,0 +1,30 @@ +# 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 diff --git a/spec/controllers/contract_templates_controller_spec.rb b/spec/controllers/contract_templates_controller_spec.rb index 72c77a4..6069598 100644 --- a/spec/controllers/contract_templates_controller_spec.rb +++ b/spec/controllers/contract_templates_controller_spec.rb @@ -118,6 +118,57 @@ describe ContractTemplatesController do end end + describe '#edit' do + let(:contract_template) do + create(:contract_template, + name: 'My Contract Template', fee: 50, release_type: 'appearance', + project: project) + end + + it 'responds ok' do + get :edit, params: { project_id: project, id: contract_template } + + expect(response).to be_successful + end + + context 'when current user is an associate' do + let(:current_user) { create(:user, :associate) } + + it 'raises exception' do + expect do + get :edit, params: { project_id: project, id: contract_template } + end.to raise_error(Pundit::NotAuthorizedError) + end + end + + + end + + describe '#update' do + let(:contract_template) do + create(:contract_template, + name: 'My Contract Template', fee: 50, release_type: 'appearance', + project: project) + end + + it 'redirects' do + patch :update, params: { project_id: project, id: contract_template, contract_template: contract_template_params } + + expect(response).to redirect_to(project_contract_templates_path(project)) + end + + + context 'when current user is an associate' do + let(:current_user) { create(:user, :associate) } + + it 'raises exception' do + expect do + patch :update, params: { project_id: project, id: contract_template, contract_template: contract_template_params } + end.to raise_error(Pundit::NotAuthorizedError) + end + end + end + describe '#destroy' do let!(:contract_template) { create(:contract_template, project: project) } diff --git a/spec/features/user_manages_contract_templates_spec.rb b/spec/features/user_manages_contract_templates_spec.rb index c37b3e9..6985b3c 100644 --- a/spec/features/user_manages_contract_templates_spec.rb +++ b/spec/features/user_manages_contract_templates_spec.rb @@ -262,6 +262,93 @@ RSpec.feature 'User manages contract templates', type: :feature do expect(page).to have_content('Active template') end + scenario 'edit button is visible for not-signed contract template' do + create(:contract_template, project: project) + + visit project_contract_templates_path(project) + + expect(page).to have_link(edit_button_label, exact: true, count: 1) + end + + scenario 'edit button is not visible for signed contract template' do + ct = create(:contract_template, project: project) + create(:appearance_release, contract_template: ct) + + visit project_contract_templates_path(project) + + expect(page).to have_link(edit_button_label, exact: true, count: 0) + end + + scenario 'duplicate button is visible for not signed contract template' do + create(:contract_template, project: project) + + visit project_contract_templates_path(project) + + expect(page).to have_link(duplicate_button_label, exact: true, count: 1) + end + + scenario 'duplicate button is visible for signed contract template' do + ct = create(:contract_template, project: project) + create(:appearance_release, contract_template: ct) + + visit project_contract_templates_path(project) + + expect(page).to have_link(duplicate_button_label, exact: true, count: 1) + end + + scenario 'clicking edit button opens edit page for contract template' do + ct = create(:contract_template, project: project) + + visit project_contract_templates_path(project) + + expect(page).to have_content ct.name + + expect(page).not_to have_content 'Updated CT' + expect(page).not_to have_content 'Medical' + + click_link edit_button_label + + expect(page).to have_content edit_page_heading + + fill_in name_field, with: 'Updated CT' + select 'Medical Release', from: 'Release type' + fill_in_trix body_field, with: 'Updated legal text' + click_on update_contract_template_button_label + + expect(page).to have_content 'Updated CT' + expect(page).to have_content 'Medical' + end + + scenario 'clicking duplicate button opens edit page for newly created contract template' do + ct = create(:contract_template, project: project) + + visit project_contract_templates_path(project) + + expect(page).to have_content ct.name + + expect(page).not_to have_content 'Modified duplicate' + expect(page).not_to have_content 'Misc' + + expect do + click_link duplicate_button_label + end.to change(ContractTemplate, :count).by(1) + + expect(page).to have_content edit_page_heading + name_input = find("##{name_field}") + expect(name_input.value).to eq duplicate_release_name(ct.name) + + fill_in name_field, with: 'Modified duplicate' + select 'Misc Release', from: 'Release type' + fill_in_trix body_field, with: 'Legal text for duplicate' + click_on update_contract_template_button_label + + expect(page).to have_content 'Modified duplicate' + expect(page).to have_content 'Misc' + expect(ct.body.id).not_to eq ContractTemplate.last.body.id + expect(ct.guardian_clause.id).not_to eq ContractTemplate.last.guardian_clause.id + expect(ct.signature_legal_text.id).not_to eq ContractTemplate.last.signature_legal_text.id + end + context 'When the user is associate' do let(:current_user) { create(:user, :associate) } @@ -280,6 +367,22 @@ RSpec.feature 'User manages contract templates', type: :feature do expect(page).to have_content schedule_demo expect(page).not_to have_content create_release_template end + + it 'does not show edit button' do + create(:contract_template, project: project) + + visit project_contract_templates_path(project) + + expect(page).to have_link(edit_button_label, exact: true, count: 0) + end + + it 'does not show duplicate button' do + create(:contract_template, project: project) + + visit project_contract_templates_path(project) + + expect(page).to have_link(duplicate_button_label, exact: true, count: 0) + end end context 'When the user is account manager' do @@ -300,6 +403,40 @@ RSpec.feature 'User manages contract templates', type: :feature do expect(page).to have_content schedule_demo expect(page).to have_content create_release_template end + + it 'shows edit button when contract template is not signed' do + create(:contract_template, project: project) + + visit project_contract_templates_path(project) + + expect(page).to have_link(edit_button_label, exact: true, count: 1) + end + + it 'does not show edit button when contract template is signed' do + ct = create(:contract_template, project: project) + create(:appearance_release, contract_template: ct) + + visit project_contract_templates_path(project) + + expect(page).to have_link(edit_button_label, exact: true, count: 0) + end + + it 'shows duplicate button when contract template is not signed' do + create(:contract_template, project: project) + + visit project_contract_templates_path(project) + + expect(page).to have_link(duplicate_button_label, exact: true, count: 1) + end + + it 'shows duplicate button when contract template is signed' do + ct = create(:contract_template, project: project) + create(:appearance_release, contract_template: ct) + + visit project_contract_templates_path(project) + + expect(page).to have_link(duplicate_button_label, exact: true, count: 1) + end end private @@ -355,4 +492,28 @@ RSpec.feature 'User manages contract templates', type: :feature do def signature_legal_text_trix_field 'Signature legal text' end + + def edit_button_label + t 'contract_templates.contract_template.actions.edit' + end + + def duplicate_button_label + t 'contract_templates.contract_template.actions.duplicate' + end + + def edit_page_heading + t 'contract_templates.edit.heading' + end + + def name_field + 'contract_template_name' + end + + def update_contract_template_button_label + t 'helpers.submit.contract_template.update' + end + + def duplicate_release_name(template_name = '') + t 'contract_templates.duplicate.name_prefix', template_name: template_name + end end