Merge pull request #219 from gopesht/carousel_model

Added Photo model
This commit is contained in:
Gopesh Tulsyan 2014-06-19 21:27:18 +05:30
commit 983c08c8e4
6 changed files with 62 additions and 1 deletions

View file

@ -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

11
app/models/photo.rb Normal file
View file

@ -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

View file

@ -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

View file

@ -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"

12
spec/factories/photos.rb Normal file
View file

@ -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

14
spec/models/photo_spec.rb Normal file
View file

@ -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