Skip to content

Instantly share code, notes, and snippets.

@dsabanin
Created November 20, 2012 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsabanin/4118737 to your computer and use it in GitHub Desktop.
Save dsabanin/4118737 to your computer and use it in GitHub Desktop.
Idea for ruby test framework
class User < ActiveRecord::Base
test_context(:inherit => [:account_context]) do
@password = "123456"
@user = User.create(:login => "dima",
:first_name => "Dima",
:last_name => "Pupkin",
:password => @password,
:password_confirmation => @password,
:account => @account)
end
belongs_to :account
validates_presence_of :name
def self.authenticate(subdomain, login_or_email, password)
account = Account.by_subdomain(subdomain) or return(false)
if account.grandfathering_old_authentication_method?
result = account.authenticate_user_via_insensitive_login_or_email(login_or_email, password)
else
result = account.authenticate_user_via_sensitive_login(login_or_email, password)
end
if result && result.password_strength_score.nil?
result.memorize_score_for_password(password, :save => true)
end
result
end
deftest :self_authenticate, "without grandfathering" do
assert_equal @account, User.authenticate(@account.tld, @user.login, @password)
assert_instance_of Numeric, @account.password_strength_score
end
deftest :self_authenticate, "with grandfathering" do
@account.expects(:grandfathering_old_authentication_method?).returns(true)
assert_equal @account, User.authenticate(@account.tld, @user.login.upcase!, @password)
assert_instance_of Numeric, @account.password_strength_score
end
def full_name
"#{first_name} #{last_name}"
end
deftest :full_name do
assert_equal "Dima Pupkin", @user.full_name
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment