I have the following filter defined:
# application_controller.rb
class ApplicationController < ActionController::Base
before_filter :find_account
private
def find_account
@current_account = Account.find_by_subdomain!(request.subdomains.first)
end
end
and in my test:
# users_controller_test.rb
class UsersControllerTest < ActionController::TestCase
setup do
@request.host = "test.myapp.local"
end
# ...
end
Now test
is defined as the subdomain for a dummy account that I load prior to all requests using factory_girl
. However, this is throwing a nil object error, saying that @request is nil. Removing the setup block causes all of my tests to fail as find_account cannot find an account and therefore throws a RecordNotFound
error.
What am I doing wrong?
Try this:
@request.env['HTTP_HOST'] = 'test.myapp.local'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With