Skip to content

Commit

Permalink
Add missing tests for policies
Browse files Browse the repository at this point in the history
  • Loading branch information
Taucher2003 committed Jan 1, 2024
1 parent b8fbb92 commit c469ac9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
19 changes: 19 additions & 0 deletions spec/policies/global_policy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe GlobalPolicy do
subject { described_class.new(current_user, nil) }

context 'when user is present' do
let(:current_user) { create(:user) }

it { is_expected.to be_allowed(:create_team) }
end

context 'when user is nil' do
let(:current_user) { nil }

it { is_expected.not_to be_allowed(:create_team) }
end
end
33 changes: 33 additions & 0 deletions spec/policies/team_policy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe TeamPolicy do
subject { described_class.new(current_user, team) }

let(:current_user) { nil }

context 'when user is member of the team' do
let(:current_user) { create(:user) }
let(:team) { create(:team).tap { |team| create(:team_member, team: team, user: current_user) } }

it { is_expected.to be_allowed(:read_team) }
it { is_expected.to be_allowed(:read_team_member) }
end

context 'when user is not member of the team' do
let(:current_user) { create(:user) }
let(:team) { create(:team) }

it { is_expected.not_to be_allowed(:read_team) }
it { is_expected.not_to be_allowed(:read_team_member) }
end

context 'when user is nil' do
let(:current_user) { nil }
let(:team) { create(:team) }

it { is_expected.not_to be_allowed(:read_team) }
it { is_expected.not_to be_allowed(:read_team_member) }
end
end
21 changes: 21 additions & 0 deletions spec/policies/user_policy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe UserPolicy do
subject { described_class.new(current_user, user) }

let(:user) { create(:user) }

context 'when user is present' do
let(:current_user) { create(:user) }

it { is_expected.to be_allowed(:read_user) }
end

context 'when user is nil' do
let(:current_user) { nil }

it { is_expected.not_to be_allowed(:read_user) }
end
end

0 comments on commit c469ac9

Please sign in to comment.