Skip to content

Commit

Permalink
reviews table complete, schema updated accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Wheeler committed Nov 25, 2019
1 parent 62e8f4b commit cb1e5e7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/models/review.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Review < ApplicationRecord
belongs_to :user
belongs_to :listing

validates :user, presence: true
end
13 changes: 13 additions & 0 deletions db/migrate/20191125105544_create_reviews.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateReviews < ActiveRecord::Migration[5.2]
def change
create_table :reviews do |t|
t.string :title
t.integer :rating
t.text :content
t.references :user, foreign_key: true
t.references :listing, foreign_key: true

t.timestamps
end
end
end
16 changes: 15 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_11_24_155238) do
ActiveRecord::Schema.define(version: 2019_11_25_105544) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -39,6 +39,18 @@
t.index ["user_id"], name: "index_listings_on_user_id"
end

create_table "reviews", force: :cascade do |t|
t.string "title"
t.integer "rating"
t.text "content"
t.bigint "user_id"
t.bigint "listing_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["listing_id"], name: "index_reviews_on_listing_id"
t.index ["user_id"], name: "index_reviews_on_user_id"
end

create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
Expand All @@ -56,4 +68,6 @@
add_foreign_key "bookings", "listings"
add_foreign_key "bookings", "users"
add_foreign_key "listings", "users"
add_foreign_key "reviews", "listings"
add_foreign_key "reviews", "users"
end
7 changes: 7 additions & 0 deletions test/models/review_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class ReviewTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit cb1e5e7

Please sign in to comment.