diff --git a/app/views/contracts/pdf.html.erb b/app/views/contracts/pdf.html.erb
index 92d8e73..b3b17f6 100644
--- a/app/views/contracts/pdf.html.erb
+++ b/app/views/contracts/pdf.html.erb
@@ -16,7 +16,7 @@
<%= contract_template.guardian_clause %>
<% end %>
-<% if releasable.respond_to?(:question_1_answer) %>
+<% if contract_template.present? && contract_template.has_questionnaire? %>
<%= render "contracts/questionnaire", releasable: releasable, contract_template: contract_template, preview: preview %>
diff --git a/spec/factories/contract_templates.rb b/spec/factories/contract_templates.rb
index 64757f8..685b6f2 100644
--- a/spec/factories/contract_templates.rb
+++ b/spec/factories/contract_templates.rb
@@ -19,6 +19,22 @@ FactoryBot.define do
amendment_clause "Amendment Legal Language"
end
+ trait :with_questionnaire_legal_text do
+ questionnaire_legal_text "Questionnaire Legal Text"
+ end
+
+ trait :with_one_question do
+ question_1_text "Is this a question?"
+ end
+
+ trait :with_exhibits do
+ exhibit_a_legal_text "Exhibit A legal text"
+ exhibit_b_legal_text "Exhibit B legal text"
+
+ exhibit_a_question_text "Exhibit A question text"
+ exhibit_b_question_text "Exhibit B question text"
+ end
+
factory :appearance_release_contract_template do
release_type "appearance"
end
diff --git a/spec/features/user_managing_appearance_releases_spec.rb b/spec/features/user_managing_appearance_releases_spec.rb
index 5f61077..bdcfb05 100644
--- a/spec/features/user_managing_appearance_releases_spec.rb
+++ b/spec/features/user_managing_appearance_releases_spec.rb
@@ -544,7 +544,7 @@ feature 'User managing appearance releases' do
expect(pdf_body).to have_content('Guardian Email')
end
- scenario "viewing the contract PDF when exhibit A is signed" do
+ scenario "viewing the contract PDF when exhibit A is signed and without questionnaire" do
contract_template = create(:appearance_release_contract_template, project: project, exhibit_a_legal_text: "Exhibit A legal text", exhibit_a_question_text: "Exhibit A question text")
appearance_release = create(:appearance_release,
:amendment_signed,
@@ -566,10 +566,113 @@ feature 'User managing appearance releases' do
expect(pdf_body).to have_content("John Doe")
- expect(pdf_body).to have_content "Exhibit A"
+ expect(pdf_body).to have_content exhibit_a_heading
expect(pdf_body).to have_content "Exhibit A legal text"
expect(pdf_body).to have_content "Exhibit A question text"
expect(pdf_body).to have_content "Answer to exhibit A question"
+
+ expect(pdf_body).not_to have_content questionnaire_heading
+ expect(pdf_body).not_to have_content exhibit_b_heading
+ end
+
+ scenario "viewing the contract PDF when exhibit B is signed and without questionnaire" do
+ contract_template = create(:appearance_release_contract_template, project: project, exhibit_b_legal_text: "Exhibit B legal text", exhibit_b_question_text: "Exhibit B question text")
+ appearance_release = create(:appearance_release,
+ :amendment_signed,
+ :native,
+ contract_template: contract_template,
+ project: project,
+ person_first_name: "John",
+ person_last_name: "Doe",
+ exhibit_b_answer: "Answer to exhibit B question"
+ )
+
+ 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_filename).to include("doe-john")
+
+ expect(pdf_body).to have_content("John Doe")
+
+ expect(pdf_body).to have_content exhibit_b_heading
+ expect(pdf_body).to have_content "Exhibit B legal text"
+ expect(pdf_body).to have_content "Exhibit B question text"
+ expect(pdf_body).to have_content "Answer to exhibit B question"
+
+ expect(pdf_body).not_to have_content questionnaire_heading
+ expect(pdf_body).not_to have_content exhibit_a_heading
+ end
+
+ scenario "viewing the contract PDF with questionnaire and without exhibits" do
+ contract_template = create(:appearance_release_contract_template, :with_questionnaire_legal_text, :with_one_question, project: project)
+ appearance_release = create(:appearance_release,
+ :amendment_signed,
+ :native,
+ contract_template: contract_template,
+ project: project,
+ person_first_name: "John",
+ person_last_name: "Doe",
+ question_1_answer: "Yes"
+ )
+
+ 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_filename).to include("doe-john")
+
+ expect(pdf_body).to have_content questionnaire_heading
+ expect(pdf_body).to have_content contract_template.question_1_text
+ expect(pdf_body).to have_content appearance_release.question_1_answer
+
+ expect(pdf_body).not_to have_content exhibit_a_heading
+ expect(pdf_body).not_to have_content exhibit_b_heading
+ end
+
+ scenario "viewing the contract PDF with questionnaire and with exhibits" do
+ contract_template = create(:appearance_release_contract_template,
+ :with_questionnaire_legal_text,
+ :with_one_question,
+ :with_exhibits,
+ project: project)
+ appearance_release = create(:appearance_release,
+ :amendment_signed,
+ :native,
+ contract_template: contract_template,
+ project: project,
+ person_first_name: "John",
+ person_last_name: "Doe",
+ question_1_answer: "Yes",
+ exhibit_a_answer: "Exhibit A answer",
+ exhibit_b_answer: "Exhibit B answer"
+ )
+
+ 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_filename).to include("doe-john")
+
+ expect(pdf_body).to have_content questionnaire_heading
+ expect(pdf_body).to have_content contract_template.question_1_text
+ expect(pdf_body).to have_content appearance_release.question_1_answer
+
+ expect(pdf_body).to have_content exhibit_a_heading
+ expect(pdf_body).to have_content contract_template.exhibit_a_legal_text.to_plain_text
+ expect(pdf_body).to have_content contract_template.exhibit_a_question_text
+ expect(pdf_body).to have_content appearance_release.exhibit_a_answer
+
+ expect(pdf_body).to have_content exhibit_b_heading
+ expect(pdf_body).to have_content contract_template.exhibit_b_legal_text.to_plain_text
+ expect(pdf_body).to have_content contract_template.exhibit_b_question_text
+ expect(pdf_body).to have_content appearance_release.exhibit_b_answer
end
scenario 'deleting a release', js: true do
@@ -987,4 +1090,16 @@ feature 'User managing appearance releases' do
def amendment_signature_label
t 'contracts.amendment_page.description_labels.amendment_signature'
end
+
+ def questionnaire_heading
+ t 'contracts.questionnaire.heading.appearance_release'
+ end
+
+ def exhibit_a_heading
+ t 'contracts.exhibit_a_page.heading.appearance_release'
+ end
+
+ def exhibit_b_heading
+ t 'contracts.exhibit_b_page.heading.appearance_release'
+ end
end
diff --git a/spec/features/user_managing_medical_releases_spec.rb b/spec/features/user_managing_medical_releases_spec.rb
index 7c43ddc..2af278b 100644
--- a/spec/features/user_managing_medical_releases_spec.rb
+++ b/spec/features/user_managing_medical_releases_spec.rb
@@ -244,11 +244,32 @@ feature "User managing medical releases" do
expect(pdf_filename).to include("doe-john")
expect(pdf_body).to have_content("John Doe")
- expect(pdf_body).to have_content "MEDICAL QUESTIONNAIRE"
+ expect(pdf_body).to have_content questionnaire_heading.upcase
expect(pdf_body).to have_content "Question 1 text"
expect(pdf_body).to have_content "Question 1 answer"
expect(pdf_body).to have_content "Questionnaire legal text"
end
+
+ scenario 'viewing contract PDF without medical questionnaire' do
+ contract_template = create(:medical_release_contract_template, project: project)
+ medical_release = create(:medical_release,
+ :native,
+ contract_template: contract_template,
+ project: project,
+ person_first_name: "John",
+ 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_filename).to include("doe-john")
+
+ expect(pdf_body).not_to have_content questionnaire_heading.upcase
+ end
end
context "when the user is manager(project manager)" do
@@ -499,4 +520,8 @@ feature "User managing medical releases" do
def dummy_signature_legal_text
'Some signature legal language'
end
+
+ def questionnaire_heading
+ t 'contracts.questionnaire.heading.medical_release'
+ end
end
diff --git a/spec/features/user_managing_misc_releases_spec.rb b/spec/features/user_managing_misc_releases_spec.rb
index 81beb63..49b8a5e 100644
--- a/spec/features/user_managing_misc_releases_spec.rb
+++ b/spec/features/user_managing_misc_releases_spec.rb
@@ -80,7 +80,7 @@ feature "User managing misc releases" do
end
- scenario 'viewing the contract PDF' do
+ scenario 'viewing the contract PDF with questionnaire' do
misc_release = create(:misc_release,
:native,
contract_template: build(:misc_release_contract_template, question_1_text: 'Q1'),
@@ -121,10 +121,30 @@ feature "User managing misc releases" do
expect(pdf_body).to have_content('Woman')
expect(pdf_body).to have_content('Brunette')
expect(pdf_body).not_to have_content('Guardian Email')
- expect(pdf_body).to have_content('QUESTIONNAIRE')
+ expect(pdf_body).to have_content questionnaire_heading.upcase
expect(pdf_body).to have_content('Q1')
expect(pdf_body).to have_content('A1')
end
+
+ scenario 'viewing the contract PDF without questionnaire' do
+ misc_release = create(:misc_release,
+ :native,
+ contract_template: build(:misc_release_contract_template),
+ 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_filename).to include('doe-jane')
+
+ expect(pdf_body).not_to have_content questionnaire_heading.upcase
+ end
end
context "when the user is manager(project manager)" do
@@ -215,4 +235,8 @@ feature "User managing misc releases" do
def view_release_pdf_link_for(release)
['Download', href: misc_release_contracts_path(release, format: 'pdf')]
end
+
+ def questionnaire_heading
+ t 'contracts.questionnaire.heading.misc_release'
+ end
end