From 5c612dfb86d3938f2c4b34bfe314f15799042ecf Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Fri, 17 Apr 2015 02:13:10 +0300 Subject: [PATCH] Spec out the basic functionality of Event Remove the no longer needed functionality of Event and add specs that define the still needed parts. --- app/models/event.rb | 18 ----------------- spec/models/event_spec.rb | 42 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 spec/models/event_spec.rb diff --git a/app/models/event.rb b/app/models/event.rb index d13e3af..27a26f7 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -5,24 +5,6 @@ class Event < ActiveRecord::Base validates :description, presence: true validates :agreement, acceptance: true - belongs_to :track - has_one :conference, through: :track - belongs_to :user # XXX: Transition to candidate_speaker - belongs_to :candidate_speaker, class_name: 'User', foreign_key: 'user_id' - has_and_belongs_to_many :speakers, class_name: 'SpeakerProfile' - - enum state: [:undecided, :approved, :rejected, :backup] - - scope :confirmed, -> { where.not confirmed_at: nil } - - # XXX: this belongs in a decorator - STATE_TO_GLYPH = {undecided: 'question-sign', rejected: 'remove', approved: 'ok', backup: 'retweet'} - STATE_TO_CLASS = {undecided: 'warning', rejected: 'danger', approved: 'success', backup: 'info'} - - def confirmed? - !!confirmed_at - end - private def self.inheritance_column diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb new file mode 100644 index 0000000..91fe587 --- /dev/null +++ b/spec/models/event_spec.rb @@ -0,0 +1,42 @@ +require 'rails_helper' + +describe Event, type: :model do + let(:event) { build :event } + + it 'is invalid if the event agrement is not accepted' do + event.agreement = false + expect(event).to have_error_on :agreement + end + + it 'is invalid without a title' do + event.title = '' + expect(event).to have_error_on :title + end + + describe 'length' do + it 'must be present' do + event.length = '' + expect(event).to have_error_on :length + end + + it 'must be a number' do + event.length = 'foo' + expect(event).to have_error_on :length + end + + it 'must be larger than zero' do + event.length = '-10' + expect(event).to have_error_on :length + end + end + + it 'is invalid without an abstract' do + event.abstract = '' + expect(event).to have_error_on :abstract + end + + it 'is invalid without a description' do + event.description = '' + expect(event).to have_error_on :description + end +end