Commit 9d7da7aad987b7a36bfa4d57ef24e2eced510bb7
1 parent
691dced5
Exists in
master
and in
29 other branches
ActionItem78: finishing requirement
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@648 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
6 changed files
with
47 additions
and
7 deletions
Show diff stats
app/controllers/public/account_controller.rb
@@ -75,6 +75,7 @@ class AccountController < PublicController | @@ -75,6 +75,7 @@ class AccountController < PublicController | ||
75 | # Posts back. | 75 | # Posts back. |
76 | def forgot_password | 76 | def forgot_password |
77 | @change_password = ChangePassword.new(params[:change_password]) | 77 | @change_password = ChangePassword.new(params[:change_password]) |
78 | + | ||
78 | if request.post? | 79 | if request.post? |
79 | begin | 80 | begin |
80 | @change_password.save! | 81 | @change_password.save! |
app/models/change_password.rb
@@ -72,9 +72,10 @@ class ChangePassword < Task | @@ -72,9 +72,10 @@ class ChangePassword < Task | ||
72 | def create_message | 72 | def create_message |
73 | hostname = self.requestor.environment.default_hostname | 73 | hostname = self.requestor.environment.default_hostname |
74 | code = self.code | 74 | code = self.code |
75 | + url = generate_url(:host => hostname, :controller => 'account', :action => 'new_password', :code => code) | ||
75 | 76 | ||
76 | lambda do | 77 | lambda do |
77 | - _("In order to change your password, please visit the following address:\n\n%s") % url_for(:host => hostname, :controller => 'account', :action => 'new_password', :code => code) | 78 | + _("In order to change your password, please visit the following address:\n\n%s") % url |
78 | end | 79 | end |
79 | end | 80 | end |
80 | 81 |
lib/noosfero/url.rb
@@ -45,11 +45,11 @@ module Noosfero::URL | @@ -45,11 +45,11 @@ module Noosfero::URL | ||
45 | Noosfero::URL.config['path'] | 45 | Noosfero::URL.config['path'] |
46 | end | 46 | end |
47 | 47 | ||
48 | - def url_for(options) | 48 | + def generate_url(options) |
49 | local_options = {} | 49 | local_options = {} |
50 | local_options[:port] = self.port unless self.port.nil? | 50 | local_options[:port] = self.port unless self.port.nil? |
51 | 51 | ||
52 | - url = super(local_options.merge(options)) | 52 | + url = url_for(local_options.merge(options)) |
53 | 53 | ||
54 | if self.path.blank? | 54 | if self.path.blank? |
55 | url | 55 | url |
test/functional/account_controller_test.rb
@@ -184,10 +184,10 @@ class AccountControllerTest < Test::Unit::TestCase | @@ -184,10 +184,10 @@ class AccountControllerTest < Test::Unit::TestCase | ||
184 | 184 | ||
185 | should 'respond to forgotten password change request' do | 185 | should 'respond to forgotten password change request' do |
186 | change = ChangePassword.new | 186 | change = ChangePassword.new |
187 | - ChangePassword.expects(:new).returns(change) | 187 | + ChangePassword.expects(:new).with('login' => 'test', 'email' => 'test@localhost.localdomain').returns(change) |
188 | change.expects(:save!).returns(true) | 188 | change.expects(:save!).returns(true) |
189 | 189 | ||
190 | - post :forgot_password | 190 | + post :forgot_password, :change_password => { :login => 'test', :email => 'test@localhost.localdomain' } |
191 | assert_template 'password_recovery_sent' | 191 | assert_template 'password_recovery_sent' |
192 | end | 192 | end |
193 | 193 |
@@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
1 | +require "#{File.dirname(__FILE__)}/../test_helper" | ||
2 | + | ||
3 | +class ForgotPasswordTest < ActionController::IntegrationTest | ||
4 | + | ||
5 | + def test_forgot_password | ||
6 | + | ||
7 | + User.destroy_all | ||
8 | + Profile.destroy_all | ||
9 | + ChangePassword.destroy_all | ||
10 | + | ||
11 | + User.create!(:login => 'forgotten', :password => 'test', :password_confirmation => 'test', :email => 'forgotten@localhost.localdomain') | ||
12 | + | ||
13 | + get '/account/forgot_password' | ||
14 | + | ||
15 | + assert_response :success | ||
16 | + assert_tag :tag => 'form', :attributes => { :action => '/account/forgot_password', :method => 'post' } | ||
17 | + | ||
18 | + post '/account/forgot_password', :change_password => { :login => 'forgotten', :email => 'forgotten@localhost.localdomain' } | ||
19 | + | ||
20 | + assert_response :success | ||
21 | + assert_template 'password_recovery_sent' | ||
22 | + | ||
23 | + assert_equal 1, ChangePassword.count | ||
24 | + code = ChangePassword.find(:first).code | ||
25 | + | ||
26 | + get "/account/new_password/#{code}" | ||
27 | + assert_response :success | ||
28 | + assert_tag :tag => 'form', :attributes => { :action => "/account/new_password/#{code}" } | ||
29 | + | ||
30 | + post "/account/new_password/#{code}", :change_password => { :password => 'newpass', :password_confirmation => 'newpass'} | ||
31 | + assert_response :success | ||
32 | + assert_template 'new_password_ok' | ||
33 | + assert_tag :tag => 'a', :attributes => { :href => "/account/login" } | ||
34 | + | ||
35 | + assert User.find_by_login('forgotten').authenticated?('newpass') | ||
36 | + end | ||
37 | + | ||
38 | +end |
test/unit/noosfero_url_test.rb
@@ -37,13 +37,13 @@ class NoosferoURLTest < Test::Unit::TestCase | @@ -37,13 +37,13 @@ class NoosferoURLTest < Test::Unit::TestCase | ||
37 | should 'add path when needed' do | 37 | should 'add path when needed' do |
38 | self.stubs(:path).returns('/somepath') | 38 | self.stubs(:path).returns('/somepath') |
39 | self.stubs(:port).returns(nil) | 39 | self.stubs(:port).returns(nil) |
40 | - assert_equal('http://example.com/somepath/', url_for(:host => 'example.com', :controller => 'home')) | 40 | + assert_equal('http://example.com/somepath/', generate_url(:host => 'example.com', :controller => 'home')) |
41 | end | 41 | end |
42 | 42 | ||
43 | should 'not add path when it is not needed' do | 43 | should 'not add path when it is not needed' do |
44 | self.stubs(:path).returns(nil) | 44 | self.stubs(:path).returns(nil) |
45 | self.stubs(:port).returns(nil) | 45 | self.stubs(:port).returns(nil) |
46 | - assert_equal('http://example.com/', url_for(:host => 'example.com', :controller => 'home')) | 46 | + assert_equal('http://example.com/', generate_url(:host => 'example.com', :controller => 'home')) |
47 | end | 47 | end |
48 | 48 | ||
49 | end | 49 | end |