Question: MODIFYING ROTTENPOTATOES APP **** RUBY ON RAILS 5**** I am getting some failures and I was wondering if anyone could fix them. There is a
MODIFYING ROTTENPOTATOES APP **** RUBY ON RAILS 5****
I am getting some failures and I was wondering if anyone could fix them. There is a lot of other code, but this is the only code you should need to edit the code given to you.
#movies_controller.rb (there is other code but you should only be needing to edit the index class)
def index @all_ratings = Movie.ratings @sort = params[:sort] || session[:sort] session[:ratings] = session[:ratings] || {'G'=>'','PG'=>'','PG-13'=>'','R'=>''} @t_param = params[:ratings] || session[:ratings] session[:sort] = @sort session[:ratings] = @t_param @movies = Movie.where(rating: session[:ratings].keys).order(session[:sort]) if (params[:sort].nil? and !(session[:sort ].nil?)) or (params[:ratings].nil? and !(session[:ratings].nil?)) flash.keep redirect_to movies_path(sort: session[:sort],ratings: session[:ratings]) end end
#movie.rb class Movie < ActiveRecord::Base def self.ratings Movie.select(:rating).distinct.inject([]) { |a, m| a.push m.rating} end end
-# This file is app/views/movies/index.html.haml %h1 All Movies = form_tag movies_path, :method => :get do Include: - @all_ratings.each do |rating| = rating = check_box_tag "ratings[#{rating}]",'',('checked' if @t_param.include? rating) = submit_tag 'Refresh' %table#movies %thead %tr %th{class:('hilite' if @sort =='title')}=link_to "Movie Title", movies_path(sort:"title"), id:"title_header" %th Rating %th{class:('hilite' if @sort =='release_date')}=link_to "Release Date", movies_path(sort:"release_date"), id:"release_date_header" %th More Info %tbody - @movies.each do |movie| %tr %td= movie.title %td= movie.rating %td= movie.release_date %td= link_to "More about #{movie.title}", movie_path(movie)
= link_to 'Add new movie', new_movie_path
Failures: 1) GET /movies should have #ratings_form form [5 points] Failure/Error: expect(@page.form_with(:id =>'ratings_form')).not_to be_nil expected: not nil got: nil 2) GET /movies should have #ratings_submit button [5 points] Failure/Error: expect(@page.form_with(:id => 'ratings_form').button_with(:id => 'ratings_submit')).not_to equal(nil) NoMethodError: undefined method `button_with' for nil:NilClass 3) GET /movies should have checkboxes [5 points] Failure/Error: @page.form_with(:id => 'ratings_form').checkboxes.each do |checkbox| expect(checkbox[:id]).to match(/ratings_\w+/) end NoMethodError: undefined method `checkboxes' for nil:NilClass 4) GET /movies When I first visit the page should have all checkboxes checked [8 points] Failure/Error: checked_boxes=@page.form_with(:id => 'ratings_form').checkboxes_with(:checked=>true) NoMethodError: undefined method `checkboxes_with' for nil:NilClass 5) GET /movies basic tests should have a form with id ratings_form Failure/Error: expect(@page.form_with(:id =>'ratings_form')).not_to be_nil expected: not nil got: nil 6) GET /movies basic tests should have #ratings_submit button Failure/Error: expect(@page.form_with(:id =>'ratings_form').button_with(:id => 'ratings_submit')).not_to equal(nil) NoMethodError: undefined method `button_with' for nil:NilClass 7) GET /movies basic tests should have checkboxes Failure/Error: @page.form_with(:id => 'ratings_form').checkboxes.each do |checkbox| expect(checkbox[:id]).to match(/ratings_\w+/) end NoMethodError: undefined method `checkboxes' for nil:NilClass Finished in 12.96 seconds (files took 6 minutes 12 seconds to load) 29 examples, 7 failures
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
