I''m using devise and in application_controller I have before_filter :authenticate! In sector_controller I have: skip_filter :authenticate_user!, :only => [:index, :search_categories_by_sector] When I run rspec it says: undefined method authenticate!, even for index action. But I'' set skip_filter for index action. Why rspec needs authenticate for index? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 June 2011 15:45, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m using devise and in application_controller I have before_filter > :authenticate! > In sector_controller I have: > > skip_filter :authenticate_user!, :only => [:index, :search_categories_by_sector] > > When I run rspec it says: undefined method authenticate!, even for > index action. > But I'' set skip_filter for index action. > Why rspec needs authenticate for index?Because you have specified skip for :authenticate_user! not :authenticate! ? Colin> > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 June 2011 14:48, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 7 June 2011 15:45, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> I''m using devise and in application_controller I have before_filter >> :authenticate! >> In sector_controller I have: >> >> skip_filter :authenticate_user!, :only => [:index, :search_categories_by_sector] >> >> When I run rspec it says: undefined method authenticate!, even for >> index action. >> But I'' set skip_filter for index action. >> Why rspec needs authenticate for index? > > Because you have specified skip for :authenticate_user! not :authenticate! ?I''ve make a mistake writing, in application_controller I have: before_filter :authenticate_user! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 June 2011 15:53, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 7 June 2011 14:48, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 7 June 2011 15:45, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> I''m using devise and in application_controller I have before_filter >>> :authenticate! >>> In sector_controller I have: >>> >>> skip_filter :authenticate_user!, :only => [:index, :search_categories_by_sector] >>> >>> When I run rspec it says: undefined method authenticate!, even for >>> index action. >>> But I'' set skip_filter for index action. >>> Why rspec needs authenticate for index? >> >> Because you have specified skip for :authenticate_user! not :authenticate! ? > > I''ve make a mistake writing, in application_controller I have: > before_filter :authenticate_user!In that case, as you are getting an error ''undefined method authenticate!'' that is nothing to do with the filter. It is no good re-typing what you think you have when asking questions, it is vital that we know *exactly* what you have. I suggest that you copy and paste the relevant code out of application_controller.rb and sector_controller.rb and also copy and paste the test that is failing and the error. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 June 2011 15:07, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 7 June 2011 15:53, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On 7 June 2011 14:48, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>> On 7 June 2011 15:45, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> I''m using devise and in application_controller I have before_filter >>>> :authenticate! >>>> In sector_controller I have: >>>> >>>> skip_filter :authenticate_user!, :only => [:index, :search_categories_by_sector] >>>> >>>> When I run rspec it says: undefined method authenticate!, even for >>>> index action. >>>> But I'' set skip_filter for index action. >>>> Why rspec needs authenticate for index? >>> >>> Because you have specified skip for :authenticate_user! not :authenticate! ? >> >> I''ve make a mistake writing, in application_controller I have: >> before_filter :authenticate_user! > > In that case, as you are getting an error ''undefined method > authenticate!'' that is nothing to do with the filter. > > It is no good re-typing what you think you have when asking questions, > it is vital that we know *exactly* what you have. > I suggest that you copy and paste the relevant code out of > application_controller.rb and sector_controller.rb and also copy and > paste the test that is failing and the error.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-9nJhxSmdgFE@public.gmane.org'', :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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 June 2011 17:12, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 7 June 2011 15:07, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 7 June 2011 15:53, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> On 7 June 2011 14:48, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>>> On 7 June 2011 15:45, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>> I''m using devise and in application_controller I have before_filter >>>>> :authenticate! >>>>> In sector_controller I have: >>>>> >>>>> skip_filter :authenticate_user!, :only => [:index, :search_categories_by_sector] >>>>> >>>>> When I run rspec it says: undefined method authenticate!, even for >>>>> index action. >>>>> But I'' set skip_filter for index action. >>>>> Why rspec needs authenticate for index? >>>> >>>> Because you have specified skip for :authenticate_user! not :authenticate! ? >>> >>> I''ve make a mistake writing, in application_controller I have: >>> before_filter :authenticate_user! >> >> In that case, as you are getting an error ''undefined method >> authenticate!'' that is nothing to do with the filter. >> >> It is no good re-typing what you think you have when asking questions, >> it is vital that we know *exactly* what you have. >> I suggest that you copy and paste the relevant code out of >> application_controller.rb and sector_controller.rb and also copy and >> paste the test that is failing and the error. > > 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-9nJhxSmdgFE@public.gmane.org'', > :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:NilClassDon''t you get a trace showing where the error occurred? I haven''t used Devise though so someone else may be better able to help now that we have determined exactly what is happening. Could it be due to the fact that you are using InheritedResources? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 June 2011 16:33, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> I haven''t used Devise thoughWhat to you use to authenticate?>.... Could it > be due to the fact that you are using InheritedResources?I think so, I''ll do more testing. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.