Spec out the basic functionality of Event

Remove the no longer needed functionality of Event and add specs that
define the still needed parts.
This commit is contained in:
Petko Bordjukov 2015-04-17 02:13:10 +03:00
parent cc4f1e9c13
commit 5c612dfb86
2 changed files with 42 additions and 18 deletions

View File

@ -5,24 +5,6 @@ class Event < ActiveRecord::Base
validates :description, presence: true validates :description, presence: true
validates :agreement, acceptance: 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 private
def self.inheritance_column def self.inheritance_column

42
spec/models/event_spec.rb Normal file
View File

@ -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