diff --git a/app/controllers/passport_confirmations_controller.rb b/app/controllers/passport_confirmations_controller.rb index a1467da..1417dee 100644 --- a/app/controllers/passport_confirmations_controller.rb +++ b/app/controllers/passport_confirmations_controller.rb @@ -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 diff --git a/app/policies/passport_confirmation_policy.rb b/app/policies/passport_confirmation_policy.rb index cd4331b..0d1822f 100644 --- a/app/policies/passport_confirmation_policy.rb +++ b/app/policies/passport_confirmation_policy.rb @@ -7,4 +7,10 @@ class PassportConfirmationPolicy < ApplicationPolicy policy(record.passport).show? end + + class Scope < Scope + def resolve + scope.all + end + end end diff --git a/app/views/passport_confirmations/index.html.erb b/app/views/passport_confirmations/index.html.erb new file mode 100644 index 0000000..14b1af5 --- /dev/null +++ b/app/views/passport_confirmations/index.html.erb @@ -0,0 +1,23 @@ +
+ + + + + + + + + + <% @passport_confirmations.each do |passport_confirmation| %> + + + + + <% end %> + +
+ <%= PassportConfirmation.human_attribute_name :id %> + + <%= PassportConfirmation.human_attribute_name :account %> +
<%= passport_confirmation.id %><%= truncate passport_confirmation.account.user&.email %>
+
diff --git a/config/locales/activerecord/en.yml b/config/locales/activerecord/en.yml index e33c909..a3aa9bf 100644 --- a/config/locales/activerecord/en.yml +++ b/config/locales/activerecord/en.yml @@ -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 diff --git a/config/locales/activerecord/ru.yml b/config/locales/activerecord/ru.yml index 0e91fb9..c9e228b 100644 --- a/config/locales/activerecord/ru.yml +++ b/config/locales/activerecord/ru.yml @@ -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: Фамилия diff --git a/config/routes.rb b/config/routes.rb index 5ec98d1..306b232 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/requests/passports/passport_confirmations/index_spec.rb b/spec/requests/passports/passport_confirmations/index_spec.rb new file mode 100644 index 0000000..839ac2a --- /dev/null +++ b/spec/requests/passports/passport_confirmations/index_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 795e596..68b34e7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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