File tree 5 files changed +40
-1
lines changed
5 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 27
27
28
28
# Ignore master key for decrypting credentials and more.
29
29
/config /master.key
30
+ .byebug_history
Original file line number Diff line number Diff line change @@ -221,4 +221,4 @@ RUBY VERSION
221
221
ruby 3.2.2p53
222
222
223
223
BUNDLED WITH
224
- 2.4.10
224
+ 2.4.19
Original file line number Diff line number Diff line change
1
+ class Api ::ProductsController < ApplicationController
2
+ def index
3
+ @products = Product . all
4
+ render json : @products , status : :ok
5
+ end
6
+ end
Original file line number Diff line number Diff line change 3
3
4
4
# Defines the root path route ("/")
5
5
# root "articles#index"
6
+ namespace :api do
7
+ resources :products , only : [ :index ]
8
+ end
6
9
end
Original file line number Diff line number Diff line change
1
+ require 'rails_helper'
2
+
3
+ RSpec . describe "Api::Products" , type : :request do
4
+ let! ( :products ) { FactoryBot . create_list ( :product , 2 ) }
5
+
6
+ describe 'GET /api/products' do
7
+ before do
8
+ get '/api/products'
9
+ end
10
+
11
+ it 'returns a list of all existing products with the correct attributes' do
12
+ expect ( response ) . to have_http_status ( 200 )
13
+ products_response = JSON . parse ( response . body )
14
+
15
+ expect ( products_response . size ) . to eq ( 2 )
16
+ products_response . each_with_index do |product_response , index |
17
+ product = products [ index ]
18
+
19
+ expect ( product_response [ 'id' ] ) . to eq ( product . id )
20
+ expect ( product_response [ 'code' ] ) . to eq ( product . code )
21
+ expect ( product_response [ 'name' ] ) . to eq ( product . name )
22
+ expect ( product_response [ 'price' ] ) . to eq ( product . price . to_s )
23
+
24
+ expect ( product_response [ 'created_at' ] . to_datetime . to_i ) . to eq ( product . created_at . to_datetime . to_i )
25
+ expect ( product_response [ 'updated_at' ] . to_datetime . to_i ) . to eq ( product . updated_at . to_datetime . to_i )
26
+ end
27
+ end
28
+ end
29
+ end
You can’t perform that action at this time.
0 commit comments