diff --git a/app/models/organization.rb b/app/models/organization.rb new file mode 100644 index 00000000..3434f59f --- /dev/null +++ b/app/models/organization.rb @@ -0,0 +1,11 @@ +class Organization < ActiveRecord::Base + attr_accessible :name, :logo, :description, :phone_number, :email, :website_url + 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 + validates_uniqueness_of :email +end diff --git a/db/migrate/20140605101748_create_organizations.rb b/db/migrate/20140605101748_create_organizations.rb new file mode 100644 index 00000000..bfc37329 --- /dev/null +++ b/db/migrate/20140605101748_create_organizations.rb @@ -0,0 +1,16 @@ +class CreateOrganizations < ActiveRecord::Migration + def change + create_table :organizations do |t| + t.string :name + t.string :email + t.string :phone_number + t.string :website_url + t.text :description + t.string :logo_file_name + t.string :logo_content_type + t.integer :logo_file_size + t.datetime :logo_updated_at + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index cdaa250a..bbef9dc1 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: 20140604142949) do +ActiveRecord::Schema.define(version: 20140605101748) do create_table "answers", force: true do |t| t.string "title" @@ -50,15 +50,15 @@ ActiveRecord::Schema.define(version: 20140604142949) 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" @@ -186,6 +186,20 @@ ActiveRecord::Schema.define(version: 20140604142949) do t.integer "event_id" end + create_table "organizations", force: true do |t| + t.string "name" + t.string "email" + t.string "phone_number" + t.string "website_url" + t.text "description" + t.string "logo_file_name" + t.string "logo_content_type" + t.integer "logo_file_size" + t.datetime "logo_updated_at" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "people", force: true do |t| t.string "guid", null: false t.string "first_name", default: "" @@ -308,9 +322,9 @@ ActiveRecord::Schema.define(version: 20140604142949) 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/organizations.rb b/spec/factories/organizations.rb new file mode 100644 index 00000000..4c8a5ad4 --- /dev/null +++ b/spec/factories/organizations.rb @@ -0,0 +1,11 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :organization do + name 'Example organization' + sequence(:email) { |n| "example#{n}@example.com" } + website_url 'www.esxample.com' + description 'Lorem Ipsum Dolor' + phone_number '900099009' + end +end diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb new file mode 100644 index 00000000..1a6dbc78 --- /dev/null +++ b/spec/models/organization_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe Organization do + describe 'validations' do + + it 'has a valid factory' do + expect(build(:organization)).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 + + it 'is not valid with a duplicate email' do + should validate_uniqueness_of(:email) + end + end +end