-
Notifications
You must be signed in to change notification settings - Fork 0
/
unwatch.rb
93 lines (78 loc) · 2.3 KB
/
unwatch.rb
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
require File.expand_path('../test_helper', __FILE__)
class UnwatchTest < Test::Unit::TestCase
def test_index_unauthorized
get '/'
assert last_response.ok?
end
def test_index_authorized
get '/', {}, 'rack.session' => { :access_token => 'dummy' }
assert_equal 302, last_response.status
assert_equal "http://unwatch.heroku.com/unwatch", last_response.location
end
def test_redirect_to_github_for_authentication
get '/auth/github'
follow_redirect!
assert_match /https:\/\/github.com\/login\/oauth\/authorize/, last_request.url
end
def test_pass_client_id_to_github
get '/auth/github'
follow_redirect!
assert_not_nil last_request.params['client_id']
assert !last_request.params['client_id'].empty?
end
def test_pass_scope_to_github
get '/auth/github'
follow_redirect!
assert_not_nil last_request.params['scope']
assert !last_request.params['scope'].empty?
end
def test_redirect_uri
get '/auth/github'
follow_redirect!
assert_equal "http://unwatch.heroku.com/auth/github/callback", last_request.params['redirect_uri']
end
def test_github_callback_unauthorized
get '/auth/github/callback'
assert_equal 200, last_response.status
assert_match "Retry", last_response.body
end
def test_github_callback_authorized
mock_app(Unwatch) do
helpers do
def get_token(code)
"dummy_token"
end
end
end
get '/auth/github/callback'
assert_equal 302, last_response.status
assert_equal "http://unwatch.heroku.com/", last_response.location
end
def test_unwatch_unauthorized
get '/unwatch'
assert_equal 302, last_response.status
assert_equal "http://unwatch.heroku.com/", last_response.location
end
def test_unwatch_authorized
mock_app(Unwatch) do
helpers do
def get_init_data
@username = "zhengjia"
@watched = fixture_watched
end
end
end
get '/unwatch', {}, 'rack.session' => { :access_token => 'dummy' }
assert_equal 200, last_response.status
end
def test_unwatch_repo
mock_app(Unwatch) do
helpers do
def unwatch_repo(username, repo)
end
end
end
get '/unwatch/zhengjia/unwatch'
assert_equal 302, last_response.status
end
end