summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-04-04 17:55:20 -0600
committerHombreLaser <sebastian-440@live.com>2023-04-04 17:55:20 -0600
commitdb9b4b712271a67e60e6c0bf58c9ce510f177682 (patch)
tree791da60f29a1ac3b73efff46493d96c0116318e0 /spec
parent3afd35371caa0677fd2f66491bd337d1673013dc (diff)
Mejora presentaciĆ³n de mensajes de error
Diffstat (limited to 'spec')
-rw-r--r--spec/models/product_review_spec.rb12
-rw-r--r--spec/requests/addresses_controller/create_spec.rb3
-rw-r--r--spec/requests/addresses_controller/update_spec.rb4
-rw-r--r--spec/requests/cards_controller/create_spec.rb10
-rw-r--r--spec/requests/cards_controller/update_spec.rb10
-rw-r--r--spec/requests/companies_controller/create_spec.rb2
-rw-r--r--spec/requests/companies_controller/update_spec.rb2
-rw-r--r--spec/requests/products_controller/create_spec.rb4
-rw-r--r--spec/requests/products_controller/update_spec.rb4
-rw-r--r--spec/requests/user_accounts_controller/create_spec.rb2
-rw-r--r--spec/requests/user_accounts_controller/update_spec.rb2
11 files changed, 33 insertions, 22 deletions
diff --git a/spec/models/product_review_spec.rb b/spec/models/product_review_spec.rb
index f4e4999..c8f7b69 100644
--- a/spec/models/product_review_spec.rb
+++ b/spec/models/product_review_spec.rb
@@ -3,6 +3,9 @@ require 'rails_helper'
RSpec.describe ProductReview, type: :model do
let(:review) { build(:product_review) }
+ it { should belong_to(:user_account) }
+ it { should belong_to(:product) }
+
it { should validate_presence_of(:review) }
it { should validate_presence_of(:rating) }
@@ -14,4 +17,13 @@ RSpec.describe ProductReview, type: :model do
expect(review.save).to be_falsey
end
end
+
+ describe '#sole_user_review' do
+ it "doesn't allow a user to post more than one review for any given product" do
+ review.save
+ other_review = build(:product_review, user_account: review.user_account, product: review.product)
+ expect(other_review.save).to be_falsey
+ expect(other_review.errors[:review]).to_not be_nil
+ end
+ end
end
diff --git a/spec/requests/addresses_controller/create_spec.rb b/spec/requests/addresses_controller/create_spec.rb
index befb80b..5987e0f 100644
--- a/spec/requests/addresses_controller/create_spec.rb
+++ b/spec/requests/addresses_controller/create_spec.rb
@@ -15,8 +15,7 @@ RSpec.describe 'POST /account/addresses', type: :request do
it_behaves_like 'a POST request' do
let(:route) { '/api/account/addresses' }
let(:expected_error_messages) do
- ["Number can't be blank", "Street can't be blank", "Zip code can't be blank",
- 'Country is invalid', "City can't be blank"]
+ ["can't be blank", "can't be blank", "can't be blank", 'is invalid', "can't be blank"]
end
let(:desired_error_status) { 422 }
let(:expected_text) { [address.number.to_s, address.zip_code.to_s, address.country, address.street, address.city] }
diff --git a/spec/requests/addresses_controller/update_spec.rb b/spec/requests/addresses_controller/update_spec.rb
index 0c3662e..a5b993a 100644
--- a/spec/requests/addresses_controller/update_spec.rb
+++ b/spec/requests/addresses_controller/update_spec.rb
@@ -21,8 +21,8 @@ RSpec.describe 'PUT /api/account/addresses', type: :request do
let(:route) { "/api/account/addresses/#{address.id}" }
let(:wrong_route) { "/api/account/addresses/#{SecureRandom.hex(8)}" }
let(:expected_error_messages) do
- ["Number can't be blank", "Street can't be blank", "Zip code can't be blank",
- 'Country is invalid', "City can't be blank"]
+ ["can't be blank", "can't be blank", "can't be blank",
+ 'is invalid', "can't be blank"]
end
let(:expected_text) do
[new_address.number.to_s, new_address.zip_code.to_s, new_address.country, new_address.street,
diff --git a/spec/requests/cards_controller/create_spec.rb b/spec/requests/cards_controller/create_spec.rb
index 465288b..af04a23 100644
--- a/spec/requests/cards_controller/create_spec.rb
+++ b/spec/requests/cards_controller/create_spec.rb
@@ -15,11 +15,11 @@ RSpec.describe 'POST /account/cards', type: :request do
it_behaves_like 'a POST request' do
let(:route) { '/api/account/cards' }
let(:expected_error_messages) do
- ['Number is the wrong length (should be 16 characters)',
- 'Expiration year must be greater than 1970',
- 'Expiration month is not included in the list',
- 'Expiration day is not included in the list',
- "Security code can't be blank"]
+ ['is the wrong length (should be 16 characters)',
+ 'must be greater than 1970',
+ 'is not included in the list',
+ 'is not included in the list',
+ "can't be blank"]
end
let(:desired_error_status) { 422 }
let(:expected_text) do
diff --git a/spec/requests/cards_controller/update_spec.rb b/spec/requests/cards_controller/update_spec.rb
index 77b4c4f..453befc 100644
--- a/spec/requests/cards_controller/update_spec.rb
+++ b/spec/requests/cards_controller/update_spec.rb
@@ -17,11 +17,11 @@ RSpec.describe 'PUT /api/account/addresses', type: :request do
let(:route) { "/api/account/cards/#{card.id}" }
let(:wrong_route) { "/api/account/cards/#{SecureRandom.hex(8)}" }
let(:expected_error_messages) do
- ['Number is the wrong length (should be 16 characters)',
- 'Expiration year must be greater than 1970',
- 'Expiration month is not included in the list',
- 'Expiration day is not included in the list',
- "Security code can't be blank"]
+ ['is the wrong length (should be 16 characters)',
+ 'must be greater than 1970',
+ 'is not included in the list',
+ 'is not included in the list',
+ "can't be blank"]
end
let(:expected_text) do
[new_card.number, new_card.expiration_year, new_card.expiration_month, new_card.expiration_day,
diff --git a/spec/requests/companies_controller/create_spec.rb b/spec/requests/companies_controller/create_spec.rb
index 219868b..74a448a 100644
--- a/spec/requests/companies_controller/create_spec.rb
+++ b/spec/requests/companies_controller/create_spec.rb
@@ -12,7 +12,7 @@ RSpec.describe 'POST /api/companies', type: :request do
let(:headers) { { 'CONTENT_TYPE' => 'application/json', 'Authorization' => "Bearer #{token['token']}" } }
let(:route) { '/api/companies' }
let(:expected_error_messages) do
- ["Name can't be blank", "Short name can't be blank", "Country can't be blank"]
+ ["can't be blank", "can't be blank", "can't be blank"]
end
let(:desired_error_status) { 422 }
let(:expected_text) { [company.name, company.short_name, company.country, 'logo', 'http'] }
diff --git a/spec/requests/companies_controller/update_spec.rb b/spec/requests/companies_controller/update_spec.rb
index fd23365..de8cb2a 100644
--- a/spec/requests/companies_controller/update_spec.rb
+++ b/spec/requests/companies_controller/update_spec.rb
@@ -14,7 +14,7 @@ RSpec.describe 'PUT /api/companies/company_id', type: :request do
let(:route) { "/api/companies/#{company.short_name}" }
let(:wrong_route) { "/api/companies/#{SecureRandom.hex(8)}" }
let(:expected_error_messages) do
- ["Name can't be blank", "Short name can't be blank", "Country can't be blank"]
+ ["can't be blank", "can't be blank", "can't be blank"]
end
let(:expected_text) { [new_company.name, new_company.short_name, new_company.country, 'logo', 'http'] }
let(:params) do
diff --git a/spec/requests/products_controller/create_spec.rb b/spec/requests/products_controller/create_spec.rb
index 400fd18..4d6a9bc 100644
--- a/spec/requests/products_controller/create_spec.rb
+++ b/spec/requests/products_controller/create_spec.rb
@@ -17,8 +17,8 @@ RSpec.describe 'POST /api/products', type: :request do
let(:headers) { { 'CONTENT_TYPE' => 'application/json', 'Authorization' => "Bearer #{token['token']}" } }
let(:route) { '/api/products' }
let(:expected_error_messages) do
- ["Name can't be blank", 'Unitary price must be greater than 0', 'Bulk price must be greater than 0',
- 'Available quantity must be greater than 0', 'Company must exist']
+ ["can't be blank", 'must be greater than 0', 'must be greater than 0',
+ 'must be greater than 0', 'must exist']
end
let(:desired_error_status) { 422 }
let(:expected_text) do
diff --git a/spec/requests/products_controller/update_spec.rb b/spec/requests/products_controller/update_spec.rb
index f916d6a..c84c5bd 100644
--- a/spec/requests/products_controller/update_spec.rb
+++ b/spec/requests/products_controller/update_spec.rb
@@ -19,8 +19,8 @@ RSpec.describe 'PUT /api/products/product_id', type: :request do
let(:route) { "/api/products/#{product.public_id}" }
let(:wrong_route) { "/api/products/#{SecureRandom.hex(8)}" }
let(:expected_error_messages) do
- ["Name can't be blank", 'Unitary price must be greater than 0', 'Bulk price must be greater than 0',
- 'Available quantity must be greater than 0', 'Company must exist']
+ ["can't be blank", 'must be greater than 0', 'must be greater than 0',
+ 'must be greater than 0', 'must exist']
end
let(:desired_error_status) { 422 }
let(:expected_text) do
diff --git a/spec/requests/user_accounts_controller/create_spec.rb b/spec/requests/user_accounts_controller/create_spec.rb
index a45e02b..7b70268 100644
--- a/spec/requests/user_accounts_controller/create_spec.rb
+++ b/spec/requests/user_accounts_controller/create_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe 'POST /api/user_accounts', type: :request do
let(:headers) { {} }
let(:route) { '/api/user_accounts' }
let(:expected_error_messages) do
- ["Password can't be blank", 'Email is invalid', "First name can't be blank", "Last name can't be blank"]
+ ["can't be blank", 'is invalid', "can't be blank", "can't be blank"]
end
let(:desired_error_status) { 422 }
let(:expected_text) { %w[token refresh] }
diff --git a/spec/requests/user_accounts_controller/update_spec.rb b/spec/requests/user_accounts_controller/update_spec.rb
index fcfb28e..e26f819 100644
--- a/spec/requests/user_accounts_controller/update_spec.rb
+++ b/spec/requests/user_accounts_controller/update_spec.rb
@@ -17,7 +17,7 @@ RSpec.describe 'PUT /api/account', type: :request do
let(:desired_error_status) { 422 }
let(:wrong_params) { { email: 'notanemail', password: '', first_name: '', last_name: '' } }
let(:expected_error_messages) do
- ['Email is invalid', "First name can't be blank", "Last name can't be blank"]
+ ['is invalid', "can't be blank", "can't be blank"]
end
end
end