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_response :success
 
  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_decline_by_not_checking_the_boxes
 
  53         user = create(:user, :terms_seen => false, :terms_agreed => nil, :tou_agreed => nil)
 
  56         put account_terms_path, :params => { :continue => "Continue" }
 
  58         assert_redirected_to account_path
 
  59         assert_equal({ :partial => "accounts/terms/terms_declined_flash" }, flash[:notice])
 
  62         assert user.terms_seen
 
  63         assert_nil user.terms_agreed
 
  64         assert_nil user.tou_agreed
 
  68     def test_update_decline_by_cancel
 
  70         user = create(:user, :terms_seen => false, :terms_agreed => nil, :tou_agreed => nil)
 
  73         put account_terms_path, :params => { :read_ct => 1, :read_tou => 1, :decline => "Cancel" }
 
  75         assert_redirected_to account_path
 
  76         assert_equal({ :partial => "accounts/terms/terms_declined_flash" }, flash[:notice])
 
  79         assert user.terms_seen
 
  80         assert_nil user.terms_agreed
 
  81         assert_nil user.tou_agreed
 
  85     def test_update_decline_previously_accepted_by_not_checking_the_boxes
 
  87         user = create(:user, :terms_seen => true, :terms_agreed => Date.yesterday, :tou_agreed => Date.yesterday)
 
  90         put account_terms_path, :params => { :continue => "Continue" }
 
  92         assert_redirected_to account_path
 
  93         assert_equal({ :partial => "accounts/terms/terms_declined_flash" }, flash[:notice])
 
  96         assert user.terms_seen
 
  97         assert_equal Date.yesterday, user.terms_agreed
 
  98         assert_equal Date.yesterday, user.tou_agreed
 
 102     def test_update_decline_previously_accepted_by_cancel
 
 104         user = create(:user, :terms_seen => true, :terms_agreed => Date.yesterday, :tou_agreed => Date.yesterday)
 
 107         put account_terms_path, :params => { :read_ct => 1, :read_tou => 1, :decline => "Cancel" }
 
 109         assert_redirected_to account_path
 
 110         assert_equal({ :partial => "accounts/terms/terms_declined_flash" }, flash[:notice])
 
 113         assert user.terms_seen
 
 114         assert_equal Date.yesterday, user.terms_agreed
 
 115         assert_equal Date.yesterday, user.tou_agreed
 
 119     def test_update_accept_not_seen
 
 121         user = create(:user, :terms_seen => false, :terms_agreed => nil, :tou_agreed => nil)
 
 124         put account_terms_path, :params => { :read_ct => 1, :read_tou => 1 }
 
 126         assert_redirected_to account_path
 
 127         assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
 
 130         assert user.terms_seen
 
 131         assert_equal Time.now.utc, user.terms_agreed
 
 132         assert_equal Time.now.utc, user.tou_agreed
 
 136     def test_update_accept_not_seen_with_referer
 
 138         user = create(:user, :terms_seen => false, :terms_agreed => nil, :tou_agreed => nil)
 
 141         put account_terms_path, :params => { :referer => "/test", :read_ct => 1, :read_tou => 1 }
 
 143         assert_redirected_to "/test"
 
 144         assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
 
 147         assert user.terms_seen
 
 148         assert_equal Time.now.utc, user.terms_agreed
 
 149         assert_equal Time.now.utc, user.tou_agreed
 
 153     def test_update_accept_previously_accepted
 
 155         user = create(:user, :terms_seen => true, :terms_agreed => Date.yesterday, :tou_agreed => Date.yesterday)
 
 158         put account_terms_path, :params => { :read_ct => 1, :read_tou => 1 }
 
 160         assert_redirected_to account_path
 
 161         assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
 
 164         assert user.terms_seen
 
 165         assert_equal Time.now.utc, user.terms_agreed
 
 166         assert_equal Time.now.utc, user.tou_agreed
 
 170     # Check that if you haven't seen the terms, and make a request that requires authentication,
 
 171     # that your request is redirected to view the terms
 
 172     def test_terms_not_seen_redirection
 
 173       user = create(:user, :terms_seen => false, :terms_agreed => nil)
 
 177       assert_redirected_to account_terms_path(:referer => account_path)