summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/api/addresses_controller.rb13
-rw-r--r--config/routes.rb1
-rw-r--r--spec/requests/addresses_controller/index_spec.rb2
-rw-r--r--spec/requests/addresses_controller/show_spec.rb21
4 files changed, 35 insertions, 2 deletions
diff --git a/app/controllers/api/addresses_controller.rb b/app/controllers/api/addresses_controller.rb
index dbd77d9..834f721 100644
--- a/app/controllers/api/addresses_controller.rb
+++ b/app/controllers/api/addresses_controller.rb
@@ -9,6 +9,16 @@ module Api
render json: serialized_collection.serializable_hash, status: :ok
end
+ def show
+ @address = current_user_account.addresses.find_by(id: params[:id])
+
+ if @address.nil?
+ render status: :not_found
+ else
+ render json: serialized_object.serializable_hash, status: :ok
+ end
+ end
+
def create
@service = Addresses::CreateAddressService.new(current_user_account, service_params)
@@ -40,7 +50,8 @@ module Api
render json: serialized_object.serializable_hash, status: :ok
end
rescue ActiveRecord::RecordNotUnique
- render json: { error_message: 'Ya cuenta con esta dirección' }, status: :unprocessable_entity
+ @address = current_user_account.addresses.find(params[:id])
+ render json: serialized_object.serializable_hash, status: :ok
end
end
diff --git a/config/routes.rb b/config/routes.rb
index bc38e3f..b5289c8 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -11,6 +11,7 @@ Rails.application.routes.draw do
get '/account', to: 'user_accounts#show'
get '/account/addresses', to: 'addresses#index'
post '/account/addresses', to: 'addresses#create'
+ get '/account/addresses/:id', to: 'addresses#show'
put '/account/addresses/:id', to: 'addresses#update'
delete '/account/addresses/:id', to: 'addresses#destroy'
get '/account/cart', to: 'carts#show'
diff --git a/spec/requests/addresses_controller/index_spec.rb b/spec/requests/addresses_controller/index_spec.rb
index 63fc776..b64d5e3 100644
--- a/spec/requests/addresses_controller/index_spec.rb
+++ b/spec/requests/addresses_controller/index_spec.rb
@@ -16,4 +16,4 @@ RSpec.describe 'GET /api/account/addresses', type: :request do
let(:route) { '/api/account/addresses' }
let(:pagination_size) { 5 }
end
-end \ No newline at end of file
+end
diff --git a/spec/requests/addresses_controller/show_spec.rb b/spec/requests/addresses_controller/show_spec.rb
new file mode 100644
index 0000000..aaa97fb
--- /dev/null
+++ b/spec/requests/addresses_controller/show_spec.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe 'GET /api/account/addreses/:id', type: :request do
+ it_behaves_like 'a GET resource request' do
+ let(:user) { create(:user_account) }
+ let(:token) { jwt(user) }
+ let(:headers) { { 'Authorization' => "Bearer #{token['token']}" } }
+ let(:address) do
+ address = create(:address)
+ user.addresses << address
+ user.save
+ address.save
+ address
+ end
+ let(:route) { "/api/account/addresses/#{address.id.to_s}" }
+ let(:invalid_route) { "/api/account/addresses/#{Faker::Lorem.word}" }
+ let(:expected_text) { [address.street, address.id.to_s, address.zip_code, address.city, address.country] }
+ end
+end