-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ffd72b0
commit 84d63ad
Showing
18 changed files
with
77 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Admin::AdminUserPolicy do | ||
subject(:policy) { described_class } | ||
subject { described_class } | ||
|
||
permissions :update?, :index?, :show?, :create?, :new?, :edit?, :destroy? do | ||
let(:admin) { create(:admin_user) } | ||
|
||
it 'allows access' do | ||
expect(policy).to permit(admin, admin) | ||
expect(subject).to permit(admin, admin) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Admin::ApplicationPolicy do | ||
subject(:policy) { described_class } | ||
subject { described_class } | ||
|
||
permissions :update?, :index?, :show?, :create?, :new?, :edit?, :destroy? do | ||
context 'when is an admin user' do | ||
let(:admin) { build(:admin_user) } | ||
|
||
it 'allows access' do | ||
expect(policy).to permit(admin, admin) | ||
expect(subject).to permit(admin, admin) | ||
end | ||
end | ||
|
||
context 'when is a user' do | ||
let(:user) { build(:user) } | ||
|
||
it 'denies access' do | ||
expect(policy).not_to permit(user, user) | ||
expect(subject).not_to permit(user, user) | ||
end | ||
end | ||
end | ||
|
||
describe 'scope' do | ||
subject(:scope) { ApplicationPolicy::Scope.new(admin, mock_model).resolve } | ||
subject { ApplicationPolicy::Scope.new(admin, mock_model).resolve } | ||
|
||
let(:admin) { create(:admin_user) } | ||
let(:mock_model) { instance_double('MockModel', all: true) } | ||
|
||
it 'shows all models' do | ||
expect(scope).to be(true) | ||
expect(subject).to be(true) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Admin::UserPolicy do | ||
subject(:policy) { described_class } | ||
subject { described_class } | ||
|
||
permissions :update?, :index?, :show?, :create?, :new?, :edit?, :destroy? do | ||
let(:admin) { create(:admin_user) } | ||
let(:user) { create(:user) } | ||
|
||
it 'allow access' do | ||
expect(policy).to permit(admin, user) | ||
expect(subject).to permit(admin, user) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
describe AdminUserPolicy do | ||
subject(:policy) { described_class } | ||
subject { described_class } | ||
|
||
permissions :update?, :index?, :show?, :create?, :new?, :edit?, :destroy? do | ||
let(:admin) { create(:admin_user) } | ||
let(:user) { create(:user) } | ||
|
||
it 'denies access' do | ||
expect(policy).not_to permit(user, admin) | ||
expect(subject).not_to permit(user, admin) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
describe ApplicationPolicy do | ||
subject(:policy) { described_class } | ||
subject { described_class } | ||
|
||
permissions :update?, :index?, :show?, :create?, :new?, :edit?, :destroy? do | ||
context 'when is an user' do | ||
let(:user) { build(:user) } | ||
|
||
it 'denies access' do | ||
expect(policy).not_to permit(user, user) | ||
expect(subject).not_to permit(user, user) | ||
end | ||
end | ||
end | ||
|
||
describe 'scope' do | ||
subject(:scope) { ApplicationPolicy::Scope.new(user, mock_model).resolve } | ||
subject { ApplicationPolicy::Scope.new(user, mock_model).resolve } | ||
|
||
let(:user) { create(:user) } | ||
let(:mock_model) { instance_double('MockModel', all: true) } | ||
|
||
it 'shows all models' do | ||
expect(scope).to be(true) | ||
expect(subject).to be(true) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
describe UserPolicy do | ||
subject(:policy) { described_class } | ||
subject { described_class } | ||
|
||
permissions :update? do | ||
let(:user1) { create(:user) } | ||
let(:user2) { create(:user) } | ||
|
||
it 'denies access if user is not the same' do | ||
expect(policy).not_to permit(user1, user2) | ||
expect(subject).not_to permit(user1, user2) | ||
end | ||
|
||
it 'allow access if user is the same' do | ||
expect(policy).to permit(user1, user1) | ||
expect(subject).to permit(user1, user1) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
describe 'POST api/v1/users/password' do | ||
subject(:endpoint) { post user_password_path, params:, as: :json } | ||
subject { post user_password_path, params:, as: :json } | ||
|
||
let!(:user) { create(:user, password: 'mypass123') } | ||
|
||
|
@@ -12,30 +12,30 @@ | |
it_behaves_like 'there must not be a Set-Cookie in Header' | ||
|
||
it 'returns a successful response' do | ||
endpoint | ||
subject | ||
expect(response).to have_http_status(:success) | ||
end | ||
|
||
it 'returns the user email' do | ||
endpoint | ||
subject | ||
expect(json[:message]).to match(/#{user.email}/) | ||
end | ||
|
||
it 'sends an email' do | ||
expect { endpoint }.to change { ActionMailer::Base.deliveries.count }.by(1) | ||
expect { subject }.to change { ActionMailer::Base.deliveries.count }.by(1) | ||
end | ||
end | ||
|
||
context 'with invalid params' do | ||
let(:params) { { email: '[email protected]' } } | ||
|
||
it 'does not return a successful response' do | ||
endpoint | ||
subject | ||
expect(response).to have_http_status(:not_found) | ||
end | ||
|
||
it 'does not send an email' do | ||
expect { endpoint }.not_to change { ActionMailer::Base.deliveries.count } | ||
expect { subject }.not_to change { ActionMailer::Base.deliveries.count } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.