diff --git a/app/models/conference.rb b/app/models/conference.rb index 558fa349..54ea9f33 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -42,7 +42,7 @@ class Conference < ActiveRecord::Base has_many :vchoices, :dependent => :destroy has_many :sponsorship_levels, dependent: :destroy has_many :sponsors, dependent: :destroy - + has_many :photos, dependent: :destroy belongs_to :venue accepts_nested_attributes_for :rooms, :reject_if => proc {|r| r["name"].blank?}, :allow_destroy => true diff --git a/app/models/photo.rb b/app/models/photo.rb new file mode 100644 index 00000000..22a8d9c2 --- /dev/null +++ b/app/models/photo.rb @@ -0,0 +1,11 @@ +class Photo < ActiveRecord::Base + attr_accessible :picture, :description + belongs_to :conference + validates_presence_of :picture + has_attached_file :picture, + styles: { thumb: '100x100>', large: '300x300>' } + + validates_attachment_content_type :picture, + content_type: [/jpg/, /jpeg/, /png/, /gif/], + size: { in: 0..500.kilobytes } +end diff --git a/db/migrate/20140610064046_create_photos.rb b/db/migrate/20140610064046_create_photos.rb new file mode 100644 index 00000000..846b7934 --- /dev/null +++ b/db/migrate/20140610064046_create_photos.rb @@ -0,0 +1,13 @@ +class CreatePhotos < ActiveRecord::Migration + def change + create_table :photos do |t| + t.text :description + t.string :picture_file_name + t.string :picture_content_type + t.integer :picture_file_size + t.datetime :picture_updated_at + t.belongs_to :conference + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 557c2177..8e5a3c61 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -245,6 +245,17 @@ ActiveRecord::Schema.define(version: 20140618062623) do t.string "languages" end + create_table "photos", force: true do |t| + t.text "description" + t.string "picture_file_name" + t.string "picture_content_type" + t.integer "picture_file_size" + t.datetime "picture_updated_at" + t.integer "conference_id" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "qanswers", force: true do |t| t.integer "question_id" t.integer "answer_id" diff --git a/spec/factories/photos.rb b/spec/factories/photos.rb new file mode 100644 index 00000000..aa9f0f96 --- /dev/null +++ b/spec/factories/photos.rb @@ -0,0 +1,12 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :photo do + picture_file_name 'rails.png' + picture_content_type 'image/png' + picture_file_size '1024' + picture_updated_at DateTime.now + description 'Lorem Ipsum Dolor' + conference + end +end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb new file mode 100644 index 00000000..cf70fc7c --- /dev/null +++ b/spec/models/photo_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' + +describe Photo do + describe 'validations' do + + it 'has a valid factory' do + expect(build(:photo)).to be_valid + end + + it 'is not valid without a picture' do + should validate_presence_of(:picture) + end + end +end