Conversation
…table relationshps
Match2 constructor media ranker
Media RankerWhat We're Looking For
|
| Rails.application.routes.draw do | ||
|
|
||
| root 'works#main' | ||
| resources :users |
There was a problem hiding this comment.
Do you need the full CRUD routes for users? You're not using :edit or :destroy for example.
| @@ -0,0 +1,5 @@ | |||
| class User < ApplicationRecord | |||
| has_many :works | |||
There was a problem hiding this comment.
No validations? Username can be blank? What about requiring unique usernames?
This isn't essential, but something to think about.
| belongs_to :user | ||
| belongs_to :work | ||
|
|
||
| validates :user_id, presence: true, uniqueness: { scope: :work, message: "You can only add one vote per work"} |
There was a problem hiding this comment.
Since a vote belongs to a user by default user_id is required. The uniqueness of combining user_id and work_id is good. The custom message is great!
| has_many :votes, dependent: :destroy | ||
| # has_many :users, through :votes | ||
|
|
||
| validates :title, presence: true, uniqueness: {scope: :category} |
There was a problem hiding this comment.
I like the uniqueness using the scope category here.
| validates :publication_year, numericality: true, length: {is: 4} | ||
| validates :creator, presence: true | ||
|
|
||
| def self.sort_by_category(category) |
There was a problem hiding this comment.
The name sort_by_category doesn't sound right since this method doesn't really do sorting. Instead it does filtering.
| end | ||
|
|
||
| it 'can only be voted on by a unique user once' do | ||
| # first_vote = Vote.first |
There was a problem hiding this comment.
I would suggest here, creating a new vote which is identical to one from your fixtures.
| it 'must have a publication_year with a 4 integers' do | ||
| work.publication_year = 0 | ||
| # Arrange | ||
| work.publication_year += 999 |
| expect(poodr.errors.messages).must_include :title | ||
| end | ||
| end | ||
|
|
There was a problem hiding this comment.
No test for category being present?
| # below each fixture, per the syntax in the comments below | ||
| # | ||
| one: | ||
| user_id: 1 |
There was a problem hiding this comment.
You should use the nicknames of existing fixtures in users.yml and works.yml
| category: movie | ||
| description: magical movie | ||
|
|
||
|
|
Media Ranker
Congratulations! You're submitting your assignment!
Comprehension Questions
sessionandflash? What is the difference between them?