1
0
Fork 0

Allow to create passport without passport map

This commit is contained in:
Alex Kotov 2018-12-03 03:20:16 +05:00
parent c8f63f58d0
commit 7a2734a582
No known key found for this signature in database
GPG key ID: 4E831250F47DE154
3 changed files with 26 additions and 1 deletions

View file

@ -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

View file

@ -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+"

View file

@ -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