Commit e9c28cd3 by Hoang Phuc Do

RSpec for models

parent 89ae0bfe
FactoryGirl.define do
factory :product_item do
end
end
FactoryGirl.define do
factory :user do
end
end
......@@ -3,8 +3,8 @@ require 'rails_helper'
RSpec.describe Category, type: :model do
describe 'db schema' do
context 'columns' do
it { should have_db_column(:title).of_type(:string) }
it { should have_db_column(:description).of_type(:text) }
it { is_expected.to have_db_column(:title).of_type(:string) }
it { is_expected.to have_db_column(:description).of_type(:text) }
end
end
end
......@@ -3,12 +3,12 @@ require 'rails_helper'
RSpec.describe Order, type: :model do
describe 'db schema' do
context 'columns' do
it { should define_enum_for(:order_status).with(['Pending', 'Done']) }
it { is_expected.to define_enum_for(:order_status).with(['Pending', 'Done']) }
end
end
describe 'associations' do
it { should belong_to(:user) }
it { should have_many(:product_items) }
context 'associations' do
it { is_expected.to belong_to(:user) }
it { is_expected.to have_many(:product_items) }
end
end
require 'rails_helper'
RSpec.describe ProductItem, type: :model do
describe 'db schema' do
context 'columns' do
it { is_expected.to have_db_column(:quantity).of_type(:integer) }
end
end
describe 'validations' do
it { is_expected.to validate_numericality_of(:quantity).is_greater_than(0) }
end
describe 'associations' do
it { is_expected.to belong_to(:order) }
it { is_expected.to belong_to(:product) }
end
end
......@@ -3,22 +3,22 @@ require 'rails_helper'
RSpec.describe Product, type: :model do
describe 'db schema' do
context 'columns' do
it { should have_db_column(:title).of_type(:string) }
it { should have_db_column(:description).of_type(:text) }
it { should have_db_column(:sku).of_type(:string) }
it { should have_db_column(:quantity).of_type(:integer) }
it { should have_db_column(:price).of_type(:decimal) }
it { is_expected.to have_db_column(:title).of_type(:string) }
it { is_expected.to have_db_column(:description).of_type(:text) }
it { is_expected.to have_db_column(:sku).of_type(:string) }
it { is_expected.to have_db_column(:quantity).of_type(:integer) }
it { is_expected.to have_db_column(:price).of_type(:decimal) }
end
end
describe 'validations' do
it { should validate_presence_of(:title) }
it { should validate_presence_of (:price) }
it { should validate_numericality_of (:price) }
context 'validations' do
it { is_expected.to validate_presence_of(:title) }
it { is_expected.to validate_presence_of (:price) }
it { is_expected.to validate_numericality_of (:price) }
end
describe 'associations' do
it { should belong_to(:user) }
it { should belong_to(:category) }
context 'associations' do
it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:category) }
end
end
require 'rails_helper'
RSpec.describe User, type: :model do
describe 'db schema' do
context 'columns' do
it { is_expected.to have_db_column(:first_name) }
it { is_expected.to have_db_column(:last_name) }
it { is_expected.to have_db_column(:email) }
it { is_expected.to have_db_column(:username) }
end
end
context 'validations' do
it { is_expected.to validate_presence_of(:email) }
end
context 'associations' do
it { is_expected.to have_many(:orders) }
it { is_expected.to have_many(:products) }
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment