From 98ed8f1cc818562060a861842298f2610c828c9e Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 14 Dec 2018 11:17:02 +0500 Subject: [PATCH] Change MembershipAppsController#show --- app/controllers/membership_apps_controller.rb | 13 ++++++++++--- app/views/home/show.html.erb | 2 +- app/views/membership_app_mailer/tracking.html.erb | 2 -- config/routes.rb | 2 +- features/desktop/membership_app.feature | 2 +- features/step_definitions/membership_application.rb | 2 +- spec/requests/membership_apps/create_spec.rb | 2 -- spec/requests/membership_apps/show_spec.rb | 8 ++++---- 8 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/controllers/membership_apps_controller.rb b/app/controllers/membership_apps_controller.rb index 7ca0966..7378270 100644 --- a/app/controllers/membership_apps_controller.rb +++ b/app/controllers/membership_apps_controller.rb @@ -2,9 +2,10 @@ class MembershipAppsController < ApplicationController before_action :set_membership_app, only: :show + before_action :verify_joined, only: :show before_action :verify_not_joined, only: :new - # GET /membership_apps/:id + # GET /membership_app def show authorize @membership_app end @@ -31,7 +32,6 @@ class MembershipAppsController < ApplicationController remember_if_guest_account @membership_app.account redirect_to membership_app_url( - @membership_app, guest_token: @membership_app.account.guest_token, ) end @@ -39,7 +39,14 @@ class MembershipAppsController < ApplicationController private def set_membership_app - @membership_app = MembershipApp.find params[:id] + @membership_app = current_account&.own_membership_app + end + + def verify_joined + return if current_account&.own_membership_app + + skip_authorization + redirect_to join_url end def verify_not_joined diff --git a/app/views/home/show.html.erb b/app/views/home/show.html.erb index c1f9f2c..15ddef5 100644 --- a/app/views/home/show.html.erb +++ b/app/views/home/show.html.erb @@ -14,7 +14,7 @@ <% end %> <% unless current_account&.own_membership_app.nil? %> - + <%= translate '.tracking' %> <% end %> diff --git a/app/views/membership_app_mailer/tracking.html.erb b/app/views/membership_app_mailer/tracking.html.erb index cc8a1a7..720adaa 100644 --- a/app/views/membership_app_mailer/tracking.html.erb +++ b/app/views/membership_app_mailer/tracking.html.erb @@ -1,10 +1,8 @@

<%= translate '.lead_text' %>

<%= link_to membership_app_url( - @membership_app, guest_token: @membership_app.account.guest_token, ), membership_app_url( - @membership_app, guest_token: @membership_app.account.guest_token, ) %> diff --git a/config/routes.rb b/config/routes.rb index 87ecd7c..f0eecb7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,7 @@ Rails.application.routes.draw do get :join, to: 'membership_apps#new' post :join, to: 'membership_apps#create' - resources :membership_apps, only: :show + resource :membership_app, only: :show ############### # User routes # diff --git a/features/desktop/membership_app.feature b/features/desktop/membership_app.feature index b0ccf70..3c2da66 100644 --- a/features/desktop/membership_app.feature +++ b/features/desktop/membership_app.feature @@ -16,5 +16,5 @@ Feature: Membership application | Членство в других общественных организациях | Не скажу | | Комментарий | Примите, плиз | And I click the form button "Отправить заявление" - Then I am at "/membership_apps/\d+" + Then I am at "/membership_app" And I see text "Ваше заявление в обработке" diff --git a/features/step_definitions/membership_application.rb b/features/step_definitions/membership_application.rb index 8ba1889..e60f870 100644 --- a/features/step_definitions/membership_application.rb +++ b/features/step_definitions/membership_application.rb @@ -9,7 +9,7 @@ Then 'I see membership application creation form' do end Then 'I see the membership application tracking page' do - expect(page.current_path).to match %r{\A/membership_apps/\d+\z} + expect(page.current_path).to eq '/membership_app' expect(page).to have_css 'h2', text: 'Ваше заявление в обработке' end diff --git a/spec/requests/membership_apps/create_spec.rb b/spec/requests/membership_apps/create_spec.rb index 9801913..f8fcc12 100644 --- a/spec/requests/membership_apps/create_spec.rb +++ b/spec/requests/membership_apps/create_spec.rb @@ -97,7 +97,6 @@ RSpec.describe 'POST /join' do membership_app = MembershipApp.last expect(response).to redirect_to membership_app_url( - membership_app, guest_token: membership_app.account.guest_token, ) end @@ -142,7 +141,6 @@ RSpec.describe 'POST /join' do membership_app = MembershipApp.last expect(response).to redirect_to membership_app_url( - membership_app, guest_token: membership_app.account.guest_token, ) end diff --git a/spec/requests/membership_apps/show_spec.rb b/spec/requests/membership_apps/show_spec.rb index e22aa9f..3dbfbc1 100644 --- a/spec/requests/membership_apps/show_spec.rb +++ b/spec/requests/membership_apps/show_spec.rb @@ -2,8 +2,8 @@ require 'rails_helper' -RSpec.describe 'GET /membership_apps/:id' do - let :membership_app do +RSpec.describe 'GET /membership_app' do + let! :membership_app do create :membership_app, account: owner end @@ -11,7 +11,7 @@ RSpec.describe 'GET /membership_apps/:id' do before do sign_in current_account&.user if current_account&.user - get "/membership_apps/#{membership_app.id}" + get '/membership_app' end context 'when owner is authenticated' do @@ -24,7 +24,7 @@ RSpec.describe 'GET /membership_apps/:id' do for_account_types nil, :guest, :usual, :superuser do specify do - expect(response).to have_http_status :unauthorized + expect(response).to redirect_to join_url end end end