Skip to content

Commit

Permalink
Create Meeting::Content model
Browse files Browse the repository at this point in the history
  • Loading branch information
sobrinho committed Dec 30, 2009
1 parent ffef6ba commit d088038
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/meeting.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Meeting < ActiveRecord::Base
# Associations
belongs_to :user
has_many :content, :class_name => 'Meeting::Content'

# Validations
validates_presence_of :user, :name, :description
Expand Down
20 changes: 20 additions & 0 deletions app/models/meeting/content.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Meeting::Content < ActiveRecord::Base
# Table name
set_table_name 'meeting_content'

# Associations
belongs_to :meeting

# Validations
validates_presence_of :meeting, :name, :url

with_options :allow_blank => true do |c|
c.validates_length_of :name, :in => 1..255
# FIXME: c.validates_as_uri :url
end

def to_s
name
end
end

18 changes: 18 additions & 0 deletions db/migrate/20091230223150_create_meeting_content.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class CreateMeetingContent < ActiveRecord::Migration
def self.up
create_table :meeting_content do |t|
t.references :meeting
t.string :name
t.string :url

t.timestamps
end

add_index :meeting_content, :meeting_id
end

def self.down
drop_table :meeting_content
end
end

6 changes: 6 additions & 0 deletions spec/blueprints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@
description 'An example of meeting'
end

Meeting::Content.blueprint do
meeting { Meeting.make }
name 'Video'
url 'http://www.youtube.com/watch?v=xxx'
end

32 changes: 32 additions & 0 deletions spec/models/meeting/content_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'

describe Meeting::Content do
before do
@meeting_content = Meeting::Content.make
end

# Database
should_have_column :meeting_id, :type => :integer
should_have_columns :name, :url, :type => :string
should_have_index :meeting_id

# Associations
should_belong_to :meeting

# Validations
should_validate_presence_of :meeting, :name, :url

with_options :allow_blank => true do |c|
c.should_validate_length_of :name, :in => 1..255
# FIXME: c.should_validate_as_uri :url
end

it 'table_name should be meeting_content' do
Meeting::Content.table_name.should be_eql('meeting_content')
end

it 'to_s should return name' do
@meeting_content.to_s.should be_eql(@meeting_content.name)
end
end

1 change: 1 addition & 0 deletions spec/models/meeting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# Associations
should_belong_to :user
should_have_many :content, :class_name => 'Meeting::Content'

# Validations
should_validate_presence_of :user, :name, :description
Expand Down

0 comments on commit d088038

Please sign in to comment.