Testing a Rails ApplicationController method with rspec -


just having trouble figuring out how test action utilizes private applicationcontroller method. explain:

a user has , belongs many organisations (through roles), , vice versa. organisation has bunch of related entities, in app user dealing single organisation @ time, of controller methods want scope current organisation. in applicationcontroller:

private  # returns organisation being operated on in session. def current_org   # org id session. if doesn't exist, or org no longer operable current user,   # find appropriate 1 , return that.   if (!session[:current_organisation_id] || !current_user.organisations.where(['organisations.id = ?', session[:current_organisation_id]]).first)     # if org doesn't exist user, hope lost, go home page     redirect_to '/' if (!current_user.organisations.first)     # otherwise set session new org     session[:current_organisation_id] = current_user.organisations.first.id;   end   # return current org!   current_user.organisations.first end 

first things first, don't know if best way scope. i'd love elegant default_scope thing, use of session variables seems problematic. anyway, above let's me in controllers:

class housescontroller < applicationcontroller   def index     @houses = current_org.houses   end end 

so want use rspec test controllers. how can make sure current_org method can called , returns 1 of factory_girl organisation models can write spec. i'm confused @ how best bring factory, spec, action , appcontrolled method together.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -