simple_roles 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ script: "rake"
5
+ gemfile:
6
+ - Gemfile
7
+ env:
8
+ - DB=sqlite
9
+ - DB=mysql
10
+ before_script:
11
+ - "mysql -e 'create database simple_roles_test;' >/dev/null"
data/Gemfile CHANGED
@@ -16,5 +16,5 @@ group :development, :test do
16
16
  gem 'jeweler'
17
17
  gem 'cutter'
18
18
  gem 'rspec'
19
- gem 'factory_girl'
19
+ gem 'factory_girl', '2.6.4'
20
20
  end
data/README.md CHANGED
@@ -6,6 +6,8 @@ Initially, it was created as demo role-system to accompany [CanTango gem](https:
6
6
 
7
7
  Now it is good to be used as a real role system inspite of or due to its almost maximum simplicity.
8
8
 
9
+ [![Build Status](https://secure.travis-ci.org/stanislaw/simple_roles.png)](http://travis-ci.org/stanislaw/simple_roles)
10
+
9
11
  ## Installiation
10
12
 
11
13
  ### Prerequisites
@@ -144,6 +146,9 @@ user.role = :admin
144
146
  user.role # => :admin
145
147
  user.admin? # => true
146
148
  user.is_admin? # => true
149
+ user.has_role? :admin # => true
150
+ user.has_role? :user # => false
151
+ user.has_any_role? :user, :editor, :admin # => true
147
152
 
148
153
  # Accepts strings too
149
154
  user.role = 'instructor'
@@ -186,6 +191,18 @@ user.has_any_role?(:admin, :blip) # => true
186
191
  user.has_role?(:blogger) # => false
187
192
  ```
188
193
 
194
+ ### Both strategies
195
+
196
+ For each of valid roles both strategies automatically define scope methods in User model:
197
+
198
+ ```ruby
199
+ SimpleRoles.config.valid_roles # => [:user, :admin, :editor]
200
+
201
+ User.users # => []
202
+ User.admins # => []
203
+ User.editors # => []
204
+ ```
205
+
189
206
  ## Copyright
190
207
 
191
208
  Copyright (c) 2012 Stanislaw Pankevich.
data/Rakefile CHANGED
@@ -44,4 +44,10 @@ load 'rails/tasks/engine.rake'
44
44
 
45
45
  Bundler::GemHelper.install_tasks
46
46
 
47
- # task :default => :test
47
+ require 'rspec/core'
48
+ require 'rspec/core/rake_task'
49
+ RSpec::Core::RakeTask.new(:spec) do |spec|
50
+ spec.pattern = FileList['spec/**/*_spec.rb']
51
+ end
52
+
53
+ task :default => :spec
@@ -15,6 +15,18 @@ module SimpleRoles
15
15
  end
16
16
  alias_method :update_role, :set_role
17
17
 
18
+ def has_role? r
19
+ role == r
20
+ end
21
+
22
+ def has_any_role? *rolez
23
+ rolez.flatten!
24
+
25
+ rolez.any? do |r|
26
+ has_role? r
27
+ end
28
+ end
29
+
18
30
  module DynamicMethods
19
31
  class << self
20
32
  def extended base
@@ -1,3 +1,3 @@
1
1
  module SimpleRoles
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/simple_roles.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "simple_roles"
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["stanislaw"]
12
- s.date = "2012-06-27"
12
+ s.date = "2012-06-28"
13
13
  s.description = "Simple Role System for Rails Apps"
14
14
  s.email = "s.pankevich@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  ]
18
18
  s.files = [
19
19
  ".rspec",
20
+ ".travis.yml",
20
21
  "CHANGELOG.md",
21
22
  "Gemfile",
22
23
  "MIT-LICENSE",
@@ -172,7 +173,7 @@ Gem::Specification.new do |s|
172
173
  s.add_development_dependency(%q<jeweler>, [">= 0"])
173
174
  s.add_development_dependency(%q<cutter>, [">= 0"])
174
175
  s.add_development_dependency(%q<rspec>, [">= 0"])
175
- s.add_development_dependency(%q<factory_girl>, [">= 0"])
176
+ s.add_development_dependency(%q<factory_girl>, ["= 2.6.4"])
176
177
  else
177
178
  s.add_dependency(%q<require_all>, [">= 0"])
178
179
  s.add_dependency(%q<sugar-high>, [">= 0"])
@@ -184,7 +185,7 @@ Gem::Specification.new do |s|
184
185
  s.add_dependency(%q<jeweler>, [">= 0"])
185
186
  s.add_dependency(%q<cutter>, [">= 0"])
186
187
  s.add_dependency(%q<rspec>, [">= 0"])
187
- s.add_dependency(%q<factory_girl>, [">= 0"])
188
+ s.add_dependency(%q<factory_girl>, ["= 2.6.4"])
188
189
  end
189
190
  else
190
191
  s.add_dependency(%q<require_all>, [">= 0"])
@@ -197,7 +198,7 @@ Gem::Specification.new do |s|
197
198
  s.add_dependency(%q<jeweler>, [">= 0"])
198
199
  s.add_dependency(%q<cutter>, [">= 0"])
199
200
  s.add_dependency(%q<rspec>, [">= 0"])
200
- s.add_dependency(%q<factory_girl>, [">= 0"])
201
+ s.add_dependency(%q<factory_girl>, ["= 2.6.4"])
201
202
  end
202
203
  end
203
204
 
@@ -73,6 +73,25 @@ describe SimpleRoles::One do
73
73
  end
74
74
  end
75
75
 
76
+ it "#has_role?" do
77
+ user.role = :admin
78
+
79
+ user.has_role?(:admin).should be_true
80
+ user.has_role?(:editor).should be_false
81
+
82
+ user.role = :user
83
+
84
+ user.has_role?(:user).should be_true
85
+ user.has_role?(:admin).should be_false
86
+ end
87
+
88
+ it "#has_any_role?" do
89
+ user.role = :admin
90
+
91
+ user.has_any_role?(:admin, :editor).should be_true
92
+ user.has_any_role?(:editor, :user).should be_false
93
+ end
94
+
76
95
  describe "Dynamic methods" do
77
96
  SimpleRoles.config.valid_roles.each do |r|
78
97
  specify { user.should respond_to :"#{r}?" }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_roles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-27 00:00:00.000000000 Z
12
+ date: 2012-06-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: require_all
@@ -176,17 +176,17 @@ dependencies:
176
176
  requirement: !ruby/object:Gem::Requirement
177
177
  none: false
178
178
  requirements:
179
- - - ! '>='
179
+ - - '='
180
180
  - !ruby/object:Gem::Version
181
- version: '0'
181
+ version: 2.6.4
182
182
  type: :development
183
183
  prerelease: false
184
184
  version_requirements: !ruby/object:Gem::Requirement
185
185
  none: false
186
186
  requirements:
187
- - - ! '>='
187
+ - - '='
188
188
  - !ruby/object:Gem::Version
189
- version: '0'
189
+ version: 2.6.4
190
190
  description: Simple Role System for Rails Apps
191
191
  email: s.pankevich@gmail.com
192
192
  executables: []
@@ -195,6 +195,7 @@ extra_rdoc_files:
195
195
  - README.md
196
196
  files:
197
197
  - .rspec
198
+ - .travis.yml
198
199
  - CHANGELOG.md
199
200
  - Gemfile
200
201
  - MIT-LICENSE
@@ -344,7 +345,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
344
345
  version: '0'
345
346
  segments:
346
347
  - 0
347
- hash: -398652943
348
+ hash: -339353645
348
349
  required_rubygems_version: !ruby/object:Gem::Requirement
349
350
  none: false
350
351
  requirements: