Add action PassportsController#update
This commit is contained in:
parent
ed4676d486
commit
139770b4ce
8 changed files with 45 additions and 4 deletions
|
@ -31,6 +31,15 @@ class PassportsController < ApplicationController
|
|||
redirect_to @passport
|
||||
end
|
||||
|
||||
# PATCH/PUT /passports/:id
|
||||
def update
|
||||
authorize @passport
|
||||
|
||||
return render :show unless @passport.update permitted_attributes @passport
|
||||
|
||||
redirect_to @passport
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_passport
|
||||
|
|
|
@ -9,6 +9,10 @@ class PassportPolicy < ApplicationPolicy
|
|||
true
|
||||
end
|
||||
|
||||
def update?
|
||||
true
|
||||
end
|
||||
|
||||
def permitted_attributes_for_create
|
||||
%i[
|
||||
surname given_name patronymic sex date_of_birth place_of_birth series
|
||||
|
|
|
@ -11,6 +11,11 @@
|
|||
<div class="col-md-6">
|
||||
<% if @passport.image.attached? %>
|
||||
<%= image_tag url_for(@passport.image), class: 'img-fluid' %>
|
||||
<% elsif policy(@passport).update? %>
|
||||
<%= simple_form_for @passport do |f| %>
|
||||
<%= f.input :image %>
|
||||
<%= f.button :submit %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -25,6 +25,7 @@ en:
|
|||
comment: Comment
|
||||
passport:
|
||||
id: ID
|
||||
image: Image
|
||||
surname: Surname
|
||||
given_name: Given names
|
||||
patronymic: Patronymic
|
||||
|
|
|
@ -25,6 +25,7 @@ ru:
|
|||
comment: Комментарий
|
||||
passport:
|
||||
id: ID
|
||||
image: Изображение
|
||||
surname: Фамилия
|
||||
given_name: Имя
|
||||
patronymic: Отчество
|
||||
|
|
|
@ -28,7 +28,7 @@ Rails.application.routes.draw do
|
|||
|
||||
resources :membership_applications, only: %i[new create]
|
||||
|
||||
resources :passports, only: %i[index show new create]
|
||||
resources :passports, only: %i[index show new create update]
|
||||
|
||||
resources :telegram_bot_updates, only: :create
|
||||
end
|
||||
|
|
|
@ -6,9 +6,7 @@ FactoryBot.define do
|
|||
image_filename { image_fixture }
|
||||
image_fixture { "passport_image_#{rand(1..4)}.jpg" }
|
||||
|
||||
image_path do
|
||||
File.join File.expand_path('..', __dir__), 'fixtures', image_fixture
|
||||
end
|
||||
image_path { Rails.root.join 'fixtures', image_fixture }
|
||||
end
|
||||
|
||||
surname { Faker::Name.last_name }
|
||||
|
|
23
spec/requests/passports/update_spec.rb
Normal file
23
spec/requests/passports/update_spec.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'PATCH/PUT /passports/:id' do
|
||||
let!(:passport) { create :passport }
|
||||
|
||||
let :passport_attributes do
|
||||
{ image: Rack::Test::UploadedFile.new(File.open(passport_image_path)) }
|
||||
end
|
||||
|
||||
let :passport_image_path do
|
||||
Rails.root.join 'fixtures', 'passport_image_1.jpg'
|
||||
end
|
||||
|
||||
before do
|
||||
patch "/passports/#{passport.id}", params: { passport: passport_attributes }
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(response).to redirect_to passport_url passport
|
||||
end
|
||||
end
|
Reference in a new issue