|
4 | 4 |
|
5 | 5 | # rubocop:disable Metrics/BlockLength |
6 | 6 | RSpec.describe 'BetterTogether::Joatu::Requests', :as_user do |
7 | | - let(:user) { create(:user, :confirmed) } |
| 7 | + include AutomaticTestConfiguration |
| 8 | + |
| 9 | + let(:locale) { I18n.default_locale } |
| 10 | + let(:user) { find_or_create_test_user('[email protected]', 'password12345', :user) } |
8 | 11 | let(:person) { user.person } |
9 | 12 | let(:category) { create(:better_together_joatu_category) } |
10 | 13 | let(:valid_attributes) do |
11 | 14 | { name: 'New Request', description: 'Request description', creator_id: person.id, |
12 | 15 | category_ids: [category.id].compact } |
13 | 16 | end |
14 | | - let(:request_record) { create(:joatu_request) } |
| 17 | + let(:request_record) { create(:joatu_request, creator: person) } |
15 | 18 |
|
16 | 19 | describe 'routing' do |
17 | 20 | it 'routes to #index' do |
18 | | - get "/#{I18n.locale}/exchange/requests" |
| 21 | + get "/#{locale}/exchange/requests" |
19 | 22 | expect(response).to have_http_status(:ok) |
20 | 23 | end |
21 | 24 | end |
22 | 25 |
|
23 | 26 | describe 'GET /index' do |
24 | 27 | it 'returns success' do |
25 | | - get better_together.joatu_requests_path(locale: I18n.locale) |
| 28 | + get better_together.joatu_requests_path(locale: locale) |
26 | 29 | expect(response).to be_successful |
27 | 30 | end |
28 | 31 | end |
29 | 32 |
|
30 | 33 | describe 'POST /create' do |
31 | 34 | it 'creates a request' do |
32 | 35 | expect do |
33 | | - post better_together.joatu_requests_path(locale: I18n.locale), params: { joatu_request: valid_attributes } |
| 36 | + post better_together.joatu_requests_path(locale: locale), params: { joatu_request: valid_attributes } |
34 | 37 | end.to change(BetterTogether::Joatu::Request, :count).by(1) |
35 | 38 | end |
36 | 39 | end |
37 | 40 |
|
38 | 41 | describe 'GET /show' do |
39 | 42 | it 'returns success' do |
40 | | - get better_together.joatu_request_path(request_record, locale: I18n.locale) |
| 43 | + get better_together.joatu_request_path(request_record, locale: locale) |
41 | 44 | expect(response).to be_successful |
42 | 45 | end |
43 | 46 | end |
|
46 | 49 | # rubocop:todo RSpec/MultipleExpectations |
47 | 50 | it 'updates the request' do # rubocop:todo RSpec/ExampleLength, RSpec/MultipleExpectations |
48 | 51 | # rubocop:enable RSpec/MultipleExpectations |
49 | | - patch better_together.joatu_request_path(request_record, locale: I18n.locale), |
| 52 | + patch better_together.joatu_request_path(request_record, locale: locale), |
50 | 53 | params: { joatu_request: { status: 'closed' } } |
51 | 54 | expect(response).to redirect_to( |
52 | | - better_together.edit_joatu_request_path(request_record, locale: I18n.locale) |
| 55 | + better_together.edit_joatu_request_path(request_record, locale: locale) |
53 | 56 | ) |
54 | 57 | expect(request_record.reload.status).to eq('closed') |
55 | 58 | end |
56 | 59 | end |
57 | 60 |
|
58 | 61 | describe 'DELETE /destroy' do |
59 | 62 | it 'destroys the request' do |
60 | | - to_delete = create(:joatu_request) |
| 63 | + to_delete = create(:joatu_request, creator: person) |
61 | 64 | expect do |
62 | | - delete better_together.joatu_request_path(to_delete, locale: I18n.locale) |
| 65 | + delete better_together.joatu_request_path(to_delete, locale: locale) |
63 | 66 | end.to change(BetterTogether::Joatu::Request, :count).by(-1) |
64 | 67 | end |
65 | 68 | end |
|
0 commit comments