add specs
This commit is contained in:
@@ -9,8 +9,14 @@ class Public::AmendmentsController < Public::BaseController
|
||||
end
|
||||
|
||||
def create
|
||||
if @release.amendment_signed?
|
||||
render :create, locals: { already_signed: true }
|
||||
return
|
||||
end
|
||||
|
||||
@release.amendment_signer_name = release_params[:amendment_signer_name]
|
||||
@release.amendment_signature_base64 = release_params[:amendment_signature_base64]
|
||||
|
||||
render :new unless @release.save
|
||||
end
|
||||
|
||||
|
||||
112
spec/controllers/public/amendments_controller_spec.rb
Normal file
112
spec/controllers/public/amendments_controller_spec.rb
Normal file
@@ -0,0 +1,112 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Public::AmendmentsController, type: :controller do
|
||||
let(:user) { create(:user) }
|
||||
let(:account) { user.primary_account }
|
||||
let(:project) { create(:project, account: account) }
|
||||
let(:contract_template) { create(:location_release_contract_template, :with_amendment_clause, project: project) }
|
||||
let(:location_release) { create(:location_release, contract_template: contract_template, project: project) }
|
||||
|
||||
render_views
|
||||
|
||||
describe "#new" do
|
||||
it "shows amendment signing form for non-signed amendment of a release" do
|
||||
expect(location_release.amendment_signed?).to be_falsey
|
||||
|
||||
get :new, params: {
|
||||
account_id: account,
|
||||
project_id: project,
|
||||
contract_template_id: location_release.contract_template,
|
||||
location_release_id: location_release
|
||||
}
|
||||
|
||||
expect(response).to be_successful
|
||||
|
||||
body = CGI.unescape_html(response.body)
|
||||
expect(body).not_to match already_signed_message
|
||||
end
|
||||
|
||||
it "shows already signed message for signed amendment of a release" do
|
||||
signed_release = create(:location_release, :amendment_signed, contract_template: contract_template, project: project)
|
||||
|
||||
expect(signed_release.amendment_signed?).to be_truthy
|
||||
|
||||
get :new, params: {
|
||||
account_id: account,
|
||||
project_id: project,
|
||||
contract_template_id: location_release.contract_template,
|
||||
location_release_id: signed_release
|
||||
}
|
||||
|
||||
expect(response).to be_successful
|
||||
|
||||
body = CGI.unescape_html(response.body)
|
||||
expect(body).to match already_signed_message
|
||||
end
|
||||
end
|
||||
|
||||
describe "#create" do
|
||||
it "signs amendment" do
|
||||
expect(location_release.amendment_signed?).to be_falsey
|
||||
|
||||
post :create, params: {
|
||||
account_id: account,
|
||||
project_id: project,
|
||||
contract_template_id: location_release.contract_template,
|
||||
location_release_id: location_release,
|
||||
location_release: {
|
||||
amendment_signer_name: "Signer Name",
|
||||
amendment_signature_base64: signature_base64
|
||||
}
|
||||
}
|
||||
|
||||
expect(response).to be_successful
|
||||
|
||||
body = CGI.unescape_html(response.body)
|
||||
expect(body).not_to match already_signed_message
|
||||
expect(body).to match signed_successfully_message
|
||||
|
||||
expect(LocationRelease.last.amendment_signed?).to be_truthy
|
||||
expect(LocationRelease.last.amendment_signer_name).to eq "Signer Name"
|
||||
end
|
||||
|
||||
it "shows already signed message for signed amendment of a release" do
|
||||
signed_release = create(:location_release, :amendment_signed, name: "Test Loc", amendment_signer_name: "Big Signer", contract_template: contract_template, project: project)
|
||||
|
||||
expect(signed_release.amendment_signed?).to be_truthy
|
||||
|
||||
post :create, params: {
|
||||
account_id: account,
|
||||
project_id: project,
|
||||
contract_template_id: location_release.contract_template,
|
||||
location_release_id: signed_release,
|
||||
location_release: {
|
||||
amendment_signer_name: "Signer Who",
|
||||
amendment_signature_base64: signature_base64
|
||||
}
|
||||
}
|
||||
|
||||
expect(response).to be_successful
|
||||
|
||||
body = CGI.unescape_html(response.body)
|
||||
expect(body).to match already_signed_message
|
||||
|
||||
expect(signed_release.amendment_signed?).to be_truthy
|
||||
expect(signed_release.amendment_signer_name).to eq "Big Signer"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def already_signed_message
|
||||
t 'public.amendments.create.amendment_already_signed_message'
|
||||
end
|
||||
|
||||
def signed_successfully_message
|
||||
t 'public.amendments.create.amendment_signed_message'
|
||||
end
|
||||
|
||||
def signature_base64
|
||||
@signature_base64 ||= Base64Image.from_image(file_fixture('signature.png')).data_uri
|
||||
end
|
||||
end
|
||||
@@ -13,6 +13,10 @@ FactoryBot.define do
|
||||
archived_at Time.zone.now
|
||||
end
|
||||
|
||||
trait :with_amendment_clause do
|
||||
amendment_clause "Amendment Legal Language"
|
||||
end
|
||||
|
||||
factory :appearance_release_contract_template do
|
||||
release_type "appearance"
|
||||
end
|
||||
|
||||
@@ -22,6 +22,14 @@ FactoryBot.define do
|
||||
end
|
||||
end
|
||||
|
||||
trait :amendment_signed do
|
||||
amendment_signature do
|
||||
path = Rails.root.join("spec", "fixtures", "files", "signature.png")
|
||||
Rack::Test::UploadedFile.new(path, "image/png")
|
||||
end
|
||||
amendment_signer_name "Amendment Signer"
|
||||
end
|
||||
|
||||
trait :non_native do
|
||||
contract do
|
||||
path = Rails.root.join("spec", "fixtures", "files", "contract.pdf")
|
||||
|
||||
@@ -78,6 +78,38 @@ feature "User managing location releases" do
|
||||
|
||||
expect(page).to have_content dummy_signature_legal_text
|
||||
end
|
||||
|
||||
scenario "signing amendment for a not-signed amendment release", js: true do
|
||||
contract_template = create(:location_release_contract_template, :with_amendment_clause, project: project)
|
||||
release = create(:location_release, contract_template: contract_template, project: project)
|
||||
|
||||
expect(release.amendment_signed?).to be_falsey
|
||||
|
||||
visit new_account_project_contract_template_location_release_amendment_path(project.account, project, contract_template, release)
|
||||
|
||||
expect(page).to have_content amendments_heading
|
||||
|
||||
fill_in amendment_signer_name_field, with: 'Big Signer'
|
||||
draw_signature file_fixture("signature.png"), amendment_signature_field
|
||||
|
||||
click_button sign_amendment_button
|
||||
|
||||
expect(page).to have_content signed_successfully_message
|
||||
expect(LocationRelease.find(release.id).amendment_signed?).to be_truthy
|
||||
end
|
||||
|
||||
scenario "opening signing amendment page for a signed amendment release shows already signed message", js: true do
|
||||
contract_template = create(:location_release_contract_template, :with_amendment_clause, project: project)
|
||||
release = create(:location_release, :amendment_signed, contract_template: contract_template, project: project)
|
||||
|
||||
expect(release.amendment_signed?).to be_truthy
|
||||
|
||||
visit new_account_project_contract_template_location_release_amendment_path(project.account, project, contract_template, release)
|
||||
|
||||
expect(page).not_to have_content amendments_heading
|
||||
expect(page).not_to have_content signed_successfully_message
|
||||
expect(page).to have_content already_signed_message
|
||||
end
|
||||
end
|
||||
|
||||
context "when signed in" do
|
||||
@@ -110,7 +142,7 @@ feature "User managing location releases" do
|
||||
expect(page).to have_content(create_release_notice)
|
||||
expect(page).to have_photo("location_photo.png")
|
||||
|
||||
click_on "Manage"
|
||||
click_on manage_button
|
||||
expect(page).to have_link("Download")
|
||||
end
|
||||
end
|
||||
@@ -119,7 +151,7 @@ feature "User managing location releases" do
|
||||
location_release = create(:location_release_with_photo, :non_native, project: project)
|
||||
|
||||
visit project_location_releases_path(project)
|
||||
click_on "Manage"
|
||||
click_on manage_button
|
||||
click_link *update_location_release_link(location_release)
|
||||
|
||||
within ".dropzone" do
|
||||
@@ -139,7 +171,7 @@ feature "User managing location releases" do
|
||||
location_release = create(:location_release, project: project)
|
||||
|
||||
visit project_location_releases_path(project)
|
||||
click_on "Manage"
|
||||
click_on manage_button
|
||||
|
||||
accept_alert do
|
||||
click_link *destroy_location_release_link(location_release)
|
||||
@@ -172,7 +204,7 @@ feature "User managing location releases" do
|
||||
|
||||
expect(page).to have_content("Needs Photo")
|
||||
|
||||
click_on "Manage"
|
||||
click_on manage_button
|
||||
click_on "Photos"
|
||||
|
||||
expect(page).to have_content("Add Photos")
|
||||
@@ -184,6 +216,71 @@ feature "User managing location releases" do
|
||||
expect(page).to have_content("The release has been updated")
|
||||
expect(page).to have_photo("location_photo.png")
|
||||
end
|
||||
|
||||
scenario "signing amendment for a not-signed amendment release", js: true do
|
||||
contract_template = create(:location_release_contract_template, :with_amendment_clause, project: project)
|
||||
release = create(:location_release, name: "Test Loc", contract_template: contract_template, project: project)
|
||||
|
||||
expect(release.amendment_signed?).to be_falsey
|
||||
|
||||
visit project_location_releases_path(project)
|
||||
|
||||
expect(page).to have_content "Test Loc"
|
||||
|
||||
click_on manage_button
|
||||
|
||||
expect(page).to have_link sign_amendment_link
|
||||
|
||||
new_window = window_opened_by { click_link sign_amendment_link }
|
||||
within_window new_window do
|
||||
expect(page).to have_content amendments_heading
|
||||
|
||||
fill_in amendment_signer_name_field, with: 'Big Signer'
|
||||
draw_signature file_fixture("signature.png"), amendment_signature_field
|
||||
|
||||
click_button sign_amendment_button
|
||||
|
||||
expect(page).to have_content signed_successfully_message
|
||||
expect(LocationRelease.find(release.id).amendment_signed?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
scenario "signed amendment release does not have sign amendment option in manage dropdown", js: true do
|
||||
contract_template = create(:location_release_contract_template, :with_amendment_clause, project: project)
|
||||
release = create(:location_release, :amendment_signed, name: "Test Loc", contract_template: contract_template, project: project)
|
||||
|
||||
expect(release.amendment_signed?).to be_truthy
|
||||
|
||||
visit project_location_releases_path(project)
|
||||
|
||||
expect(page).to have_content "Test Loc"
|
||||
|
||||
click_on manage_button
|
||||
|
||||
expect(page).not_to have_link sign_amendment_link
|
||||
end
|
||||
|
||||
scenario "signed amendment release have checked box in location releases index table", js: true do
|
||||
contract_template = create(:location_release_contract_template, :with_amendment_clause, project: project)
|
||||
not_signed_release = create(:location_release, name: "Not Yet Loc", contract_template: contract_template, project: project)
|
||||
expect(not_signed_release.amendment_signed?).to be_falsey
|
||||
|
||||
visit project_location_releases_path(project)
|
||||
|
||||
expect(page).to have_content "Not Yet Loc"
|
||||
expect(page).to have_css('i.fa.fa-square-o', count: 1)
|
||||
expect(page).to have_css('i.fa.fa-check-square', count: 0)
|
||||
|
||||
signed_release = create(:location_release, :amendment_signed, name: "Signed A Loc", contract_template: contract_template, project: project)
|
||||
expect(signed_release.amendment_signed?).to be_truthy
|
||||
|
||||
visit project_location_releases_path(project)
|
||||
|
||||
expect(page).to have_content "Signed A Loc"
|
||||
|
||||
expect(page).to have_css('i.fa.fa-square-o', count: 1)
|
||||
expect(page).to have_css('i.fa.fa-check-square-o', count: 1)
|
||||
end
|
||||
end
|
||||
|
||||
scenario "viewing the contract PDF" do
|
||||
@@ -327,7 +424,7 @@ feature "User managing location releases" do
|
||||
create(:location_release_with_contract_template, :native, project: project)
|
||||
|
||||
visit project_location_releases_path(project)
|
||||
click_on "Manage"
|
||||
click_on manage_button
|
||||
|
||||
expect(page).not_to have_link(review_action, exact: true)
|
||||
end
|
||||
@@ -345,7 +442,7 @@ feature "User managing location releases" do
|
||||
|
||||
visit project_location_releases_path(project)
|
||||
|
||||
click_on "Manage"
|
||||
click_on manage_button
|
||||
expect(page).not_to have_link("Download", exact: true)
|
||||
end
|
||||
|
||||
@@ -353,7 +450,7 @@ feature "User managing location releases" do
|
||||
create(:location_release_with_contract_template, :native, project: project)
|
||||
|
||||
visit project_location_releases_path(project)
|
||||
click_on "Manage"
|
||||
click_on manage_button
|
||||
|
||||
expect(page).not_to have_link(review_action, exact: true)
|
||||
end
|
||||
@@ -535,4 +632,36 @@ feature "User managing location releases" do
|
||||
def date_issued
|
||||
t 'contracts.for_office_use_only.description_labels.date_issued'
|
||||
end
|
||||
|
||||
def amendments_heading
|
||||
t 'public.amendments.new.amendment.heading'
|
||||
end
|
||||
|
||||
def amendment_signer_name_field
|
||||
'location_release[amendment_signer_name]'
|
||||
end
|
||||
|
||||
def amendment_signature_field
|
||||
'location_release_amendment_signature_base64'
|
||||
end
|
||||
|
||||
def sign_amendment_button
|
||||
t 'shared.submit_release_long'
|
||||
end
|
||||
|
||||
def already_signed_message
|
||||
t 'public.amendments.create.amendment_already_signed_message'
|
||||
end
|
||||
|
||||
def signed_successfully_message
|
||||
t 'public.amendments.create.amendment_signed_message'
|
||||
end
|
||||
|
||||
def manage_button
|
||||
t 'location_releases.location_release.actions.manage'
|
||||
end
|
||||
|
||||
def sign_amendment_link
|
||||
t 'location_releases.location_release.actions.sign_amendment'
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user