daily pastebin goal
2%
SHARE
TWEET

Untitled

a guest Mar 17th, 2018 227 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require 'test_helper'
  2.  
  3. class UsersControllerTest < ActionController::TestCase
  4.   tests Clearance::UsersController
  5.  
  6.   context "controlling mass assignment on the controller level" do
  7.  
  8.     setup do
  9.       @protected = {:encrypted_password => "test",
  10.                      :salt => "test",
  11.                      :confirmation_token => "test",
  12.                      :remember_token => "test",
  13.                      :email_confirmed => "test"}
  14.       @valid = {:email => "email@person.com",
  15.                 :password => "secret",
  16.                 :password_confirmation => "secret"}
  17.       begin
  18.         stub(ClearanceMailer).deliver_confirmation.with_any_args {true}
  19.       rescue ArgumentError
  20.         # why does this get thrown the first time I stub out the mailer
  21.       end
  22.  
  23.       stub(ClearanceMailer).deliver_confirmation.with_any_args {true}
  24.     end
  25.  
  26.     context "on POST to :create with valid params" do
  27.       setup do
  28.         post :create, :user => {:email => "steve@hodgkiss.com",
  29.              :password => "secret",
  30.              :password_confirmation => "secret"}
  31.       end
  32.  
  33.       should_change 'User.count', :by => 1
  34.       should_redirect_to_url_after_create
  35.     end
  36.     [:encrypted_password, :salt, :confirmation_token,
  37.      :remember_token, :email_confirmed].each do |key|
  38.       context "on POST to :create with invalid params #{key}" do
  39.         setup do
  40.           @valid[key.to_sym] = @protected[key]
  41.           post :create, :user => @valid
  42.         end
  43.  
  44.         should "not allow assignment of #{key}" do
  45.           assert_not_equal @protected[key], User.first.send(key)
  46.         end
  47.       end
  48.     end
  49.   end
  50. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top