1
0
Fork 0

Remove passport images feature

This commit is contained in:
Alex Kotov 2019-07-18 23:35:12 +05:00
parent 10e638f970
commit 0d39c24a86
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
15 changed files with 4 additions and 65 deletions

View File

@ -7,20 +7,12 @@ class Passport < ApplicationRecord
belongs_to :person, optional: true
has_many_attached :images
has_many :passport_maps,
dependent: :restrict_with_exception
accepts_nested_attributes_for :passport_maps,
reject_if: :blank_passport_map?
###############
# Validations #
###############
validates :images, passport_image: true
###########
# Methods #
###########
@ -29,10 +21,6 @@ class Passport < ApplicationRecord
passport_maps.order(created_at: :asc).last
end
def image
images.order(created_at: :asc).last
end
private
def blank_passport_map?(passport_map_attributes)

View File

@ -1,11 +0,0 @@
# frozen_string_literal: true
class PassportImageValidator < ImageValidator
class Validation < Validation
MAX_SIZE = 20.megabytes
def max_size
MAX_SIZE
end
end
end

View File

@ -41,7 +41,6 @@ en:
native_name: Name
passport:
id: ID
images: Images
passport_map:
id: ID
first_name: First name

View File

@ -41,7 +41,6 @@ ru:
native_name: Название
passport:
id: ID
images: Изображения
passport_map:
id: ID
first_name: Имя

View File

@ -9,33 +9,9 @@ FactoryBot.define do
create :passport_map, passport: passport
end
end
trait :with_image 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.images.attach(
filename: evaluator.image_filename,
io: File.open(evaluator.image_path),
)
end
end
end
factory :passport_with_map,
parent: :empty_passport,
traits: %i[with_map]
factory :passport_with_image,
parent: :empty_passport,
traits: %i[with_image]
factory :passport_with_map_and_image,
parent: :empty_passport,
traits: %i[with_map with_image]
end

View File

@ -18,7 +18,7 @@ Feature: Staff person comments
When I fill form with the following data:
| key | value |
| Текст | foobar |
And I upload "passport_image_1.jpg" as "Приложение"
And I upload "avatar.jpg" as "Приложение"
And I click the form button "Отправить"
Then I see text "foobar"
And I see text "passport_image_1.jpg"
And I see text "avatar.jpg"

View File

@ -72,8 +72,6 @@ When 'I fill the passport creation form' do
fill_in 'Номер', with: @passport_attributes['Номер']
fill_in 'Кем выдан', with: @passport_attributes['Кем выдан']
fill_in 'Код подразделения', with: @passport_attributes['Код подразделения']
attach_file 'Изображения', Rails.root.join('fixtures', 'passport_image_1.jpg')
end
Then 'I see the passport page' do

BIN
fixtures/avatar.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 446 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

View File

@ -14,5 +14,4 @@ RSpec.describe Passport do
end
pending '#passport_map'
pending '#image'
end

View File

@ -8,10 +8,8 @@ RSpec.describe 'GET /staff/people/:person_id/passports' do
before do
sign_in current_account.user if current_account&.user
create :empty_passport, person: person
create :passport_with_map, person: person
create :passport_with_image, person: person
create :passport_with_map_and_image, person: person
create :empty_passport, person: person
create :passport_with_map, person: person
get "/staff/people/#{person.to_param}/passports"
end

View File

@ -1,7 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe PassportImageValidator do
pending "add some examples to (or delete) #{__FILE__}"
end