I am looking for clarification and an understanding on how to effectively test my controllers with Rspec, I don't want to write tests that are not testing the potential issues at hand.
My scenario is as follows.
I am using Active Admin to create a Category, to do so you must obviously be logged into Active Admin.
What I want to ensure is that
1) A logged in user can create a Category
2) A Category cannot be created if you are not logged in
3) Attempts to create a Category outside of active admin are met with a 404 template
So what i have so far (and i really want to check i haven't gone over the top or performing unnecessary tests) is as follows.
spec/controllers/categories_controller_spec.rb
require 'rails_helper' include Warden::Test::Helpers # Ensure 404 pages are returned when requesting URLS RSpec.describe CategoriesController, type: :request do describe 'Routes' do context 'All CRUD actions render 404' do it '#create' do post '/categories' expect(response.status).to eq(404) expect(response).to render_template(:file => "#{Rails.root}/public/404.html.erb") end # All other actions here end end end RSpec.describe Admin::CategoriesController, type: :request do describe 'No Authorised Login' do context 'All CRUD actions redirect correctly' do it 'redirects when accessing #index' do get '/admin/categories' expect(response.status).to eq(302) expect(response).to redirect_to(admin_root_path + '/login') end # All other actions here end end end # Ensure actions in admin can be carried out if logged in RSpec.describe Admin::CategoriesController, type: :request do before(:each) do @user = FactoryGirl.create(:admin_user) login_as @user end after(:each) do @user.destroy end describe 'Authorised Login' do context 'All CRUD actions perform as expected' do it 'navigates to Categories #index' do get '/my_admin_panel/categories' expect(response.status).to eq(200) expect(response).to render_template(:index) end # All other actions here end end spec/routing/categories_routing.spec
RSpec.describe CategoriesController, type: :routing do describe 'Routes' do it 'does not get #index' do expect(get: '/categories').to route_to( controller: 'application', action: 'raise_not_found', unmatched_route: 'categories' ) end end end Should I be testing post /categories without supplying params, is that a wasted test? Am I over complicating what should be a simple set of tests ?