1 require File.dirname(__FILE__) + '/../test_helper'
3 class UserTermsSeenTest < ActionDispatch::IntegrationTest
7 with_terms_seen(true) do
8 user = users(:terms_not_seen_user)
10 get "/api/#{API_VERSION}/user/preferences", nil, auth_header(user.display_name, "test")
11 assert_response :forbidden
13 # touch it so that the user has seen the terms
14 user.terms_seen = true
17 get "/api/#{API_VERSION}/user/preferences", nil, auth_header(user.display_name, "test")
18 assert_response :success
22 def test_terms_presented_at_login
23 with_terms_seen(true) do
24 user = users(:terms_not_seen_user)
27 get_via_redirect "/login"
28 assert_response :success
29 assert_template 'user/login'
30 post "/login", {'username' => user.email, 'password' => 'test', :referer => "/"}
31 assert_response :redirect
32 # but now we need to look at the terms
33 assert_redirected_to "controller" => "user", "action" => "terms", :referer => "/"
35 assert_response :success
37 # don't agree to the terms, but hit decline
38 post "/user/save", {'decline' => 'decline', 'referer' => '/'}
39 assert_redirected_to "/"
42 # should be carried through to a normal login with a message
43 assert_response :success
44 assert !flash[:notice].nil?
48 def test_terms_cant_be_circumvented
49 with_terms_seen(true) do
50 user = users(:terms_not_seen_user)
53 get_via_redirect "/login"
54 assert_response :success
55 assert_template 'user/login'
56 post "/login", {'username' => user.email, 'password' => 'test', :referer => "/"}
57 assert_response :redirect
58 # but now we need to look at the terms
59 assert_redirected_to "controller" => "user", "action" => "terms", :referer => "/"
61 assert_response :success
63 # check that if we go somewhere else now, it redirects
64 # back to the terms page.
66 assert_redirected_to "controller" => "user", "action" => "terms", :referer => "/traces/mine"
72 def auth_header(user, pass)
73 {"HTTP_AUTHORIZATION" => "Basic %s" % Base64.encode64("#{user}:#{pass}")}
76 def with_terms_seen(value)
77 require_terms_seen = Object.send("remove_const", "REQUIRE_TERMS_SEEN")
78 Object.const_set("REQUIRE_TERMS_SEEN", value)
82 Object.send("remove_const", "REQUIRE_TERMS_SEEN")
83 Object.const_set("REQUIRE_TERMS_SEEN", require_terms_seen)