Complete Lesson 38 Part 1

main
Simon Quigley 7 months ago
parent 38e5234b64
commit 5a1ee09fd3

@ -0,0 +1,2 @@
class GenresController < ApplicationController
end

@ -0,0 +1,2 @@
module GenresHelper
end

@ -0,0 +1,4 @@
class Characterization < ApplicationRecord
belongs_to :movie
belongs_to :genre
end

@ -0,0 +1,6 @@
class Genre < ApplicationRecord
validates :name, presence: true, uniqueness: true
has_many :characterizations, dependent: :destroy
has_many :movies, through: :characterizations
end

@ -12,6 +12,8 @@ class Movie < ApplicationRecord
has_many :reviews, dependent: :destroy
has_many :favorites, dependent: :destroy
has_many :fans, through: :favorites, source: :user
has_many :characterizations, dependent: :destroy
has_many :genres, through: :characterizations
def flop?
total_gross.blank? || total_gross < 225_000_000

@ -1,4 +1,5 @@
Rails.application.routes.draw do
resources :genres
resource :session, only: [:new, :create, :destroy]
resources :users
resources :reviews

@ -0,0 +1,9 @@
class CreateGenres < ActiveRecord::Migration[7.0]
def change
create_table :genres do |t|
t.string :name
t.timestamps
end
end
end

@ -0,0 +1,10 @@
class CreateCharacterizations < ActiveRecord::Migration[7.0]
def change
create_table :characterizations do |t|
t.references :movie, null: false, foreign_key: true
t.references :genre, null: false, foreign_key: true
t.timestamps
end
end
end

19
db/schema.rb generated

@ -10,7 +10,16 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_09_27_123732) do
ActiveRecord::Schema[7.0].define(version: 2023_09_27_130526) do
create_table "characterizations", force: :cascade do |t|
t.integer "movie_id", null: false
t.integer "genre_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["genre_id"], name: "index_characterizations_on_genre_id"
t.index ["movie_id"], name: "index_characterizations_on_movie_id"
end
create_table "favorites", force: :cascade do |t|
t.integer "movie_id", null: false
t.integer "user_id", null: false
@ -20,6 +29,12 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_27_123732) do
t.index ["user_id"], name: "index_favorites_on_user_id"
end
create_table "genres", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "movies", force: :cascade do |t|
t.string "title"
t.string "rating"
@ -52,6 +67,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_27_123732) do
t.boolean "admin", default: false
end
add_foreign_key "characterizations", "genres"
add_foreign_key "characterizations", "movies"
add_foreign_key "favorites", "movies"
add_foreign_key "favorites", "users"
add_foreign_key "reviews", "movies"

@ -0,0 +1,7 @@
require "test_helper"
class GenresControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

@ -0,0 +1,9 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
movie: one
genre: one
two:
movie: two
genre: two

@ -0,0 +1,7 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
two:
name: MyString

@ -0,0 +1,7 @@
require "test_helper"
class CharacterizationTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

@ -0,0 +1,7 @@
require "test_helper"
class GenreTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
Loading…
Cancel
Save