I successfully received controller specifications working with subdomains using a filter before this
before do
request.host = "an_account.example.com"
end
When a user tries to access a subdomain from which they are not part, they log out and are sent back to work out a sign in action, which is ISNT under the ie subdomain
www.example.com/users/sign_in
Everything works fine in the browser, hidden users are redirected, it is forbidden to enter unrelated subdomains and instead redirect to the sign form.
However, my controller specifications do not work with
"The expected answer is a redirect to http://example.com/users/sign_in , but has been redirected to http://an_account.example.com/users/sign_in "
Can anyone help with this?
Below is the before_filter option, which allows 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' do
let(:user) { create(:user_with_account) }
let(:proposal) { create(:proposal, :account => user.account) }
let(:subdomain) { user.account.subdomain }
before do
sign_in user
end
context "when accessing other subdomain" do
before do
other_subdomain = "other_subdomain"
@request.host = "#{other_subdomain}.example.com"
end
it "can not access show action" do
post :show, :id => 1
access_denied!
end
end
end
def access_denied!
response.should redirect_to new_user_session_url(:subdomain => false)
flash[:warning].should == I18n.t('errors.unauthorized')
end
source
share