mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
commit
983c08c8e4
6 changed files with 62 additions and 1 deletions
|
|
@ -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
11
app/models/photo.rb
Normal 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
|
||||
13
db/migrate/20140610064046_create_photos.rb
Normal file
13
db/migrate/20140610064046_create_photos.rb
Normal 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
|
||||
11
db/schema.rb
11
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"
|
||||
|
|
|
|||
12
spec/factories/photos.rb
Normal file
12
spec/factories/photos.rb
Normal 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
14
spec/models/photo_spec.rb
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue