diff --git a/app/models/meeting.rb b/app/models/meeting.rb index df4ce2a..b8cc287 100644 --- a/app/models/meeting.rb +++ b/app/models/meeting.rb @@ -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 diff --git a/app/models/meeting/content.rb b/app/models/meeting/content.rb new file mode 100644 index 0000000..534eb3f --- /dev/null +++ b/app/models/meeting/content.rb @@ -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 + diff --git a/db/migrate/20091230223150_create_meeting_content.rb b/db/migrate/20091230223150_create_meeting_content.rb new file mode 100644 index 0000000..755c661 --- /dev/null +++ b/db/migrate/20091230223150_create_meeting_content.rb @@ -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 + diff --git a/spec/blueprints.rb b/spec/blueprints.rb index 1d76861..b48335c 100644 --- a/spec/blueprints.rb +++ b/spec/blueprints.rb @@ -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 + diff --git a/spec/models/meeting/content_spec.rb b/spec/models/meeting/content_spec.rb new file mode 100644 index 0000000..a31ab7d --- /dev/null +++ b/spec/models/meeting/content_spec.rb @@ -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 + diff --git a/spec/models/meeting_spec.rb b/spec/models/meeting_spec.rb index 62ccdf3..f27937f 100644 --- a/spec/models/meeting_spec.rb +++ b/spec/models/meeting_spec.rb @@ -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