Permalink
Browse files

better specs and now fixtures and helpers

  • Loading branch information...
1 parent ee61255 commit fd09424d8f49751c3d2591140b46addc46109db0 @kristianmandrup committed Dec 8, 2011
View
@@ -2,11 +2,11 @@ source :rubygems
group :default do
gem 'rails', '>= 3.1'
- gem 'sugar-high', '>= 0.6.0'
- gem 'sweetloader', '~> 0.1.5'
- gem 'hashie', '~> 0.4.0'
+ gem 'sugar-high', '>= 0.6.1'
+ gem 'sweetloader', '>= 0.1.6'
+ gem 'hashie', '>= 1.2.0'
- gem 'cantango-config', :git => 'git://github.com/kristianmandrup/cantango-config.git'
+ gem 'cantango-config', '~> 0.1.8'
end
group :development do
View
@@ -1,14 +1,3 @@
-GIT
- remote: git://github.com/kristianmandrup/cantango-config.git
- revision: e17a6646e319b013255ccf37b9815ad8fdbe6a94
- specs:
- cantango-config (0.1.2)
- cantango-core
- hashie
- rails (>= 3.1)
- sugar-high (>= 0.6.0)
- sweetloader (~> 0.1.0)
-
GEM
remote: http://rubygems.org/
specs:
@@ -43,12 +32,18 @@ GEM
arel (2.2.1)
builder (3.0.0)
cancan (1.6.7)
- cantango-core (0.1.2)
+ cantango-config (0.1.9.2)
+ cantango-core (~> 0.1.9)
+ hashie (~> 1.2)
+ rails (>= 3.1)
+ sugar-high (>= 0.6.1)
+ sweetloader (~> 0.1.6)
+ cantango-core (0.1.9.2)
cancan (>= 1.4)
- hashie
+ hashie (~> 1.2)
rails (>= 3.0.1)
sugar-high (>= 0.6.0)
- sweetloader (~> 0.1.0)
+ sweetloader (~> 0.1.5)
colorize (0.5.8)
cutter (0.8.2)
activesupport (>= 2.3.5)
@@ -60,7 +55,7 @@ GEM
activesupport
forgery (0.5.0)
git (1.2.5)
- hashie (0.4.0)
+ hashie (1.2.0)
hike (1.2.1)
i18n (0.6.0)
jeweler (1.6.4)
@@ -118,9 +113,9 @@ GEM
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.4)
- sugar-high (0.6.0)
+ sugar-high (0.6.2.1)
activesupport (>= 3.0.1)
- sweetloader (0.1.5)
+ sweetloader (0.1.6)
activesupport (>= 3.0.1)
i18n
thor (0.14.6)
@@ -135,18 +130,18 @@ PLATFORMS
DEPENDENCIES
bundler (>= 1.1.rc)
- cantango-config!
+ cantango-config (~> 0.1.8)
cutter
database_cleaner
factory_girl
forgery
- hashie (~> 0.4.0)
+ hashie (>= 1.2.0)
jeweler (>= 1.6.4)
rails (>= 3.1)
rcov
require_all (~> 1.2.0)
rspec (>= 2.6.0)
spork
sqlite3
- sugar-high (>= 0.6.0)
- sweetloader (~> 0.1.5)
+ sugar-high (>= 0.6.1)
+ sweetloader (>= 0.1.6)
View
@@ -42,7 +42,7 @@ end
task :default => :test
-require 'rake/rdoctask'
+require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
View
@@ -1 +1 @@
-0.0.0
+0.1.0
@@ -1,9 +1,9 @@
module CanTango
- autoload_scope :ns => {:CanTango => 'cantango/roles'} do
- autoload_modules :Ability, :Builder, :Configuration, :Engine, :Filter, :Helpers
+ sweet_scope :ns => {:CanTango => 'cantango/roles'} do
+ sweetload :Ability, :Builder, :Configuration, :Engine, :Filter, :Helpers
if defined? CanTango::Permit
- autoload_modules :Permit
+ sweetload :Permit
end
end
end
@@ -1,21 +1,17 @@
-module CanTango
- class Ability
- module Helper
- module Role
- include CanTango::Helpers::Role
+module CanTango::Ability::Helper
+ module Role
+ include CanTango::Helpers::Role
- # return list roles the user has
- def roles
- return [] if !subject.respond_to?(roles_list_meth) || roles_of(subject).blank?
- roles_of(subject).flatten
- end
+ # return list roles the user has
+ def roles
+ return [] if !subject.respond_to?(roles_list_meth) || roles_of(subject).blank?
+ roles_of(subject).flatten
+ end
- protected
+ protected
- def roles_of subject
- @subj_roles ||= subject.send(roles_list_meth)
- end
- end
+ def roles_of subject
+ @subj_roles ||= subject.send(roles_list_meth)
end
end
end
@@ -1,7 +1,5 @@
-module CanTango
- module Engine
- class Permits < Base
- include CanTango::Ability::Helpers::Role
- end
+module CanTango::Engine
+ class Permits < Base
+ include CanTango::Ability::Helpers::Role
end
end
@@ -0,0 +1,30 @@
+require 'spec_helper'
+require 'fixtures/models'
+require 'helpers/current_users'
+
+class Permits
+ include CanTango::Ability::Helpers::RoleGroup
+
+ attr_accessor :subject
+
+ def initialize subject
+ @subject = subject
+ 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]
+ end
+
+ subject { Permits.new @user }
+
+ describe 'role_groups' do
+ specify { subject.role_groups.should == [:admins, :editors]
+ end
+end
@@ -0,0 +1,30 @@
+require 'spec_helper'
+require 'fixtures/models'
+require 'helpers/current_users'
+
+class Permits
+ include CanTango::Ability::Helpers::Role
+
+ attr_accessor :subject
+
+ def initialize subject
+ @subject = subject
+ 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]
+ end
+
+ subject { Permits.new @user }
+
+ describe 'roles' do
+ specify { subject.roles.should == [:admin, :editor]
+ end
+end
@@ -0,0 +1,6 @@
+require 'spec_helper'
+require 'cantngo/ability/helper/shared/role_ex'
+
+describe CanTango::Engine::Permits do
+ # use shared Role helper example
+end
@@ -9,26 +9,26 @@
end
-class UserRolePermit < CanTango::RolePermit
+class UserRolePermit < CanTango::Permit::Role
def initialize ability
super
end
protected
- def static_rules
+ def calculate_rules
can :read, Comment
end
end
-class AdminRolePermit < CanTango::RolePermit
+class AdminRolePermit < CanTango::Permit::Role
def initialize ability
super
end
protected
- def static_rules
+ def calculate_rules
can :read, Post
end
end
No changes.
@@ -0,0 +1,26 @@
+require 'spec_helper'
+require 'cantango/configuration/role_registry_ex'
+
+class Subject
+end
+
+describe CanTango::Helpers::RoleGroup do
+ before do
+ CanTango.config.roles.system = :troles
+ end
+
+ subject do
+ Subject.new
+ end
+
+ specify do
+ subject.role_method(:has).should == :in_role_group?
+ end
+
+ specify do
+ subject.role_method(:list).should == :role_group_list
+ end
+end
+
+
+
File renamed without changes.
View
@@ -0,0 +1,2 @@
+require 'require_all'
+require_all File.dirname(__FILE__) + '/models'
@@ -0,0 +1,2 @@
+class Admin < User
+end
@@ -0,0 +1,22 @@
+class AdminAccount
+ attr_accessor :user, :roles, :role_groups
+
+ def initialize user, options = {}
+ @user = user
+ @roles = options[:roles]
+ @role_groups = options[:role_groups]
+ end
+
+ def has_role? name
+ true
+ end
+
+ def roles_list
+ roles
+ end
+
+ def role_groups_list
+ role_groups
+ end
+end
+
@@ -0,0 +1,8 @@
+class Post
+end
+
+class Article
+end
+
+class Comment
+end
@@ -0,0 +1,12 @@
+class Permission
+ attr_accessor :thing, :thing_type, :action, :user
+
+ def initialize user, action, thing
+ @user, @action, @thing = [user, action, thing]
+ @thing_type = @thing.class.to_s
+ end
+
+ def thing_id
+ thing.id
+ end
+end
@@ -0,0 +1,2 @@
+class Project #< ActiveRecord::Base
+end
Oops, something went wrong.

0 comments on commit fd09424

Please sign in to comment.