application_controller.rb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
before_filter :require_account
before_filter :require_user

def require_account
    if current_account.nil?
      redirect_to account_finder_url(:subdomain => false)
    end
end

def require_user
    unless current_user
      redirect_to login_url 
    end
end

test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def setup
    host! "test.example.org"

    @account = Account.first
    unless @account
      @account = Account.new({:subdomain => 'test'})
      @account.save(:validate => false)

      @user = @account.users.first
      @user.update_attributes({:email => "[email protected]", :password => "test"})
      @user.save(:validate => false)
    end
end


test "authenticates with valid credentials" do
    visit login_url

    fill_in "user_session_email", :with => "[email protected]"
    fill_in "user_session_password", :with => "test"
    click_button "log in"
    follow_redirect!

    assert_have_no_selector "form"
end

info

1
2
3
4
5
6
7
- when no account exists and a subdomain is requested, it redirects to www.example.com/account_finder
- when visiting www.example.com/login, it also redirects to account_finder (because authentication is based on subdomain)

REQUESTING PAGE: POST /user_sessions with {"commit"=>"log in", "user_session"=>{"password"=>"test", "email"=>"[email protected]"}, "utf8"=>"✓"}
 and HTTP headers {"HTTP_REFERER"=>"http://test.example.org/login"}

=> 1 failure, because i am redirected to /account_finder