I have an application that detects the subdomain on a request and sets the result to a variable.
e.g.
before_filter :get_trust_from_subdomain
def get_trust_from_subdomain
@selected_trust = "test"
end
How can I test this with Test::Unit / Shoulda? I don’t see a way of getting into ApplicationController and seeing what’s set…
The
assignsmethod should allow you to query the value of@selected_trust. To assert that its value equals “test” as follows:Given a controller
foo_controller.rbone might write a functional test as follows in
foo_controller_test.rb:Related to comment: note that the filter can be placed in
ApplicationControllerand then any derived controller will also inherit this filter behaviour: