hashrocket-clearance 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/clearance.rb CHANGED
@@ -8,6 +8,7 @@ require 'clearance/app/models/user'
8
8
  require 'clearance/app/models/clearance_mailer'
9
9
  require 'clearance/app/models/clearance_facebook_mailer'
10
10
  require 'clearance/spec/controllers/sessions_controller_spec'
11
+ require 'clearance/spec/controllers/passwords_controller_spec'
11
12
  require 'clearance/spec/models/user_spec'
12
13
  require 'clearance/test/functional/confirmations_controller_test'
13
14
  require 'clearance/test/functional/sessions_controller_test'
@@ -22,15 +22,26 @@ module Clearance
22
22
  flash.now[:error] = 'Unknown email'
23
23
  render :action => :new
24
24
  else
25
- user.generate_reset_password_code
26
- ClearanceMailer.deliver_forgot_password user
27
- redirect_to url_after_create
25
+ if user.facebook_user?
26
+ flash.now[:error] = 'This is a Facebook account, please visit facebook.com to recover your password.'
27
+ render :action => :new
28
+ else
29
+ if user.confirmed?
30
+ user.generate_reset_password_code
31
+ ClearanceMailer.deliver_forgot_password user
32
+ redirect_to url_after_create
33
+ else
34
+ flash.now[:error] = 'Sorry, this account is not active.'
35
+ render :action => :new
36
+ end
37
+ end
28
38
  end
29
39
  end
30
40
 
31
41
  def update
32
42
  if @user.reset_password(params)
33
43
  session[:user_id] = @user.id
44
+ flash[:success] = "Your password has been updated."
34
45
  redirect_to url_after_update
35
46
  else
36
47
  flash.now[:error] = 'Password not changed.'
@@ -0,0 +1,53 @@
1
+ module Clearance
2
+ module Spec
3
+ module Controllers
4
+ module PasswordsController
5
+ def self.included(base)
6
+ base.class_eval do
7
+ include ActionController::UrlWriter
8
+
9
+ describe "#create when called for a facebook user" do
10
+ before(:each) do
11
+ @user = stub(:facebook_user? => true, :generate_reset_password_code => nil)
12
+ User.stubs(:find_by_email).returns(@user)
13
+ ClearanceMailer.stubs(:deliver_forgot_password)
14
+ end
15
+
16
+ it "should assign an error message" do
17
+ @controller.instance_eval{flash.stubs(:sweep)}
18
+ post :create
19
+ flash.now[:error].should be
20
+ end
21
+
22
+ it "should render the new template" do
23
+ post :create
24
+ response.should render_template('new')
25
+ end
26
+ end
27
+
28
+ describe "#create when called for a normal user that is unconfirmed" do
29
+ before(:each) do
30
+ @user = stub(:facebook_user? => false, :confirmed? => false, :generate_reset_password_code => nil)
31
+ User.stubs(:find_by_email).returns(@user)
32
+ ClearanceMailer.stubs(:deliver_forgot_password)
33
+ end
34
+
35
+ it "should assign an error message" do
36
+ @controller.instance_eval{flash.stubs(:sweep)}
37
+ post :create
38
+ flash.now[:error].should be
39
+ end
40
+
41
+ it "should render the new template" do
42
+ post :create
43
+ response.should render_template('new')
44
+ end
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
@@ -12,7 +12,7 @@ module Clearance
12
12
  should_route :put, '/passwords/:id', :action => 'update', :id => 'reset_password_code'
13
13
 
14
14
  context 'with a user' do
15
- setup { @user = Factory :user }
15
+ setup { @user = Factory :user, :confirmed => true }
16
16
 
17
17
  context 'A GET to #new' do
18
18
  setup { get :new }
@@ -2,6 +2,6 @@
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
- PATCH = 2
5
+ PATCH = 3
6
6
  end
7
7
  end
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe PasswordsController do
4
+ include Clearance::Spec::Controllers::PasswordsController
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashrocket-clearance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoughtbot, inc.
@@ -95,6 +95,7 @@ files:
95
95
  - lib/clearance/app/models/user.rb
96
96
  - lib/clearance/spec
97
97
  - lib/clearance/spec/controllers
98
+ - lib/clearance/spec/controllers/passwords_controller_spec.rb
98
99
  - lib/clearance/spec/controllers/sessions_controller_spec.rb
99
100
  - lib/clearance/spec/models
100
101
  - lib/clearance/spec/models/user_spec.rb
@@ -223,6 +224,7 @@ files:
223
224
  - test/rails_root/script/spec_server
224
225
  - test/rails_root/spec
225
226
  - test/rails_root/spec/controllers
227
+ - test/rails_root/spec/controllers/passwords_controller_spec.rb
226
228
  - test/rails_root/spec/controllers/session_controller_spec.rb
227
229
  - test/rails_root/spec/models
228
230
  - test/rails_root/spec/models/user_spec.rb