1
0
Fork 0

Do not allow MembershipAppsController#new if already joined

This commit is contained in:
Alex Kotov 2018-12-14 05:19:36 +05:00
parent a003466ce2
commit 9ad8b3f95f
No known key found for this signature in database
GPG Key ID: 4E831250F47DE154
2 changed files with 35 additions and 0 deletions

View File

@ -2,6 +2,7 @@
class MembershipAppsController < ApplicationController
before_action :set_membership_app, only: :show
before_action :verify_not_joined, only: :new
# GET /membership_apps/:id
def show
@ -40,4 +41,11 @@ private
def set_membership_app
@membership_app = MembershipApp.find params[:id]
end
def verify_not_joined
return if current_account&.own_membership_app.nil?
skip_authorization
redirect_to current_account.own_membership_app
end
end

View File

@ -3,8 +3,17 @@
require 'rails_helper'
RSpec.describe 'GET /join' do
let!(:membership_app) { create :membership_app, account: owner }
let(:owner) { create :guest_account }
before do
sign_in current_account.user if current_account&.user
if current_account&.guest?
get root_url guest_token: current_account.guest_token
end
get '/join'
end
@ -13,4 +22,22 @@ RSpec.describe 'GET /join' do
expect(response).to have_http_status :ok
end
end
context 'when guest owner is authenticated' do
let(:owner) { create :guest_account }
let(:current_account) { owner }
specify do
expect(response).to redirect_to membership_app
end
end
context 'when usual owner is authenticated' do
let(:owner) { create :usual_account }
let(:current_account) { owner }
specify do
expect(response).to redirect_to membership_app
end
end
end