make all location release fields required for native release
This commit is contained in:
@@ -36,7 +36,12 @@ class LocationRelease < ApplicationRecord
|
||||
validate :end_date_after_start_date
|
||||
|
||||
with_options on: :native do
|
||||
validates :person_first_name, :person_last_name, presence: true
|
||||
validates :address_street1, :address_city, :address_state, :address_zip, :address_country,
|
||||
:person_first_name, :person_last_name,
|
||||
:person_phone, :person_email, :person_company, :person_title,
|
||||
:person_address_street1, :person_address_city, :person_address_state,
|
||||
:person_address_zip, :person_address_country,
|
||||
:filming_started_on, :filming_ended_on, :filming_hours, presence: true
|
||||
validates :signature, attached: true
|
||||
end
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ describe Public::LocationReleasesController do
|
||||
it "logs analytics" do
|
||||
contract_template = create(:contract_template, project: project)
|
||||
|
||||
expect {
|
||||
expect do
|
||||
post :create, params: { account_id: project.account.to_param, project_id: project, contract_template_id: contract_template, location_release: location_release_params }
|
||||
}.to(
|
||||
end.to(
|
||||
have_enqueued_job(TrackAnalyticsJob)
|
||||
.with(nil, nil, :track_create_native_release, release_type: "LocationRelease", account: project.account, user_agent: "Rails Testing", user_ip: "0.0.0.0")
|
||||
)
|
||||
@@ -31,28 +31,54 @@ describe Public::LocationReleasesController do
|
||||
contract_template = create(:contract_template, project: project)
|
||||
sign_in(user)
|
||||
|
||||
post :create, params: { account_id: user.primary_account.to_param, project_id: project, contract_template_id: contract_template, location_release: { person_address_city: "Albuquerque", filming_started_on: '02/02/02', filming_ended_on: '01/01/02' } }
|
||||
expect do
|
||||
post :create, params: {
|
||||
account_id: user.primary_account.to_param,
|
||||
project_id: project,
|
||||
contract_template_id: contract_template,
|
||||
location_release: attributes_for(:empty_location_release)
|
||||
}
|
||||
end.not_to change(LocationRelease, :count)
|
||||
|
||||
body = CGI.unescape_html(response.body)
|
||||
expect(body).to match /Name can't be blank/
|
||||
expect(body).to match />can't be blank</
|
||||
# expect(body).to match /must be after the filming started on date/
|
||||
expect(body).to match /Address street1 can't be blank/
|
||||
expect(body).to match /Address city can't be blank/
|
||||
expect(body).to match /Address state can't be blank/
|
||||
expect(body).to match /Address zip can't be blank/
|
||||
expect(body).to match /Address country can't be blank/
|
||||
expect(body).to match /Person first name can't be blank/
|
||||
expect(body).to match /Person last name can't be blank/
|
||||
expect(body).to match /Phone can't be blank/
|
||||
expect(body).to match /Email can't be blank/
|
||||
expect(body).to match /Company can't be blank/
|
||||
expect(body).to match /Title can't be blank/
|
||||
expect(body).to match /Person address street1 can't be blank/
|
||||
expect(body).to match /Person address city can't be blank/
|
||||
expect(body).to match /Person address state can't be blank/
|
||||
expect(body).to match /Person address zip can't be blank/
|
||||
expect(body).to match /Person address country can't be blank/
|
||||
expect(body).to match /Filming started on can't be blank/
|
||||
expect(body).to match /Filming ended on can't be blank/
|
||||
expect(body).to match /Filming hours can't be blank/
|
||||
expect(body).to match /Signature is not attached/
|
||||
end
|
||||
|
||||
it "renders a success page" do
|
||||
contract_template = create(:contract_template, project: project)
|
||||
|
||||
post :create, params: { account_id: user.primary_account.to_param, project_id: project, contract_template_id: contract_template, location_release: location_release_params, filming_started_on: '01/02/20', filming_ended_on: '03/18/20' }
|
||||
|
||||
expect {
|
||||
post :create, params: { account_id: user.primary_account.to_param, project_id: project, contract_template_id: contract_template, location_release: location_release_params, filming_started_on: '01/02/20', filming_ended_on: '03/18/20' }
|
||||
}.to change(LocationRelease, :count).by(1)
|
||||
expect(response).to be_successful
|
||||
end
|
||||
|
||||
it "runs set tags for releasable job" do
|
||||
contract_template = create(:contract_template, project: project)
|
||||
|
||||
expect {
|
||||
expect do
|
||||
post :create, params: { account_id: project.account.to_param, project_id: project, contract_template_id: contract_template, location_release: location_release_params }
|
||||
}.to(
|
||||
end.to(
|
||||
have_enqueued_job(SetTagsForReleasableJob)
|
||||
.with(LocationRelease.last)
|
||||
)
|
||||
@@ -61,9 +87,9 @@ describe Public::LocationReleasesController do
|
||||
it "runs attach contract to releasable job" do
|
||||
contract_template = create(:contract_template, project: project)
|
||||
|
||||
expect {
|
||||
expect do
|
||||
post :create, params: { account_id: project.account.to_param, project_id: project, contract_template_id: contract_template, location_release: location_release_params }
|
||||
}.to(
|
||||
end.to(
|
||||
have_enqueued_job(AttachContractToReleasableJob)
|
||||
.with(LocationRelease.last)
|
||||
)
|
||||
@@ -73,11 +99,11 @@ describe Public::LocationReleasesController do
|
||||
private
|
||||
|
||||
def location_release_params
|
||||
attributes_for(:location_release, :native).except(:signature).merge(signature_param).merge(person_address_params)
|
||||
attributes_for(:location_release, :full_native).except(:signature).merge(signature_param).merge(person_address_params)
|
||||
end
|
||||
|
||||
def location_release_params_with_photos
|
||||
attributes_for(:location_release, :native, :with_photo).except(:signature).merge(signature_param)
|
||||
attributes_for(:location_release, :full_native, :with_photo).except(:signature).merge(signature_param)
|
||||
end
|
||||
|
||||
def person_address_params
|
||||
|
||||
@@ -29,6 +29,32 @@ FactoryBot.define do
|
||||
end
|
||||
end
|
||||
|
||||
trait :full_native do
|
||||
address_street1 'Dummy St.'
|
||||
address_city 'Dummy City'
|
||||
address_state 'Dummy State'
|
||||
address_zip '12121'
|
||||
address_country 'US'
|
||||
person_first_name 'John'
|
||||
person_last_name 'Doe'
|
||||
person_phone '222223333'
|
||||
person_email 'mail@mail.com'
|
||||
person_company 'Dummy Company Inc.'
|
||||
person_title 'mr.'
|
||||
person_address_street1 'Dummy St. 2'
|
||||
person_address_city 'Dummy City 2'
|
||||
person_address_state 'Dummy State 2'
|
||||
person_address_zip '1111111'
|
||||
person_address_country 'US'
|
||||
filming_ended_on DateTime.now
|
||||
filming_started_on '01/02/20'
|
||||
filming_hours '04-20'
|
||||
end
|
||||
|
||||
factory :empty_location_release do
|
||||
name nil
|
||||
end
|
||||
|
||||
factory :location_release_with_contract_template do
|
||||
after(:build) do |location_release, _|
|
||||
location_release.contract_template = build(:location_release_contract_template)
|
||||
|
||||
@@ -17,20 +17,35 @@ feature "User managing location releases" do
|
||||
|
||||
visit new_account_project_contract_template_location_release_path(project.account, project, contract_template)
|
||||
|
||||
click_button submit_release_button
|
||||
expect(page).not_to have_content submitted_release_notice
|
||||
|
||||
by "filling out the form" do
|
||||
fill_in location_name_field, with: "Benny's Burritos"
|
||||
fill_in address_street1_field, with: "100 Broadway"
|
||||
fill_in address_city_field, with: "D"
|
||||
fill_in address_state_field, with: "CA"
|
||||
fill_in address_zip_field, with: "123"
|
||||
fill_in person_first_name_field, with: "Jane"
|
||||
fill_in person_last_name_field, with: "Doe"
|
||||
fill_in person_phone_field, with: "555-555-5555"
|
||||
fill_in person_email_field, with: "jane.doe@test.com"
|
||||
fill_in person_company_field, with: "Inc"
|
||||
fill_in person_title_field, with: "Mrs."
|
||||
fill_in person_address_street1_field, with: "100 Broadway"
|
||||
fill_in person_address_city_field, with: "D"
|
||||
fill_in person_address_state_field, with: "CA"
|
||||
fill_in person_address_zip_field, with: "123"
|
||||
fill_filming_started_on_field
|
||||
fill_filming_ended_on_field
|
||||
fill_in filming_hours_field, with: "04:00 - 22:00"
|
||||
|
||||
draw_signature file_fixture("signature.png"), "location_release_signature_base64"
|
||||
end
|
||||
|
||||
click_button submit_release_button
|
||||
|
||||
expect(page).to have_content("Your release was successfully submitted. Thank you.")
|
||||
expect(page).to have_content submitted_release_notice
|
||||
end
|
||||
|
||||
scenario "creating a release with photos", js: true do
|
||||
@@ -251,14 +266,66 @@ feature "User managing location releases" do
|
||||
"location_release[person_email]"
|
||||
end
|
||||
|
||||
def person_company_field
|
||||
"location_release[person_company]"
|
||||
end
|
||||
|
||||
def person_title_field
|
||||
"location_release[person_title]"
|
||||
end
|
||||
|
||||
def address_street1_field
|
||||
"location_release[address_street1]"
|
||||
end
|
||||
|
||||
def address_city_field
|
||||
"location_release[address_city]"
|
||||
end
|
||||
|
||||
def address_state_field
|
||||
"location_release[address_state]"
|
||||
end
|
||||
|
||||
def address_zip_field
|
||||
"location_release[address_zip]"
|
||||
end
|
||||
|
||||
def address_country_field
|
||||
"location_release[address_country]"
|
||||
end
|
||||
|
||||
def person_address_street1_field
|
||||
"location_release[person_address_street1]"
|
||||
end
|
||||
|
||||
def person_address_city_field
|
||||
"location_release[person_address_city]"
|
||||
end
|
||||
|
||||
def person_address_state_field
|
||||
"location_release[person_address_state]"
|
||||
end
|
||||
|
||||
def person_address_zip_field
|
||||
"location_release[person_address_zip]"
|
||||
end
|
||||
|
||||
def person_address_country_field
|
||||
"location_release[person_address_country]"
|
||||
end
|
||||
|
||||
def person_phone_field
|
||||
"location_release[person_phone]"
|
||||
end
|
||||
|
||||
def fill_filming_started_on_field
|
||||
page.execute_script("$('#location_release_filming_started_on').val('01/03/20')")
|
||||
end
|
||||
|
||||
def fill_filming_ended_on_field
|
||||
page.execute_script("$('#location_release_filming_ended_on').val('03/03/20')")
|
||||
end
|
||||
|
||||
def filming_hours_field
|
||||
"location_release[filming_hours]"
|
||||
end
|
||||
@@ -291,6 +358,10 @@ feature "User managing location releases" do
|
||||
t("shared.submit_release_long")
|
||||
end
|
||||
|
||||
def submitted_release_notice
|
||||
"Your release was successfully submitted. Thank you."
|
||||
end
|
||||
|
||||
def create_release_notice
|
||||
t "location_releases.create.notice"
|
||||
end
|
||||
|
||||
@@ -13,7 +13,27 @@ RSpec.describe LocationRelease do
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
it { is_expected.to validate_presence_of(:name) }
|
||||
it { is_expected.to validate_presence_of(:name).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:address_street1).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:address_city).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:address_state).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:address_zip).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:address_country).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:person_first_name).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:person_last_name).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:person_phone).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:person_email).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:person_company).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:person_title).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:person_address_street1).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:person_address_city).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:person_address_state).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:person_address_zip).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:person_address_country).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:filming_ended_on).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:filming_started_on).on(:native) }
|
||||
it { is_expected.to validate_presence_of(:filming_hours).on(:native) }
|
||||
it { is_expected.to validate_attachment_of(:signature).on(:native) }
|
||||
it { is_expected.to allow_value("test@test.com", nil).for(:person_email) }
|
||||
it { is_expected.not_to allow_values("foo", "test@foo", "N/A").for(:person_email) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user