Skip to content

Commit

Permalink
style: rubocopの指摘箇所を修正 (#66)
Browse files Browse the repository at this point in the history
RSpec/ExampleLengthとRSpec/MultipleExpectationsを無効にした
  • Loading branch information
djkazunoko committed Apr 11, 2024
1 parent 6d9384a commit 574a34d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
6 changes: 2 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ inherit_gem:
- "config/rails.yml"

RSpec/ExampleLength:
Exclude:
- spec/system/*
Enabled: false

RSpec/MultipleExpectations:
Exclude:
- spec/system/*
Enabled: false
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class User < ApplicationRecord
validates :provider, presence: true
validates :uid, presence: true, uniqueness: { scope: :provider }
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

FactoryBot.define do
factory :user do
provider { 'github' }
Expand Down
16 changes: 9 additions & 7 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe User, type: :model do
Expand Down Expand Up @@ -75,12 +77,12 @@
context 'when user does not exist' do
it 'creates a new user' do
expect do
User.find_or_create_from_auth_hash!(auth_hash)
end.to change(User, :count).by(1)
described_class.find_or_create_from_auth_hash!(auth_hash)
end.to change(described_class, :count).by(1)
end

it 'returns the created user' do
user = User.find_or_create_from_auth_hash!(auth_hash)
user = described_class.find_or_create_from_auth_hash!(auth_hash)
expect(user).to have_attributes(
provider: 'github',
uid: '0001',
Expand All @@ -91,16 +93,16 @@
end

context 'when user already exists' do
let!(:existing_user) { FactoryBot.create(:user) }
before { FactoryBot.create(:user) }

it 'does not create a new user' do
expect do
User.find_or_create_from_auth_hash!(auth_hash)
end.not_to change(User, :count)
described_class.find_or_create_from_auth_hash!(auth_hash)
end.not_to change(described_class, :count)
end

it 'returns the existing user' do
user = User.find_or_create_from_auth_hash!(auth_hash)
user = described_class.find_or_create_from_auth_hash!(auth_hash)
expect(user).to have_attributes(
provider: 'github',
uid: '0001',
Expand Down

0 comments on commit 574a34d

Please sign in to comment.