How to test routes added by a Rails Controller Concern -


i trying test routes added controller via concern. want write acceptance tests include concern's routes in controller in order avoid regressions document concern's use cases. make sense? if so, how 1 go accessing routes added controller via concern in tests?

following stripped down version of app's routes. permissionable concern routes work expected when running app.

#routes.rb routes.draw   concern :permissionable     member       'permission', action: "permission_show"      end   end    resources :profiles, concerns: :permissionable end 

and stripped down version of controller concern, included profilescontroller

module permissionactions   extend activesupport::concern    def permission_show     if current_user.admin?       render :text => "you have permissions entity"     end     render :text => "no permission entity"   end     def test_a_thing       "test"   end end 

finally, answers in question, rspec examples this.

describe applicationcontroller, type: :controller   controller     include permissionactions      def index; end   end    describe 'a controller permission actions'     'can call method'       expect(@controller.test_a_thing()).to eq("test")     end      'exposes permission route'       :permission     end   end end 

the first example works, second example complains no route matches {:action=>"permission", :controller=>"anonymous"}

i tried many things list of them here, solution thought work sure re-draw routes inside test this:

... 'exposes permission route'   routes.draw {     concern :permissionable       member         'permission', action: "permission_show"       end     end     resources :anonymous, concerns: :permissionable   }    # response = @controller.permission_show()   :permission, :id => "anyid"    expect(response).to have_http_status(200) end 


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -