From b63f3fa7c9567cf7f554a9b371698f6f271769d5 Mon Sep 17 00:00:00 2001 From: Gopesh Tulsyan Date: Thu, 5 Jun 2014 16:27:51 +0530 Subject: [PATCH 1/2] Adds organization model --- app/models/organization.rb | 11 ++++++ .../20140605101748_create_organizations.rb | 16 +++++++++ db/schema.rb | 34 +++++++++++++------ spec/factories/organizations.rb | 11 ++++++ spec/models/organization_spec.rb | 22 ++++++++++++ 5 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 app/models/organization.rb create mode 100644 db/migrate/20140605101748_create_organizations.rb create mode 100644 spec/factories/organizations.rb create mode 100644 spec/models/organization_spec.rb 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 From 62c78641c2ca7bf93575e077e1807a39131e3c81 Mon Sep 17 00:00:00 2001 From: Gopesh Tulsyan Date: Thu, 5 Jun 2014 16:43:55 +0530 Subject: [PATCH 2/2] removed phone_number and email --- app/models/organization.rb | 4 ++-- db/migrate/20140605101748_create_organizations.rb | 2 -- db/schema.rb | 2 -- spec/factories/organizations.rb | 4 +--- spec/models/organization_spec.rb | 4 ++-- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/app/models/organization.rb b/app/models/organization.rb index 3434f59f..cb44d66f 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -1,5 +1,5 @@ class Organization < ActiveRecord::Base - attr_accessible :name, :logo, :description, :phone_number, :email, :website_url + attr_accessible :name, :logo, :description, :website_url has_attached_file :logo, styles: { thumb: '100x100>', large: '300x300>' } @@ -7,5 +7,5 @@ class Organization < ActiveRecord::Base content_type: [/jpg/, /jpeg/, /png/, /gif/], size: { in: 0..500.kilobytes } validates_presence_of :name, :website_url - validates_uniqueness_of :email + validates_uniqueness_of :website_url end diff --git a/db/migrate/20140605101748_create_organizations.rb b/db/migrate/20140605101748_create_organizations.rb index bfc37329..1a1c43c2 100644 --- a/db/migrate/20140605101748_create_organizations.rb +++ b/db/migrate/20140605101748_create_organizations.rb @@ -2,8 +2,6 @@ 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 diff --git a/db/schema.rb b/db/schema.rb index bbef9dc1..c985fb9d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -188,8 +188,6 @@ ActiveRecord::Schema.define(version: 20140605101748) do 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" diff --git a/spec/factories/organizations.rb b/spec/factories/organizations.rb index 4c8a5ad4..98d9a628 100644 --- a/spec/factories/organizations.rb +++ b/spec/factories/organizations.rb @@ -3,9 +3,7 @@ FactoryGirl.define do factory :organization do name 'Example organization' - sequence(:email) { |n| "example#{n}@example.com" } - website_url 'www.esxample.com' + sequence(:website_url) { |n| "example#{n}@example.com" } description 'Lorem Ipsum Dolor' - phone_number '900099009' end end diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb index 1a6dbc78..414a225b 100644 --- a/spec/models/organization_spec.rb +++ b/spec/models/organization_spec.rb @@ -15,8 +15,8 @@ describe Organization do should validate_presence_of(:website_url) end - it 'is not valid with a duplicate email' do - should validate_uniqueness_of(:email) + it 'is not valid with a duplicate website_url' do + should validate_uniqueness_of(:website_url) end end end