Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'test_helper'
- class UsersControllerTest < ActionController::TestCase
- tests Clearance::UsersController
- context "controlling mass assignment on the controller level" do
- setup do
- @protected = {:encrypted_password => "test",
- :salt => "test",
- :confirmation_token => "test",
- :remember_token => "test",
- :email_confirmed => "test"}
- @valid = {:email => "email@person.com",
- :password => "secret",
- :password_confirmation => "secret"}
- begin
- stub(ClearanceMailer).deliver_confirmation.with_any_args {true}
- rescue ArgumentError
- # why does this get thrown the first time I stub out the mailer
- end
- stub(ClearanceMailer).deliver_confirmation.with_any_args {true}
- end
- context "on POST to :create with valid params" do
- setup do
- post :create, :user => {:email => "steve@hodgkiss.com",
- :password => "secret",
- :password_confirmation => "secret"}
- end
- should_change 'User.count', :by => 1
- should_redirect_to_url_after_create
- end
- [:encrypted_password, :salt, :confirmation_token,
- :remember_token, :email_confirmed].each do |key|
- context "on POST to :create with invalid params #{key}" do
- setup do
- @valid[key.to_sym] = @protected[key]
- post :create, :user => @valid
- end
- should "not allow assignment of #{key}" do
- assert_not_equal @protected[key], User.first.send(key)
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment