diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb new file mode 100644 index 0000000..b3d77cc --- /dev/null +++ b/app/controllers/reviews_controller.rb @@ -0,0 +1,2 @@ +class ReviewsController < ApplicationController +end diff --git a/app/helpers/reviews_helper.rb b/app/helpers/reviews_helper.rb new file mode 100644 index 0000000..682b7b1 --- /dev/null +++ b/app/helpers/reviews_helper.rb @@ -0,0 +1,2 @@ +module ReviewsHelper +end diff --git a/app/models/review.rb b/app/models/review.rb new file mode 100644 index 0000000..e16e5e1 --- /dev/null +++ b/app/models/review.rb @@ -0,0 +1,3 @@ +class Review < ApplicationRecord + belongs_to :movie +end diff --git a/config/routes.rb b/config/routes.rb index 32474ba..7b6f8ff 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :reviews root "movies#index" resources :movies diff --git a/db/migrate/20230926165701_create_reviews.rb b/db/migrate/20230926165701_create_reviews.rb new file mode 100644 index 0000000..cc9d7cb --- /dev/null +++ b/db/migrate/20230926165701_create_reviews.rb @@ -0,0 +1,12 @@ +class CreateReviews < ActiveRecord::Migration[7.0] + def change + create_table :reviews do |t| + t.string :name + t.integer :stars + t.text :comment + t.references :movie, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index d292225..b208283 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_09_25_205851) do +ActiveRecord::Schema[7.0].define(version: 2023_09_26_165701) do create_table "movies", force: :cascade do |t| t.string "title" t.string "rating" @@ -24,4 +24,15 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_25_205851) do t.string "image_file_name" end + create_table "reviews", force: :cascade do |t| + t.string "name" + t.integer "stars" + t.text "comment" + t.integer "movie_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["movie_id"], name: "index_reviews_on_movie_id" + end + + add_foreign_key "reviews", "movies" end diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb new file mode 100644 index 0000000..fed8577 --- /dev/null +++ b/test/controllers/reviews_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class ReviewsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml new file mode 100644 index 0000000..8e16172 --- /dev/null +++ b/test/fixtures/reviews.yml @@ -0,0 +1,13 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + stars: 1 + comment: MyText + movie: one + +two: + name: MyString + stars: 1 + comment: MyText + movie: two diff --git a/test/models/review_test.rb b/test/models/review_test.rb new file mode 100644 index 0000000..04f9c86 --- /dev/null +++ b/test/models/review_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class ReviewTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end