I am very new to testing with rails and have seemed to got myself lost in the world of testing. I am currently testing my dashboard controller and everything passes when I remove the load_and_authorize_resource line from my controller. I am using cancan for authorization.
dashboard_controller.rb
def update
@dashboard = Dashboard.find(params[:id])
respond_to do |format|
if @dashboard.update_attributes(params[:dashboard])
format.html { redirect_to dashboards_path, notice: 'dashboard was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @dashboard.errors, status: :unprocessable_entity }
end
end
end
dashboard_controller_spec.rb
require 'spec_helper'
describe DashboardsController do
login_user
before :each do
@dashboard = create(:dashboard, dashboard_name: "My Own Dashboard", id: 1)
end
describe "GET #index" do
it "should have a current_user" do
subject.current_user.should_not be_nil
end
it "renders the :index view" do
get :index
response.should render_template :index
end
it "Creates new dashboard" do
get :new
response.should render_template :new
end
end
describe "Get #edit" do
it "assigns dashboard to @dashboard" do
get :edit, id: @dashboard
assigns(:dashboard).should == @dashboard
end
it "renders the :edit template" do
get :edit, id: @dashboard
response.should render_template :edit
end
end
end
The error I receive from console
1) DashboardsController Get #edit renders the :edit template
Failure/Error: response.should render_template :edit
expecting <"edit"> but rendering with <"">
# ./spec/controllers/dashboard_controller_spec.rb:37:in `block (3 levels) in <top (required)>'
Anyway to bypass this error without removing the load_and_authorize_resource in my dashboard_controller?