Add more specs, fix code
This commit is contained in:
parent
39dfdd031e
commit
335e880da1
3 changed files with 58 additions and 1 deletions
|
@ -2,7 +2,10 @@
|
||||||
|
|
||||||
class MembershipApplicationPolicy < ApplicationPolicy
|
class MembershipApplicationPolicy < ApplicationPolicy
|
||||||
def show?
|
def show?
|
||||||
record.account.in? [context.account, context.guest_account]
|
return false if context.guest_account.nil?
|
||||||
|
|
||||||
|
context.guest_account.is_superuser? ||
|
||||||
|
record.account == context.guest_account
|
||||||
end
|
end
|
||||||
|
|
||||||
def create?
|
def create?
|
||||||
|
|
|
@ -6,4 +6,10 @@ FactoryBot.define do
|
||||||
factory :account_with_user, parent: :empty_account do
|
factory :account_with_user, parent: :empty_account do
|
||||||
association :user
|
association :user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :superuser_account, parent: :account_with_user do
|
||||||
|
after :create do |account, _evaluator|
|
||||||
|
account.add_role :superuser
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
48
spec/requests/membership_applications/show_spec.rb
Normal file
48
spec/requests/membership_applications/show_spec.rb
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe 'GET /membership_applications/:id' do
|
||||||
|
let :membership_application do
|
||||||
|
create :membership_application, account: owner
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:owner) { create :account_with_user }
|
||||||
|
|
||||||
|
before do
|
||||||
|
sign_in current_account&.user if current_account&.user
|
||||||
|
get "/membership_applications/#{membership_application.id}"
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when owner is authenticated' do
|
||||||
|
let(:current_account) { owner }
|
||||||
|
|
||||||
|
specify do
|
||||||
|
expect(response).to have_http_status :ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when no account is authenticated' do
|
||||||
|
let(:current_account) { nil }
|
||||||
|
|
||||||
|
specify do
|
||||||
|
expect(response).to have_http_status :unauthorized
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when unauthorized account is authenticated' do
|
||||||
|
let(:current_account) { create :account_with_user }
|
||||||
|
|
||||||
|
specify do
|
||||||
|
expect(response).to have_http_status :unauthorized
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when superuser account is authenticated' do
|
||||||
|
let(:current_account) { create :superuser_account }
|
||||||
|
|
||||||
|
specify do
|
||||||
|
expect(response).to have_http_status :ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Reference in a new issue