summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-03-18 12:15:43 -0600
committerHombreLaser <sebastian-440@live.com>2023-03-18 12:15:43 -0600
commit3e106dc7f5fbd6961c67f41aea66033c27b5142f (patch)
tree1cc3c2046a506e8d0bba7cfa300c8d0734cce6ae /spec
parent717fa996842012a8666bcff985218c2abddd9991 (diff)
Añade spec de products_controller#show
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/products_controller_spec.rb14
-rw-r--r--spec/factories/product.rb2
-rw-r--r--spec/models/product_spec.rb7
-rw-r--r--spec/requests/products_controller/show_products_controller_spec.rb16
4 files changed, 33 insertions, 6 deletions
diff --git a/spec/controllers/products_controller_spec.rb b/spec/controllers/products_controller_spec.rb
index d4f1373..aabab4b 100644
--- a/spec/controllers/products_controller_spec.rb
+++ b/spec/controllers/products_controller_spec.rb
@@ -3,11 +3,15 @@
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 do
+ should route(:put, '/api/products/0439733420a4c5a3e8239bb1').to(action: :update, id: '0439733420a4c5a3e8239bb1')
+ end
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) }
+ it do
+ should route(:get, '/api/products/0439733420a4c5a3e8239bb1').to(action: :show, id: '0439733420a4c5a3e8239bb1')
+ end
+ it do
+ should route(:delete, '/api/products/0439733420a4c5a3e8239bb1').to(action: :destroy, id: '0439733420a4c5a3e8239bb1')
+ end
end
diff --git a/spec/factories/product.rb b/spec/factories/product.rb
index ab65cd0..abdf4bc 100644
--- a/spec/factories/product.rb
+++ b/spec/factories/product.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
FactoryBot.define do
- factory :company, class: 'Company' do
+ factory :product, class: 'Product' do
name { Faker::Commerce.product_name }
unitary_price { rand(1000.0) }
bulk_price { rand(1000.0) }
diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb
index b3790fe..d9d0c64 100644
--- a/spec/models/product_spec.rb
+++ b/spec/models/product_spec.rb
@@ -10,4 +10,11 @@ RSpec.describe Product, type: :model do
it { should have_one_attached(:picture) }
it { should belong_to(:company) }
it { should serialize(:categories) }
+
+ describe '#to_param' do
+ it "describes the param the product's routes expect" do
+ product = create(:product, public_id: SecureRandom.hex(12))
+ expect(product.to_param).to eq(product.public_id)
+ end
+ end
end
diff --git a/spec/requests/products_controller/show_products_controller_spec.rb b/spec/requests/products_controller/show_products_controller_spec.rb
new file mode 100644
index 0000000..3ef5148
--- /dev/null
+++ b/spec/requests/products_controller/show_products_controller_spec.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe 'GET /api/products/:public_id', type: :request do
+ it_behaves_like 'a GET resource request' do
+ let(:headers) { {} }
+ let(:product) { create(:product, public_id: SecureRandom.hex(12)) }
+ let(:route) { "/api/products/#{product.public_id}" }
+ let(:invalid_route) { "/api/products/#{Faker::Lorem.word}" }
+ let(:expected_text) do
+ product.categories.concat([product.name, product.id.to_s, product.unitary_price.to_s, product.bulk_price.to_s,
+ product.available_quantity.to_s, product.company.name, product.company.short_name])
+ end
+ end
+end