Skip to content

Commit

Permalink
improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Reinsch committed Mar 18, 2010
1 parent b85f587 commit efbedfa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
8 changes: 4 additions & 4 deletions test/acts_as_authentic_test.rb
Expand Up @@ -14,7 +14,7 @@ def test_password_not_required_on_create
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 redirecting_to_yahoo?
assert_redirecting_to_yahoo "for_model"
end

def test_password_required_on_create
Expand Down Expand Up @@ -69,7 +69,7 @@ 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 redirecting_to_yahoo?
assert_redirecting_to_yahoo "for_model"
end

def test_updating_without_openid
Expand All @@ -78,14 +78,14 @@ def test_updating_without_openid
ben.password = "test"
ben.password_confirmation = "test"
assert ben.save
assert !redirecting_to_yahoo?
assert_not_redirecting
end

def test_updating_without_validation
ben = users(:ben)
ben.openid_identifier = "https://me.yahoo.com/a/9W0FJjRj0o981TMSs0vqVxPdmMUVOQ--"
assert ben.save(false)
assert !redirecting_to_yahoo?
assert_not_redirecting
end

def test_updating_without_a_block
Expand Down
4 changes: 2 additions & 2 deletions test/session_test.rb
Expand Up @@ -20,13 +20,13 @@ def test_validate_openid_error
def test_validate_by_nil_openid_identifier
session = UserSession.new
assert !session.save
assert !redirecting_to_yahoo?
assert_not_redirecting
end

def test_validate_by_correct_openid_identifier
session = UserSession.new
session.openid_identifier = "https://me.yahoo.com/a/9W0FJjRj0o981TMSs0vqVxPdmMUVOQ--"
assert !session.save
assert redirecting_to_yahoo?
assert_redirecting_to_yahoo "for_session"
end
end
13 changes: 9 additions & 4 deletions test/test_helper.rb
Expand Up @@ -105,8 +105,13 @@ def create_controller
Authlogic::ControllerAdapters::RailsAdapter.new(c)
end

def redirecting_to_yahoo?
expected = "OpenID identifier=\"https://me.yahoo.com/a/9W0FJjRj0o981TMSs0vqVxPdmMUVOQ--\", return_to=\"http://test.host/?for_model=1\", optional=\"\", method=\"post\", required=\"\""
@response.headers["WWW-Authenticate"] == expected
def assert_redirecting_to_yahoo(for_param)
[ /^OpenID identifier="https:\/\/me.yahoo.com\/a\/9W0FJjRj0o981TMSs0vqVxPdmMUVOQ--"/,
/return_to=\"http:\/\/test.host\/\?#{for_param}=1"/,
/method="post"/ ].each {|p| assert_match p, @response.headers["WWW-Authenticate"]}
end
end

def assert_not_redirecting
assert ! @response.headers["WWW-Authenticate"]
end
end

0 comments on commit efbedfa

Please sign in to comment.