From f0f2e7174418a4ede3d70dc013757e65460957a3 Mon Sep 17 00:00:00 2001 From: "naoki.kodama" Date: Mon, 12 Aug 2024 10:25:01 +0900 Subject: [PATCH 01/10] =?UTF-8?q?lottery=E3=81=AErequest=20spec=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/requests/lotteries_spec.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 spec/requests/lotteries_spec.rb diff --git a/spec/requests/lotteries_spec.rb b/spec/requests/lotteries_spec.rb new file mode 100644 index 0000000..e69de29 From 0251f0489bea063b9b4d3e88dd5062ba4423bbba Mon Sep 17 00:00:00 2001 From: "naoki.kodama" Date: Wed, 14 Aug 2024 23:26:59 +0900 Subject: [PATCH 02/10] =?UTF-8?q?request=20spec=E5=86=85=E3=81=A7=E3=82=82?= =?UTF-8?q?devise=E3=81=AE=E3=83=98=E3=83=AB=E3=83=91=E3=83=BC=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E4=BD=BF=E3=81=88=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/rails_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 2c50727..a76fcba 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -64,5 +64,6 @@ # config.filter_gems_from_backtrace("gem name") config.include FactoryBot::Syntax::Methods config.include Devise::Test::IntegrationHelpers, type: :system + config.include Devise::Test::IntegrationHelpers, type: :request config.include ActiveSupport::Testing::TimeHelpers end From 8745d4a6c445a7eeeb7e24487543242734aed1ae Mon Sep 17 00:00:00 2001 From: "naoki.kodama" Date: Wed, 14 Aug 2024 23:28:41 +0900 Subject: [PATCH 03/10] =?UTF-8?q?lotteries=5Fpath=E3=81=B8=E3=81=AE?= =?UTF-8?q?=E3=83=AA=E3=82=B9=E3=82=AF=E3=82=A8=E3=82=B9=E3=83=88spec?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/requests/lotteries_spec.rb | 0 spec/requests/lottery_spec.rb | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+) delete mode 100644 spec/requests/lotteries_spec.rb create mode 100644 spec/requests/lottery_spec.rb diff --git a/spec/requests/lotteries_spec.rb b/spec/requests/lotteries_spec.rb deleted file mode 100644 index e69de29..0000000 diff --git a/spec/requests/lottery_spec.rb b/spec/requests/lottery_spec.rb new file mode 100644 index 0000000..a908a11 --- /dev/null +++ b/spec/requests/lottery_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Lottery, type: :request do + 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) + end + end +end From 20cf190af5fc9dd3411950f2977fade0f0449ee4 Mon Sep 17 00:00:00 2001 From: "naoki.kodama" Date: Wed, 14 Aug 2024 23:59:30 +0900 Subject: [PATCH 04/10] =?UTF-8?q?edit=E3=83=9A=E3=83=BC=E3=82=B8=E3=81=B8?= =?UTF-8?q?=E3=81=AErequest=E3=82=B9=E3=83=9A=E3=83=83=E3=82=AF=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/requests/lottery_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/requests/lottery_spec.rb b/spec/requests/lottery_spec.rb index a908a11..705a993 100644 --- a/spec/requests/lottery_spec.rb +++ b/spec/requests/lottery_spec.rb @@ -15,4 +15,18 @@ expect(response).to have_http_status(:ok) end end + + 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) + end + end end From e7d217cacc6b65be8cd238719b5a4fff6139f302 Mon Sep 17 00:00:00 2001 From: "naoki.kodama" Date: Wed, 14 Aug 2024 23:59:56 +0900 Subject: [PATCH 05/10] =?UTF-8?q?show=E3=83=9A=E3=83=BC=E3=82=B8=E3=81=B8?= =?UTF-8?q?=E3=81=AE=E3=83=AA=E3=82=AF=E3=82=A8=E3=82=B9=E3=83=88=E3=82=B9?= =?UTF-8?q?=E3=83=9A=E3=83=83=E3=82=AF=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/requests/lottery_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/requests/lottery_spec.rb b/spec/requests/lottery_spec.rb index 705a993..77e5413 100644 --- a/spec/requests/lottery_spec.rb +++ b/spec/requests/lottery_spec.rb @@ -29,4 +29,18 @@ expect(response).to have_http_status(:ok) end end + + 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) + end + end end From eeeb0c82cbbb260170cb34fc787130640339551c Mon Sep 17 00:00:00 2001 From: "naoki.kodama" Date: Sun, 18 Aug 2024 21:01:38 +0900 Subject: [PATCH 06/10] =?UTF-8?q?new=E3=83=9A=E3=83=BC=E3=82=B8=E3=81=B8?= =?UTF-8?q?=E3=81=AE=E3=83=AA=E3=82=AF=E3=82=A8=E3=82=B9=E3=83=88=E3=82=B9?= =?UTF-8?q?=E3=83=9A=E3=83=83=E3=82=AF=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/requests/lottery_spec.rb | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/spec/requests/lottery_spec.rb b/spec/requests/lottery_spec.rb index 77e5413..57cd096 100644 --- a/spec/requests/lottery_spec.rb +++ b/spec/requests/lottery_spec.rb @@ -43,4 +43,59 @@ expect(response).to have_http_status(:ok) end end + + 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_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) + # end + # end + + # describe 'PATCH /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) + # end + # end + + # describe 'DELETE /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) + # end + # end end From c00e5058fb02e9564311a106738108c4f37de06b Mon Sep 17 00:00:00 2001 From: "naoki.kodama" Date: Sun, 18 Aug 2024 21:42:07 +0900 Subject: [PATCH 07/10] =?UTF-8?q?crete=E3=82=A2=E3=82=AF=E3=82=B7=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E3=81=AErequest=E3=82=B9=E3=83=9A=E3=83=83=E3=82=AF?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/requests/lottery_spec.rb | 36 +++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/spec/requests/lottery_spec.rb b/spec/requests/lottery_spec.rb index 57cd096..a14a079 100644 --- a/spec/requests/lottery_spec.rb +++ b/spec/requests/lottery_spec.rb @@ -57,19 +57,35 @@ end end - # describe 'POST /lotteries' do - # subject(:request_show) { get lottery_path(lottery) } + describe 'POST /lotteries' do + subject(:request_create) { post lotteries_path(params) } - # let(:user) { create(:user) } - # let(:lottery) { create(:lottery) } + let(:user) { create(:user) } + let(:params) do + { lottery: { + user_id: user.id, + name: 'テストの抽選会', + description: 'テストの説明', + deadline: '2024-08-19', + name_field_enabled: true, + note_field_enabled: true, + prizes_attributes: [ + { name: '商品名', + winners_count: 2, + winning_email_subject: 'テストの件名', + winning_email_body: 'テストの本文', + _destroy: false } + ] + } } + end - # it 'return 200 status' do - # sign_in user - # request_show + it 'success creating lottery' do + sign_in user - # expect(response).to have_http_status(:ok) - # end - # end + expect { request_create }.to change(described_class, :count).by(1) + expect(response).to have_http_status(:found) + end + end # describe 'PATCH /lotteries/:id' do # subject(:request_show) { get lottery_path(lottery) } From 210421e646d2f4ec42f5c782f13bda60907d3961 Mon Sep 17 00:00:00 2001 From: "naoki.kodama" Date: Sun, 18 Aug 2024 22:00:07 +0900 Subject: [PATCH 08/10] =?UTF-8?q?update=E3=82=A2=E3=82=AF=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=81=B8=E3=81=AErequest=E3=82=B9=E3=83=9A?= =?UTF-8?q?=E3=83=83=E3=82=AF=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .rubocop.yml | 1 + spec/requests/lottery_spec.rb | 38 ++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2a06d96..e81bc41 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -14,3 +14,4 @@ RSpec/MultipleExpectations: RSpec/ExampleLength: Exclude: - spec/system/* + - spec/requests/* diff --git a/spec/requests/lottery_spec.rb b/spec/requests/lottery_spec.rb index a14a079..4ca8fbe 100644 --- a/spec/requests/lottery_spec.rb +++ b/spec/requests/lottery_spec.rb @@ -79,7 +79,7 @@ } } end - it 'success creating lottery' do + it 'create lottery successful' do sign_in user expect { request_create }.to change(described_class, :count).by(1) @@ -87,19 +87,33 @@ end end - # describe 'PATCH /lotteries/:id' do - # subject(:request_show) { get lottery_path(lottery) } + describe 'PATCH /lotteries/:id' do + subject(:request_update) { patch lottery_path(lottery), params: } - # let(:user) { create(:user) } - # let(:lottery) { create(:lottery) } - - # it 'return 200 status' do - # sign_in user - # request_show + let(:user) { create(:user) } + let(:lottery) { create(:lottery) } + let(:params) do + { + lottery: { + name: '更新された抽選会', + description: lottery.description, + deadline: lottery.deadline, + name_field_enabled: lottery.name_field_enabled, + note_field_enabled: lottery.note_field_enabled, + prizes_attributes: lottery.prizes.map { |prize| prize.attributes.except('id', 'created_at', 'updated_at') } + } + } + end - # expect(response).to have_http_status(:ok) - # end - # end + it 'update lottery successful' do + sign_in user + expect do + request_update + lottery.reload + end.to change(lottery, :name).from('チケットの抽選会').to('更新された抽選会') + expect(response).to have_http_status(:found) + end + end # describe 'DELETE /lotteries/:id' do # subject(:request_show) { get lottery_path(lottery) } From 80febe7a07745a4c6b9cca6b712a9189aebff0d2 Mon Sep 17 00:00:00 2001 From: "naoki.kodama" Date: Sun, 18 Aug 2024 22:13:15 +0900 Subject: [PATCH 09/10] =?UTF-8?q?delete=E3=82=A2=E3=82=AF=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=81=B8=E3=81=AErequest=E3=82=B9=E3=83=9A?= =?UTF-8?q?=E3=83=83=E3=82=AF=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/requests/lottery_spec.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/requests/lottery_spec.rb b/spec/requests/lottery_spec.rb index 4ca8fbe..f64332a 100644 --- a/spec/requests/lottery_spec.rb +++ b/spec/requests/lottery_spec.rb @@ -115,17 +115,17 @@ end end - # describe 'DELETE /lotteries/:id' do - # subject(:request_show) { get lottery_path(lottery) } + describe 'DELETE /lotteries/:id' do + subject(:request_delete) { delete lottery_path(lottery) } - # let(:user) { create(:user) } - # let(:lottery) { create(:lottery) } + let(:user) { create(:user) } + let!(:lottery) { create(:lottery) } - # it 'return 200 status' do - # sign_in user - # request_show + it 'delete lottery successful' do + sign_in user - # expect(response).to have_http_status(:ok) - # end - # end + expect { request_delete }.to change(described_class, :count).by(-1) + expect(response).to have_http_status(:found) + end + end end From a68b1586418b06aed0d366fe3d8d39f25cde4c27 Mon Sep 17 00:00:00 2001 From: "naoki.kodama" Date: Sun, 18 Aug 2024 22:20:57 +0900 Subject: [PATCH 10/10] =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=8C=96=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E9=83=A8=E5=88=86=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/requests/lottery_spec.rb | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/spec/requests/lottery_spec.rb b/spec/requests/lottery_spec.rb index f64332a..da45c45 100644 --- a/spec/requests/lottery_spec.rb +++ b/spec/requests/lottery_spec.rb @@ -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) @@ -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) @@ -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) @@ -47,10 +46,7 @@ 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) @@ -58,9 +54,8 @@ 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, @@ -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 @@ -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 { @@ -106,7 +98,6 @@ end it 'update lottery successful' do - sign_in user expect do request_update lottery.reload @@ -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