public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
mephisto / test / functional / application_controller_test.rb
100644 70 lines (59 sloc) 1.82 kb
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require File.dirname(__FILE__) + '/../test_helper'
require 'account_controller'
 
# Re-raise errors caught by the controller.
class AccountController
  def rescue_action(e) raise e end
  def test_host
    render :text => 'success'
  end
end
 
class ApplicationControllerTest < Test::Unit::TestCase
  fixtures :sites
  def setup
    @sub = Site.create!(:title => 'sub', :host => 'sub.test.host')
    @uk = Site.create!(:title => 'sub', :host => 'sub.test.co.uk')
    @controller = AccountController.new
    @request = ActionController::TestRequest.new
    @response = ActionController::TestResponse.new
  end
  
  def test_should_raise_404_if_no_site
    Site.delete_all
    host! 'test.hosts'
    get :test_host
    assert_response :missing
  end
 
  def test_should_find_site_by_host
    host! 'test.host'
    get :test_host
    assert_equal sites(:first), @controller.site
  end
 
  def test_should_find_site_with_www_prefix
    host! 'www.test.host'
    get :test_host
    assert_equal sites(:first), @controller.site
  end
  
  def test_should_find_site_by_subdomain_and_host
    host! 'sub.test.host'
    get :test_host
    assert_equal @sub, @controller.site
  end
  
  def test_should_find_site_by_subdomain_and_host_with_www_prefix
    host! 'www.sub.test.host'
    get :test_host
    assert_equal @sub, @controller.site
  end
  
  def test_should_find_site_by_uk_subdomain_and_host
    host! 'sub.test.co.uk'
    get :test_host
    assert_equal @uk, @controller.site
  end
  
  def test_should_find_site_by_uk_subdomain_and_host_with_www_prefix
    host! 'www.sub.test.co.uk'
    get :test_host
    assert_equal @uk, @controller.site
  end
  
  def test_should_return_nil_user_from_invalid_http_auth_data
    get :test_host
    @controller.send(:get_auth_data).each { |value| assert_nil value }
  end
end