Skip to content

Commit

Permalink
共通化できる部分を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
OdenTakashi committed Aug 18, 2024
1 parent 80febe7 commit a68b158
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions spec/requests/lottery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
require 'rails_helper'

RSpec.describe Lottery, type: :request do
let(:user) { create(:user) }

before do
sign_in user
end

describe 'GET /lotteries' do
subject(:request_index) { get lotteries_path }

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

it 'return 200 status' do
sign_in user
request_index

expect(response).to have_http_status(:ok)
Expand All @@ -19,11 +22,9 @@
describe 'GET /lotteries/:id/edit' do
subject(:request_edit) { get edit_lottery_path(lottery) }

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

it 'return 200 status' do
sign_in user
request_edit

expect(response).to have_http_status(:ok)
Expand All @@ -33,11 +34,9 @@
describe 'GET /lotteries/:id' do
subject(:request_show) { get lottery_path(lottery) }

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

it 'return 200 status' do
sign_in user
request_show

expect(response).to have_http_status(:ok)
Expand All @@ -47,20 +46,16 @@
describe 'GET /lotteries/new' do
subject(:request_new) { get new_lottery_path }

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

it 'return 200 status' do
sign_in user
request_new

expect(response).to have_http_status(:ok)
end
end

describe 'POST /lotteries' do
subject(:request_create) { post lotteries_path(params) }
subject(:request_create) { post lotteries_path, params: }

let(:user) { create(:user) }
let(:params) do
{ lottery: {
user_id: user.id,
Expand All @@ -80,8 +75,6 @@
end

it 'create lottery successful' do
sign_in user

expect { request_create }.to change(described_class, :count).by(1)
expect(response).to have_http_status(:found)
end
Expand All @@ -90,7 +83,6 @@
describe 'PATCH /lotteries/:id' do
subject(:request_update) { patch lottery_path(lottery), params: }

let(:user) { create(:user) }
let(:lottery) { create(:lottery) }
let(:params) do
{
Expand All @@ -106,7 +98,6 @@
end

it 'update lottery successful' do
sign_in user
expect do
request_update
lottery.reload
Expand All @@ -118,12 +109,9 @@
describe 'DELETE /lotteries/:id' do
subject(:request_delete) { delete lottery_path(lottery) }

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

it 'delete lottery successful' do
sign_in user

expect { request_delete }.to change(described_class, :count).by(-1)
expect(response).to have_http_status(:found)
end
Expand Down

0 comments on commit a68b158

Please sign in to comment.