Skip to content

Commit

Permalink
Unified references to user actions sign up, sign in, and sign out
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Feb 2, 2009
1 parent a5a8e30 commit 368d0d4
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 140 deletions.
2 changes: 1 addition & 1 deletion generators/clearance/templates/test/factories/clearance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"user#{n}@example.com"
end

Factory.define :registered_user, :class => 'user' do |user|
Factory.define :user do |user|
user.email { Factory.next :email }
user.password { "password" }
user.password_confirmation { "password" }
Expand Down
6 changes: 3 additions & 3 deletions generators/clearance_features/clearance_features_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ def manifest
m.directory File.join("features", "step_definitions")

["features/step_definitions/clearance_steps.rb",
"features/signin.feature",
"features/signout.feature",
"features/signup.feature"].each do |file|
"features/sign_in.feature",
"features/sign_out.feature",
"features/sign_up.feature"].each do |file|
m.file file, file
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
Feature: Signin
Feature: Sign in
In order to get access to protected sections of the site
A registered user
Should be able to sign in

Scenario User is not registered
Given there is no user with "email@person.com"
When I go to the signin page
When I go to the sign in page
And I sign in as "email@person.com/password"
Then I should see "Bad email or password"
And I should not be signed in

Scenario: User is not confirmed
Given I signed up with "email@person.com/password"
When I go to the signin page
When I go to the sign in page
And I sign in as "email@person.com/password"
Then I should see "User has not confirmed email"
And I should not be signed in

Scenario: User enters wrong password
Given I am signed up and confirmed as "email@person.com/password"
When I go to the signin page
When I go to the sign in page
And I sign in as "email@person.com/wrongpassword"
Then I should see "Bad email or password"
And I should not be signed in

Scenario: User signs in successfully
Given I am signed up and confirmed as "email@person.com/password"
When I go to the signin page
When I go to the sign in page
And I sign in as "email@person.com/password"
Then I should see "Signed in successfully"
And I should be signed in

Scenario: User signs in and checks "remember me"
Given I am signed up and confirmed as "email@person.com/password"
When I go to the signin page
When I go to the sign in page
And I sign in with "remember me" as "email@person.com/password"
Then I should see "Signed in successfully"
And I should be signed in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Feature: Signout
Feature: Sign out
To protect my account from unauthorized access
A signed in user
Should be able to sign out
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Feature: Signup
Feature: Sign up
In order to get access to protected sections of the site
A user
Should be able to sign up

Scenario: User signs up with invalid data
When I go to the signup page
When I go to the sign up page
And I fill in "Email" with "invalidemail"
And I fill in "Password" with "password"
And I fill in "Verify Password" with ""
And I press "Sign Up"
Then I should see error messages

Scenario: User signs up with valid data
When I go to the signup page
When I go to the sign up page
And I fill in "Email" with "email@person.com"
And I fill in "Password" with "password"
And I fill in "Verify Password" with "password"
Expand Down
30 changes: 0 additions & 30 deletions generators/clearance_features/templates/features/signup.feature

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

Given /^I signed up with "(.*)\/(.*)"$/ do |email, password|
user = Factory :registered_user,
user = Factory :user,
:email => email,
:password => password,
:password_confirmation => password
Expand Down Expand Up @@ -74,7 +74,7 @@
# Actions

When /^I sign in( with "remember me")? as "(.*)\/(.*)"$/ do |remember, email, password|
When %{I go to the signin page}
When %{I go to the sign in page}
And %{I fill in "Email" with "#{email}"}
And %{I fill in "Password" with "#{password}"}
And %{I check "Remember me"} if remember
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def self.included(controller_test)
should_filter_params :token

context "Given a user whose email has not been confirmed" do
setup { @user = Factory(:registered_user) }

setup { @user = Factory(:user) }
context "on GET to #new with correct id and token" do
setup do
get :new, :user_id => @user.to_param, :token => @user.token
Expand Down
2 changes: 1 addition & 1 deletion lib/clearance/test/functional/passwords_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def self.included(controller_test)

context "with a confirmed user" do
setup do
@user = Factory(:registered_user)
@user = Factory(:user)
@user.confirm_email!
end

Expand Down
6 changes: 3 additions & 3 deletions lib/clearance/test/functional/sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def self.included(controller_test)
should_display_a_sign_in_form
end

context "Given a registered user" do
setup { @user = Factory(:registered_user) }
context "Given a user" do
setup { @user = Factory(:user) }

context "a POST to #create with good credentials" do
setup do
Expand All @@ -41,7 +41,7 @@ def self.included(controller_test)

context "Given an email confirmed user" do
setup do
@user = Factory(:registered_user)
@user = Factory(:user)
@user.confirm_email!
end

Expand Down
4 changes: 2 additions & 2 deletions lib/clearance/test/functional/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.included(controller_test)
should_render_template :new
should_not_set_the_flash

should_display_a_registration_form
should_display_a_sign_up_form
end

context "Given email parameter when getting new User view" do
Expand All @@ -32,7 +32,7 @@ def self.included(controller_test)

context "Given valid attributes when creating a new user" do
setup do
user_attributes = Factory.attributes_for(:registered_user)
user_attributes = Factory.attributes_for(:user)
post :create, :user => user_attributes
end

Expand Down
2 changes: 1 addition & 1 deletion lib/clearance/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def self.included(test_helper)

def sign_in_as(user = nil)
unless user
user = Factory(:registered_user)
user = Factory(:user)
user.confirm_email!
end
@request.session[:user_id] = user.id
Expand Down
4 changes: 2 additions & 2 deletions lib/clearance/test/unit/clearance_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.included(mailer_test)

context "A change password email" do
setup do
@user = Factory(:registered_user)
@user = Factory(:user)
@email = ClearanceMailer.create_change_password @user
end

Expand All @@ -33,7 +33,7 @@ def self.included(mailer_test)

context "A confirmation email" do
setup do
@user = Factory(:registered_user)
@user = Factory(:user)
@email = ClearanceMailer.create_confirmation @user
end

Expand Down
28 changes: 14 additions & 14 deletions lib/clearance/test/unit/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ def self.included(unit_test)
:salt, :encrypted_password,
:token, :token_expires_at

# registering
# signing up

context "When registering" do
context "When signing up" do
should_require_attributes :email, :password
should_allow_values_for :email, "foo@example.com"
should_not_allow_values_for :email, "foo"
should_not_allow_values_for :email, "example.com"

should_validate_confirmation_of :password,
:factory => :registered_user
:factory => :user

should "initialize salt" do
assert_not_nil Factory(:registered_user).salt
assert_not_nil Factory(:user).salt
end

should "initialize token witout expiry date" do
assert_not_nil Factory(:registered_user).token
assert_nil Factory(:registered_user).token_expires_at
assert_not_nil Factory(:user).token
assert_nil Factory(:user).token_expires_at
end

context "encrypt password" do
setup do
@salt = "salt"
User.any_instance.stubs(:initialize_salt)

@user = Factory(:registered_user, :salt => @salt)
@user = Factory(:user, :salt => @salt)
@password = @user.password

@user.encrypt(@password)
Expand All @@ -49,22 +49,22 @@ def self.included(unit_test)
end

should "store email in lower case" do
user = Factory(:registered_user, :email => "John.Doe@example.com")
user = Factory(:user, :email => "John.Doe@example.com")
assert_equal "john.doe@example.com", user.email
end
end

context "When multiple users have registerd" do
setup { @user = Factory(:registered_user) }
context "When multiple users have signed up" do
setup { @user = Factory(:user) }

should_require_unique_attributes :email
end

# confirming email

context "A registered user without email confirmation" do
context "A user without email confirmation" do
setup do
@user = Factory(:registered_user)
@user = Factory(:user)
assert ! @user.email_confirmed?
end

Expand All @@ -88,7 +88,7 @@ def self.included(unit_test)

context "A user" do
setup do
@user = Factory(:registered_user)
@user = Factory(:user)
@password = @user.password
end

Expand Down Expand Up @@ -176,7 +176,7 @@ def self.included(unit_test)

context "An email confirmed user" do
setup do
@user = Factory(:registered_user)
@user = Factory(:user)
@user.confirm_email!
end

Expand Down
8 changes: 4 additions & 4 deletions shoulda_macros/clearance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def should_deny_access(opts = {})
def signed_in_user_context(&blk)
context "A signed in user" do
setup do
@user = Factory(:registered_user)
@user = Factory(:user)
@user.confirm_email!
sign_in_as @user
end
Expand Down Expand Up @@ -184,10 +184,10 @@ def should_display_a_password_update_form
end
end

def should_display_a_registration_form
should "display a form to register" do
def should_display_a_sign_up_form
should "display a form to sign up" do
assert_select "form[action=#{users_path}][method=post]",
true, "There must be a form to register" do
true, "There must be a form to sign up" do
assert_select "input[type=text][name=?]",
"user[email]", true, "There must be an email field"
assert_select "input[type=password][name=?]",
Expand Down
41 changes: 0 additions & 41 deletions test/rails_root/features/signin.feature

This file was deleted.

Loading

0 comments on commit 368d0d4

Please sign in to comment.