Assign MembershipApplication#country_state
This commit is contained in:
parent
608cbf1456
commit
41bf7c343b
3 changed files with 49 additions and 4 deletions
|
@ -9,6 +9,7 @@ class MembershipApplicationPolicy < ApplicationPolicy
|
|||
%i[
|
||||
first_name last_name middle_name date_of_birth occupation email
|
||||
phone_number telegram_username organization_membership comment
|
||||
country_state_id
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<%= f.input :first_name %>
|
||||
<%= f.input :last_name %>
|
||||
<%= f.input :middle_name %>
|
||||
<%= f.association :country_state, collection: CountryState.all %>
|
||||
<%= f.input :date_of_birth, start_year: Date.today.year - 150,
|
||||
end_year: Date.today.year %>
|
||||
<%= f.input :occupation %>
|
||||
|
|
|
@ -3,13 +3,22 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'POST /membership_applications' do
|
||||
let :membership_application_attributes do
|
||||
let :membership_application_plain_attributes do
|
||||
attributes_for :membership_application
|
||||
end
|
||||
|
||||
let :membership_application_all_attributes do
|
||||
membership_application_plain_attributes.merge(
|
||||
country_state_id: country_state&.id,
|
||||
)
|
||||
end
|
||||
|
||||
let(:country_state) { create :country_state }
|
||||
|
||||
def make_request
|
||||
post '/membership_applications',
|
||||
params: { membership_application: membership_application_attributes }
|
||||
post '/membership_applications', params: {
|
||||
membership_application: membership_application_all_attributes,
|
||||
}
|
||||
end
|
||||
|
||||
specify do
|
||||
|
@ -26,7 +35,41 @@ RSpec.describe 'POST /membership_applications' do
|
|||
|
||||
specify do
|
||||
expect(MembershipApplication.last).to \
|
||||
have_attributes membership_application_attributes
|
||||
have_attributes membership_application_plain_attributes
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(MembershipApplication.last).to have_attributes(
|
||||
country_state: country_state,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when country state is not specified' do
|
||||
let(:country_state) { nil }
|
||||
|
||||
specify do
|
||||
expect { make_request }.to \
|
||||
change(MembershipApplication, :count).from(0).to(1)
|
||||
end
|
||||
|
||||
context 'after request' do
|
||||
before { make_request }
|
||||
|
||||
specify do
|
||||
expect(response).to redirect_to root_url
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(MembershipApplication.last).to \
|
||||
have_attributes membership_application_plain_attributes
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(MembershipApplication.last).to have_attributes(
|
||||
country_state: nil,
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue