Skip to content

Commit

Permalink
fixing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoPeraza committed Aug 10, 2023
1 parent ffd72b0 commit 84d63ad
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 188 deletions.
16 changes: 12 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ require:
AllCops:
NewCops: enable
Exclude:
- db/schema.rb
- config/initializers/pagy.rb
- bin/bundle
- bin/yarn
- config/initializers/pagy.rb
- db/schema.rb
- node_modules/**/*

Layout/ClassStructure:
Expand All @@ -33,8 +33,7 @@ Layout/SpaceBeforeFirstArg:
- app/views/api/**/**/*

Lint/AmbiguousBlockAssociation:
Exclude:
- spec/**/*
AllowedMethods: change

Lint/BinaryOperatorWithIdenticalOperands:
Enabled: false
Expand Down Expand Up @@ -80,6 +79,15 @@ Rails/FilePath:
Rails/SaveBang:
Enabled: true

RSpec/ExampleLength:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false

RSpec/NamedSubject:
Enabled: false

Style/ArrayCoercion:
Enabled: true

Expand Down
17 changes: 0 additions & 17 deletions config/initializers/new_framework_defaults.rb

This file was deleted.

49 changes: 0 additions & 49 deletions config/initializers/new_framework_defaults_6_0.rb

This file was deleted.

4 changes: 2 additions & 2 deletions spec/policies/admin/admin_user_policy_spec.rb
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
10 changes: 5 additions & 5 deletions spec/policies/admin/application_policy_spec.rb
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
6 changes: 3 additions & 3 deletions spec/policies/admin/page_policy_spec.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# frozen_string_literal: true

describe Admin::PagePolicy do
subject(:policy) { described_class }
subject { described_class }

permissions :show? do
let(:user) { create(:user) }
let(:record) { instance_double('DashboardRecord', name: 'Dashboard') }

it 'allow access if record.name is Dashboard' do
expect(policy).to permit(user, record)
expect(subject).to permit(user, record)
end

context 'when the record name is distinct to Dashboard' do
let(:record) { instance_double('NoneDashboardRecord', name: 'not-valid') }

it 'denies access' do
expect(policy).not_to permit(user, record)
expect(subject).not_to permit(user, record)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/policies/admin/user_policy_spec.rb
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
4 changes: 2 additions & 2 deletions spec/policies/admin_user_policy_spec.rb
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
8 changes: 4 additions & 4 deletions spec/policies/application_policy_spec.rb
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
6 changes: 3 additions & 3 deletions spec/policies/user_policy_spec.rb
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
8 changes: 4 additions & 4 deletions spec/requests/api/v1/feature_flags_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

describe 'GET admin/feature-flags' do
subject(:endpoint) { get '/admin/feature-flags' }
subject { get '/admin/feature-flags' }

context 'with an admin_user account' do
let(:user) { create(:admin_user) }
Expand All @@ -10,13 +10,13 @@
before { sign_in user }

it 'shows the feature flags page' do
expect(endpoint).to redirect_to('/admin/feature-flags/features')
expect(subject).to redirect_to('/admin/feature-flags/features')
end
end

context 'without a valid session' do
it 'redirects the user to the admin login page' do
expect(endpoint).to redirect_to('/admin/login')
expect(subject).to redirect_to('/admin/login')
end
end
end
Expand All @@ -28,7 +28,7 @@
before { sign_in user }

it 'blocks user access to the feature flags page' do
expect(endpoint).not_to redirect_to('/admin/feature-flags/features')
expect(subject).not_to redirect_to('/admin/feature-flags/features')
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/requests/api/v1/passwords/create_spec.rb
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') }

Expand All @@ -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
7 changes: 3 additions & 4 deletions spec/requests/api/v1/passwords/edit_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

describe 'GET api/v1/users/passwords/edit' do
subject(:endpoint) { get edit_user_password_path, params: }
subject { get edit_user_password_path, params: }

let(:user) { create(:user, password: 'mypass123') }
let(:password_token) { user.send(:set_reset_password_token) }
Expand All @@ -12,18 +12,17 @@
}
end

before { subject }

it 'returns a the access token, uid and client id' do
endpoint
expect(response.header['Location']).to include('token')
end

it 'returns the uid' do
endpoint
expect(response.header['Location']).to include('uid')
end

it 'returns the client id' do
endpoint
expect(response.header['Location']).to include('client_id')
end
end
Loading

0 comments on commit 84d63ad

Please sign in to comment.