Skip to content

Commit

Permalink
Make assert_unique_email a method, conducive for overriding.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyril David committed Apr 27, 2011
1 parent 12a03de commit 531e8e6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/shield/contrib/ohm/email_password.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def email
def validate def validate
super super


assert_present(:email) && assert_email(:email) && assert_unique(:email) assert_present(:email) && assert_email(:email) && assert_unique_email(:email)


assert_present(:password) if new? assert_present(:password) if new?


Expand All @@ -53,6 +53,10 @@ def password=(password)
end end


private private
def assert_unique_email(att, error = [att, :not_unique])
assert_unique(att, error)
end

def assert_email(att, error = [att, :not_email]) def assert_email(att, error = [att, :not_email])
assert_format(att, EMAIL_REGEX, error) assert_format(att, EMAIL_REGEX, error)
end end
Expand Down
9 changes: 6 additions & 3 deletions test/helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ class Cutest::Scope
include Rack::Test::Methods include Rack::Test::Methods


def assert_redirected_to(path) def assert_redirected_to(path)
assert 302 == last_response.status assert_equal 302, last_response.status
assert path == last_response.headers["Location"]
end fullpath = last_response.headers["Location"].
gsub(%r{^http://([^/]+)}, "")


assert_equal path, fullpath
end


def session def session
last_request.env["rack.session"] last_request.env["rack.session"]
Expand Down
2 changes: 1 addition & 1 deletion test/sinatra_default_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def app
assert_redirected_to "/dashboard" assert_redirected_to "/dashboard"
follow_redirect! follow_redirect!


assert "Dashboard" == last_response.body assert_equal "Dashboard", last_response.body
end end


test "GET /logout" do test "GET /logout" do
Expand Down

0 comments on commit 531e8e6

Please sign in to comment.