From fac65a167abbc5ec17e92517daa83d1d02afc0e9 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Wed, 5 Nov 2014 11:45:04 +0200 Subject: [PATCH] Add missing specs for Tracks, Halls and Slots Document the behaviour of Tracks, Slots and Halls with specs. Leave the association between slots and events pending for now. --- spec/factories/slots.rb | 9 +++++++++ spec/models/hall_spec.rb | 24 ++++++++++++++++++++++++ spec/models/slot_spec.rb | 14 ++++++++++++++ spec/models/track_spec.rb | 5 +++++ 4 files changed, 52 insertions(+) create mode 100644 spec/factories/slots.rb create mode 100644 spec/models/hall_spec.rb create mode 100644 spec/models/slot_spec.rb diff --git a/spec/factories/slots.rb b/spec/factories/slots.rb new file mode 100644 index 0000000..eed6450 --- /dev/null +++ b/spec/factories/slots.rb @@ -0,0 +1,9 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :slot do + starts_at { Time.now } + ends_at { Time.now + 45.minutes } + hall + end +end diff --git a/spec/models/hall_spec.rb b/spec/models/hall_spec.rb new file mode 100644 index 0000000..e1db9a8 --- /dev/null +++ b/spec/models/hall_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +RSpec.describe Hall, :type => :model do + it 'is invalid without a name' do + expect(build(:hall, name: '')).to have_error_on :name + end + + it 'belongs to a conference' do + conference = create :conference + expect(build(:hall, conference_id: conference.id).conference).to eq conference + end + + it 'has many slots' do + hall = create :hall + slot = create :slot, hall: hall + expect(hall.slots).to include slot + end + + it 'destroys all associated slots when destroyed' do + hall = create :hall + create :slot, hall: hall + expect { hall.destroy }.to change { Slot.count }.by(-1) + end +end diff --git a/spec/models/slot_spec.rb b/spec/models/slot_spec.rb new file mode 100644 index 0000000..550c94b --- /dev/null +++ b/spec/models/slot_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe Slot, :type => :model do + it 'belongs to a hall' do + hall = create :hall + expect(build(:slot, hall_id: hall.id).hall).to eq hall + end + + it 'belongs to an event' do + pending 'Events not implemented' + event = create :event + expect(build(:slot, event_id: event.id).event).to eq event + end +end diff --git a/spec/models/track_spec.rb b/spec/models/track_spec.rb index 31c599e..74d8d02 100644 --- a/spec/models/track_spec.rb +++ b/spec/models/track_spec.rb @@ -16,4 +16,9 @@ RSpec.describe Track, :type => :model do expect(build(:track, color: '#000000')).to_not have_error_on :color end end + + it 'belongs to a conference' do + conference = create :conference + expect(build(:track, conference_id: conference.id).conference).to eq conference + end end