Skip to content

Commit

Permalink
Merge branch 'master' of github.com:thoughtbot/clearance
Browse files Browse the repository at this point in the history
  • Loading branch information
Chad Pytel committed Jun 21, 2010
2 parents 1b0ef0d + 7eb98af commit f615420
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 41 deletions.
8 changes: 2 additions & 6 deletions shoulda_macros/clearance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,10 @@ def public_context(&blk)

def should_create_user_successfully
warn "[DEPRECATION] should_create_user_successfully: not meant to be public, no longer used internally"
should_assign_to :user
should assign_to(:user)
should_change 'User.count', :by => 1

should "send the confirmation email" do
assert_sent_email do |email|
email.subject =~ /account confirmation/i
end
end
should have_sent_email.with_subject(/account confirmation/i)

should set_the_flash.to(/confirm/i)
should_redirect_to_url_after_create
Expand Down
5 changes: 4 additions & 1 deletion test/controllers/confirmations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ class ConfirmationsControllerTest < ActionController::TestCase

should set_the_flash.to(/already confirmed/i)
should set_the_flash.to(/sign in/i)
should_not_be_signed_in
should_redirect_to_url_already_confirmed

should "not be signed in" do
assert_nil cookies[:remember_token]
end
end

context "no users" do
Expand Down
18 changes: 7 additions & 11 deletions test/controllers/passwords_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class PasswordsControllerTest < ActionController::TestCase

tests Clearance::PasswordsController

should_route :get, '/users/1/password/edit',
:controller => 'clearance/passwords', :action => 'edit', :user_id => '1'
should route(:get, '/users/1/password/edit').
to(:controller => 'clearance/passwords', :action => 'edit', :user_id => '1')

context "a signed up user" do
setup do
Expand All @@ -30,11 +30,7 @@ class PasswordsControllerTest < ActionController::TestCase
assert_not_nil @user.reload.confirmation_token
end

should "send the change your password email" do
assert_sent_email do |email|
email.subject =~ /change your password/i
end
end
should have_sent_email.with_subject(/change your password/i)

should set_the_flash.to(/password/i)
should_redirect_to_url_after_create
Expand Down Expand Up @@ -87,7 +83,6 @@ class PasswordsControllerTest < ActionController::TestCase

should respond_with(:success)
should render_template(:edit)
should_display_a_password_update_form
end

should_forbid "on GET to #edit with correct id but blank token" do
Expand Down Expand Up @@ -155,12 +150,13 @@ class PasswordsControllerTest < ActionController::TestCase
assert_not_nil @user.confirmation_token
end

should_not_be_signed_in
should "not be signed in" do
assert_nil cookies[:remember_token]
end

should_not set_the_flash
should respond_with(:success)
should render_template(:edit)

should_display_a_password_update_form
end

should_forbid "on PUT to #update with id but no token" do
Expand Down
6 changes: 2 additions & 4 deletions test/controllers/sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class SessionsControllerTest < ActionController::TestCase
should respond_with(:success)
should render_template(:new)
should_not set_the_flash
should_display_a_sign_in_form
end

context "on POST to #create with unconfirmed credentials" do
Expand Down Expand Up @@ -144,10 +143,9 @@ class SessionsControllerTest < ActionController::TestCase
should set_the_flash.to(/bad/i)
should respond_with(:unauthorized)
should render_template(:new)
should_not_be_signed_in

should 'not create the cookie' do
assert_nil cookies['remember_token']
should "not be signed in" do
assert_nil cookies[:remember_token]
end
end

Expand Down
17 changes: 8 additions & 9 deletions test/controllers/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class UsersControllerTest < ActionController::TestCase
should respond_with(:success)
should render_template(:new)
should_not set_the_flash

should_display_a_sign_up_form
end

context "on GET to #new with email" do
Expand All @@ -37,24 +35,25 @@ class UsersControllerTest < ActionController::TestCase
post :create, :user => user_attributes
end

should_assign_to :user
should assign_to(:user)

should "create a new user" do
assert_equal @old_user_count + 1, User.count
end

should "send the confirmation email" do
assert_sent_email do |email|
email.subject =~ /account confirmation/i
end
end
should have_sent_email.with_subject(/account confirmation/i)

should set_the_flash.to(/confirm/i)
should_redirect_to_url_after_create
end
end

signed_in_user_context do
context "A signed-in user" do
setup do
@user = Factory(:email_confirmed_user)
sign_in_as @user
end

context "GET to new" do
setup { get :new }
should redirect_to("the home page") { root_url }
Expand Down
15 changes: 5 additions & 10 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class UserTest < ActiveSupport::TestCase
# signing up

context "When signing up" do
should_validate_presence_of :email, :password
should validate_presence_of(:email)
should validate_presence_of(:password)
should allow_value("foo@example.com").for(:email)
should_not allow_value("foo").for(:email)
should_not allow_value("example.com").for(:email)
Expand Down Expand Up @@ -59,11 +60,7 @@ def @user.initialize_salt; end
assert_equal "John.Doe@example.com", user.email
end

should "send the confirmation email" do
assert_sent_email do |email|
email.subject =~ /account confirmation/i
end
end
should have_sent_email.with_subject(/account confirmation/i)
end

context "When signing up with email already confirmed" do
Expand All @@ -72,14 +69,12 @@ def @user.initialize_salt; end
Factory(:user, :email_confirmed => true)
end

should "not send the confirmation email" do
assert_did_not_send_email
end
should_not have_sent_email
end

context "When multiple users have signed up" do
setup { Factory(:user) }
should_validate_uniqueness_of :email
should validate_uniqueness_of(:email)
end

# confirming email
Expand Down

0 comments on commit f615420

Please sign in to comment.