Ampers: Nora Peters#35
Conversation
…e, from welcome#index
…te button. implements vote_count method in work model.
…_to upvote button on works#index view with post request
…ow controller action and view + #pretty_date app helper method
…te controller actions for works
… #top_ranked to order works by most votes
Media RankerWhat We're Looking For
|
| <meta charset="utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
|
|
||
| <title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title> |
There was a problem hiding this comment.
Just a suggestion, changing "untitled" to a title for your site.
| post '/login', to: 'sessions#create', as: 'login' | ||
| delete '/login', to: 'sessions#destroy', as: 'logout' | ||
|
|
||
| resources :users |
There was a problem hiding this comment.
Do you need destroy, edit, update actions for the users controller?
| session[:user_id] = @user.id | ||
| flash[:success] = "Welcome back #{@user.username}" | ||
| else | ||
| @user = User.create username: params[:user][:username] |
There was a problem hiding this comment.
You need to check if the create method worked! I tried to log in with a blank username and it said, "Weclome"!
| <section class="flash"> | ||
| <% flash.each do |name, message| %> | ||
| <section class="callout <%= name %>"> | ||
| <% if name == :alert %> |
There was a problem hiding this comment.
This should be
<% if name == "alert" %>|
|
||
| validates :user_id, presence: true | ||
| validates :work_id, presence: true | ||
| validates :work_id, uniqueness: { scope: :user_id } |
There was a problem hiding this comment.
along with the line below, this is redundant.
| end | ||
|
|
||
| def self.top_ranked | ||
| left_joins(:votes) |
| user.must_respond_to :username | ||
| users(:chad).username.must_equal "Chad" | ||
|
|
||
| user.valid?.must_equal false |
There was a problem hiding this comment.
You should also test the username uniqueness.
| votes(:vote_five).user.id.must_equal todd.id | ||
| end | ||
|
|
||
| it 'must have one work' do |
There was a problem hiding this comment.
You should also test that you can't create duplicate votes.
| work.valid?.must_equal false | ||
| work.errors.must_include :publication_year | ||
|
|
||
| work = Work.create(category: 'book', title: 'work', publication_year: 1999) |
There was a problem hiding this comment.
You should also try this with a 5 digit publication year.
| end | ||
|
|
||
| describe "#top_ranked" do | ||
| it "must return the work with highest number of votes" do |
There was a problem hiding this comment.
You should also test and see what happens when there are no works and when there are no votes.
Media Ranker
Congratulations! You're submitting your assignment!
Comprehension Questions
sessionandflash? What is the difference between them?