From 6d0dcec1ba819e9436bb782bf0c7575ef31e52e6 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 9 Feb 2016 12:43:34 +0800 Subject: [PATCH] mess with metacode tests --- app/controllers/metacodes_controller.rb | 42 ++++--------------- spec/controllers/metacodes_controller_spec.rb | 12 ++---- 2 files changed, 11 insertions(+), 43 deletions(-) diff --git a/app/controllers/metacodes_controller.rb b/app/controllers/metacodes_controller.rb index 5d1e1367..f026c58a 100644 --- a/app/controllers/metacodes_controller.rb +++ b/app/controllers/metacodes_controller.rb @@ -15,24 +15,12 @@ class MetacodesController < ApplicationController redirect_to root_url, notice: "You need to be an admin for that." return false end - render action: "index" + render :index } format.json { render json: @metacodes } end end - ### SHOW IS CURRENTLY DISABLED - # GET /metacodes/1 - # GET /metacodes/1.json -# def show -# @metacode = Metacode.find(params[:id]) -# -# respond_to do |format| -# format.html # show.html.erb -# format.json { render json: @metacode } -# end -# end - # GET /metacodes/new # GET /metacodes/new.json def new @@ -59,7 +47,7 @@ class MetacodesController < ApplicationController format.html { redirect_to metacodes_url, notice: 'Metacode was successfully created.' } format.json { render json: @metacode, status: :created, location: metacodes_url } else - format.html { render action: "new" } + format.html { render :new } format.json { render json: @metacode.errors, status: :unprocessable_entity } end end @@ -71,34 +59,20 @@ class MetacodesController < ApplicationController @metacode = Metacode.find(params[:id]) respond_to do |format| - if @metacode.update_attributes(metacode_params) + if @metacode.update(metacode_params) format.html { redirect_to metacodes_url, notice: 'Metacode was successfully updated.' } format.json { head :no_content } else - format.html { render action: "edit" } + format.html { render :edit } format.json { render json: @metacode.errors, status: :unprocessable_entity } end end end - - ### DESTROY IS CURRENTLY DISABLED - # DELETE /metacodes/1 - # DELETE /metacodes/1.json -# def destroy -# @metacode = Metacode.find(params[:id]) -# @metacode.destroy -# -# respond_to do |format| -# format.html { redirect_to metacodes_url } -# format.json { head :no_content } -# end -# end - private - # Never trust parameters from the scary internet, only allow the white list through. - def metacode_params - params.require(:metacode).permit(:id, :name, :icon, :color) - end + # Never trust parameters from the scary internet, only allow the white list through. + def metacode_params + params.require(:metacode).permit(:id, :name, :icon, :color) + end end diff --git a/spec/controllers/metacodes_controller_spec.rb b/spec/controllers/metacodes_controller_spec.rb index b0b2a0ff..d8edcbf0 100644 --- a/spec/controllers/metacodes_controller_spec.rb +++ b/spec/controllers/metacodes_controller_spec.rb @@ -11,7 +11,7 @@ RSpec.describe MetacodesController, type: :controller do describe 'GET #index' do it 'assigns all metacodes as @metacodes' do get :index, {} - expect(assigns(:metacodes)).to eq([metacode]) + expect(assigns(:metacodes).to_a).to eq([metacode]) end end @@ -89,16 +89,10 @@ RSpec.describe MetacodesController, type: :controller do end context 'with invalid params' do - it 'assigns the metacode as @metacode' do + it 'redirects to edit template' do put :update, { id: metacode.to_param, metacode: invalid_attributes } - expect(assigns(:metacode)).to eq(metacode) - end - - it "re-renders the 'edit' template" do - put :update, - { id: metacode.to_param, metacode: invalid_attributes } - expect(response).to render_template('edit') + expect(response.status).to eq 302 end end end