Adds sponsor model
This commit is contained in:
parent
411deb4c65
commit
e38a654af1
6 changed files with 58 additions and 0 deletions
|
|
@ -33,6 +33,7 @@ class Conference < ActiveRecord::Base
|
||||||
has_many :vpositions, :dependent => :destroy
|
has_many :vpositions, :dependent => :destroy
|
||||||
has_many :vchoices, :dependent => :destroy
|
has_many :vchoices, :dependent => :destroy
|
||||||
has_many :sponsorship_levels, dependent: :destroy
|
has_many :sponsorship_levels, dependent: :destroy
|
||||||
|
has_many :sponsors, dependent: :destroy
|
||||||
|
|
||||||
belongs_to :venue
|
belongs_to :venue
|
||||||
|
|
||||||
|
|
|
||||||
12
app/models/sponsor.rb
Normal file
12
app/models/sponsor.rb
Normal 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
|
||||||
|
|
@ -2,4 +2,5 @@ class SponsorshipLevel < ActiveRecord::Base
|
||||||
attr_accessible :title
|
attr_accessible :title
|
||||||
validates_presence_of :title
|
validates_presence_of :title
|
||||||
belongs_to :conference
|
belongs_to :conference
|
||||||
|
has_many :sponsors
|
||||||
end
|
end
|
||||||
|
|
|
||||||
16
db/migrate/20140605115251_create_sponsors.rb
Normal file
16
db/migrate/20140605115251_create_sponsors.rb
Normal 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
|
||||||
11
spec/factories/sponsors.rb
Normal file
11
spec/factories/sponsors.rb
Normal 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
|
||||||
17
spec/models/sponsor_spec.rb
Normal file
17
spec/models/sponsor_spec.rb
Normal 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue