From 69153b46eee0fec67efa66f9b5f0499730a98829 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Thu, 16 Mar 2023 21:53:23 -0600 Subject: Mejorado código de ProductsController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/controllers/products_controller_spec.rb | 13 +++++++++++++ spec/factories/product.rb | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 spec/controllers/products_controller_spec.rb create mode 100644 spec/factories/product.rb (limited to 'spec') diff --git a/spec/controllers/products_controller_spec.rb b/spec/controllers/products_controller_spec.rb new file mode 100644 index 0000000..d4f1373 --- /dev/null +++ b/spec/controllers/products_controller_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Api::ProductsController, type: :controller do + let(:product) { create(:product) } + + it { should route(:post, '/api/products').to(action: :create) } + it { should route(:put, "/api/products#{product.public_id}").to(action: :update, id: product.public_id) } + it { should route(:get, '/api/products').to(action: :index) } + it { should route(:get, "/api/products/#{product.public_id}").to(action: :show, id: product.public_id) } + it { should route(:delete, "/api/products/#{product.public_id}").to(action: :destroy, id: product.public_id) } +end diff --git a/spec/factories/product.rb b/spec/factories/product.rb new file mode 100644 index 0000000..ab65cd0 --- /dev/null +++ b/spec/factories/product.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :company, class: 'Company' do + name { Faker::Commerce.product_name } + unitary_price { rand(1000.0) } + bulk_price { rand(1000.0) } + available_quantity { rand(1000) } + company { create(:company) } + categories do + c = [] + (0..rand(5)).each do + c.push(Faker::Commerce.department(max: 1)) + end + c + end + end +end -- cgit v1.2.3