summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/product.rb8
-rw-r--r--spec/models/product_spec.rb10
2 files changed, 17 insertions, 1 deletions
diff --git a/app/models/product.rb b/app/models/product.rb
index d12cd41..72d7f33 100644
--- a/app/models/product.rb
+++ b/app/models/product.rb
@@ -11,6 +11,14 @@
class Product < ApplicationRecord
belongs_to :company
+ validates :name, presence: true
+ validates :unitary_price, presence: true
+ validates :unitary_price, comparison: { greater_than: 0 }
+ validates :bulk_price, presence: true
+ validates :bulk_price, comparison: { greater_than: 0 }
+ validates :available_quantity, presence: true
+ validates :available_quantity, comparison: { greater_than: 0 }
+
has_one_attached :picture
serialize :categories, Array
diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb
index f22fbfd..b3790fe 100644
--- a/spec/models/product_spec.rb
+++ b/spec/models/product_spec.rb
@@ -1,5 +1,13 @@
+# frozen_string_literal: true
+
require 'rails_helper'
RSpec.describe Product, type: :model do
- pending "add some examples to (or delete) #{__FILE__}"
+ it { should validate_presence_of(:name) }
+ it { should validate_presence_of(:unitary_price) }
+ it { should validate_presence_of(:bulk_price) }
+ it { should validate_presence_of(:available_quantity) }
+ it { should have_one_attached(:picture) }
+ it { should belong_to(:company) }
+ it { should serialize(:categories) }
end