ruby on rails - Testing subdomains in controller specs in Rspec -


i've got controller specs working subdomains using before filter so

before      request.host = "an_account.example.com" end 

when user tries access subdomain not part of, logged out , sent devise's sign in action isnt under subdomain i.e.

www.example.com/users/sign_in

everything works fine in browser, sneaky users redirected barred entering unrelated subdomains , instead redirected sign in form.

however controller specs failing with

"expected response redirect http://example.com/users/sign_in redirect http://an_account.example.com/users/sign_in"

can on this?

here before_filter authorizes users

def authorize_account_subdomain!     if current_account.subdomain != request.subdomain       sign_out       flash[:warning] = t('errors.unauthorized')       redirect_to new_user_session_url(:subdomain => false)     end   end 

and test

context 'when signed_in'     let(:user)      { create(:user_with_account) }     let(:proposal)  { create(:proposal, :account => user.account) }     let(:subdomain) { user.account.subdomain }      before       sign_in user     end      context "when accessing other subdomain"        before          other_subdomain = "other_subdomain"         @request.host = "#{other_subdomain}.example.com"       end        "can not access show action"         post :show, :id => 1         access_denied!       end    end end   #test helper  def access_denied!     response.should redirect_to new_user_session_url(:subdomain => false)     flash[:warning].should == i18n.t('errors.unauthorized') end 

when @ see query correct, i.e. /users/sign_in same in both cases. tells me :subdomain => false in url helper.

see answer more clarification

https://stackoverflow.com/a/15624241/793330


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -