Adds sponsor model

This commit is contained in:
Gopesh Tulsyan 2014-06-05 17:51:22 +05:30
parent 411deb4c65
commit e38a654af1
6 changed files with 58 additions and 0 deletions

View file

@ -33,6 +33,7 @@ class Conference < ActiveRecord::Base
has_many :vpositions, :dependent => :destroy
has_many :vchoices, :dependent => :destroy
has_many :sponsorship_levels, dependent: :destroy
has_many :sponsors, dependent: :destroy
belongs_to :venue

12
app/models/sponsor.rb Normal file
View file

@ -0,0 +1,12 @@
class Sponsor < ActiveRecord::Base
attr_accessible :name, :description, :website_url, :logo
belongs_to :sponsorship_level
belongs_to :conference
has_attached_file :logo,
styles: { thumb: '100x100>', large: '300x300>' }
validates_attachment_content_type :logo,
content_type: [/jpg/, /jpeg/, /png/, /gif/],
size: { in: 0..500.kilobytes }
validates_presence_of :name, :website_url
end

View file

@ -2,4 +2,5 @@ class SponsorshipLevel < ActiveRecord::Base
attr_accessible :title
validates_presence_of :title
belongs_to :conference
has_many :sponsors
end

View file

@ -0,0 +1,16 @@
class CreateSponsors < ActiveRecord::Migration
def change
create_table :sponsors do |t|
t.string :name
t.text :description
t.string :website_url
t.string :logo_file_name
t.string :logo_content_type
t.integer :logo_file_size
t.datetime :logo_updated_at
t.belongs_to :sponsorship_level
t.belongs_to :conference
t.timestamps
end
end
end

View file

@ -0,0 +1,11 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :sponsor do
name 'Example sponsor'
website_url 'http://www.example.com'
description 'Lorem Ipsum Dolor'
sponsorship_level
conference
end
end

View file

@ -0,0 +1,17 @@
require 'spec_helper'
describe Sponsor do
describe 'validations' do
it 'has a valid factory' do
expect(build(:sponsor)).to be_valid
end
it 'is not valid without a name' do
should validate_presence_of(:name)
end
it 'is not valid without a website url' do
should validate_presence_of(:website_url)
end
end
end