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 belongs_to :person, optional: true
has_many_attached :images
has_many :passport_maps, has_many :passport_maps,
dependent: :restrict_with_exception dependent: :restrict_with_exception
accepts_nested_attributes_for :passport_maps, accepts_nested_attributes_for :passport_maps,
reject_if: :blank_passport_map? reject_if: :blank_passport_map?
###############
# Validations #
###############
validates :images, passport_image: true
########### ###########
# Methods # # Methods #
########### ###########
@ -29,10 +21,6 @@ class Passport < ApplicationRecord
passport_maps.order(created_at: :asc).last passport_maps.order(created_at: :asc).last
end end
def image
images.order(created_at: :asc).last
end
private private
def blank_passport_map?(passport_map_attributes) 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 native_name: Name
passport: passport:
id: ID id: ID
images: Images
passport_map: passport_map:
id: ID id: ID
first_name: First name first_name: First name

View file

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

View file

@ -9,33 +9,9 @@ FactoryBot.define do
create :passport_map, passport: passport create :passport_map, passport: passport
end end
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 end
factory :passport_with_map, factory :passport_with_map,
parent: :empty_passport, parent: :empty_passport,
traits: %i[with_map] 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 end

View file

@ -18,7 +18,7 @@ Feature: Staff person comments
When I fill form with the following data: When I fill form with the following data:
| key | value | | key | value |
| Текст | foobar | | Текст | foobar |
And I upload "passport_image_1.jpg" as "Приложение" And I upload "avatar.jpg" as "Приложение"
And I click the form button "Отправить" And I click the form button "Отправить"
Then I see text "foobar" 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['Кем выдан'] 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 end
Then 'I see the passport page' do 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 end
pending '#passport_map' pending '#passport_map'
pending '#image'
end end

View file

@ -10,8 +10,6 @@ RSpec.describe 'GET /staff/people/:person_id/passports' do
create :empty_passport, person: person create :empty_passport, person: person
create :passport_with_map, person: person create :passport_with_map, person: person
create :passport_with_image, person: person
create :passport_with_map_and_image, person: person
get "/staff/people/#{person.to_param}/passports" get "/staff/people/#{person.to_param}/passports"
end 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