Created
April 11, 2009 15:57
-
-
Save agibralter/93603 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/opt/local/bin/ruby /opt/local/lib/ruby/gems/1.8/gems/rspec-1.2.2/bin/spec --autospec spec/controllers/password_resets_controller_spec.rb -O spec/spec.opts | |
F.. | |
1) | |
NoMethodError in 'PasswordResetsController PUT /password_resets/update re-renders the 'edit' template' | |
You have a nil object when you didn't expect it! | |
You might have expected an instance of ActiveRecord::Base. | |
The error occurred while evaluating nil.[] | |
/Users/jeff/development/urlagg/app/controllers/password_resets_controller.rb:27:in `update' | |
./spec/controllers/password_resets_controller_spec.rb:26: | |
Finished in 0.203365 seconds | |
3 examples, 1 failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PasswordResetsController < ApplicationController | |
before_filter :load_user_using_perishable_token, :only => [:edit, :update] | |
before_filter :require_no_user | |
def new | |
render | |
end | |
def create | |
@user = User.find_by_email(params[:email]) | |
if @user | |
@user.deliver_password_reset_instructions! | |
flash[:notice] = "An email has been sent with instructions to reset your password." | |
redirect_to root_url | |
else | |
flash[:notice] = "No user was found with that email address" | |
render :action => :new | |
end | |
end | |
def edit | |
render | |
end | |
def update | |
if @user.update_password_attributes(params[:user]) | |
flash[:notice] = "Password has been changed" | |
redirect_to account_url | |
else | |
render :action => :edit | |
end | |
end | |
private | |
def load_user_using_perishable_token | |
@user = User.find_using_perishable_token(params[:id]) | |
unless @user | |
flash[:notice] = "We're sorry, but we could not locate your account. " + | |
"If you are having issues try copying and pasting the URL " + | |
"from your email into your browser or restarting the " + | |
"reset password process." | |
redirect_to root_url | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
describe PasswordResetsController do | |
include EmailSpec::Helpers | |
include EmailSpec::Matchers | |
describe "POST /password_resets/create" do | |
it "should deliver the password reset instructions email" do | |
# expect | |
@user = Factory.create(:registered_user) | |
Notifier.should_receive(:deliver_password_reset_instructions).with(@user) | |
# when | |
post :create, :email => @user.email | |
end | |
it "should display the form again if email not found" do | |
User.should_receive(:find_by_email).with("[email protected]").and_return(nil) | |
post :create, :email => '[email protected]' | |
response.should render_template('new') | |
end | |
end | |
describe "PUT /password_resets/update" do | |
def do_action(params={}) | |
put :update, {:id => "1"}.merge(params) | |
end | |
before(:each) do | |
@user = mock_model(User) | |
User.stub!(:find).and_return(@user) | |
end | |
it "should update the password attributes" do | |
@user.should_receive(:update_password_attributes).with("some password params") | |
do_action(:user => "some password params") | |
end | |
describe "failed update" do | |
before(:each) do | |
@user.stub!(:update_password_attributes).and_return(false) | |
end | |
it "should render edit" do | |
do_action | |
response.should render_template(:edit) | |
end | |
it "should flash notice" do | |
do_action | |
flash[:notice].should_not be_nil | |
end | |
end | |
describe "successful update" do | |
before(:each) do | |
@user.stub!(:update_password_attributes).and_return(true) | |
end | |
it "should redirect" do | |
do_action | |
response.should redirect_to(account_url) | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment