Add action PassportConfirmations#index
This commit is contained in:
parent
4284a2fe6d
commit
6e1edee2d2
8 changed files with 133 additions and 4 deletions
|
@ -1,9 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class PassportConfirmationsController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :authenticate_user!, only: :create
|
||||
|
||||
before_action :set_passport, only: :create
|
||||
before_action :set_passport, only: %i[index create]
|
||||
|
||||
# GET /passports/:passport_id/passport_confirmations
|
||||
def index
|
||||
@passport_confirmations = policy_scope(@passport.passport_confirmations)
|
||||
end
|
||||
|
||||
# POST /passports/:passport_id/passport_confirmations
|
||||
def create
|
||||
|
|
|
@ -7,4 +7,10 @@ class PassportConfirmationPolicy < ApplicationPolicy
|
|||
|
||||
policy(record.passport).show?
|
||||
end
|
||||
|
||||
class Scope < Scope
|
||||
def resolve
|
||||
scope.all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
23
app/views/passport_confirmations/index.html.erb
Normal file
23
app/views/passport_confirmations/index.html.erb
Normal file
|
@ -0,0 +1,23 @@
|
|||
<div class="container">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
<%= PassportConfirmation.human_attribute_name :id %>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<%= PassportConfirmation.human_attribute_name :account %>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @passport_confirmations.each do |passport_confirmation| %>
|
||||
<tr>
|
||||
<td scope="row"><%= passport_confirmation.id %></td>
|
||||
<td><%= truncate passport_confirmation.account.user&.email %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
|
@ -7,6 +7,9 @@ en:
|
|||
passport:
|
||||
one: Passport
|
||||
other: Passports
|
||||
passport_confirmation:
|
||||
one: Passport confirmation
|
||||
other: Passport confirmations
|
||||
passport_map:
|
||||
one: Passport mapping
|
||||
other: Passport mappings
|
||||
|
@ -38,6 +41,10 @@ en:
|
|||
passport/confirmed:
|
||||
'true': Confirmed
|
||||
'false': Unconfirmed
|
||||
passport_confirmation:
|
||||
id: ID
|
||||
passport: Passport
|
||||
account: Account
|
||||
passport_map:
|
||||
id: ID
|
||||
surname: Surname
|
||||
|
|
|
@ -7,6 +7,9 @@ ru:
|
|||
passport:
|
||||
one: Паспорт
|
||||
other: Паспорта
|
||||
passport_confirmation:
|
||||
one: Подтверждение паспорта
|
||||
other: Подтверждения паспортов
|
||||
passport_map:
|
||||
one: Отображение паспорта
|
||||
other: Отображения паспортов
|
||||
|
@ -38,6 +41,10 @@ ru:
|
|||
passport/confirmed:
|
||||
'true': Подтверждён
|
||||
'false': Не подтверждён
|
||||
passport_confirmation:
|
||||
id: ID
|
||||
passport: Паспорт
|
||||
account: Аккаунт
|
||||
passport_map:
|
||||
id: ID
|
||||
surname: Фамилия
|
||||
|
|
|
@ -29,7 +29,7 @@ Rails.application.routes.draw do
|
|||
resources :membership_applications, only: %i[new create]
|
||||
|
||||
resources :passports, only: %i[index show new create] do
|
||||
resources :passport_confirmations, shallow: true, only: :create
|
||||
resources :passport_confirmations, shallow: true, only: %i[index create]
|
||||
end
|
||||
|
||||
resources :telegram_bot_updates, only: :create
|
||||
|
|
81
spec/requests/passports/passport_confirmations/index_spec.rb
Normal file
81
spec/requests/passports/passport_confirmations/index_spec.rb
Normal file
|
@ -0,0 +1,81 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /passports/:passport_id/passport_confirmations' do
|
||||
let!(:passport) { create :passport_with_passport_map_and_image }
|
||||
let(:current_user) { create :user }
|
||||
|
||||
def make_request
|
||||
get "/passports/#{passport.id}/passport_confirmations"
|
||||
end
|
||||
|
||||
before do
|
||||
sign_in current_user if current_user
|
||||
make_request
|
||||
end
|
||||
|
||||
context 'when no user is authenticated' do
|
||||
let(:current_user) { nil }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
context 'when passport is empty' do
|
||||
let!(:passport) { create :empty_passport }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
context 'when passport has passport map' do
|
||||
let!(:passport) { create :passport_with_passport_map }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
context 'when passport has image' do
|
||||
let!(:passport) { create :passport_with_image }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
context 'when passport has passport map and image' do
|
||||
let!(:passport) { create :passport_with_passport_map_and_image }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
context 'when passport has almost enough confirmations' do
|
||||
let!(:passport) { create :passport_with_almost_enough_confirmations }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
context 'when passport has enough confirmations' do
|
||||
let!(:passport) { create :passport_with_enough_confirmations }
|
||||
|
||||
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
|
|
@ -76,7 +76,7 @@ RSpec.configure do |config|
|
|||
# Print the 10 slowest examples and example groups at the
|
||||
# end of the spec run, to help surface which specs are running
|
||||
# particularly slow.
|
||||
config.profile_examples = 10
|
||||
# config.profile_examples = 10
|
||||
|
||||
# Run specs in random order to surface order dependencies. If you find an
|
||||
# order dependency and want to debug it, you can fix the order by providing
|
||||
|
|
Reference in a new issue