Skip to content

Instantly share code, notes, and snippets.

@mrichman
Created June 15, 2009 15:56
Show Gist options
  • Save mrichman/130184 to your computer and use it in GitHub Desktop.
Save mrichman/130184 to your computer and use it in GitHub Desktop.
Scenario: Allow login of a user with valid credentials
Given "hector" a confirmed user with password "supersecret"
When I go to the login page
And I fill in "login" with "hector"
And I fill in "password" with "supersecret"
And I press "Login"
Then I should be logged in
Given /^"(.*)" a confirmed user with password "(.*)"$/ do |name, password|
Given "\"#{name}\" an unconfirmed user with password \"#{password}\""
And "I receive an email"
And "I open the email"
And "I should see \"confirm\" in the email"
When "I follow \"confirm\" in the email"
Then "I should see my account page"
visit '/logout'
end
Scenario: Allow login of a user with valid credentials # features/authentication/authentication.feature:16
Given "hector" a confirmed user with password "supersecret" # features/registration/step_definitions/registration_steps.rb:40
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.+ (NoMethodError)
/Users/mark/code/SpringBoard/app/models/user_mailer.rb:22:in `setup_email'
/Users/mark/code/SpringBoard/app/models/user_mailer.rb:4:in `signup_notification'
/Users/mark/code/SpringBoard/app/models/user_observer.rb:3:in `after_create'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/observer.rb:185:in `notify_observers'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/observer.rb:184:in `each'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/observer.rb:184:in `notify_observers'
/Users/mark/code/SpringBoard/vendor/plugins/active_scaffold/lib/extensions/unsaved_record.rb:15:in `save'
/Users/mark/code/SpringBoard/app/controllers/users_controller.rb:11:in `create'
(eval):2:in `click_button'
./features/step_definitions/webrat_steps.rb:15:in `/^I press "([^\"]*)"$/'
features/authentication/authentication.feature:17:in `Given "hector" a confirmed user with password "supersecret"'
When I go to the login page # features/step_definitions/webrat_steps.rb:10
And I fill in "login" with "hector" # features/step_definitions/webrat_steps.rb:22
And I fill in "password" with "supersecret" # features/step_definitions/webrat_steps.rb:22
And I press "Login" # features/step_definitions/webrat_steps.rb:14
Then I should be logged in # features/registration/step_definitions/registration_steps.rb:65
# -*- coding: utf-8 -*-
class UserMailer < ActionMailer::Base
def signup_notification(user)
setup_email(user)
@subject += I18n.t('user_mailer.signup_subject')
end
def activation(user)
setup_email(user)
@subject += I18n.t('user_mailer.activation_subject')
end
def reset_password_instructions(user)
setup_email(user)
@subject += I18n.t('user_mailer.reset_password_subject')
end
protected
def setup_email(user)
recipients user.email
from I18n.t('user_mailer.from', :email => '<notifications@example.com>')
@subject += I18n.t('user_mailer.setup_subject')
sent_on Time.now
body :user => user
end
end
class UserObserver < ActiveRecord::Observer
def after_create(user)
UserMailer.deliver_signup_notification(user)
# Easy confirmation URL for testing in the browser
if RAILS_ENV == "development"
ActiveRecord::Base.logger.debug "\nCopy & Paste Confirmation:\nlocalhost:3000/" +
"account/confirm?locale=#{I18n.locale.to_s}&token=#{user.perishable_token}\n\n"
end
end
def after_save(user)
UserMailer.deliver_activation(user) if user.recently_confirmed?
end
end
class UsersController < ApplicationController
before_filter :require_no_user, :only => [:new, :create]
before_filter :require_user, :only => [:show, :edit, :update]
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
flash[:notice] = t :register_successful
redirect_to root_url
else
render :new
end
end
def show
@user = @current_user
render :edit
end
def edit
@user = @current_user
end
def update
@user = @current_user # makes our views "cleaner" and more consistent
if @user.update_attributes(params[:user])
flash[:notice] = t :account_updated
redirect_to account_url
else
render :edit
end
end
def confirm
@user = User.find_using_perishable_token(params[:token])
if @user
@user.confirm!
UserSession.create(@user)
flash[:notice] = t :confirm_successful
redirect_to account_url
else
flash[:error] = t :confirm_unsuccessful
redirect_to root_url
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment