diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index ce0dfe9..c3b6a2c 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -3,10 +3,15 @@ class CommentsController < ApplicationController before_filter :decode_commentable_type def index @commentable=params[:commentable_type].constantize.find(params[:commentable_id]) unless params[:commentable_type].nil? or params[:commentable_id].nil? +if @commentable.nil? + render status: 404 + else @comments=@commentable.comments.order(:created_at).roots.accessible_by(current_ability, :show).page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order + respond_to do |format| format.js end +end end def hide @commentable=params[:commentable_type].constantize.find(params[:commentable_id]) unless params[:commentable_type].nil? or params[:commentable_id].nil? diff --git a/config/routes.rb b/config/routes.rb index a51a3ad..0940321 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,7 +18,7 @@ end end resources :choices - resources :answers + end themes_for_rails diff --git a/db/migrate/20150803060145_add_template_to_survey_question.rb b/db/migrate/20150803060145_add_template_to_survey_question.rb new file mode 100644 index 0000000..85988e4 --- /dev/null +++ b/db/migrate/20150803060145_add_template_to_survey_question.rb @@ -0,0 +1,4 @@ +class AddTemplateToSurveyQuestion < ActiveRecord::Migration + def change + end +end diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 3e0346d..67cb2ee 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -32,9 +32,13 @@ describe CommentsController do describe "GET index" do it "assigns all comments as @comments" do - comment = Comment.create! valid_attributes + comment = Comment.create! valid_attributes # add items to database get :index, {}, valid_session - assigns(:comments).should eq([comment]) + assigns(:comments).should eq([comment]) # check if all items are returned + end + it "has a 200 status code" do + get :index + expect(response.status).to eq(200) end end