4 class TermsControllerTest < ActionDispatch::IntegrationTest
6 # test all routes which lead to this controller
9 { :path => "/account/terms", :method => :get },
10 { :controller => "accounts/terms", :action => "show" }
13 { :path => "/account/terms", :method => :put },
14 { :controller => "accounts/terms", :action => "update" }
18 assert_redirected_to "/account/terms"
21 def test_show_not_logged_in
22 get account_terms_path
24 assert_redirected_to login_path(:referer => account_terms_path)
28 user = create(:user, :terms_seen => true, :terms_agreed => Date.yesterday)
31 get account_terms_path
32 assert_redirected_to edit_account_path
35 def test_show_not_seen_without_referer
36 user = create(:user, :terms_seen => false, :terms_agreed => nil)
39 get account_terms_path
40 assert_response :success
43 def test_show_not_seen_with_referer
44 user = create(:user, :terms_seen => false, :terms_agreed => nil)
47 get account_terms_path(:referer => "/test")
48 assert_response :success
51 def test_update_not_seen_without_referer
52 user = create(:user, :terms_seen => false, :terms_agreed => nil)
55 put account_terms_path, :params => { :user => { :consider_pd => true }, :read_ct => 1, :read_tou => 1 }
56 assert_redirected_to edit_account_path
57 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
61 assert user.consider_pd
62 assert_not_nil user.terms_agreed
63 assert user.terms_seen
66 def test_update_not_seen_with_referer
67 user = create(:user, :terms_seen => false, :terms_agreed => nil)
70 put account_terms_path, :params => { :user => { :consider_pd => true }, :referer => "/test", :read_ct => 1, :read_tou => 1 }
71 assert_redirected_to "/test"
72 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
76 assert user.consider_pd
77 assert_not_nil user.terms_agreed
78 assert user.terms_seen
81 # Check that if you haven't seen the terms, and make a request that requires authentication,
82 # that your request is redirected to view the terms
83 def test_terms_not_seen_redirection
84 user = create(:user, :terms_seen => false, :terms_agreed => nil)
88 assert_redirected_to account_terms_path(:referer => "/account/edit")