jeudi 15 février 2018

how can i test my job model and what are the missing things

Models/job.rb

class Job < ApplicationRecord
    belongs_to :user
    belongs_to :category
  belongs_to :company
  accepts_nested_attributes_for :company

  has_attached_file :image, styles: {  medium: "800x800>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
  validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
  validates :title, presence: true
  validates :title, length: {minimum: 5, maximum: 35}
  validates :description,length: {minimum: 10, maximum: 400}, presence: true

require 'rails_helper'

rspec/models/job_spec.rb

RSpec.configure do |config|
  config.include(Shoulda::Matchers::ActiveModel, type: :model)
  config.include(Shoulda::Matchers::ActiveRecord, type: :model)
end

RSpec.describe Job, type: :model do

      it { should belong_to(:user) }
      it { should belong_to(:category) }
      it { should belong_to(:company) }
      it { is_expected.to validate_presence_of(:title) }
      it { is_expected.to validate_presence_of(:description) }
      it { should accept_nested_attributes_for(:company) }
      it { should validate_length_of(:description).is_at_least(10) }
      it { should validate_length_of(:description).is_at_most(400) }
      it { should validate_length_of(:title).is_at_least(5) }
      it { should validate_length_of(:title).is_at_most(35) }
      it { should have_db_column(:user_id) }
      it { should have_db_column(:title) }
      it { should have_db_column(:description) }
      it { should have_db_column(:jobclosedate) }
      it { should have_db_column(:company) }
      it { should have_db_column(:id) }
      it do
                 should allow_value('2013-01-01').
                   for(:jobclosedate).
                  on(:create)
              end
end

i'm used to test job model(rspec), i write few unit test scenario for job models. what are the missing things that i need to add. could you please help me to write better unit test using rspec.

Aucun commentaire:

Enregistrer un commentaire