dawarich/spec/requests/visits_spec.rb

46 lines
1.1 KiB
Ruby
Raw Normal View History

2024-07-27 06:35:47 -04:00
# frozen_string_literal: true
2024-07-24 14:25:16 -04:00
2024-07-27 06:35:47 -04:00
require 'rails_helper'
2024-07-24 14:25:16 -04:00
RSpec.describe '/visits', type: :request do
2024-07-27 06:35:47 -04:00
let(:user) { create(:user) }
2024-07-24 14:25:16 -04:00
2024-07-27 06:35:47 -04:00
before do
stub_request(:any, 'https://api.github.com/repos/Freika/dawarich/tags')
.to_return(status: 200, body: '[{"name": "1.0.0"}]', headers: {})
sign_in user
end
2024-07-24 14:25:16 -04:00
describe 'GET /index' do
it 'renders a successful response' do
2024-07-24 14:25:16 -04:00
get visits_url
expect(response).to be_successful
end
end
2024-07-27 06:35:47 -04:00
describe 'PATCH /update' do
context 'with valid parameters' do
2024-07-27 06:35:47 -04:00
let(:visit) { create(:visit, user:, status: :pending) }
2024-07-24 14:25:16 -04:00
2024-07-27 06:35:47 -04:00
it 'confirms the requested visit' do
patch visit_url(visit), params: { visit: { status: :confirmed } }
2024-07-24 14:25:16 -04:00
2024-07-27 06:35:47 -04:00
expect(visit.reload.status).to eq('confirmed')
2024-07-24 14:25:16 -04:00
end
2024-07-27 06:35:47 -04:00
it 'rejects the requested visit' do
patch visit_url(visit), params: { visit: { status: :declined } }
2024-07-24 14:25:16 -04:00
2024-07-27 06:35:47 -04:00
expect(visit.reload.status).to eq('declined')
2024-07-24 14:25:16 -04:00
end
2024-07-27 06:35:47 -04:00
it 'redirects to the visit index page' do
patch visit_url(visit), params: { visit: { status: :confirmed } }
2024-07-24 14:25:16 -04:00
2024-07-27 06:35:47 -04:00
expect(response).to redirect_to(visits_url)
2024-07-24 14:25:16 -04:00
end
end
end
end