simple_auth 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -1,6 +1,15 @@
1
1
  module SimpleAuth
2
2
  module ActiveRecord
3
3
  module InstanceMethods
4
+ def password=(password)
5
+ @password_changed = true
6
+ @password = password
7
+ end
8
+
9
+ def password_changed?
10
+ @password_changed == true
11
+ end
12
+
4
13
  private
5
14
  def encrypt_password
6
15
  self.password_salt = SimpleAuth::Config.salt.call(self)
@@ -10,10 +19,14 @@ module SimpleAuth
10
19
  def erase_password
11
20
  self.password = nil
12
21
  self.password_confirmation = nil
22
+
23
+ # Mark password as unchanged after erasing passwords,
24
+ # or it will be marked as changed anyway
25
+ @password_changed = false
13
26
  end
14
27
 
15
28
  def validate_password?
16
- new_record? || password.present?
29
+ new_record? || password_changed?
17
30
  end
18
31
  end
19
32
 
@@ -62,7 +75,7 @@ module SimpleAuth
62
75
  # end
63
76
  # end
64
77
  def has_authentication(&block)
65
- attr_accessor :password
78
+ attr_reader :password
66
79
  attr_accessor :password_confirmation
67
80
 
68
81
  SimpleAuth.setup(&block)
@@ -2,7 +2,7 @@ module SimpleAuth
2
2
  module Version
3
3
  MAJOR = "0"
4
4
  MINOR = "1"
5
- PATCH = "3"
5
+ PATCH = "4"
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
data/simple_auth.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{simple_auth}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nando Vieira"]
12
- s.date = %q{2010-01-25}
12
+ s.date = %q{2010-01-27}
13
13
  s.description = %q{When Authlogic & Devise are just too much.
14
14
  }
15
15
  s.email = %q{fnando.vieira@gmail.com}
@@ -34,6 +34,22 @@ describe SimpleAuth::ActiveRecord do
34
34
  subject.password.should be_nil
35
35
  subject.password_confirmation.should be_nil
36
36
  end
37
+
38
+ it "should mark password as changed" do
39
+ subject = User.new(:password => "test")
40
+ subject.password_changed?.should be_true
41
+ end
42
+
43
+ it "should not mark password as changed" do
44
+ subject = User.new
45
+ subject.password_changed?.should be_false
46
+ end
47
+
48
+ it "should mark password as unchanged after saving" do
49
+ subject = User.new(:password => "test", :password_confirmation => "test")
50
+ subject.save(false)
51
+ subject.password_changed?.should be_false
52
+ end
37
53
  end
38
54
 
39
55
  context "existing record" do
@@ -56,11 +72,18 @@ describe SimpleAuth::ActiveRecord do
56
72
  subject.should be_valid
57
73
  end
58
74
 
59
- it "should not require password confirmation when it has changed" do
75
+ it "should require password confirmation when it has changed" do
60
76
  subject.password = "newpass"
77
+ subject.should_not be_valid
61
78
  subject.should have(1).error_on(:password_confirmation)
62
79
  end
63
80
 
81
+ it "should require password when it has changed to blank" do
82
+ subject.password = nil
83
+ subject.should_not be_valid
84
+ subject.should have(1).error_on(:password)
85
+ end
86
+
64
87
  it "should authenticate using email" do
65
88
  User.authenticate("john@doe.com", "test").should == subject
66
89
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-25 00:00:00 -02:00
12
+ date: 2010-01-27 00:00:00 -02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15