3 class UserTermsSeenTest < ActionDispatch::IntegrationTest
11 with_terms_seen(true) do
12 user = users(:terms_not_seen_user)
14 get "/api/#{API_VERSION}/user/preferences", nil, auth_header(user.display_name, "test")
15 assert_response :forbidden
17 # touch it so that the user has seen the terms
18 user.terms_seen = true
21 get "/api/#{API_VERSION}/user/preferences", nil, auth_header(user.display_name, "test")
22 assert_response :success
26 def test_terms_presented_at_login
27 with_terms_seen(true) do
28 user = users(:terms_not_seen_user)
31 get_via_redirect "/login"
32 assert_response :success
33 assert_template "user/login"
34 post "/login", :username => user.email, :password => "test", :referer => "/diary/new"
35 assert_response :redirect
36 # but now we need to look at the terms
37 assert_redirected_to :controller => :user, :action => :terms, :referer => "/diary/new"
39 assert_response :success
41 # don't agree to the terms, but hit decline
42 post "/user/save", :decline => true, :referer => "/diary/new"
43 assert_redirected_to "/diary/new"
46 # should be carried through to a normal login with a message
47 assert_response :success
48 assert !flash[:notice].nil?
52 def test_terms_cant_be_circumvented
53 with_terms_seen(true) do
54 user = users(:terms_not_seen_user)
57 get_via_redirect "/login"
58 assert_response :success
59 assert_template "user/login"
60 post "/login", :username => user.email, :password => "test", :referer => "/diary/new"
61 assert_response :redirect
62 # but now we need to look at the terms
63 assert_redirected_to :controller => :user, :action => :terms, :referer => "/diary/new"
65 # check that if we go somewhere else now, it redirects
66 # back to the terms page.
68 assert_redirected_to :controller => :user, :action => :terms, :referer => "/traces/mine"
69 get "/traces/mine", :referer => "/diary/new"
70 assert_redirected_to :controller => :user, :action => :terms, :referer => "/diary/new"
76 def auth_header(user, pass)
77 { "HTTP_AUTHORIZATION" => format("Basic %s", Base64.encode64("#{user}:#{pass}")) }
80 def with_terms_seen(value)
81 require_terms_seen = Object.send("remove_const", "REQUIRE_TERMS_SEEN")
82 Object.const_set("REQUIRE_TERMS_SEEN", value)
86 Object.send("remove_const", "REQUIRE_TERMS_SEEN")
87 Object.const_set("REQUIRE_TERMS_SEEN", require_terms_seen)