That' right.
application_controller.rb
class ApplicationController < ActionController::Base
before_filter :authenticate_user!
rescue_from DeviseLdapAuthenticatable::LdapException do |exception|
render :text => exception, :status => 500
end
suppliers_controller.rb
class SuppliersController < InheritedResources::Base
skip_filter :authenticate_user!, :only => [:index,
:search_categories_by_sector]
before_filter :load_sectors_and_categories, :except =>
:search_categories_by_sector
respond_to :js
def index
set_title("Albo Fornitori - Ricerca", "Albo Fornitori")
@search = Supplier.search(params[:search])
@suppliers = @search.page(params[:page]).per(Settings.suppliers_per_page)
end
private
def search_categories_by_sector
unless params[:sector_id].blank?
@categories = Category.find_all_by_sector_id(params[:sector_id])
render :layout => false
else
@categories = Category.all
render :layout => false
end
end
def set_title(title1, title2)
@titleBox1 = title1
@titleBox2 = title2
end
def load_sectors_and_categories
@sectors = Sector.all
@categories = Category.all
end
end
suppliers_controller_spec.rb
describe SuppliersController do
# This should return the minimal set of attributes required to create a valid
# Supplier. As you add validations to Supplier, be sure to
# update the return value of this method accordingly.
before :each do
@category = Category.make!
end
def valid_attributes
{ :company_name => 'Supplier-1', :vat_number => '12345678901',
:address => 'addres-1', :city => 'city-1',
:prov => 'prov-1', :zip_code => '12345', :inps => 'inps-1',
:inail => 'inail-1', :email => 'mauro@mauro.it',
:categories => [@category] }
end
def mock_supplier(stubs={})
@mock_supplier ||= mock_model(Supplier, stubs).as_null_object
end
describe "GET index" do
it "assigns all suppliers as @suppliers" do
sectors = Sector.all
categories = Category.all
supplier = Supplier.create! valid_attributes
get :index
assigns(:suppliers).should eq([supplier])
assigns(:sectors).should eq(sectors)
assigns(:categories).should eq(categories)
end
end
the error is:
1) SuppliersController GET index assigns all suppliers as @suppliers
Failure/Error: get :index
NoMethodError:
undefined method `authenticate!' for nil:NilClass