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 :unit_code, presence: true
|
||||||
validates :date_of_issue, presence: true
|
validates :date_of_issue, presence: true
|
||||||
|
|
||||||
validate do
|
|
||||||
errors.add :image, :blank unless image.attached?
|
|
||||||
end
|
|
||||||
|
|
||||||
before_validation do
|
before_validation do
|
||||||
self.patronymic = nil if patronymic.blank?
|
self.patronymic = nil if patronymic.blank?
|
||||||
end
|
end
|
||||||
|
|
|
@ -137,8 +137,10 @@
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-8 col-lg-6">
|
<% if @passport.image.attached? %>
|
||||||
<%= image_tag url_for(@passport.image), class: 'img-fluid' %>
|
<div class="col-md-8 col-lg-6">
|
||||||
</div>
|
<%= image_tag url_for(@passport.image), class: 'img-fluid' %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,13 +2,6 @@
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :passport 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 }
|
confirmed { false }
|
||||||
|
|
||||||
surname { Faker::Name.last_name }
|
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')}"
|
"#{rand(0..999).to_s.rjust(3, '0')}-#{rand(0..999).to_s.rjust(3, '0')}"
|
||||||
end
|
end
|
||||||
date_of_issue { Faker::Date.backward }
|
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|
|
after :build do |passport, evaluator|
|
||||||
passport.image.attach(
|
passport.image.attach(
|
||||||
|
@ -33,7 +35,7 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :confirmed_passport, parent: :passport do
|
factory :confirmed_passport, parent: :passport_with_image do
|
||||||
confirmed { true }
|
confirmed { true }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,4 +12,20 @@ RSpec.describe 'GET /passports/:id' do
|
||||||
specify do
|
specify do
|
||||||
expect(response).to have_http_status :ok
|
expect(response).to have_http_status :ok
|
||||||
end
|
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
|
end
|
||||||
|
|
Reference in a new issue