From d9818f274905a7c4e374fe5114809a72ea46bddc Mon Sep 17 00:00:00 2001 From: Gopesh Tulsyan Date: Tue, 10 Jun 2014 12:43:15 +0530 Subject: [PATCH] Added carousel model --- app/models/conference.rb | 2 +- app/models/photo.rb | 11 ++++++++ db/migrate/20140610064046_create_photos.rb | 13 +++++++++ db/schema.rb | 31 +++++++++++++++------- spec/factories/photos.rb | 12 +++++++++ spec/models/photo_spec.rb | 14 ++++++++++ 6 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 app/models/photo.rb create mode 100644 db/migrate/20140610064046_create_photos.rb create mode 100644 spec/factories/photos.rb create mode 100644 spec/models/photo_spec.rb diff --git a/app/models/conference.rb b/app/models/conference.rb index b49a901e..467ab3dd 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -31,7 +31,7 @@ class Conference < ActiveRecord::Base has_many :vdays, :dependent => :destroy has_many :vpositions, :dependent => :destroy has_many :vchoices, :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 2ef5c751..8ad51777 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140605125153) do +ActiveRecord::Schema.define(version: 20140610064046) do create_table "answers", force: true do |t| t.string "title" @@ -50,15 +50,15 @@ ActiveRecord::Schema.define(version: 20140605125153) do add_index "comments", ["user_id"], name: "index_comments_on_user_id" create_table "conferences", force: true do |t| - t.string "guid", null: false - t.string "title", null: false - t.string "short_title", null: false + t.string "guid", null: false + t.string "title", null: false + t.string "short_title", null: false t.string "social_tag" - t.string "contact_email", null: false - t.string "timezone", null: false + t.string "contact_email", null: false + t.string "timezone", null: false t.string "html_export_path" - t.date "start_date", null: false - t.date "end_date", null: false + t.date "start_date", null: false + t.date "end_date", null: false t.integer "venue_id" t.datetime "created_at" t.datetime "updated_at" @@ -209,6 +209,17 @@ ActiveRecord::Schema.define(version: 20140605125153) 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" @@ -308,9 +319,9 @@ ActiveRecord::Schema.define(version: 20140605125153) do end create_table "tracks", force: true do |t| - t.string "guid", null: false + t.string "guid", null: false t.integer "conference_id" - t.string "name", null: false + t.string "name", null: false t.text "description" t.string "color" t.datetime "created_at" 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