Skip to content

Commit

Permalink
Converted helpers test, also make schema get loaded only once
Browse files Browse the repository at this point in the history
  • Loading branch information
be9 committed May 3, 2009
1 parent bef7a67 commit 5cbd770
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 8 deletions.
94 changes: 94 additions & 0 deletions test/helpers_test.rb
@@ -0,0 +1,94 @@
require 'test_helper'
require 'action_controller'

require File.join(File.dirname(__FILE__), '..', 'lib', 'acl9')

module SomeHelper
include Acl9Helpers

access_control :the_question do
allow :hamlet, :to => :be
allow :hamlet, :except => :be
end
end

class HelperTest < Test::Unit::TestCase
module Hamlet
def current_user
user = Object.new

class <<user
def has_role?(role, obj=nil)
role == 'hamlet'
end
end

user
end
end

module NotLoggedIn
def current_user; nil end
end

module Noone
def current_user
user = Object.new

class <<user
def has_role?(*_); false end
end

user
end
end

class Base
include SomeHelper

attr_accessor :action_name
def controller
self
end
end

class Klass1 < Base
include Hamlet
end

class Klass2 < Base
include NotLoggedIn
end

class Klass3 < Base
include Noone
end

it "has :the_question method" do
Base.new.should respond_to(:the_question)
end

it "role :hamlet is allowed to be" do
k = Klass1.new
k.action_name = 'be'
k.the_question.should be_true
end

it "role :hamlet is allowed to not_be" do
k = Klass1.new
k.action_name = 'not_be'
k.the_question.should be_true
end

it "not logged in is not allowed to be" do
k = Klass2.new
k.action_name = 'be'
k.the_question.should == false
end

it "noone is not allowed to be" do
k = Klass3.new
k.action_name = 'be'
k.the_question.should == false
end
end
9 changes: 1 addition & 8 deletions test/roles_test.rb
Expand Up @@ -3,12 +3,9 @@
require 'support/models'

#Logger = ActiveRecord::Base.logger
load 'support/schema.rb'

class RolesTest < Test::Unit::TestCase
before :all do
load 'support/schema.rb'
end

before do
Role.destroy_all
[User, Foo, Bar].each { |model| model.delete_all }
Expand Down Expand Up @@ -240,10 +237,6 @@ def set_some_roles
end

class RolesWithCustomClassNamesTest < Test::Unit::TestCase
before :all do
load 'support/schema.rb'
end

before do
AnotherRole.destroy_all
[AnotherSubject, FooBar].each { |model| model.delete_all }
Expand Down

0 comments on commit 5cbd770

Please sign in to comment.