<commit_before>require 'rubygems'
require 'sinatra/base'
require 'test/unit'
require 'rack/test'
require 'dm-core'
require 'sinatra/simple-authentication'
require 'nokogiri'

module Sinatra
  class Base
    set :environment, :test
    DataMapper::Logger.new($stdout, :debug)
    DataMapper.setup(:default, "sqlite://#{Dir.pwd}/test.db")
    register Sinatra::SimpleAuthentication
  end
end

class SimpleAuthenticationTest < Test::Unit::TestCase
  include Rack::Test::Methods

  def app
    Sinatra::Application
  end

  def test_signup_page
    get '/signup'
    assert last_response.ok?

    html = Nokogiri::HTML(last_response.body)
    assert html.css('[name="email"]')
    assert html.css('[name="password"]')
    assert html.css('[name="password_confirmation"]')
  end

  def test_login_page
    get '/login'
    assert last_response.ok?

    html = Nokogiri::HTML(last_response.body)
    assert html.css('[name="email"]')
    assert html.css('[name="password"]')

    #get '/logout'
    #assert last_response.ok?
  end

  def test_user_validations
    user = User.new
    assert !user.save

    assert user.errors.include?(["Email must not be blank"])
    assert user.errors.include?(["Password must not be blank"])
    assert user.errors.include?(["Password must be between 4 and 16 characters long"])

    #Short password
    user = User.new
    user.password = "tt"
    assert !user.save
    assert user.errors.include?(["Password must be between 4 and 16 characters long", "Password does not match the confirmation"])
    assert user.errors.include?(["Email must not be blank"])

    #Long password
    user = User.new
    user.password = "<PASSWORD>"
    assert !user.save
    assert user.errors.include?(["Password must be between 4 and 16 characters long", "Password does not match the confirmation"])
    assert user.errors.include?(["Email must not be blank"])

    #Wrong format email
    user = User.new
    user.email = "tttttttttttttt"
    assert !user.save<commit_msg>Add teardown function to destroy the user created when the tests finish<commit_after>require 'rubygems'
require 'sinatra/base'
require 'test/unit'
require 'rack/test'
require 'dm-core'
require 'sinatra/simple-authentication'
require 'nokogiri'

module Sinatra
  class Base
    set :environment, :test
    DataMapper::Logger.new($stdout, :debug)
    DataMapper.setup(:default, "sqlite://#{Dir.pwd}/test.db")
    DataMapper.logger.flush
    register Sinatra::SimpleAuthentication
  end
end

class SimpleAuthenticationTest < Test::Unit::TestCase
  include Rack::Test::Methods

  def app
    Sinatra::Application
  end

  def teardown
    User.all.destroy
  end

  def test_signup_page
    get '/signup'
    assert last_response.ok?

    html = Nokogiri::HTML(last_response.body)
    assert html.css('[name="email"]')
    assert html.css('[name="password"]')
    assert html.css('[name="password_confirmation"]')
  end

  def test_login_page
    get '/login'
    assert last_response.ok?

    html = Nokogiri::HTML(last_response.body)
    assert html.css('[name="email"]')
    assert html.css('[name="password"]')
  end

  def test_user_validations
    user = User.new
    assert !user.save
    assert user.errors.include?(["Email must not be blank"])
    assert user.errors.include?(["Password must not be blank"])
    assert user.errors.include?(["Password must be between 4 and 16 characters long"])

    #Short password
    user = User.new
    user.password = "X" * 3
    assert !user.save
    assert user.errors.include?(["Password must be between 4 and 16 characters long", "Password does not match the confirmation"])
    assert user.errors.include?(["Email must not be blank"])

    #Long password
    user = User.new
    user.password = "X" * 17
    assert !user.save
    assert user.errors.include?(["Password must be between 4 and 16 characters long", "Password does not match the confirmation"])
    assert user.errors.include?(["Email must not be blank"])

    #Wrong format email
    user = User.new
    user.email = "InvaidEmailFormat"
    assert !user.save
{'fraction_non_alphanumeric': 0.11957593688362919, 'fraction_numerical': 0.005177514792899409, 'mean_word_length': 3.750585480093677, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4873075', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1222, 'n_words': 347}