#--
# Copyright (c) 2007 Robert S. Thau, Smartleaf, Inc.
# 
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
# 
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
require File.dirname(__FILE__) + '/../test_helper'

class FirmTest < Test::Unit::TestCase

  use_all_fixtures

  def test_validations
    f = Firm.new
    assert !f.valid?

    test_validation f, :name,
      :invalid => [ '', 'a', 'ab', 'Shire', 'Dubuque', 'x' * 101 ],
      :valid =>   [ 'rocky', 'bullwinkle' ]

    test_validation f, :full_name,
      :invalid => [ '', 'a', 'ab', 'Bank of the Shire', 'x' * 101 ],
      :valid =>   [ 'rocky', 'bullwinkle' ]

    # Note that we don't complain about non-positive numbers in these,
    # and probably should... easy with the one-sided range validation in 
    # the main codebase.

    test_validation f, :password_lifetime_days,
      :invalid => ['x', -1, 0],
      :valid => [nil, '', 1, 53, 1000]

    test_validation f, :max_bad_logins,
      :invalid => ['x', -1, 0],
      :valid => [nil, '', 1, 5, 20]

    assert_valid f

    assert_requires( wildcard_perm( :create, Firm )) do
      assert f.save
    end

    assert_requires( wildcard_perm( :destroy, Firm )) do
      f.destroy
    end

  end

  def test_search_name
    f = Firm.new
    f.name = 'Bologna'
    assert_equal 'Bologna', f.name
    assert_equal 'bologna', f.search_name
  end

end

