Sha256: 184dcba1f97140c27aaa5789e22919b039eb60e1ad298a28e4300350df244a59

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require "test/test_helper"

class HasRoleTest < ActiveSupport::TestCase

  context "Objects that have an aegis role" do

    setup do
      @guest = User.new(:role_name => "guest")
      @student = User.new(:role_name => "student")
      @admin = User.new(:role_name => "admin")
    end

    should "know their role" do
      assert :guest, @guest.role.name
      assert :student, @student.role.name
      assert :admin, @admin.role.name
    end

    should "know if they belong to a role" do
      assert @guest.guest?
      assert !@guest.student?
      assert !@guest.admin?
      assert !@student.guest?
      assert @student.student?
      assert !@student.admin?
      assert !@admin.guest?
      assert !@admin.student?
      assert @admin.admin?
    end

    should "still behave as usual when a method ending in a '?' does not map to a role query" do
      assert_raise NoMethodError do
        @guest.nonexisting_method?
      end
    end

    should "have a default roule" do
      assert :guest, User.new(:role_name => nil).role.name
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
Chrononaut-aegis-1.2.0 test/has_role_test.rb