Allow to create passport without passport map
This commit is contained in:
parent
c8f63f58d0
commit
7a2734a582
3 changed files with 26 additions and 1 deletions
|
@ -9,7 +9,7 @@ class Passport < ApplicationRecord
|
|||
|
||||
has_many :passport_confirmations, dependent: :restrict_with_exception
|
||||
|
||||
accepts_nested_attributes_for :passport_maps
|
||||
accepts_nested_attributes_for :passport_maps, reject_if: :blank_passport_map?
|
||||
|
||||
validates :confirmed,
|
||||
inclusion: { in: [false], unless: :enough_confirmations? }
|
||||
|
@ -29,4 +29,14 @@ class Passport < ApplicationRecord
|
|||
def enough_confirmations?
|
||||
passport_confirmations.count >= REQUIRED_CONFIRMATIONS
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def blank_passport_map?(passport_map_attributes)
|
||||
passport_map_attributes.all? do |key, value|
|
||||
next true if key.start_with? 'date_'
|
||||
|
||||
value.blank?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,3 +33,8 @@ Feature: Passport creation
|
|||
When I fill the passport creation form
|
||||
When I click the passport creation button
|
||||
Then I see the passport page
|
||||
|
||||
Scenario: only image is uploaded, no fields are filled
|
||||
When I upload "passport_image_1.jpg" as "Изображения"
|
||||
And I click the passport creation button
|
||||
Then I am at "/passports/\d+"
|
||||
|
|
|
@ -4,6 +4,10 @@ When 'I visit {string}' do |string|
|
|||
visit string
|
||||
end
|
||||
|
||||
Then 'I am at {string}' do |re|
|
||||
expect(page.current_path).to match(/\A#{re}\z/)
|
||||
end
|
||||
|
||||
When 'I fill form with the following data:' do |table|
|
||||
within 'form' do
|
||||
table.rows.each do |(key, value)|
|
||||
|
@ -12,6 +16,12 @@ When 'I fill form with the following data:' do |table|
|
|||
end
|
||||
end
|
||||
|
||||
When 'I upload {string} as {string}' do |fixture, field|
|
||||
within 'form' do
|
||||
attach_file field, Rails.root.join('fixtures', fixture)
|
||||
end
|
||||
end
|
||||
|
||||
When 'I click the button {string}' do |string|
|
||||
click_on string
|
||||
end
|
||||
|
|
Reference in a new issue