Introduce the EventType model

This model will be used to define what types of events will happen
during a conference.
This commit is contained in:
Petko Bordjukov 2015-04-17 03:39:18 +03:00
parent 5c612dfb86
commit 9f0886af1e
4 changed files with 63 additions and 0 deletions

7
app/models/event_type.rb Normal file
View File

@ -0,0 +1,7 @@
class EventType < ActiveRecord::Base
belongs_to :conference
translates :name, :description
validates :name, presence: true, uniqueness: {scope: :conference, message: :must_be_unique_for_the_conference}
validates :description, presence: true
end

View File

@ -0,0 +1,15 @@
class CreateEventTypes < ActiveRecord::Migration
def up
create_table :event_types do |t|
t.references :conference, index: true, foreign_key: true
t.timestamps null: false
end
EventType.create_translation_table! name: :string, description: :text
end
def down
drop_table :event_types
EventType.drop_translation_table!
end
end

View File

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :event_type do
name { |n| "Track #{n}" }
description 'MyText'
conference
end
end

View File

@ -0,0 +1,34 @@
require 'rails_helper'
RSpec.describe EventType, type: :model do
describe 'description' do
it 'must be present' do
expect(build(:event_type, description: nil)).to have_error_on :description
end
it 'is translatable' do
event_type = build(:event_type)
expect(event_type).to have_translatable :description
end
end
describe 'name' do
it 'must be present' do
expect(build(:event_type, name: nil)).to have_error_on :name
expect(build(:event_type, name: '')).to have_error_on :name
end
it 'must be unique for a event_type' do
conference = create :conference
create :event_type, name: 'foo', conference: conference
expect(build(:event_type, name: 'foo', conference: conference)).to have_error_on :name
expect(build(:event_type, name: 'foo', conference: create(:conference))).to_not have_error_on :name
end
it 'is translatable' do
event_type = build(:event_type)
expect(event_type).to have_translatable :name
end
end
end