|
12 | 12 | it 'renders a collection of users' do |
13 | 13 | get :index |
14 | 14 | expect(response).to have_http_status :ok |
15 | | - expect(has_valid_id_and_type_members?('users')).to be_truthy |
16 | | - expect(has_fetchable_fields?(fields)).to be_truthy |
17 | | - expect(has_relationship_members?(relationships)).to be_truthy |
| 15 | + expect(response).to have_primary_data('users') |
| 16 | + expect(response).to have_data_attributes(fields) |
| 17 | + expect(response).to have_relationships(relationships) |
18 | 18 | end |
19 | 19 |
|
20 | 20 | context 'with "include"' do |
21 | 21 | it 'returns only the required relationships in the "included" member' do |
22 | 22 | get :index, include: :posts |
23 | 23 | expect(response).to have_http_status :ok |
24 | | - expect(has_valid_id_and_type_members?('users')).to be_truthy |
25 | | - expect(has_included_relationships?(%w(posts))).to be_truthy |
| 24 | + expect(response).to have_primary_data('users') |
| 25 | + expect(response).to have_data_attributes(fields) |
| 26 | + expect(response).to have_relationships(relationships) |
| 27 | + expect(response).to have_included_relationships |
26 | 28 | end |
27 | 29 | end |
28 | 30 |
|
29 | 31 | context 'with "fields"' do |
30 | 32 | it 'returns only the required fields in the "attributes" member' do |
31 | 33 | get :index, fields: { users: :first_name } |
32 | 34 | expect(response).to have_http_status :ok |
33 | | - expect(has_valid_id_and_type_members?('users')).to be_truthy |
34 | | - expect(has_fetchable_fields?(%w(first_name))).to be_truthy |
| 35 | + expect(response).to have_primary_data('users') |
| 36 | + expect(response).to have_data_attributes(%w(first_name)) |
35 | 37 | end |
36 | 38 | end |
37 | 39 |
|
|
41 | 43 | it 'returns only results corresponding to the applied filter' do |
42 | 44 | get :index, filter: { first_name: first_name } |
43 | 45 | expect(response).to have_http_status :ok |
44 | | - expect(has_valid_id_and_type_members?('users')).to be_truthy |
45 | | - expect(record_count).to eq(1) |
| 46 | + expect(response).to have_primary_data('users') |
| 47 | + expect(response).to have_meta_record_count(1) |
46 | 48 | expect(data[0]['attributes']['first_name']).to eq(first_name) |
47 | 49 | end |
48 | 50 | end |
|
59 | 61 | get :index, page: { number: 1, size: 2 } |
60 | 62 |
|
61 | 63 | expect(response).to have_http_status :ok |
62 | | - expect(has_valid_id_and_type_members?('users')).to be_truthy |
| 64 | + expect(response).to have_primary_data('users') |
63 | 65 | expect(data.size).to eq(2) |
64 | | - expect(record_count).to eq(3) |
| 66 | + expect(response).to have_meta_record_count(3) |
65 | 67 |
|
66 | 68 | expect(json['links']['first']).to be_present |
67 | 69 | expect(json['links']['next']).to be_present |
|
74 | 76 | get :index, page: { number: 2, size: 1 } |
75 | 77 |
|
76 | 78 | expect(response).to have_http_status :ok |
77 | | - expect(has_valid_id_and_type_members?('users')).to be_truthy |
| 79 | + expect(response).to have_primary_data('users') |
78 | 80 | expect(data.size).to eq(1) |
79 | | - expect(record_count).to eq(3) |
| 81 | + expect(response).to have_meta_record_count(3) |
80 | 82 |
|
81 | 83 | expect(json['links']['first']).to be_present |
82 | 84 | expect(json['links']['prev']).to be_present |
|
90 | 92 | get :index, page: { number: 3, size: 1 } |
91 | 93 |
|
92 | 94 | expect(response).to have_http_status :ok |
93 | | - expect(has_valid_id_and_type_members?('users')).to be_truthy |
| 95 | + expect(response).to have_primary_data('users') |
94 | 96 | expect(data.size).to eq(1) |
95 | | - expect(record_count).to eq(3) |
| 97 | + expect(response).to have_meta_record_count(3) |
96 | 98 |
|
97 | 99 | expect(json['links']['first']).to be_present |
98 | 100 | expect(json['links']['prev']).to be_present |
|
105 | 107 | get :index, page: { number: 1 } |
106 | 108 | expect(response).to have_http_status :ok |
107 | 109 | expect(data.size).to eq(JSONAPI.configuration.default_page_size) |
108 | | - expect(record_count).to eq(3) |
| 110 | + expect(response).to have_meta_record_count(3) |
109 | 111 | end |
110 | 112 | end |
111 | 113 | end |
|
121 | 123 | get :index, page: { offset: 0, limit: 2 } |
122 | 124 |
|
123 | 125 | expect(response).to have_http_status :ok |
124 | | - expect(has_valid_id_and_type_members?('users')).to be_truthy |
| 126 | + expect(response).to have_primary_data('users') |
125 | 127 | expect(data.size).to eq(2) |
126 | | - expect(record_count).to eq(3) |
| 128 | + expect(response).to have_meta_record_count(3) |
127 | 129 |
|
128 | 130 | expect(json['links']['first']).to be_present |
129 | 131 | expect(json['links']['next']).to be_present |
|
136 | 138 | get :index, page: { offset: 1, limit: 1 } |
137 | 139 |
|
138 | 140 | expect(response).to have_http_status :ok |
139 | | - expect(has_valid_id_and_type_members?('users')).to be_truthy |
| 141 | + expect(response).to have_primary_data('users') |
140 | 142 | expect(data.size).to eq(1) |
141 | | - expect(record_count).to eq(3) |
| 143 | + expect(response).to have_meta_record_count(3) |
142 | 144 |
|
143 | 145 | expect(json['links']['first']).to be_present |
144 | 146 | expect(json['links']['previous']).to be_present |
|
152 | 154 | get :index, page: { offset: 2, limit: 1 } |
153 | 155 |
|
154 | 156 | expect(response).to have_http_status :ok |
155 | | - expect(has_valid_id_and_type_members?('users')).to be_truthy |
| 157 | + expect(response).to have_primary_data('users') |
156 | 158 | expect(data.size).to eq(1) |
157 | | - expect(record_count).to eq(3) |
| 159 | + expect(response).to have_meta_record_count(3) |
158 | 160 |
|
159 | 161 | expect(json['links']['first']).to be_present |
160 | 162 | expect(json['links']['previous']).to be_present |
|
167 | 169 | get :index, page: { offset: 1 } |
168 | 170 | expect(response).to have_http_status :ok |
169 | 171 | expect(data.size).to eq(JSONAPI.configuration.default_page_size) |
170 | | - expect(record_count).to eq(3) |
| 172 | + expect(response).to have_meta_record_count(3) |
171 | 173 | end |
172 | 174 | end |
173 | 175 | end |
|
182 | 184 | first_name2 = data[1]['attributes']['first_name'] |
183 | 185 |
|
184 | 186 | expect(response).to have_http_status :ok |
185 | | - expect(has_valid_id_and_type_members?('users')).to be_truthy |
| 187 | + expect(response).to have_primary_data('users') |
186 | 188 | expect(first_name1).to be <= first_name2 |
187 | 189 | end |
188 | 190 | end |
|
196 | 198 | sorted = first_name1 > first_name2 || (first_name1 == first_name2 && last_name1 >= last_name2) |
197 | 199 |
|
198 | 200 | expect(response).to have_http_status :ok |
199 | | - expect(has_valid_id_and_type_members?('users')).to be_truthy |
| 201 | + expect(response).to have_primary_data('users') |
200 | 202 | expect(sorted).to be_truthy |
201 | 203 | end |
202 | 204 | end |
|
209 | 211 | it 'renders a single user' do |
210 | 212 | get :show, id: user.id |
211 | 213 | expect(response).to have_http_status :ok |
212 | | - expect(has_valid_id_and_type_members?('users')).to be_truthy |
213 | | - expect(has_relationship_members?(relationships)).to be_truthy |
| 214 | + expect(response).to have_primary_data('users') |
| 215 | + expect(response).to have_data_attributes(fields) |
214 | 216 | expect(data['attributes']['first_name']).to eq("User ##{user.id}") |
215 | 217 | end |
216 | 218 |
|
|
0 commit comments