From a493076f9b281cba5f35364737e9d27d4eb358dd Mon Sep 17 00:00:00 2001 From: Senad Uka Date: Mon, 24 Aug 2020 15:52:23 +0200 Subject: [PATCH] Upstream sync --- app/controllers/approvals_controller.rb | 22 +- app/models/concerns/approvable.rb | 17 +- app/views/approvals/new.html.erb | 8 +- app/views/contracts/_for_office_use_only.erb | 8 +- app/views/contracts/pdf.html.erb | 6 +- spec/controllers/approvals_controller_spec.rb | 9 +- .../user_approving_releasables_spec.rb | 191 ++++++++++++++++++ ...r_managing_acquired_media_releases_spec.rb | 131 ------------ .../user_managing_appearance_releases_spec.rb | 139 ------------- .../user_managing_location_releases_spec.rb | 140 ------------- .../user_managing_material_releases_spec.rb | 140 ------------- .../user_managing_medical_releases_spec.rb | 121 ----------- .../user_managing_misc_releases_spec.rb | 121 ----------- .../user_managing_music_releases_spec.rb | 57 +----- .../user_managing_talent_releases_spec.rb | 140 ------------- spec/models/acquired_media_release_spec.rb | 1 + spec/models/appearance_release_spec.rb | 1 + spec/models/location_release_spec.rb | 1 + spec/models/material_release_spec.rb | 1 + spec/models/medical_release_spec.rb | 1 + spec/models/misc_release_spec.rb | 1 + spec/models/music_release_spec.rb | 1 + spec/models/talent_release_spec.rb | 1 + .../shared_examples_for_an_approvable.rb | 47 +++++ spec/support/signature_helper.rb | 2 +- 25 files changed, 307 insertions(+), 1000 deletions(-) create mode 100644 spec/features/user_approving_releasables_spec.rb create mode 100644 spec/support/shared_examples_for_an_approvable.rb diff --git a/app/controllers/approvals_controller.rb b/app/controllers/approvals_controller.rb index 8b680cd..e99f1e6 100644 --- a/app/controllers/approvals_controller.rb +++ b/app/controllers/approvals_controller.rb @@ -6,9 +6,12 @@ class ApprovalsController < ApplicationController def create @releasable.approve_by(current_user) + @releasable.approved_by_user_signature.attach(approved_by_user_signature_params) if signature_data.present? - if @releasable.save + if @releasable.save(context: :approval) redirect_to [@project, "#{@releasable_param.name.pluralize}"], notice: t('.release_approved', release_type: @releasable.model_name.human) + else + render :new end end @@ -25,4 +28,21 @@ class ApprovalsController < ApplicationController def set_project @project = @releasable.project end + + def releasable_params + params.require(releasable_param.name).permit(approved_by_user_signature: :data) + end + + def signature_data + releasable_params.dig(:approved_by_user_signature, :data) + end + + def approved_by_user_signature_params + { + data: signature_data, + filename: "approved_by_user_signature.png", + content_type: "image/png", + identify: false, + } + end end diff --git a/app/models/concerns/approvable.rb b/app/models/concerns/approvable.rb index d55b64b..1f516e3 100644 --- a/app/models/concerns/approvable.rb +++ b/app/models/concerns/approvable.rb @@ -1,15 +1,24 @@ module Approvable extend ActiveSupport::Concern - + included do + include ActiveStorageSupport::SupportForBase64 + + has_one_base64_attached :approved_by_user_signature + + # Requires signature when saving in the approval context + with_options on: :approval do + validates :approved_by_user_signature, attached: true + end + def approve_by(user) return unless approved_at.nil? - + self.approved_by_user_name = user.full_name self.approved_by_user_email = user.email - self.approved_at = Time.zone.now + self.approved_at = BigMediaTime.time_zone_now end - + def approved? self.approved_at.present? end diff --git a/app/views/approvals/new.html.erb b/app/views/approvals/new.html.erb index cc1127d..658b416 100644 --- a/app/views/approvals/new.html.erb +++ b/app/views/approvals/new.html.erb @@ -1,9 +1,13 @@
<%= card_header text: t(".heading", release_type: @releasable_param.name.titleize), close_action_path: [@project, "#{@releasable_param.name.pluralize}"] %>
- " width="90%" height="1200" /> + " width="90%" height="1200" /> + <%= errors_summary_for @releasable %> <%= bootstrap_form_with model: @releasable, method: :post, url: public_send("#{@releasable_param.name}_approvals_path", @releasable), local: true do |form| %> + <%= card_field_set_tag 'Signature' do %> + <%= render "shared/signature_fields", form: form, signature_field: 'approved_by_user_signature[data]' %> + <% end %>
<%= link_to t("shared.cancel"), [@releasable.project, "#{@releasable_param.name.pluralize}"], class: "col-3 text-reset" %>
@@ -12,4 +16,4 @@
<% end %>
-
\ No newline at end of file +
diff --git a/app/views/contracts/_for_office_use_only.erb b/app/views/contracts/_for_office_use_only.erb index 26b8629..9f0f400 100644 --- a/app/views/contracts/_for_office_use_only.erb +++ b/app/views/contracts/_for_office_use_only.erb @@ -10,4 +10,10 @@ <%= description_list_pair t('.description_labels.issued_to'), releasable.name %> <%= description_list_pair t('.description_labels.issued_by'), releasable.approved_by_user_name %> <%= description_list_pair t('.description_labels.date_issued'), releasable.approved_at %> - \ No newline at end of file + + +<% if preview %> + <%= image_tag dummy_signature %> +<% elsif releasable.approved_by_user_signature.attached? %> + <%= image_tag releasable.approved_by_user_signature.variant(auto_orient: true, resize: "200x200") %> +<% end %> diff --git a/app/views/contracts/pdf.html.erb b/app/views/contracts/pdf.html.erb index 9600641..a261f96 100644 --- a/app/views/contracts/pdf.html.erb +++ b/app/views/contracts/pdf.html.erb @@ -16,11 +16,10 @@ <%= contract_template.guardian_clause %> <% end %> -<%# if releasable.model_name.in? %w(MedicalRelease MiscRelease AppearanceRelease) %> <% if releasable.respond_to?(:question_1_answer) %>
<%= render "contracts/questionnaire", releasable: releasable, contract_template: contract_template, preview: preview %> -
+ <% end %>
@@ -47,8 +46,7 @@ <% end %> <% end %> - -<% if releasable.respond_to?(:approved?) && releasable.approved? %> +<% if releasable.try(:approved?) %>
<%= render "contracts/for_office_use_only", releasable: releasable, preview: preview %>
diff --git a/spec/controllers/approvals_controller_spec.rb b/spec/controllers/approvals_controller_spec.rb index ad374d1..3699116 100644 --- a/spec/controllers/approvals_controller_spec.rb +++ b/spec/controllers/approvals_controller_spec.rb @@ -27,10 +27,17 @@ RSpec.describe ApprovalsController, type: :controller do expect(MedicalRelease.last.approved?).to eq false - post :create, params: { medical_release_id: medical_release } + post :create, params: { medical_release_id: medical_release, medical_release: approvable_params } expect(response).to redirect_to [project, :medical_releases] expect(MedicalRelease.last.approved?).to eq true end end + + private + + def approvable_params + signature_base64 ||= Base64Image.from_image(file_fixture('signature.png')).data_uri + { approved_by_user_signature: { data: signature_base64 } } + end end diff --git a/spec/features/user_approving_releasables_spec.rb b/spec/features/user_approving_releasables_spec.rb new file mode 100644 index 0000000..a60c169 --- /dev/null +++ b/spec/features/user_approving_releasables_spec.rb @@ -0,0 +1,191 @@ +require 'rails_helper' + +feature 'User approving releasables' do + shared_examples 'an approvable UI' do + let(:current_user) { create(:user, :associate) } + let(:project) { create(:project, members: current_user, account: current_user.primary_account) } + + before :each do + sign_in current_user + end + + shared_examples 'not authorized to review' do + it 'does not show the review action' do + visit polymorphic_path [project, subject.model_name.plural] + click_on manage_button + + expect(page).not_to have_link(review_action, exact: true) + end + end + + scenario 'approval status is indicating by a checkmark' do + approved_releasable = create("#{subject.model_name.singular}", approved_at: 1.day.ago, project: project) + + visit polymorphic_path [project, subject.model_name.plural] + + expect(page).not_to be_approved(subject) + expect(page).not_to be_approved(approved_releasable) + end + + context 'as an account manager' do + let(:current_user) { create(:user, :account_manager) } + + scenario 'approving a release', js: true do + visit polymorphic_path [project, subject.model_name.plural] + + click_on manage_button + click_link review_action + + expect(page).to have_content review_page_heading(subject.model_name) + expect(page).to have_content approve_button + expect(page).to have_content signature_field + + click_on approve_button + + expect(page).not_to have_content approved_notice(subject.model_name) + expect(page).to have_content 'is not attached' + + by 'adding signature' do + draw_signature file_fixture('signature.png'), signature_data_field(subject.model_name) + click_on approve_button + + expect(page).to have_content approved_notice(subject.model_name) + end + end + + scenario 'viewing the contract PDF for an unapproved release' do + visit polymorphic_path [project, subject.model_name.plural] + click_on 'Manage' + click_link 'Download' + + expect(content_type).to eq('application/pdf') + expect(content_disposition).to include('inline') + expect(pdf_body).not_to have_content for_office_use_only + end + + scenario 'viewing the contract PDF of an approved release' do + approver = create(:user, email: 'big.doe@test.com', first_name: 'Big', last_name: 'Joe') + subject.approve_by(approver) + subject.save! + + visit polymorphic_path([subject, :contracts], format: 'pdf') + + expect(content_type).to eq('application/pdf') + expect(content_disposition).to include('inline') + expect(pdf_body).to have_content for_office_use_only.upcase + expect(pdf_body).to have_content producer_label + expect(pdf_body).to have_content production_label + expect(pdf_body).to have_content issued_to_label + expect(pdf_body).to have_content issued_by_label + expect(pdf_body).to have_content date_issued + expect(pdf_body).to have_content 'Big Joe' + end + end + + context 'as a manager' do + let(:current_user) { create(:user, :manager) } + + include_examples 'not authorized to review' + end + + context 'as an associate' do + let(:current_user) { create(:user, :associate) } + + include_examples 'not authorized to review' + end + + private + + def approve_button + t 'approvals.new.actions.approve' + end + + def approved_notice(model_name) + t('approvals.create.release_approved', release_type: model_name.human) + end + + def be_approved(releasable) + releasable_dom_id = "##{releasable.model_name.singular}_#{releasable.id}" + have_css("#{releasable_dom_id }i.fa.fa-check-circle.fa-2x", count: 1) + end + + def manage_button + 'Manage' + end + + def review_action + 'Review' + end + + def review_page_heading(model_name) + t 'approvals.new.heading', release_type: model_name.human.titleize + end + + def signature_field + 'SIGNATURE' + end + + def signature_data_field(model_name) + "#{model_name.singular}_approved_by_user_signature[data]" + end + + def for_office_use_only + t('contracts.for_office_use_only.heading').upcase + end + + def producer_label + t 'contracts.for_office_use_only.description_labels.producer' + end + + def production_label + t 'contracts.for_office_use_only.description_labels.production' + end + + def issued_to_label + t 'contracts.for_office_use_only.description_labels.issued_to' + end + + def issued_by_label + t 'contracts.for_office_use_only.description_labels.issued_by' + end + + def date_issued + t 'contracts.for_office_use_only.description_labels.date_issued' + end + end + + context 'for an appearance release' do + subject { create(:appearance_release_with_contract_template, :native, project: project) } + it_behaves_like 'an approvable UI' + end + + context 'for a talent release' do + subject { create(:talent_release_with_contract_template, :native, project: project) } + it_behaves_like 'an approvable UI' + end + + context 'for a location release' do + subject { create(:location_release_with_contract_template, :native, project: project) } + it_behaves_like 'an approvable UI' + end + + context 'for a material release' do + subject { create(:material_release_with_contract_template, :native, project: project) } + it_behaves_like 'an approvable UI' + end + + context 'for a acquired media release' do + subject { create(:acquired_media_release_with_contract_template, :native, project: project) } + it_behaves_like 'an approvable UI' + end + + context 'for a medical release' do + subject { create(:medical_release_with_contract_template, :native, project: project) } + it_behaves_like 'an approvable UI' + end + + context 'for a misc release' do + subject { create(:misc_release_with_contract_template, :native, project: project) } + it_behaves_like 'an approvable UI' + end +end diff --git a/spec/features/user_managing_acquired_media_releases_spec.rb b/spec/features/user_managing_acquired_media_releases_spec.rb index 69849fd..c128457 100644 --- a/spec/features/user_managing_acquired_media_releases_spec.rb +++ b/spec/features/user_managing_acquired_media_releases_spec.rb @@ -444,104 +444,9 @@ feature "User managing acquired_media releases" do end context "when the user is account manager" do - let(:current_user) { create(:user, :account_manager) } - - before do - sign_in current_user - end - - scenario "Review action in Manage menu is visible" do - create(:acquired_media_release_with_contract_template, :native, project: project) - - visit project_acquired_media_releases_path(project) - - expect(page).to have_link(review_action, exact: true) - end - - scenario "Reviewing release" do - create(:acquired_media_release_with_contract_template, :native, project: project) - - visit project_acquired_media_releases_path(project) - - click_link review_action - - expect(page).to have_content review_page_heading - expect(page).to have_content approve_button - end - - scenario "Approved releases have checkmark and non-approved releases don't have checkmarks" do - create(:acquired_media_release_with_contract_template, :native, project: project) - - visit project_acquired_media_releases_path(project) - expect(page).to have_css('i.fa.fa-check-circle.fa-2x', count: 0) - - create(:acquired_media_release_with_contract_template, :native, project: project, approved_by_user_email: "some@email.com", approved_at: DateTime.now) - visit project_acquired_media_releases_path(project) - - expect(page).to have_css('i.fa.fa-check-circle.fa-2x', count: 1) - end - - scenario 'When viewing the contract PDF of approved release there is page for office use only' do - acquired_media_release = create(:acquired_media_release_with_contract_template, - :native, - project: project, - person_first_name: 'Jane', - person_last_name: 'Doe', - approved_by_user_name: "Big Joe", - approved_by_user_email: "some@email.com", - approved_at: DateTime.now) - - sign_in(current_user) - visit project_acquired_media_releases_path(project) - click_link *view_release_pdf_link_for(acquired_media_release) - - expect(content_type).to eq('application/pdf') - expect(content_disposition).to include('inline') - expect(pdf_body).to have_content for_office_use_only.upcase - expect(pdf_body).to have_content producer_label - expect(pdf_body).to have_content production_label - expect(pdf_body).to have_content issued_to_label - expect(pdf_body).to have_content issued_by_label - expect(pdf_body).to have_content date_issued - expect(pdf_body).to have_content 'Big Joe' - end - - scenario 'When viewing the contract PDF of not approved release there is no page for office use only' do - acquired_media_release = create(:acquired_media_release_with_contract_template, - :native, - project: project, - person_first_name: 'Jane', - person_last_name: 'Doe') - - sign_in(current_user) - visit project_acquired_media_releases_path(project) - click_link *view_release_pdf_link_for(acquired_media_release) - - expect(content_type).to eq('application/pdf') - expect(content_disposition).to include('inline') - expect(pdf_body).not_to have_content for_office_use_only.upcase - expect(pdf_body).not_to have_content producer_label - expect(pdf_body).not_to have_content production_label - expect(pdf_body).not_to have_content issued_to_label - expect(pdf_body).not_to have_content issued_by_label - expect(pdf_body).not_to have_content date_issued - expect(pdf_body).not_to have_content 'Big Joe' - end end context "when the user is project manager" do - before do - sign_in current_user - end - - scenario "Review action in Manage menu is not visible" do - create(:acquired_media_release_with_contract_template, project: project) - - visit project_acquired_media_releases_path(project) - click_on "Manage" - - expect(page).not_to have_link(review_action, exact: true) - end end context "when the user is associate" do @@ -703,42 +608,6 @@ feature "User managing acquired_media releases" do 'Some signature legal language' end - def review_action - t 'acquired_media_releases.acquired_media_release.actions.review' - end - - def review_page_heading - t 'approvals.new.heading', release_type: "Acquired Media Release" - end - - def approve_button - t 'approvals.new.actions.approve' - end - - def for_office_use_only - t 'contracts.for_office_use_only.heading' - end - - def producer_label - t 'contracts.for_office_use_only.description_labels.producer' - end - - def production_label - t 'contracts.for_office_use_only.description_labels.production' - end - - def issued_to_label - t 'contracts.for_office_use_only.description_labels.issued_to' - end - - def issued_by_label - t 'contracts.for_office_use_only.description_labels.issued_by' - end - - def date_issued - t 'contracts.for_office_use_only.description_labels.date_issued' - end - def person_is_minor_checkbox 'acquired_media_release_minor' end diff --git a/spec/features/user_managing_appearance_releases_spec.rb b/spec/features/user_managing_appearance_releases_spec.rb index d4ae013..5f61077 100644 --- a/spec/features/user_managing_appearance_releases_spec.rb +++ b/spec/features/user_managing_appearance_releases_spec.rb @@ -687,103 +687,9 @@ feature 'User managing appearance releases' do context "when the user is account manager" do let(:current_user) { create(:user, :account_manager) } - - before do - sign_in current_user - end - - scenario "Review action in Manage menu is visible" do - create(:appearance_release_with_contract_template, :native, project: project) - - visit project_appearance_releases_path(project) - - expect(page).to have_link(review_action, exact: true) - end - - scenario "Reviewing release" do - create(:appearance_release_with_contract_template, :native, project: project) - - visit project_appearance_releases_path(project) - - click_link review_action - - expect(page).to have_content review_page_heading - expect(page).to have_content approve_button - end - - scenario "Approved releases have checkmark and non-approved releases don't have checkmarks" do - create(:appearance_release_with_contract_template, :native, project: project) - - visit project_appearance_releases_path(project) - expect(page).to have_css('i.fa.fa-check-circle.fa-2x', count: 0) - - create(:appearance_release_with_contract_template, :native, project: project, approved_by_user_email: "some@email.com", approved_at: DateTime.now) - visit project_appearance_releases_path(project) - - expect(page).to have_css('i.fa.fa-check-circle.fa-2x', count: 1) - end - - scenario 'When viewing the contract PDF of approved release there is page for office use only' do - appearance_release = create(:appearance_release_with_contract_template, - :native, - project: project, - person_first_name: 'Jane', - person_last_name: 'Doe', - approved_by_user_name: "Big Joe", - approved_by_user_email: "some@email.com", - approved_at: DateTime.now) - - sign_in(current_user) - visit project_appearance_releases_path(project) - click_link *view_release_pdf_link_for(appearance_release) - - expect(content_type).to eq('application/pdf') - expect(content_disposition).to include('inline') - expect(pdf_body).to have_content for_office_use_only.upcase - expect(pdf_body).to have_content producer_label - expect(pdf_body).to have_content production_label - expect(pdf_body).to have_content issued_to_label - expect(pdf_body).to have_content issued_by_label - expect(pdf_body).to have_content date_issued - expect(pdf_body).to have_content 'Big Joe' - end - - scenario 'When viewing the contract PDF of not approved release there is no page for office use only' do - appearance_release = create(:appearance_release_with_contract_template, - :native, - project: project, - person_first_name: 'Jane', - person_last_name: 'Doe') - - sign_in(current_user) - visit project_appearance_releases_path(project) - click_link *view_release_pdf_link_for(appearance_release) - - expect(content_type).to eq('application/pdf') - expect(content_disposition).to include('inline') - expect(pdf_body).not_to have_content for_office_use_only.upcase - expect(pdf_body).not_to have_content producer_label - expect(pdf_body).not_to have_content production_label - expect(pdf_body).not_to have_content issued_to_label - expect(pdf_body).not_to have_content issued_by_label - expect(pdf_body).not_to have_content date_issued - expect(pdf_body).not_to have_content 'Big Joe' - end end context "when the user is project manager" do - before do - sign_in current_user - end - - scenario "Review action in Manage menu is not visible" do - create(:appearance_release_with_contract_template, :native, project: project) - - visit project_appearance_releases_path(project) - click_on manage_button - - expect(page).not_to have_link(review_action, exact: true) - end end context 'when the user is associate' do @@ -801,15 +707,6 @@ feature 'User managing appearance releases' do click_on manage_button expect(page).not_to have_link('Download', exact: true) end - - scenario "Review action in Manage menu is not visible" do - create(:appearance_release_with_contract_template, :native, project: project) - - visit project_appearance_releases_path(project) - click_on manage_button - - expect(page).not_to have_link(review_action, exact: true) - end end private @@ -1039,42 +936,6 @@ feature 'User managing appearance releases' do 'Some signature legal language' end - def review_action - t 'appearance_releases.appearance_release.actions.review' - end - - def review_page_heading - t 'approvals.new.heading', release_type: "Appearance Release" - end - - def approve_button - t 'approvals.new.actions.approve' - end - - def for_office_use_only - t 'contracts.for_office_use_only.heading' - end - - def producer_label - t 'contracts.for_office_use_only.description_labels.producer' - end - - def production_label - t 'contracts.for_office_use_only.description_labels.production' - end - - def issued_to_label - t 'contracts.for_office_use_only.description_labels.issued_to' - end - - def issued_by_label - t 'contracts.for_office_use_only.description_labels.issued_by' - end - - def date_issued - t 'contracts.for_office_use_only.description_labels.date_issued' - end - def amendments_heading t 'public.amendments.new.amendment.heading' end diff --git a/spec/features/user_managing_location_releases_spec.rb b/spec/features/user_managing_location_releases_spec.rb index 74dfec5..055a047 100644 --- a/spec/features/user_managing_location_releases_spec.rb +++ b/spec/features/user_managing_location_releases_spec.rb @@ -383,104 +383,9 @@ feature "User managing location releases" do end context "when the user is account manager" do - let(:current_user) { create(:user, :account_manager) } - - before do - sign_in current_user - end - - scenario "Review action in Manage menu is visible" do - create(:location_release_with_contract_template, :native, project: project) - - visit project_location_releases_path(project) - - expect(page).to have_link(review_action, exact: true) - end - - scenario "Reviewing release" do - create(:location_release_with_contract_template, :native, project: project) - - visit project_location_releases_path(project) - - click_link review_action - - expect(page).to have_content review_page_heading - expect(page).to have_content approve_button - end - - scenario "Approved releases have checkmark and non-approved releases don't have checkmarks" do - create(:location_release_with_contract_template, :native, project: project) - - visit project_location_releases_path(project) - expect(page).to have_css('i.fa.fa-check-circle.fa-2x', count: 0) - - create(:location_release_with_contract_template, :native, project: project, approved_by_user_email: "some@email.com", approved_at: DateTime.now) - visit project_location_releases_path(project) - - expect(page).to have_css('i.fa.fa-check-circle.fa-2x', count: 1) - end - - scenario 'When viewing the contract PDF of approved release there is page for office use only' do - location_release = create(:location_release_with_contract_template, - :native, - project: project, - person_first_name: 'Jane', - person_last_name: 'Doe', - approved_by_user_name: "Big Joe", - approved_by_user_email: "some@email.com", - approved_at: DateTime.now) - - sign_in(current_user) - visit project_location_releases_path(project) - click_link *view_release_pdf_link_for(location_release) - - expect(content_type).to eq('application/pdf') - expect(content_disposition).to include('inline') - expect(pdf_body).to have_content for_office_use_only.upcase - expect(pdf_body).to have_content producer_label - expect(pdf_body).to have_content production_label - expect(pdf_body).to have_content issued_to_label - expect(pdf_body).to have_content issued_by_label - expect(pdf_body).to have_content date_issued - expect(pdf_body).to have_content 'Big Joe' - end - - scenario 'When viewing the contract PDF of not approved release there is no page for office use only' do - location_release = create(:location_release_with_contract_template, - :native, - project: project, - person_first_name: 'Jane', - person_last_name: 'Doe') - - sign_in(current_user) - visit project_location_releases_path(project) - click_link *view_release_pdf_link_for(location_release) - - expect(content_type).to eq('application/pdf') - expect(content_disposition).to include('inline') - expect(pdf_body).not_to have_content for_office_use_only.upcase - expect(pdf_body).not_to have_content producer_label - expect(pdf_body).not_to have_content production_label - expect(pdf_body).not_to have_content issued_to_label - expect(pdf_body).not_to have_content issued_by_label - expect(pdf_body).not_to have_content date_issued - expect(pdf_body).not_to have_content 'Big Joe' - end end context "when the user is project manager" do - before do - sign_in current_user - end - - scenario "Review action in Manage menu is not visible" do - create(:location_release_with_contract_template, :native, project: project) - - visit project_location_releases_path(project) - click_on manage_button - - expect(page).not_to have_link(review_action, exact: true) - end end context "when the user is associate" do @@ -498,15 +403,6 @@ feature "User managing location releases" do click_on manage_button expect(page).not_to have_link("Download", exact: true) end - - scenario "Review action in Manage menu is not visible" do - create(:location_release_with_contract_template, :native, project: project) - - visit project_location_releases_path(project) - click_on manage_button - - expect(page).not_to have_link(review_action, exact: true) - end end private @@ -650,42 +546,6 @@ feature "User managing location releases" do 'Some signature legal language' end - def review_action - t 'location_releases.location_release.actions.review' - end - - def review_page_heading - t 'approvals.new.heading', release_type: "Location Release" - end - - def approve_button - t 'approvals.new.actions.approve' - end - - def for_office_use_only - t 'contracts.for_office_use_only.heading' - end - - def producer_label - t 'contracts.for_office_use_only.description_labels.producer' - end - - def production_label - t 'contracts.for_office_use_only.description_labels.production' - end - - def issued_to_label - t 'contracts.for_office_use_only.description_labels.issued_to' - end - - def issued_by_label - t 'contracts.for_office_use_only.description_labels.issued_by' - end - - def date_issued - t 'contracts.for_office_use_only.description_labels.date_issued' - end - def amendments_heading t 'public.amendments.new.amendment.heading' end diff --git a/spec/features/user_managing_material_releases_spec.rb b/spec/features/user_managing_material_releases_spec.rb index 594d20a..9eda8be 100644 --- a/spec/features/user_managing_material_releases_spec.rb +++ b/spec/features/user_managing_material_releases_spec.rb @@ -421,104 +421,9 @@ feature "User managing material releases" do end context "when the user is account manager" do - let(:current_user) { create(:user, :account_manager) } - - before do - sign_in current_user - end - - scenario "Review action in Manage menu is visible" do - create(:material_release_with_contract_template, :native, project: project) - - visit project_material_releases_path(project) - - expect(page).to have_link(review_action, exact: true) - end - - scenario "Reviewing release" do - create(:material_release_with_contract_template, :native, project: project) - - visit project_material_releases_path(project) - - click_link review_action - - expect(page).to have_content review_page_heading - expect(page).to have_content approve_button - end - - scenario "Approved releases have checkmark and non-approved releases don't have checkmarks" do - create(:material_release_with_contract_template, :native, project: project) - - visit project_material_releases_path(project) - expect(page).to have_css('i.fa.fa-check-circle.fa-2x', count: 0) - - create(:material_release_with_contract_template, :native, project: project, approved_by_user_email: "some@email.com", approved_at: DateTime.now) - visit project_material_releases_path(project) - - expect(page).to have_css('i.fa.fa-check-circle.fa-2x', count: 1) - end - - scenario 'When viewing the contract PDF of approved release there is page for office use only' do - material_release = create(:material_release_with_contract_template, - :native, - project: project, - person_first_name: 'Jane', - person_last_name: 'Doe', - approved_by_user_name: "Big Joe", - approved_by_user_email: "some@email.com", - approved_at: DateTime.now) - - sign_in(current_user) - visit project_material_releases_path(project) - click_link *view_release_pdf_link_for(material_release) - - expect(content_type).to eq('application/pdf') - expect(content_disposition).to include('inline') - expect(pdf_body).to have_content for_office_use_only.upcase - expect(pdf_body).to have_content producer_label - expect(pdf_body).to have_content production_label - expect(pdf_body).to have_content issued_to_label - expect(pdf_body).to have_content issued_by_label - expect(pdf_body).to have_content date_issued - expect(pdf_body).to have_content 'Big Joe' - end - - scenario 'When viewing the contract PDF of not approved release there is no page for office use only' do - material_release = create(:material_release_with_contract_template, - :native, - project: project, - person_first_name: 'Jane', - person_last_name: 'Doe') - - sign_in(current_user) - visit project_material_releases_path(project) - click_link *view_release_pdf_link_for(material_release) - - expect(content_type).to eq('application/pdf') - expect(content_disposition).to include('inline') - expect(pdf_body).not_to have_content for_office_use_only.upcase - expect(pdf_body).not_to have_content producer_label - expect(pdf_body).not_to have_content production_label - expect(pdf_body).not_to have_content issued_to_label - expect(pdf_body).not_to have_content issued_by_label - expect(pdf_body).not_to have_content date_issued - expect(pdf_body).not_to have_content 'Big Joe' - end end context "when the user is project manager" do - before do - sign_in current_user - end - - scenario "Review action in Manage menu is not visible" do - create(:material_release_with_contract_template, :native, project: project) - - visit project_material_releases_path(project) - click_on "Manage" - - expect(page).not_to have_link(review_action, exact: true) - end end context "when the user is associate" do @@ -536,15 +441,6 @@ feature "User managing material releases" do click_on "Manage" expect(page).not_to have_link("Download", exact: true) end - - scenario "Review action in Manage menu is not visible" do - create(:material_release_with_contract_template, :native, project: project) - - visit project_material_releases_path(project) - click_on "Manage" - - expect(page).not_to have_link(review_action, exact: true) - end end private @@ -693,42 +589,6 @@ feature "User managing material releases" do 'Some signature legal language' end - def review_action - t 'material_releases.material_release.actions.review' - end - - def review_page_heading - t 'approvals.new.heading', release_type: "Material Release" - end - - def approve_button - t 'approvals.new.actions.approve' - end - - def for_office_use_only - t 'contracts.for_office_use_only.heading' - end - - def producer_label - t 'contracts.for_office_use_only.description_labels.producer' - end - - def production_label - t 'contracts.for_office_use_only.description_labels.production' - end - - def issued_to_label - t 'contracts.for_office_use_only.description_labels.issued_to' - end - - def issued_by_label - t 'contracts.for_office_use_only.description_labels.issued_by' - end - - def date_issued - t 'contracts.for_office_use_only.description_labels.date_issued' - end - def person_is_minor_checkbox 'material_release_minor' end diff --git a/spec/features/user_managing_medical_releases_spec.rb b/spec/features/user_managing_medical_releases_spec.rb index 9e77852..7c43ddc 100644 --- a/spec/features/user_managing_medical_releases_spec.rb +++ b/spec/features/user_managing_medical_releases_spec.rb @@ -215,15 +215,6 @@ feature "User managing medical releases" do expect(page).to have_link("Download", exact: true, count: 2) end - scenario "Review action in Manage menu is visible" do - create(:medical_release_with_contract_template, :native, project: project) - create(:medical_release_with_contract_template, :non_native, project: project) - - visit project_medical_releases_path(project) - - expect(page).to have_link(review_action, exact: true) - end - scenario "Downloading PDF of native medical release is possible" do native_release = create(:medical_release_with_contract_template, :native, project: project) @@ -233,64 +224,6 @@ feature "User managing medical releases" do expect(content_type).to eq('application/pdf') end - scenario "Reviewing release" do - create(:medical_release_with_contract_template, :native, project: project) - - visit project_medical_releases_path(project) - - click_link review_action - - expect(page).to have_content review_page_heading - expect(page).to have_content approve_button - end - - scenario 'When viewing the contract PDF of approved release there is page for office use only' do - medical_release = create(:medical_release_with_contract_template, - :native, - project: project, - person_first_name: 'Jane', - person_last_name: 'Doe', - approved_by_user_name: "Big Joe", - approved_by_user_email: "some@email.com", - approved_at: DateTime.now) - - sign_in(current_user) - visit project_medical_releases_path(project) - click_link *view_release_pdf_link_for(medical_release) - - expect(content_type).to eq('application/pdf') - expect(content_disposition).to include('inline') - expect(pdf_body).to have_content for_office_use_only.upcase - expect(pdf_body).to have_content producer_label - expect(pdf_body).to have_content production_label - expect(pdf_body).to have_content issued_to_label - expect(pdf_body).to have_content issued_by_label - expect(pdf_body).to have_content date_issued - expect(pdf_body).to have_content 'Big Joe' - end - - scenario 'When viewing the contract PDF of not approved release there is no page for office use only' do - medical_release = create(:medical_release_with_contract_template, - :native, - project: project, - person_first_name: 'Jane', - person_last_name: 'Doe') - - sign_in(current_user) - visit project_medical_releases_path(project) - click_link *view_release_pdf_link_for(medical_release) - - expect(content_type).to eq('application/pdf') - expect(content_disposition).to include('inline') - expect(pdf_body).not_to have_content for_office_use_only.upcase - expect(pdf_body).not_to have_content producer_label - expect(pdf_body).not_to have_content production_label - expect(pdf_body).not_to have_content issued_to_label - expect(pdf_body).not_to have_content issued_by_label - expect(pdf_body).not_to have_content date_issued - expect(pdf_body).not_to have_content 'Big Joe' - end - scenario 'viewing contract PDF with medical questionnaire' do contract_template = create(:medical_release_contract_template, project: project, questionnaire_legal_text: "Questionnaire legal text", question_1_text: "Question 1 text") medical_release = create(:medical_release, @@ -343,15 +276,6 @@ feature "User managing medical releases" do expect(page).to have_link("Download", exact: true, count: 0) end - scenario "Review action in Manage menu is not visible" do - create(:medical_release_with_contract_template, :native, project: project) - create(:medical_release_with_contract_template, :non_native, project: project) - - visit project_medical_releases_path(project) - - expect(page).not_to have_link(review_action, exact: true) - end - scenario "Downloading PDF of native medical release is not possible" do native_release = create(:medical_release_with_contract_template, :native, project: project) @@ -396,15 +320,6 @@ feature "User managing medical releases" do expect(page).to have_link("Download", exact: true, count: 0) end - scenario "Review action in Manage menu is not visible" do - create(:medical_release_with_contract_template, :native, project: project) - create(:medical_release_with_contract_template, :non_native, project: project) - - visit project_medical_releases_path(project) - - expect(page).not_to have_link(review_action, exact: true) - end - scenario "Downloading PDF of native medical release is not possible" do native_release = create(:medical_release_with_contract_template, :native, project: project) @@ -584,40 +499,4 @@ feature "User managing medical releases" do def dummy_signature_legal_text 'Some signature legal language' end - - def review_action - t 'medical_releases.medical_release.actions.review' - end - - def review_page_heading - t 'approvals.new.heading', release_type: "Medical Release" - end - - def approve_button - t 'approvals.new.actions.approve' - end - - def for_office_use_only - t 'contracts.for_office_use_only.heading' - end - - def producer_label - t 'contracts.for_office_use_only.description_labels.producer' - end - - def production_label - t 'contracts.for_office_use_only.description_labels.production' - end - - def issued_to_label - t 'contracts.for_office_use_only.description_labels.issued_to' - end - - def issued_by_label - t 'contracts.for_office_use_only.description_labels.issued_by' - end - - def date_issued - t 'contracts.for_office_use_only.description_labels.date_issued' - end end diff --git a/spec/features/user_managing_misc_releases_spec.rb b/spec/features/user_managing_misc_releases_spec.rb index 673472b..81beb63 100644 --- a/spec/features/user_managing_misc_releases_spec.rb +++ b/spec/features/user_managing_misc_releases_spec.rb @@ -79,83 +79,6 @@ feature "User managing misc releases" do expect(content_type).to eq('application/pdf') end - scenario "Review action in Manage menu is visible" do - create(:misc_release_with_contract_template, :native, project: project) - - visit project_misc_releases_path(project) - - expect(page).to have_link(review_action, exact: true) - end - - scenario "Reviewing release" do - create(:misc_release_with_contract_template, :native, project: project) - - visit project_misc_releases_path(project) - - click_link review_action - - expect(page).to have_content review_page_heading - expect(page).to have_content approve_button - end - - scenario "Approved releases have checkmark and non-approved releases don't have checkmarks" do - create(:misc_release_with_contract_template, :native, project: project) - - visit project_misc_releases_path(project) - expect(page).to have_css('i.fa.fa-check-circle.fa-2x', count: 0) - - create(:misc_release_with_contract_template, :native, project: project, approved_by_user_email: "some@email.com", approved_at: DateTime.now) - visit project_misc_releases_path(project) - - expect(page).to have_css('i.fa.fa-check-circle.fa-2x', count: 1) - end - - scenario 'When viewing the contract PDF of approved release there is page for office use only' do - misc_release = create(:misc_release_with_contract_template, - :native, - project: project, - person_first_name: 'Jane', - person_last_name: 'Doe', - approved_by_user_name: "Big Joe", - approved_by_user_email: "some@email.com", - approved_at: DateTime.now) - - sign_in(current_user) - visit project_misc_releases_path(project) - click_link *view_release_pdf_link_for(misc_release) - - expect(content_type).to eq('application/pdf') - expect(content_disposition).to include('inline') - expect(pdf_body).to have_content for_office_use_only.upcase - expect(pdf_body).to have_content producer_label - expect(pdf_body).to have_content production_label - expect(pdf_body).to have_content issued_to_label - expect(pdf_body).to have_content issued_by_label - expect(pdf_body).to have_content date_issued - expect(pdf_body).to have_content 'Big Joe' - end - - scenario 'When viewing the contract PDF of not approved release there is no page for office use only' do - misc_release = create(:misc_release_with_contract_template, - :native, - project: project, - person_first_name: 'Jane', - person_last_name: 'Doe') - - sign_in(current_user) - visit project_misc_releases_path(project) - click_link *view_release_pdf_link_for(misc_release) - - expect(content_type).to eq('application/pdf') - expect(content_disposition).to include('inline') - expect(pdf_body).not_to have_content for_office_use_only.upcase - expect(pdf_body).not_to have_content producer_label - expect(pdf_body).not_to have_content production_label - expect(pdf_body).not_to have_content issued_to_label - expect(pdf_body).not_to have_content issued_by_label - expect(pdf_body).not_to have_content date_issued - expect(pdf_body).not_to have_content 'Big Joe' - end scenario 'viewing the contract PDF' do misc_release = create(:misc_release, @@ -218,14 +141,6 @@ feature "User managing misc releases" do expect(page).to have_link("Download", exact: true, count: 0) end - - scenario "Review action in Manage menu is not visible" do - create(:misc_release_with_contract_template, :native, project: project) - - visit project_misc_releases_path(project) - - expect(page).not_to have_link(review_action, exact: true) - end end private @@ -300,40 +215,4 @@ feature "User managing misc releases" do def view_release_pdf_link_for(release) ['Download', href: misc_release_contracts_path(release, format: 'pdf')] end - - def review_action - t 'misc_releases.misc_release.actions.review' - end - - def review_page_heading - t 'approvals.new.heading', release_type: "Misc Release" - end - - def approve_button - t 'approvals.new.actions.approve' - end - - def for_office_use_only - t 'contracts.for_office_use_only.heading' - end - - def producer_label - t 'contracts.for_office_use_only.description_labels.producer' - end - - def production_label - t 'contracts.for_office_use_only.description_labels.production' - end - - def issued_to_label - t 'contracts.for_office_use_only.description_labels.issued_to' - end - - def issued_by_label - t 'contracts.for_office_use_only.description_labels.issued_by' - end - - def date_issued - t 'contracts.for_office_use_only.description_labels.date_issued' - end end diff --git a/spec/features/user_managing_music_releases_spec.rb b/spec/features/user_managing_music_releases_spec.rb index 1e9689a..0414983 100644 --- a/spec/features/user_managing_music_releases_spec.rb +++ b/spec/features/user_managing_music_releases_spec.rb @@ -92,39 +92,9 @@ feature "User managing music releases" do before do sign_in current_user end - - scenario "Review action in Manage menu is visible" do - create(:music_release_with_contract_template, project: project) - - visit project_music_releases_path(project) - click_on "Manage" - - expect(page).to have_link(review_action, exact: true) - end - - scenario "Reviewing release" do - create(:music_release_with_contract_template, project: project) - - visit project_music_releases_path(project) - click_on "Manage" - - click_link review_action - - expect(page).to have_content review_page_heading - expect(page).to have_content approve_button - end end context "when the user is project manager" do - scenario "Review action in Manage menu is not visible" do - create(:music_release_with_contract_template, project: project) - - sign_in current_user - visit project_music_releases_path(project) - click_on "Manage" - - expect(page).not_to have_link(review_action, exact: true) - end end context "when the user is associate" do @@ -133,24 +103,15 @@ feature "User managing music releases" do before do sign_in current_user end - + scenario "should not show download" do collection1 = create(:music_release, name: "EDM Music", project: project) - + visit project_music_releases_path(project) - + click_on "Manage" expect(page).not_to have_link("Download", exact: true) end - - scenario "Review action in Manage menu is not visible" do - create(:music_release_with_contract_template, project: project) - - visit project_music_releases_path(project) - click_on "Manage" - - expect(page).not_to have_link(review_action, exact: true) - end end private @@ -216,16 +177,4 @@ feature "User managing music releases" do select "Other", from: "Restriction" fill_in "Describe other restrictions", with: "Test" end - - def review_action - t 'music_releases.music_release.actions.review' - end - - def review_page_heading - t 'approvals.new.heading', release_type: "Music Release" - end - - def approve_button - t 'approvals.new.actions.approve' - end end diff --git a/spec/features/user_managing_talent_releases_spec.rb b/spec/features/user_managing_talent_releases_spec.rb index c11108e..5199119 100644 --- a/spec/features/user_managing_talent_releases_spec.rb +++ b/spec/features/user_managing_talent_releases_spec.rb @@ -374,104 +374,9 @@ feature "User managing talent releases" do end context "when the user is account manager" do - let(:current_user) { create(:user, :account_manager) } - - before do - sign_in current_user - end - - scenario "Review action in Manage menu is visible" do - create(:talent_release_with_contract_template, :native, project: project) - - visit project_talent_releases_path(project) - - expect(page).to have_link(review_action, exact: true) - end - - scenario "Reviewing release" do - create(:talent_release_with_contract_template, :native, project: project) - - visit project_talent_releases_path(project) - - click_link review_action - - expect(page).to have_content review_page_heading - expect(page).to have_content approve_button - end - - scenario "Approved releases have checkmark and non-approved releases don't have checkmarks" do - create(:talent_release_with_contract_template, :native, project: project) - - visit project_talent_releases_path(project) - expect(page).to have_css('i.fa.fa-check-circle.fa-2x', count: 0) - - create(:talent_release_with_contract_template, :native, project: project, approved_by_user_email: "some@email.com", approved_at: DateTime.now) - visit project_talent_releases_path(project) - - expect(page).to have_css('i.fa.fa-check-circle.fa-2x', count: 1) - end - - scenario 'When viewing the contract PDF of approved release there is page for office use only' do - talent_release = create(:talent_release_with_contract_template, - :native, - project: project, - person_first_name: 'Jane', - person_last_name: 'Doe', - approved_by_user_name: "Big Joe", - approved_by_user_email: "some@email.com", - approved_at: DateTime.now) - - sign_in(current_user) - visit project_talent_releases_path(project) - click_link *view_release_pdf_link_for(talent_release) - - expect(content_type).to eq('application/pdf') - expect(content_disposition).to include('inline') - expect(pdf_body).to have_content for_office_use_only.upcase - expect(pdf_body).to have_content producer_label - expect(pdf_body).to have_content production_label - expect(pdf_body).to have_content issued_to_label - expect(pdf_body).to have_content issued_by_label - expect(pdf_body).to have_content date_issued - expect(pdf_body).to have_content 'Big Joe' - end - - scenario 'When viewing the contract PDF of not approved release there is no page for office use only' do - talent_release = create(:talent_release_with_contract_template, - :native, - project: project, - person_first_name: 'Jane', - person_last_name: 'Doe') - - sign_in(current_user) - visit project_talent_releases_path(project) - click_link *view_release_pdf_link_for(talent_release) - - expect(content_type).to eq('application/pdf') - expect(content_disposition).to include('inline') - expect(pdf_body).not_to have_content for_office_use_only.upcase - expect(pdf_body).not_to have_content producer_label - expect(pdf_body).not_to have_content production_label - expect(pdf_body).not_to have_content issued_to_label - expect(pdf_body).not_to have_content issued_by_label - expect(pdf_body).not_to have_content date_issued - expect(pdf_body).not_to have_content 'Big Joe' - end end context "when the user is project manager" do - before do - sign_in current_user - end - - scenario "Review action in Manage menu is not visible" do - create(:talent_release_with_contract_template, :native, project: project) - - visit project_talent_releases_path(project) - click_on "Manage" - - expect(page).not_to have_link(review_action, exact: true) - end end context "when the user is associate" do @@ -489,15 +394,6 @@ feature "User managing talent releases" do click_on "Manage" expect(page).not_to have_link("Download", exact: true) end - - scenario "Review action in Manage menu is not visible" do - create(:talent_release_with_contract_template, :native, project: project) - - visit project_talent_releases_path(project) - click_on "Manage" - - expect(page).not_to have_link(review_action, exact: true) - end end private @@ -679,40 +575,4 @@ feature "User managing talent releases" do def dummy_signature_legal_text 'Some signature legal language' end - - def review_action - t 'talent_releases.talent_release.actions.review' - end - - def review_page_heading - t 'approvals.new.heading', release_type: "Talent Release" - end - - def approve_button - t 'approvals.new.actions.approve' - end - - def for_office_use_only - t 'contracts.for_office_use_only.heading' - end - - def producer_label - t 'contracts.for_office_use_only.description_labels.producer' - end - - def production_label - t 'contracts.for_office_use_only.description_labels.production' - end - - def issued_to_label - t 'contracts.for_office_use_only.description_labels.issued_to' - end - - def issued_by_label - t 'contracts.for_office_use_only.description_labels.issued_by' - end - - def date_issued - t 'contracts.for_office_use_only.description_labels.date_issued' - end end diff --git a/spec/models/acquired_media_release_spec.rb b/spec/models/acquired_media_release_spec.rb index d1a2f12..83ff532 100644 --- a/spec/models/acquired_media_release_spec.rb +++ b/spec/models/acquired_media_release_spec.rb @@ -1,6 +1,7 @@ require "rails_helper" RSpec.describe AcquiredMediaRelease do + it_behaves_like 'an approvable' it_behaves_like "a contractable" it_behaves_like "an exploitable" it_behaves_like "a notable" diff --git a/spec/models/appearance_release_spec.rb b/spec/models/appearance_release_spec.rb index 1792ee4..61b71fe 100644 --- a/spec/models/appearance_release_spec.rb +++ b/spec/models/appearance_release_spec.rb @@ -3,6 +3,7 @@ require 'rails_helper' RSpec.describe AppearanceRelease do + it_behaves_like 'an approvable' it_behaves_like 'a contractable' it_behaves_like 'an exploitable' it_behaves_like 'a notable' diff --git a/spec/models/location_release_spec.rb b/spec/models/location_release_spec.rb index 219711c..30c12e2 100644 --- a/spec/models/location_release_spec.rb +++ b/spec/models/location_release_spec.rb @@ -1,6 +1,7 @@ require "rails_helper" RSpec.describe LocationRelease do + it_behaves_like 'an approvable' it_behaves_like "a contractable" it_behaves_like "an exploitable" it_behaves_like "a notable" diff --git a/spec/models/material_release_spec.rb b/spec/models/material_release_spec.rb index a15f9ac..666a588 100644 --- a/spec/models/material_release_spec.rb +++ b/spec/models/material_release_spec.rb @@ -1,6 +1,7 @@ require "rails_helper" RSpec.describe MaterialRelease do + it_behaves_like 'an approvable' it_behaves_like "a contractable" it_behaves_like "an exploitable" it_behaves_like "a notable" diff --git a/spec/models/medical_release_spec.rb b/spec/models/medical_release_spec.rb index 53860fb..a706371 100644 --- a/spec/models/medical_release_spec.rb +++ b/spec/models/medical_release_spec.rb @@ -1,6 +1,7 @@ require "rails_helper" RSpec.describe MedicalRelease do + it_behaves_like 'an approvable' it_behaves_like "a contractable" it_behaves_like "a notable" it_behaves_like "a photoable" diff --git a/spec/models/misc_release_spec.rb b/spec/models/misc_release_spec.rb index ce68b16..0acf153 100644 --- a/spec/models/misc_release_spec.rb +++ b/spec/models/misc_release_spec.rb @@ -1,6 +1,7 @@ require 'rails_helper' RSpec.describe MiscRelease, type: :model do + it_behaves_like 'an approvable' it_behaves_like "a contractable" it_behaves_like "a notable" it_behaves_like "a photoable" diff --git a/spec/models/music_release_spec.rb b/spec/models/music_release_spec.rb index 53882cb..66065c7 100644 --- a/spec/models/music_release_spec.rb +++ b/spec/models/music_release_spec.rb @@ -1,6 +1,7 @@ require "rails_helper" RSpec.describe MusicRelease do + it_behaves_like 'an approvable' it_behaves_like "a contractable" it_behaves_like "an exploitable" it_behaves_like "a notable" diff --git a/spec/models/talent_release_spec.rb b/spec/models/talent_release_spec.rb index fcdab6c..ed9da80 100644 --- a/spec/models/talent_release_spec.rb +++ b/spec/models/talent_release_spec.rb @@ -1,6 +1,7 @@ require "rails_helper" RSpec.describe TalentRelease do + it_behaves_like 'an approvable' it_behaves_like "a contractable" it_behaves_like "an exploitable" it_behaves_like "a notable" diff --git a/spec/support/shared_examples_for_an_approvable.rb b/spec/support/shared_examples_for_an_approvable.rb new file mode 100644 index 0000000..077c876 --- /dev/null +++ b/spec/support/shared_examples_for_an_approvable.rb @@ -0,0 +1,47 @@ +shared_examples_for "an approvable" do + it { is_expected.to respond_to(:approved_by_user_signature) } + + describe "#approve_by" do + before do + allow(BigMediaTime).to receive(:time_zone_now).and_return(1.week.ago) + end + + it "stores info about the approving user" do + user = double(full_name: "Jane Doe", email: "jane.doe@test.com") + + subject.approve_by(user) + + expect(subject.approved_by_user_name).to eq "Jane Doe" + expect(subject.approved_by_user_email).to eq "jane.doe@test.com" + expect(subject.approved_at).to eq BigMediaTime.time_zone_now + end + + context "when approval has already been given" do + it "does not change the existing info" do + user1 = double(full_name: "Jane Doe", email: "jane.doe@test.com") + subject.approve_by(user1) + + expect(subject.approved_by_user_name).to eq "Jane Doe" + expect(subject.approved_by_user_email).to eq "jane.doe@test.com" + expect(subject.approved_at).to eq BigMediaTime.time_zone_now + + user2 = double(full_name: "John Doe", email: "john.doe@test.com") + subject.approve_by(user2) + + expect(subject.approved_by_user_name).to eq "Jane Doe" + expect(subject.approved_by_user_email).to eq "jane.doe@test.com" + expect(subject.approved_at).to eq BigMediaTime.time_zone_now + end + end + end + + describe "#approved?" do + it "indicates whether or not it has been approved" do + subject.approved_at = nil + expect(subject).not_to be_approved + + subject.approved_at = 1.week.ago + expect(subject).to be_approved + end + end +end diff --git a/spec/support/signature_helper.rb b/spec/support/signature_helper.rb index 5c7d44c..a1b52b5 100644 --- a/spec/support/signature_helper.rb +++ b/spec/support/signature_helper.rb @@ -2,7 +2,7 @@ module SignatureHelper def draw_signature(file, signature_field_id) data_uri = ActionController::Base.helpers.escape_javascript(Base64Image.from_image(file).data_uri) page.execute_script <<-JS - $("##{signature_field_id}").val("#{data_uri}") + document.getElementById("#{signature_field_id}").value = "#{data_uri}"; JS end end