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 => { :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_not_nil user.terms_agreed
62 assert user.terms_seen
65 def test_update_not_seen_with_referer
66 user = create(:user, :terms_seen => false, :terms_agreed => nil)
69 put account_terms_path, :params => { :referer => "/test", :read_ct => 1, :read_tou => 1 }
70 assert_redirected_to "/test"
71 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
75 assert_not_nil user.terms_agreed
76 assert user.terms_seen
79 # Check that if you haven't seen the terms, and make a request that requires authentication,
80 # that your request is redirected to view the terms
81 def test_terms_not_seen_redirection
82 user = create(:user, :terms_seen => false, :terms_agreed => nil)
86 assert_redirected_to account_terms_path(:referer => "/account/edit")