Do not require Passport#image
This commit is contained in:
parent
2813a922a3
commit
a8b927960c
4 changed files with 31 additions and 15 deletions
|
@ -20,10 +20,6 @@ class Passport < ApplicationRecord
|
|||
validates :unit_code, presence: true
|
||||
validates :date_of_issue, presence: true
|
||||
|
||||
validate do
|
||||
errors.add :image, :blank unless image.attached?
|
||||
end
|
||||
|
||||
before_validation do
|
||||
self.patronymic = nil if patronymic.blank?
|
||||
end
|
||||
|
|
|
@ -137,8 +137,10 @@
|
|||
</dl>
|
||||
</div>
|
||||
|
||||
<div class="col-md-8 col-lg-6">
|
||||
<%= image_tag url_for(@passport.image), class: 'img-fluid' %>
|
||||
</div>
|
||||
<% if @passport.image.attached? %>
|
||||
<div class="col-md-8 col-lg-6">
|
||||
<%= image_tag url_for(@passport.image), class: 'img-fluid' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -2,13 +2,6 @@
|
|||
|
||||
FactoryBot.define do
|
||||
factory :passport do
|
||||
transient do
|
||||
image_filename { image_fixture }
|
||||
image_fixture { "passport_image_#{rand(1..4)}.jpg" }
|
||||
|
||||
image_path { Rails.root.join 'fixtures', image_fixture }
|
||||
end
|
||||
|
||||
confirmed { false }
|
||||
|
||||
surname { Faker::Name.last_name }
|
||||
|
@ -24,6 +17,15 @@ FactoryBot.define do
|
|||
"#{rand(0..999).to_s.rjust(3, '0')}-#{rand(0..999).to_s.rjust(3, '0')}"
|
||||
end
|
||||
date_of_issue { Faker::Date.backward }
|
||||
end
|
||||
|
||||
factory :passport_with_image, parent: :passport do
|
||||
transient do
|
||||
image_filename { image_fixture }
|
||||
image_fixture { "passport_image_#{rand(1..4)}.jpg" }
|
||||
|
||||
image_path { Rails.root.join 'fixtures', image_fixture }
|
||||
end
|
||||
|
||||
after :build do |passport, evaluator|
|
||||
passport.image.attach(
|
||||
|
@ -33,7 +35,7 @@ FactoryBot.define do
|
|||
end
|
||||
end
|
||||
|
||||
factory :confirmed_passport, parent: :passport do
|
||||
factory :confirmed_passport, parent: :passport_with_image do
|
||||
confirmed { true }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,4 +12,20 @@ RSpec.describe 'GET /passports/:id' do
|
|||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
|
||||
context 'when passport has an image' do
|
||||
let!(:passport) { create :passport_with_image }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
context 'when passport is confirmed' do
|
||||
let!(:passport) { create :confirmed_passport }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue