Skip to content
This repository was archived by the owner on Sep 24, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ gem 'graphiql-rails', '~> 1.4.1'

gem 'uglifier'

gem 'bcrypt'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ GEM
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (7.1.4)
bcrypt (3.1.11)
builder (3.2.3)
byebug (9.0.6)
concurrent-ruby (1.0.4)
Expand Down Expand Up @@ -134,6 +135,7 @@ PLATFORMS
ruby

DEPENDENCIES
bcrypt
byebug
graphiql-rails (~> 1.4.1)
graphql (~> 1.4.3)
Expand Down
3 changes: 3 additions & 0 deletions app/models/film.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ class Film < ApplicationRecord
join_table: 'films_people',
foreign_key: 'film_id',
association_foreign_key: 'person_id'

has_many :ratings
has_many :critics, through: :ratings, source: :user
end
6 changes: 6 additions & 0 deletions app/models/rating.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Rating < ApplicationRecord
belongs_to :user
belongs_to :film

validates_inclusion_of :number, in: 0..5
end
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class User < ApplicationRecord
has_secure_password
has_many :ratings
has_many :rated_films, through: :ratings, source: :film
end
17 changes: 17 additions & 0 deletions db/migrate/20170212195638_create_ratings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CreateRatings < ActiveRecord::Migration[5.0]
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :password_digest
t.timestamps
end

create_table :ratings do |t|
t.belongs_to :user, index: true
t.belongs_to :film, index: true
t.integer :rating
t.timestamps
end
end
end
20 changes: 19 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: 20170211182808) do
ActiveRecord::Schema.define(version: 20170212195638) do

create_table "films", force: :cascade do |t|
t.string "title"
Expand Down Expand Up @@ -103,6 +103,16 @@
t.datetime "updated_at", null: false
end

create_table "ratings", force: :cascade do |t|
t.integer "user_id"
t.integer "film_id"
t.integer "rating"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["film_id"], name: "index_ratings_on_film_id"
t.index ["user_id"], name: "index_ratings_on_user_id"
end

create_table "species", force: :cascade do |t|
t.string "name"
t.string "classification"
Expand Down Expand Up @@ -137,6 +147,14 @@
t.datetime "updated_at", null: false
end

create_table "users", force: :cascade do |t|
t.string "name"
t.string "email"
t.string "password_digest"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "vehicles", force: :cascade do |t|
t.string "name"
t.string "model"
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/ratings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
good-rating:
user: test-user
film: a-new-hope
rating: 5
3 changes: 3 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test-user:
name: xuorig
password_digest: <%= BCrypt::Password.create('averysecurepassword', cost: BCrypt::Engine.cost) %>