From 6a8b9f8d2d4a2476defd4f3730f4692987de23ce Mon Sep 17 00:00:00 2001 From: nasia Date: Sat, 10 Jun 2017 15:17:19 +0300 Subject: [PATCH] Create tests for models --- app/models/call_for_booth.rb | 2 ++ spec/models/booth_spec.rb | 24 ++++++++++++++++++++++++ spec/models/call_for_booth_spec.rb | 15 +++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 spec/models/booth_spec.rb create mode 100644 spec/models/call_for_booth_spec.rb diff --git a/app/models/call_for_booth.rb b/app/models/call_for_booth.rb index 0f16cdcd..321ca2b9 100644 --- a/app/models/call_for_booth.rb +++ b/app/models/call_for_booth.rb @@ -1,6 +1,8 @@ class CallForBooth < ActiveRecord::Base belongs_to :conference + has_one :conference + validates :start_date, :end_date, :booth_limit, presence: true validate :before_end_of_conference validate :start_date_before_end_date diff --git a/spec/models/booth_spec.rb b/spec/models/booth_spec.rb new file mode 100644 index 00000000..04e6bf3f --- /dev/null +++ b/spec/models/booth_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe 'Booth' do + subject { create(:booth) } + let!(:conference) { create(:conference) } + + describe 'validation' do + it 'has a valid factory' do + expect(build(:booth)).to be_valid + end + + it { is_expected.to validate_presence_of(:conference) } + + it 'is not valid without a title' do + should validate_presence_of(:title) + end + end + + describe 'association' do + it { is_expected.to belong_to(:conference) } + it { is_expected.to have_many(:booth_requests) } + end + +end diff --git a/spec/models/call_for_booth_spec.rb b/spec/models/call_for_booth_spec.rb new file mode 100644 index 00000000..a9a07254 --- /dev/null +++ b/spec/models/call_for_booth_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe CallForBooth do + it 'has a valid factory' do + expect(build(:call_for_booths)).to be_valid + end + + it 'is not valid without a start_date' do + should validate_presence_of(:start_date) + end + + it 'is not valid without an end_date' do + should validate_presence_of(:end_date) + end +end