|
8 | 8 | let(:fields) { (PostResource.fetchable_fields - %i(id author)).map(&:to_s) } |
9 | 9 | let(:relationships) { %w(author) } |
10 | 10 | let(:first_post) { Post.first } |
| 11 | + let(:user_id) { first_post.user_id } |
11 | 12 |
|
12 | 13 | let(:attributes) do |
13 | 14 | { title: 'Lorem ipsum', body: 'Lorem ipsum dolor sit amet.' } |
14 | 15 | end |
15 | 16 |
|
16 | 17 | let(:author_params) do |
17 | | - { data: { type: 'users', id: first_post.user_id } } |
| 18 | + { data: { type: 'users', id: user_id } } |
18 | 19 | end |
19 | 20 |
|
20 | 21 | let(:post_params) do |
|
27 | 28 | describe '#index' do |
28 | 29 | context 'with ActiveRecord::Relation' do |
29 | 30 | it 'renders a collection of users' do |
30 | | - get :index, user_id: first_post.user_id |
| 31 | + get :index, user_id: user_id |
31 | 32 | expect(response).to have_http_status :ok |
32 | 33 | expect(response).to have_primary_data('posts') |
33 | 34 | expect(response).to have_data_attributes(fields) |
|
50 | 51 | describe '#show' do |
51 | 52 | context 'with ActiveRecord' do |
52 | 53 | it 'renders a single post' do |
53 | | - get :show, user_id: first_post.user_id, id: first_post.id |
| 54 | + get :show, user_id: user_id, id: first_post.id |
54 | 55 | expect(response).to have_http_status :ok |
55 | 56 | expect(response).to have_primary_data('posts') |
56 | 57 | expect(response).to have_data_attributes(fields) |
|
73 | 74 | context 'when resource was not found' do |
74 | 75 | context 'with conventional id' do |
75 | 76 | it 'renders a 404 response' do |
76 | | - get :show, user_id: first_post.user_id, id: 999 |
| 77 | + get :show, user_id: user_id, id: 999 |
77 | 78 | expect(response).to have_http_status :not_found |
78 | 79 | expect(error['title']).to eq('Record not found') |
79 | 80 | expect(error['detail']).to include('999') |
|
85 | 86 | let(:uuid) { SecureRandom.uuid } |
86 | 87 |
|
87 | 88 | it 'renders a 404 response' do |
88 | | - get :show, user_id: first_post.user_id, id: uuid |
| 89 | + get :show, user_id: user_id, id: uuid |
89 | 90 | expect(response).to have_http_status :not_found |
90 | 91 | expect(error['title']).to eq('Record not found') |
91 | 92 | expect(error['detail']).to include(uuid) |
|
97 | 98 | let(:slug) { 'some-awesome-slug' } |
98 | 99 |
|
99 | 100 | it 'renders a 404 response' do |
100 | | - get :show, user_id: first_post.user_id, id: slug |
| 101 | + get :show, user_id: user_id, id: slug |
101 | 102 | expect(response).to have_http_status :not_found |
102 | 103 | expect(error['title']).to eq('Record not found') |
103 | 104 | expect(error['detail']).to include(slug) |
|
0 commit comments