#--
# 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 PermissionTest < Test::Unit::TestCase

  use_all_fixtures

  def test_description
    assert_equal 'grant permission to take any action on anything ',
      (Permission.new :class_name => 'any', :privilege => :any, 
       :is_grant=>true).description
    assert_equal 'grant permission (with grant option) to edit roles ',
      (Permission.new :class_name => 'Role', :privilege => :edit,
       :is_grant=>true, :has_grant_option => true).description
    assert_equal 'create roles owned by grantee',
      (Permission.new :class_name => 'Role', :privilege => :create,
       :target_owned_by_self => true).description
    assert_equal 'destroy roles owned by lucy',
      (Permission.new :class_name => 'Role', :privilege => :destroy,
       :target_owner => users(:lucy)).description
    assert_equal 'gimbal roles owned by lucy, of firm Ricardo',
      (Permission.new :class_name => 'Role', :privilege => :gimbal,
       :target_owner => users(:lucy), :target_owner_firm => firms(:ricardo)).
       description
    assert_equal 'twaddle role "twiddler"',
      (Permission.new :class_name => 'Role', :privilege => :twaddle,
       :target => roles(:ricardo_twiddler)).description
  end

end

