Skip to content

Commit

Permalink
Added associate line model
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Sieh committed Sep 14, 2010
1 parent 56e7ae5 commit 01e645e
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/models/associate_line.rb
@@ -0,0 +1,6 @@
class AssociateLine < ActiveRecord::Base
belongs_to :exhibitor_associate

validates_presence_of :exhibitor_associate_id, :line, :priority
validates_length_of :line, :maximum => 40, :allow_blank => true
end
1 change: 1 addition & 0 deletions app/models/exhibitor_associate.rb
@@ -1,5 +1,6 @@
class ExhibitorAssociate < ActiveRecord::Base
belongs_to :exhibitor_registration
has_many :associate_lines

validates_presence_of :exhibitor_registration_id, :first_name, :last_name
validates_length_of :first_name, :maximum => 40, :allow_blank => true
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20100914175146_create_associate_lines.rb
@@ -0,0 +1,15 @@
class CreateAssociateLines < ActiveRecord::Migration
def self.up
create_table :associate_lines do |t|
t.integer :exhibitor_associate_id, :null => false
t.string :line, :limit => 40, :null => false
t.integer :priority, :null => false

t.timestamps
end
end

def self.down
drop_table :associate_lines
end
end
10 changes: 9 additions & 1 deletion db/schema.rb
Expand Up @@ -9,7 +9,15 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20100914172844) do
ActiveRecord::Schema.define(:version => 20100914175146) do

create_table "associate_lines", :force => true do |t|
t.integer "exhibitor_associate_id", :null => false
t.string "line", :limit => 40, :null => false
t.integer "priority", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "buyers", :force => true do |t|
t.integer "store_id", :null => false
Expand Down
7 changes: 7 additions & 0 deletions spec/factories/factory_girl_factories.rb
Expand Up @@ -68,3 +68,10 @@
Factory.define :exhibitor_registration do |f|
f.room '12'
end

# Pass in an exhibitor_registration
Factory.define :exhibitor_associate do |f|
f.first_name Factory.next :name
f.last_name Factory.next :name
f.room '101'
end
43 changes: 43 additions & 0 deletions spec/models/associate_line_spec.rb
@@ -0,0 +1,43 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe AssociateLine do
before(:each) do
exhibitor = Factory.create(:exhibitor)
venue = Factory.create(:venue)
coordinator = Factory.create(:coordinator)
show = Factory.create(:show, :venue => venue, :coordinator => coordinator)
@exhibitor_registration = Factory.create(:exhibitor_registration,
:show => show,
:exhibitor => exhibitor)
@exhibitor_associate = Factory.create(:exhibitor_associate,
:exhibitor_registration => @exhibitor_registration)
@associate_line = AssociateLine.new
end

it "should allow valid values to be set" do
@associate_line.exhibitor_associate_id = @exhibitor_associate.id
@associate_line.line = 'a line'
@associate_line.priority = 1

@associate_line.valid?.should be true
end

it "should ensure that all required fields have been specified" do
@associate_line.valid?.should be false
@associate_line.errors.count.should be 3
@associate_line.errors[:exhibitor_associate_id].blank?.should_not be true
@associate_line.errors[:line].blank?.should_not be true
@associate_line.errors[:priority].blank?.should_not be true
end

it "should ensure that the lengths of all the fields are valid" do
@associate_line.exhibitor_associate_id = @exhibitor_associate.id
@associate_line.line = '01234567890123456789012345678901234567890'
@associate_line.priority = 1

@associate_line.valid?.should be false
@associate_line.errors.count.should be 1
@associate_line.errors[:line].blank?.should_not be true
end

end

0 comments on commit 01e645e

Please sign in to comment.