Permalink
Browse files

* Only authenticate with OpenID for models when a block is passed.

  • Loading branch information...
1 parent 05a6a96 commit 77def850a71128d049b1e06ec29e2509ac764c31 @binarylogic binarylogic committed Apr 4, 2009
Showing with 26 additions and 10 deletions.
  1. +4 −0 CHANGELOG.rdoc
  2. +4 −7 lib/authlogic_openid/acts_as_authentic.rb
  3. +18 −3 test/acts_as_authentic_test.rb
View
@@ -1,3 +1,7 @@
+== 1.0.4
+
+* Only authenticate with OpenID for models when a block is passed.
+
== 1.0.3 released 2009-4-3
* Added find_by_openid_identifier config option for AuthlogicOpenid::Session.
@@ -68,13 +68,10 @@ def openid_identifier=(value)
# Another advantage of taking this approach is that we can set fields from their OpenID profile before we save the record,
# if their OpenID provider supports it.
def save(perform_validation = true, &block)
- if !perform_validation || !authenticate_with_openid? || (authenticate_with_openid? && authenticate_with_openid)
- result = super
- yield(result) if block_given?
- result
- else
- false
- end
+ return false if perform_validation && block_given? && authenticate_with_openid? && !authenticate_with_openid
+ result = super
+ yield(result) if block_given?
+ result
end
private
@@ -13,7 +13,7 @@ def test_password_not_required_on_create
user.login = "sweet"
user.email = "a@a.com"
user.openid_identifier = "https://me.yahoo.com/a/9W0FJjRj0o981TMSs0vqVxPdmMUVOQ--"
- assert !user.save # because we are redirecting, the user was NOT saved
+ assert !user.save {} # because we are redirecting, the user was NOT saved
assert redirecting_to_yahoo?
end
@@ -32,7 +32,7 @@ def test_password_not_required_on_update
assert ben.save
end
- def test_password__required_on_update
+ def test_password_required_on_update
ben = users(:ben)
ben.openid_identifier = nil
assert_nil ben.crypted_password
@@ -68,7 +68,7 @@ def test_blank_openid_identifer_gets_set_to_nil
def test_updating_with_openid
ben = users(:ben)
ben.openid_identifier = "https://me.yahoo.com/a/9W0FJjRj0o981TMSs0vqVxPdmMUVOQ--"
- assert !ben.save # because we are redirecting
+ assert !ben.save {} # because we are redirecting
assert redirecting_to_yahoo?
end
@@ -87,4 +87,19 @@ def test_updating_without_validation
assert ben.save(false)
assert !redirecting_to_yahoo?
end
+
+ def test_updating_without_a_block
+ ben = users(:ben)
+ ben.openid_identifier = "https://me.yahoo.com/a/9W0FJjRj0o981TMSs0vqVxPdmMUVOQ--"
+ assert ben.save
+ ben.reload
+ assert_equal "https://me.yahoo.com/a/9W0FJjRj0o981TMSs0vqVxPdmMUVOQ--", ben.openid_identifier
+ end
+
+ def test_updating_while_not_activated
+ UserSession.controller = nil
+ ben = users(:ben)
+ ben.openid_identifier = "https://me.yahoo.com/a/9W0FJjRj0o981TMSs0vqVxPdmMUVOQ--"
+ assert ben.save {}
+ end
end

0 comments on commit 77def85

Please sign in to comment.