Skip to content

Commit 30580d7

Browse files
committed
Merge branch 'current-user-bug' of https://github.com/alindeman/hackety-hack.com into alindeman-current-user-bug
2 parents 63df1d5 + 2bf5820 commit 30580d7

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

helpers.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
# keep track of that by just setting a session variable with their id. If it
2020
# doesn't exist, we just want to return nil.
2121
def current_user
22-
return Hacker.first(:id => session[:hacker_id]) if session[:hacker_id]
23-
nil
22+
return nil unless session[:hacker_id]
23+
24+
# Memoize to make sure code like this works properly:
25+
# current_user.password = 'foo'
26+
# current_user.save
27+
@current_user ||= Hacker.first(:id => session[:hacker_id]) if session[:hacker_id]
2428
end
2529

2630
# This very simple method checks if we've got a logged in user. That's pretty

spec/acceptance/hacker_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,19 @@
9292
page.should have_content "Following: 0"
9393
end
9494

95+
scenario "can change password" do
96+
@andy = Factory(:hacker, :username => "alindeman")
97+
log_in @andy
98+
99+
visit "/hackers/alindeman"
100+
fill_in "password[new]", :with => "abc123"
101+
fill_in "password[confirm]", :with => "abc123"
102+
click_button "Change password"
103+
104+
page.should have_content "Password updated!"
105+
106+
# Verify password was changed in the underlying datastore
107+
Hacker.authenticate("alindeman", "abc123").should be
108+
end
109+
95110
end

0 commit comments

Comments
 (0)