From 3d9ac5a85f52151d2ac9e7c780758e732c83a08e Mon Sep 17 00:00:00 2001 From: nasia Date: Tue, 30 May 2017 13:05:13 +0300 Subject: [PATCH] add relationships for booths --- app/models/booth.rb | 5 +++++ app/models/booth_request.rb | 4 ++++ app/models/conference.rb | 1 + app/models/user.rb | 4 +++- db/migrate/20170530112510_create_booth_requests.rb | 11 +++++++++++ db/schema.rb | 13 ++++++++++++- test/factories/booth_requests.rb | 7 +++++++ test/models/booth_request_test.rb | 7 +++++++ 8 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 app/models/booth_request.rb create mode 100644 db/migrate/20170530112510_create_booth_requests.rb create mode 100644 test/factories/booth_requests.rb create mode 100644 test/models/booth_request_test.rb diff --git a/app/models/booth.rb b/app/models/booth.rb index f1b6fa8d..e9d8dd7c 100644 --- a/app/models/booth.rb +++ b/app/models/booth.rb @@ -1,2 +1,7 @@ class Booth < ActiveRecord::Base + belongs_to :conference + has_many :booth_requests + has_many :users, through: :booth_requests + + validate :title, presence: true end diff --git a/app/models/booth_request.rb b/app/models/booth_request.rb new file mode 100644 index 00000000..c0b8802e --- /dev/null +++ b/app/models/booth_request.rb @@ -0,0 +1,4 @@ +class BoothRequest < ActiveRecord::Base + belongs_to :booth + belongs_to :user +end diff --git a/app/models/conference.rb b/app/models/conference.rb index 1c4ccc73..6a07181b 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -22,6 +22,7 @@ class Conference < ActiveRecord::Base has_many :supporters, through: :ticket_purchases, source: :user has_many :tickets, dependent: :destroy has_many :resources, dependent: :destroy + has_many :booths, dependent: :destroy has_many :lodgings, dependent: :destroy has_many :registrations, dependent: :destroy diff --git a/app/models/user.rb b/app/models/user.rb index a63d721e..81a83c43 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -50,11 +50,13 @@ class User < ActiveRecord::Base has_many :votes, dependent: :destroy has_many :voted_events, through: :votes, source: :events has_many :subscriptions, dependent: :destroy + has_many :booth_requests + has_many :booths, through: :users_booths accepts_nested_attributes_for :roles scope :admin, -> { where(is_admin: true) } scope :active, -> { where(is_disabled: false) } - + validates :email, presence: true validates :username, diff --git a/db/migrate/20170530112510_create_booth_requests.rb b/db/migrate/20170530112510_create_booth_requests.rb new file mode 100644 index 00000000..75e73a93 --- /dev/null +++ b/db/migrate/20170530112510_create_booth_requests.rb @@ -0,0 +1,11 @@ +class CreateBoothRequests < ActiveRecord::Migration + def change + create_table :booth_requests do |t| + t.references :booth, index: true, foreign_key: true + t.references :user, index: true, foreign_key: true + t.string :role + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 4bfb9c2d..9d06ade8 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: 20170516190048) do +ActiveRecord::Schema.define(version: 20170530112510) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -31,6 +31,17 @@ ActiveRecord::Schema.define(version: 20170516190048) do t.datetime "updated_at" end + create_table "booth_requests", force: :cascade do |t| + t.integer "booth_id" + t.integer "user_id" + t.string "role" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "booth_requests", ["booth_id"], name: "index_booth_requests_on_booth_id" + add_index "booth_requests", ["user_id"], name: "index_booth_requests_on_user_id" + create_table "booths", force: :cascade do |t| t.string "title" t.text "description" diff --git a/test/factories/booth_requests.rb b/test/factories/booth_requests.rb new file mode 100644 index 00000000..9a035c3c --- /dev/null +++ b/test/factories/booth_requests.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :booth_request do + booth nil + user nil + role "MyString" + end +end diff --git a/test/models/booth_request_test.rb b/test/models/booth_request_test.rb new file mode 100644 index 00000000..c775f191 --- /dev/null +++ b/test/models/booth_request_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class BoothRequestTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end