Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ability helper specs pass

  • Loading branch information...
commit 5231ac189dc6d224df5ab5db54f458aa51b60080 1 parent fd09424
@kristianmandrup authored
View
1  .rspec
@@ -0,0 +1 @@
+--color
View
4 lib/cantango/roles_ext.rb
@@ -1,6 +1,6 @@
module CanTango
- sweet_scope :ns => {:CanTango => 'cantango/roles'} do
- sweetload :Ability, :Builder, :Configuration, :Engine, :Filter, :Helpers
+ sweet_scope :ns => {:CanTango => 'cantango/roles_ext'} do
+ sweetload :Helpers, :Ability, :Builder, :Configuration, :Engine, :Filter
if defined? CanTango::Permit
sweetload :Permit
View
7 lib/cantango/roles_ext/ability.rb
@@ -0,0 +1,7 @@
+module CanTango
+ module Ability
+ sweet_scope :ns => {:CanTango => 'cantango/roles_ext'} do
+ sweetload :Helper
+ end
+ end
+end
View
7 lib/cantango/roles_ext/ability/helper.rb
@@ -0,0 +1,7 @@
+module CanTango::Ability
+ module Helper
+ sweet_scope :ns => {:CanTango => 'cantango/roles_ext'} do
+ sweetload :Role, :RoleGroup
+ end
+ end
+end
View
28 lib/cantango/roles_ext/ability/helper/role_group.rb
@@ -1,21 +1,17 @@
-module CanTango
- class Ability
- module Helper
- module RoleGroup
- include CanTango::Helpers::RoleGroup
+module CanTango::Ability::Helper
+ module RoleGroup
+ include CanTango::Helpers::RoleGroup
- # return list of symbols for role groups the user belongs to
- def role_groups
- return [] if !subject.respond_to?(role_groups_list_meth) || role_groups_of(subject).blank?
- role_groups_of(subject).flatten
- end
+ # return list of symbols for role groups the user belongs to
+ def role_groups
+ return [] if !subject.respond_to?(role_groups_list_meth) || role_groups_of(subject).blank?
+ role_groups_of(subject).flatten
+ end
- protected
+ protected
- def role_groups_of subject
- @subj_role_groups ||= subject.send(role_groups_list_meth)
- end
- end
+ def role_groups_of subject
+ @subj_role_groups ||= subject.send(role_groups_list_meth)
end
end
-end
+end
View
7 lib/cantango/roles_ext/builder.rb
@@ -0,0 +1,7 @@
+module CanTango
+ module Builder
+ sweet_scope :ns => {:CanTango => 'cantango/roles_ext'} do
+ sweetload :Permit
+ end
+ end
+end
View
7 lib/cantango/roles_ext/builder/permit.rb
@@ -0,0 +1,7 @@
+module CanTango::Builder
+ module Permit
+ if defined? CanTango::Permit
+ sweetload :Role, :RoleGroup
+ end
+ end
+end
View
10 lib/cantango/roles_ext/configuration.rb
@@ -1,9 +1,13 @@
module CanTango
class Configuration
- autoload_modules :RoleGroups, :Roles, :System
-
module Registry
- autoload_modules :Role
+ sweet_scope :ns => {:CanTango => 'cantango/roles_ext'} do
+ sweetload :Role
+ end
+ end
+
+ sweet_scope :ns => {:CanTango => 'cantango/roles_ext'} do
+ sweetload :System, :RoleGroups, :Roles
end
end
end
View
4 lib/cantango/roles_ext/engine.rb
@@ -1,7 +1,7 @@
module CanTango
- module Engine
+ class Engine
if defined? CanTango::Permit
- autoload_modules :Permit
+ sweetload :Permit
end
end
end
View
4 lib/cantango/roles_ext/filter.rb
@@ -1,5 +1,7 @@
module CanTango
module Filter
- autoload_modules :Role, :RoleGroup
+ sweet_scope :ns => {:CanTango => 'cantango/roles_ext'} do
+ sweetload :Role, :RoleGroup
+ end
end
end
View
4 lib/cantango/roles_ext/helpers.rb
@@ -1,5 +1,7 @@
module CanTango
module Helpers
- autoload_modules :Role, :RoleGroup
+ sweet_scope :ns => {:CanTango => 'cantango/roles_ext'} do
+ sweetload :Role, :RoleGroup
+ end
end
end
View
11 spec/cantango/ability/helper/role_group_spec.rb
@@ -3,28 +3,31 @@
require 'helpers/current_users'
class Permits
- include CanTango::Ability::Helpers::RoleGroup
+ include CanTango::Ability::Helper::RoleGroup
attr_accessor :subject
def initialize subject
@subject = subject
end
+
+ def role_groups_list_meth
+ :role_groups_list
+ end
end
class User
- include ::CurrentUsers
include_and_extend SimpleRoles
end
describe CanTango::Ability::Helper::RoleGroup do
before do
- @user = User.new 'mike', :role_groups => [:admins, :editors]
+ @user = User.new 'mike', 'mike@mail.ru', :role_groups => [:admins, :editors]
end
subject { Permits.new @user }
describe 'role_groups' do
- specify { subject.role_groups.should == [:admins, :editors]
+ specify { subject.role_groups.should == [:admins, :editors] }
end
end
View
11 spec/cantango/ability/helper/role_spec.rb
@@ -3,28 +3,31 @@
require 'helpers/current_users'
class Permits
- include CanTango::Ability::Helpers::Role
+ include CanTango::Ability::Helper::Role
attr_accessor :subject
def initialize subject
@subject = subject
end
+
+ def roles_list_meth
+ :roles_list
+ end
end
class User
- include ::CurrentUsers
include_and_extend SimpleRoles
end
describe CanTango::Ability::Helper::Role do
before do
- @user = User.new 'mike', :roles => [:admin, :editor]
+ @user = User.new 'mike', 'mike@mail.ru', :roles => [:admin, :editor]
end
subject { Permits.new @user }
describe 'roles' do
- specify { subject.roles.should == [:admin, :editor]
+ specify { subject.roles.should == [:admin, :editor] }
end
end
View
5 spec/fixtures/models/simple_roles.rb
@@ -20,7 +20,6 @@ def roles
end
module InstanceMethods
-
attr_accessor :role_groups_list
def has_role? role
@@ -32,7 +31,7 @@ def has_any_role? roles
end
def roles_list
- role.to_s.scan(/\w+/).map{|r| r.to_sym}
+ roles.map{|r| r.to_sym}
end
def is_in_group? group
@@ -41,7 +40,7 @@ def is_in_group? group
alias_method :in_role_group?, :is_in_group?
def role_groups_list
- return role_groups.scan(/\w+/).map(&:to_sym) if respond_to?(:role_groups) && !role_groups.nil?
+ return role_groups.map(&:to_sym) if respond_to?(:role_groups) && !role_groups.nil?
@role_groups_list || [] #[:bloggers]
end
end
View
2  spec/fixtures/models/user.rb
@@ -1,7 +1,7 @@
require 'fixtures/models/simple_roles'
class User
- attr_accessor :name, :account, :email
+ attr_accessor :name, :account, :email, :roles, :role_groups
# tango_user # see macros
View
4 spec/helpers/current_user_accounts.rb
@@ -10,11 +10,11 @@ def self.included(base)
end
def current_user_account
- ::UserAccount.new(current_user, :roles => [:user])
+ @current_user_account ||= ::UserAccount.new(current_user, :roles => [:user])
end
def current_admin_account
- ::AdminAccount.new(current_admin, :roles => [:admin])
+ @current_admin_account ||= ::AdminAccount.new(current_admin, :roles => [:admin])
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.