rolify 3.3.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: adb734bf9468069dbead78c35683ac1ace1525d8
4
- data.tar.gz: b4a221f3435dda2c84ccccf7086bc4a41eadda8d
3
+ metadata.gz: 0230aba90b592f3e2873858db202652f0610e63a
4
+ data.tar.gz: 213155ee533962044ebe70808910f6a27fb40a35
5
5
  SHA512:
6
- metadata.gz: 7168a6699067f23cf85cb6b74b599a043e26720be10c9746e7910cc7cbdc296b5d9ffe5922ea2d8484167ccb3c9c6ce6c347efddb20c14c7d843791d0f186e52
7
- data.tar.gz: 2f701c24d16d9dccbac72a270a93f9cd6e470dd60584c548812a97a09458b75f00829d5b0320ae3ab080d123c713c2c5ad32282b4c615b8ebf11e672dd576de9
6
+ metadata.gz: 1ac7b0db9d222976eea090aa5fc8f91e4861e61175385316625e4d4cd85b11844f6b61013f655735895380e7fa908f629acda1f6a3dc8704837ea58d295f1703
7
+ data.tar.gz: 2f7a94b6bef880b5bad088fb66b5623677a631a8d1b0371f3f942fc821054a8807b1b1d622232f63548b841d1245bb8495b004dbb0a25b008f90f8c5e8d0f035
@@ -1,7 +1,8 @@
1
1
  rvm:
2
2
  - 1.9.3
3
3
  - 2.0.0
4
- - rbx-19mode
4
+ - 2.1.0
5
+ - rbx
5
6
  - jruby-19mode
6
7
 
7
8
  gemfile:
@@ -14,4 +15,11 @@ env:
14
15
 
15
16
  services: mongodb
16
17
 
17
- before_script: rails --version
18
+ matrix:
19
+ exclude:
20
+ - rvm: rbx
21
+ gemfile: gemfiles/Gemfile.rails-3.2
22
+ env: ADAPTER=mongoid
23
+ - rvm: rbx
24
+ gemfile: gemfiles/Gemfile.rails-4.0
25
+ env: ADAPTER=mongoid
@@ -1,4 +1,14 @@
1
- = 3.3 (not released yet)
1
+ = 3.4 (Jan 28, 2014)
2
+ * fixed an initializer bug preventing the rails app to boot
3
+ * enhanced documentation regarding <tt>with_role</tt> method (thanks to @vicomte)
4
+ * added <tt>select(:id)</tt> in SQL subquery used by <tt>in</tt> method in ActiveRecord adapter (thanks to @ryanaip and @badaboda)
5
+ * improved speed when removing roles using <tt>LIMIT(1)</tt> instead of <tt>COUNT</tt> (thanks to @yankovski)
6
+ * fixed travis builds for rubinius and mongoid
7
+ * fixed sanity check running before <tt>Rolify.config</tt> to ensure roles table exists
8
+ * fixed <tt>has_any_role?</tt> to work with unsaved records (thanks to @mhw)
9
+ * fixed specs for Mongoid
10
+
11
+ = 3.3 (Jan 26, 2014)
2
12
  * <b>DEPRECATION NOTICE:</b>Rails 3.1 support dropped: if you use Rails 3.1, please stick to rolify 3.2
3
13
  * code cleanup in finders methods
4
14
  * generators rewritten entirely. now using ActiveRecord/Mongoid model generator to create Role model
data/Gemfile CHANGED
@@ -1,20 +1,18 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- case ENV["ADAPTER"]
4
- when nil, "active_record"
5
- group :test do
3
+ group :test do
4
+ case ENV["ADAPTER"]
5
+ when nil, "active_record"
6
6
  gem "activerecord-jdbcsqlite3-adapter", ">= 1.3.0.rc", :platform => "jruby"
7
7
  gem "sqlite3", :platform => "ruby"
8
+ gem "activerecord", ">= 3.2.0", :require => "active_record"
9
+ when "mongoid"
10
+ gem "mongoid", ">= 3.1"
11
+ gem "bson_ext", :platform => "ruby"
12
+ else
13
+ raise "Unknown model adapter: #{ENV["ADAPTER"]}"
8
14
  end
9
- gem "activerecord", ">= 3.2.0", :require => "active_record"
10
- when "mongoid"
11
- gem "mongoid", ">= 3.1"
12
- gem "bson_ext", :platform => "ruby"
13
- else
14
- raise "Unknown model adapter: #{ENV["ADAPTER"]}"
15
- end
16
-
17
- group :test do
15
+
18
16
  gem 'coveralls', :require => false
19
17
  end
20
18
 
data/README.md CHANGED
@@ -187,6 +187,10 @@ Forum.with_role(:admin, current_user)
187
187
 
188
188
  User.with_any_role(:user, :admin)
189
189
  # => [ list of User instances that has role "admin" or "user" binded to it ]
190
+ User.with_role(:site_admin, current_site)
191
+ # => [ list of User instances that have a scoped role of "site_admin" to a site instance ]
192
+ User.with_role(:site_admin, :any)
193
+ # => [ list of User instances that have a scoped role of "site_admin" for any site instances ]
190
194
 
191
195
  Forum.find_roles
192
196
  # => [ list of roles that binded to any Forum instance or to the Forum class ]
@@ -211,7 +215,9 @@ Please read the [upgrade instructions](UPGRADE.rdoc).
211
215
 
212
216
  ## Known issues
213
217
 
214
- If you are using Mongoid and/or less-rails gem, please read [this](https://github.com/EppO/rolify/wiki/FAQ#when-i-start-rails-using-server-console-whatever-i-get-this-error)
218
+ * If you are using Mongoid and/or less-rails gem, please read [this](https://github.com/EppO/rolify/wiki/FAQ#when-i-start-rails-using-server-console-whatever-i-get-this-error)
219
+ * Moped library (ruby driver for Mongodb used by Mongoid) doesn't support rubinius 2.2 yet (see https://github.com/mongoid/moped/issues/231)
220
+ * If you use Rails 4 and Mongoid, use Mongoid ~> 4 (not released yet). rolify is fully tested with Rails 4 and Mongoid master branch
215
221
 
216
222
  ## Questions or Problems?
217
223
 
@@ -1,21 +1,28 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- case ENV["ADAPTER"]
4
- when nil, "active_record"
5
- group :test do
6
- gem "activerecord-jdbcsqlite3-adapter", ">= 1.3.0.rc", :platform => "jruby"
7
- gem "sqlite3", :platform => "ruby"
8
- end
9
- gem "activerecord", "~> 3.2.0", :require => "active_record"
10
- when "mongoid"
11
- gem "mongoid", "~> 3.1"
12
- gem "bson_ext", :platform => "ruby"
13
- else
14
- raise "Unknown model adapter: #{ENV["ADAPTER"]}"
3
+ platforms :rbx do
4
+ gem 'racc'
5
+ gem 'rubysl', '~> 2.0'
6
+ gem 'psych'
7
+ gem 'json'
8
+ gem 'rubinius-coverage', '~> 2.0'
9
+ gem 'rubysl-test-unit'
15
10
  end
16
11
 
17
12
  group :test do
13
+ case ENV["ADAPTER"]
14
+ when nil, "active_record"
15
+ gem "activerecord-jdbcsqlite3-adapter", ">= 1.3.0.rc", :platform => "jruby"
16
+ gem "sqlite3", :platform => "ruby"
17
+ gem "activerecord", ">= 3.2.0", :require => "active_record"
18
+ when "mongoid"
19
+ gem "mongoid", ">= 3.1"
20
+ gem "bson_ext", :platform => "ruby"
21
+ else
22
+ raise "Unknown model adapter: #{ENV["ADAPTER"]}"
23
+ end
24
+
18
25
  gem 'coveralls', :require => false
19
26
  end
20
27
 
21
- gemspec :path => '../'
28
+ gemspec :path => '../'
@@ -1,27 +1,34 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- case ENV["ADAPTER"]
4
- when nil, "active_record"
5
- gem "activerecord", "~> 4.0.0.rc", :require => "active_record"
6
- when "mongoid"
7
- gem "mongoid", :git => "git://github.com/mongoid/mongoid.git"
8
- gem "bson_ext", :platform => "ruby"
9
- else
10
- raise "Unknown model adapter: #{ENV["ADAPTER"]}"
3
+ platforms :rbx do
4
+ gem 'racc'
5
+ gem 'rubysl', '~> 2.0'
6
+ gem 'psych'
7
+ gem 'json'
8
+ gem 'rubinius-coverage', '~> 2.0'
9
+ gem 'rubysl-test-unit'
11
10
  end
12
11
 
13
12
  group :test do
14
- gem "rails", "~> 4.0.0.rc"
13
+ gem "rails", "~> 4.0.1"
15
14
  gem "ammeter"
16
15
  gem "rake"
17
16
  gem "rspec"
18
17
  gem "rspec-rails"
19
18
  gem "fuubar"
20
19
  gem "bundler"
21
-
22
- gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.0.beta", :platform => "jruby"
23
- gem "sqlite3", :platform => "ruby"
24
- gem "activerecord", "~> 4.0.0.rc", :require => "active_record"
25
- gem "mongoid", :git => "git://github.com/mongoid/mongoid.git"
20
+
26
21
  gem 'coveralls', :require => false
27
- end
22
+
23
+ case ENV["ADAPTER"]
24
+ when nil, "active_record"
25
+ gem "activerecord", "~> 4.0.1", :require => "active_record"
26
+ gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.5", :platform => "jruby"
27
+ gem "sqlite3", :platform => "ruby"
28
+ when "mongoid"
29
+ gem "mongoid", github: 'mongoid/mongoid'
30
+ gem "bson_ext", :platform => "ruby"
31
+ else
32
+ raise "Unknown model adapter: #{ENV["ADAPTER"]}"
33
+ end
34
+ end
@@ -12,7 +12,7 @@ module Rolify
12
12
  end
13
13
 
14
14
  def in(relation, user, role_names)
15
- roles = user.roles.where(:name => role_names)
15
+ roles = user.roles.where(:name => role_names).select(:id)
16
16
  relation.where("#{quote(role_class.table_name)}.#{role_class.primary_key} IN (?) AND ((resource_id = #{quote(relation.table_name)}.#{relation.primary_key}) OR (resource_id IS NULL))", roles)
17
17
  end
18
18
 
@@ -24,7 +24,7 @@ module Rolify
24
24
  if roles
25
25
  relation.roles.delete(roles)
26
26
  roles.each do |role|
27
- role.destroy if role.send(ActiveSupport::Inflector.demodulize(user_class).tableize.to_sym).empty?
27
+ role.destroy if role.send(ActiveSupport::Inflector.demodulize(user_class).tableize.to_sym).limit(1).empty?
28
28
  end
29
29
  end
30
30
  roles
@@ -29,7 +29,7 @@ module Rolify
29
29
  end
30
30
 
31
31
  def use_dynamic_shortcuts
32
- self.dynamic_shortcuts = true #if defined?(Rails::Server) || defined?(Rails::Console)
32
+ self.dynamic_shortcuts = true
33
33
  end
34
34
 
35
35
  def use_defaults
@@ -45,7 +45,7 @@ module Rolify
45
45
  role_cnames = [ "Role" ] if role_cnames.empty?
46
46
  role_cnames.each do |role_cname|
47
47
  role_class = role_cname.constantize
48
- if role_class.superclass.to_s == "ActiveRecord" && !role_class.table_exists?
48
+ if role_class.superclass.to_s == "ActiveRecord::Base" && !role_class.table_exists?
49
49
  warn "[WARN] table '#{role_cname}' doesn't exist. Did you run the migration ? Ignoring rolify config."
50
50
  return false
51
51
  end
@@ -1,3 +1,5 @@
1
+ require 'rspec/expectations'
2
+
1
3
  RSpec::Matchers.define :have_role do |*args|
2
4
  match do |resource|
3
5
  resource.has_role?(*args)
@@ -11,3 +13,19 @@ RSpec::Matchers.define :have_role do |*args|
11
13
  "expected not to have role #{args.map(&:inspect).join(" ")}"
12
14
  end
13
15
  end
16
+
17
+ RSpec::Matchers.define :be_the_same_role do |*expected|
18
+ match do |actual|
19
+ if expected.size > 1
20
+ if expected[1].is_a? Class
21
+ actual[:name] == expected[0] && actual[:resource_type] == expected[1].to_s
22
+ else
23
+ actual[:name] == expected[0] &&
24
+ actual[:resource_type] == expected[1].class.name &&
25
+ actual[:resource_id] == expected[1].id
26
+ end
27
+ else
28
+ actual[:name] == expected[0]
29
+ end
30
+ end
31
+ end
@@ -3,7 +3,7 @@ require 'rails'
3
3
 
4
4
  module Rolify
5
5
  class Railtie < Rails::Railtie
6
- initializer 'rolify.initialize', :after do
6
+ initializer 'rolify.initialize' do
7
7
  ActiveSupport.on_load(:active_record) do
8
8
  ActiveRecord::Base.send :extend, Rolify
9
9
  end
@@ -44,7 +44,11 @@ module Rolify
44
44
  end
45
45
 
46
46
  def has_any_role?(*args)
47
- self.class.adapter.where(self.roles, *args).size > 0
47
+ if new_record?
48
+ args.any? { |r| self.has_role?(r) }
49
+ else
50
+ self.class.adapter.where(self.roles, *args).size > 0
51
+ end
48
52
  end
49
53
 
50
54
  def only_has_role?(role_name, resource = nil)
@@ -1,3 +1,3 @@
1
1
  module Rolify
2
- VERSION = "3.3.0"
2
+ VERSION = "3.4.0"
3
3
  end
@@ -6,6 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.name = "rolify"
7
7
  s.version = Rolify::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
+ s.license = "MIT"
9
10
  s.authors = ["Florent Monbillard"]
10
11
  s.email = ["f.monbillard@gmail.com"]
11
12
  s.homepage = "http://eppo.github.com/rolify/"
@@ -25,6 +26,4 @@ Gem::Specification.new do |s|
25
26
  s.add_development_dependency "rspec-rails", ">= 2.0"
26
27
  s.add_development_dependency "bundler"
27
28
  s.add_development_dependency "fuubar"
28
- s.add_development_dependency "activerecord", ">= 3.2.0"
29
- s.add_development_dependency "mongoid", ">= 3.1"
30
29
  end
@@ -1,6 +1,5 @@
1
1
  require 'generators_helper'
2
2
 
3
- require 'rails/all'
4
3
  # Generators are not automatically loaded by Rails
5
4
  require 'generators/rolify/rolify_generator'
6
5
 
@@ -1,7 +1,5 @@
1
1
  require 'generators_helper'
2
2
 
3
- require 'mongoid'
4
-
5
3
  # Generators are not automatically loaded by Rails
6
4
  require 'generators/rolify/rolify_generator'
7
5
 
@@ -3,19 +3,23 @@ require "bundler/setup"
3
3
 
4
4
  require 'rolify'
5
5
  require 'rolify/matchers'
6
- require 'rails/all'
6
+ require 'rails'
7
7
 
8
8
  require 'coveralls'
9
9
  Coveralls.wear_merged!
10
10
 
11
+ ENV['ADAPTER'] ||= 'active_record'
12
+
13
+ if ENV['ADAPTER'] == 'active_record'
14
+ require 'active_record/railtie'
15
+ else
16
+ require 'mongoid'
17
+ end
18
+
11
19
  module TestApp
12
20
  class Application < ::Rails::Application
13
21
  config.root = File.dirname(__FILE__)
14
22
  end
15
23
  end
16
24
 
17
- require 'ammeter/init'
18
-
19
- ENV['ADAPTER'] ||= 'active_record'
20
-
21
-
25
+ require 'ammeter/init'
@@ -1,14 +1,14 @@
1
1
  require "spec_helper"
2
- require "active_record"
3
- require "mongoid"
4
2
 
5
- class ARUser < ActiveRecord::Base
6
- extend Rolify
7
- end
8
-
9
- class MUser
10
- include Mongoid::Document
11
- extend Rolify
3
+ if ENV['ADAPTER'] == 'active_record'
4
+ class ARUser < ActiveRecord::Base
5
+ extend Rolify
6
+ end
7
+ else
8
+ class MUser
9
+ include Mongoid::Document
10
+ extend Rolify
11
+ end
12
12
  end
13
13
 
14
14
  describe Rolify do
@@ -35,14 +35,14 @@ describe Rolify do
35
35
  end
36
36
 
37
37
  describe :orm do
38
- context "using defaults values" do
38
+ context "using defaults values", :if => ENV['ADAPTER'] == 'active_record' do
39
39
  subject { Rolify.orm }
40
40
 
41
41
  it { should eq("active_record") }
42
42
 
43
43
  context "on the User class" do
44
44
  before do
45
- ARUser.rolify
45
+ subject.rolify
46
46
  end
47
47
 
48
48
  subject { ARUser }
@@ -52,7 +52,7 @@ describe Rolify do
52
52
 
53
53
  context "on the Forum class" do
54
54
  before do
55
- Forum.resourcify
55
+ subject.resourcify
56
56
  end
57
57
 
58
58
  subject { Forum }
@@ -61,7 +61,7 @@ describe Rolify do
61
61
  end
62
62
  end
63
63
 
64
- context "using custom values" do
64
+ context "using custom values", :if => ENV['ADAPTER'] == 'mongoid' do
65
65
  context "using :orm setter method" do
66
66
  before do
67
67
  Rolify.orm = "mongoid"
@@ -165,7 +165,7 @@ describe Rolify do
165
165
  its(:dynamic_shortcuts) { should be_true }
166
166
  its(:orm) { should eq("mongoid") }
167
167
 
168
- context "on the User class" do
168
+ context "on the User class", :if => ENV['ADAPTER'] == 'mongoid' do
169
169
  before do
170
170
  MUser.rolify
171
171
  end
@@ -46,7 +46,7 @@ describe Rolify::Resource do
46
46
  it "should be able to modify the resource", :if => ENV['ADAPTER'] == 'active_record' do
47
47
  forum_resource = subject.with_role(:forum).first
48
48
  forum_resource.name = "modified name"
49
- expect(forum_resource.save).not_to raise_error
49
+ expect { forum_resource.save }.not_to raise_error
50
50
  end
51
51
  end
52
52
 
@@ -339,12 +339,13 @@ describe Rolify::Resource do
339
339
  end
340
340
 
341
341
  describe "#roles" do
342
+ before(:all) { Role.destroy_all }
342
343
  subject { Forum.first }
343
344
 
344
345
  it { should respond_to :roles }
345
346
 
346
347
  context "on a Forum instance" do
347
- its(:roles) { should eq([ forum_role, sneaky_role ]) }
348
+ its(:roles) { should match_array( [ forum_role, sneaky_role ]) }
348
349
  its(:roles) { should_not include(group_role, godfather_role, tourist_role) }
349
350
  end
350
351
 
@@ -10,11 +10,9 @@ shared_examples_for "#add_role_examples" do |param_name, param_method|
10
10
  end
11
11
 
12
12
  context "considering a new global role" do
13
- subject { role_class.last }
14
-
15
- its(:name) { should eq("moderator") }
16
- its(:resource_type) { should be(nil) }
17
- its(:resource_id) { should be(nil) }
13
+ it "creates a new class scoped role" do
14
+ expect(subject.add_role "expert".send(param_method)).to be_the_same_role("expert")
15
+ end
18
16
  end
19
17
 
20
18
  context "should not create another role" do
@@ -40,11 +38,9 @@ shared_examples_for "#add_role_examples" do |param_name, param_method|
40
38
  end
41
39
 
42
40
  context "considering a new class scoped role" do
43
- subject { role_class.last }
44
-
45
- its(:name) { should eq("moderator") }
46
- its(:resource_type) { should eq(Forum.to_s) }
47
- its(:resource_id) { should be(nil) }
41
+ it "creates a new class scoped role" do
42
+ expect(subject.add_role "boss".send(param_method), Forum).to be_the_same_role("boss", Forum)
43
+ end
48
44
  end
49
45
 
50
46
  context "should not create another role" do
@@ -69,11 +65,8 @@ shared_examples_for "#add_role_examples" do |param_name, param_method|
69
65
  expect { subject.add_role "member".send(param_method), Forum.last }.to change { role_class.count }.by(1)
70
66
  end
71
67
 
72
- context "considering a new class scoped role" do
73
- subject { role_class.last }
74
-
75
- its(:name) { should eq("member") }
76
- its(:resource) { should eq(Forum.last) }
68
+ it "creates a new instance scoped role" do
69
+ expect(subject.add_role "mate".send(param_method), Forum.last).to be_the_same_role("mate", Forum.last)
77
70
  end
78
71
 
79
72
  context "should not create another role" do
@@ -44,7 +44,6 @@ shared_examples_for Rolify::Dynamic do
44
44
  moderator
45
45
  end
46
46
 
47
- it { should respond_to(:is_admin?).with(0).arguments }
48
47
  it { should respond_to(:is_moderator?).with(0).arguments }
49
48
  it { should respond_to(:is_moderator_of?).with(1).arguments }
50
49
  it { should_not respond_to(:is_god?) }
@@ -76,9 +75,6 @@ shared_examples_for Rolify::Dynamic do
76
75
  manager
77
76
  end
78
77
 
79
- it { should respond_to(:is_admin?).with(0).arguments }
80
- it { should respond_to(:is_moderator?).with(0).arguments }
81
- it { should respond_to(:is_moderator_of?).with(1).arguments }
82
78
  it { should respond_to(:is_manager?).with(0).arguments }
83
79
  it { should respond_to(:is_manager_of?).with(1).arguments }
84
80
  it { should_not respond_to(:is_god?) }
@@ -5,33 +5,19 @@ shared_examples_for "#remove_role_examples" do |param_name, param_method|
5
5
  it { expect { subject.remove_role("admin".send(param_method)) }.to change { subject.roles.size }.by(-1) }
6
6
 
7
7
  it { should_not have_role("admin".send(param_method)) }
8
- it { should have_role("staff".send(param_method)) }
9
- it { should have_role("manager".send(param_method), Group) }
10
- it { should have_role("moderator".send(param_method), Forum.last) }
11
- it { should have_role("moderator".send(param_method), Group.last) }
12
- it { should have_role("anonymous".send(param_method), Forum.first) }
13
8
  end
14
9
 
15
10
  context "being a class scoped role to the user" do
16
11
  it { expect { subject.remove_role("manager".send(param_method)) }.to change { subject.roles.size }.by(-1) }
17
12
 
18
- it { should_not have_role("admin".send(param_method)) }
19
- it { should have_role("staff".send(param_method)) }
20
13
  it { should_not have_role("manager".send(param_method), Group) }
21
- it { should have_role("moderator".send(param_method), Forum.last) }
22
- it { should have_role("moderator".send(param_method), Group.last) }
23
- it { should have_role("anonymous".send(param_method), Forum.first) }
24
14
  end
25
15
 
26
16
  context "being instance scoped roles to the user" do
27
17
  it { expect { subject.remove_role("moderator".send(param_method)) }.to change { subject.roles.size }.by(-2) }
28
18
 
29
- it { should_not have_role("admin".send(param_method)) }
30
- it { should have_role("staff".send(param_method)) }
31
- it { should_not have_role("manager".send(param_method), Group) }
32
19
  it { should_not have_role("moderator".send(param_method), Forum.last) }
33
20
  it { should_not have_role("moderator".send(param_method), Group.last) }
34
- it { should have_role("anonymous".send(param_method), Forum.first) }
35
21
  end
36
22
 
37
23
  context "not being a role of the user" do
@@ -46,12 +32,7 @@ shared_examples_for "#remove_role_examples" do |param_name, param_method|
46
32
 
47
33
  it { expect { subject.remove_role("staff".send(param_method)) }.not_to change { role_class.count } }
48
34
 
49
- it { should_not have_role("admin".send(param_method)) }
50
35
  it { should_not have_role("staff".send(param_method)) }
51
- it { should_not have_role("manager".send(param_method), Group) }
52
- it { should_not have_role("moderator".send(param_method), Forum.last) }
53
- it { should_not have_role("moderator".send(param_method), Group.last) }
54
- it { should have_role("anonymous".send(param_method), Forum.first) }
55
36
  end
56
37
 
57
38
  context "not used by anyone else" do
@@ -71,23 +52,14 @@ shared_examples_for "#remove_role_examples" do |param_name, param_method|
71
52
  context "being a class scoped role to the user" do
72
53
  it { expect { subject.remove_role("manager".send(param_method), Forum) }.to change{ subject.roles.size }.by(-1) }
73
54
 
74
- it { should have_role("warrior") }
75
55
  it { should_not have_role("manager", Forum) }
76
- it { should have_role("player", Forum) }
77
- it { should have_role("moderator".send(param_method), Forum.last) }
78
- it { should have_role("moderator".send(param_method), Group.last) }
79
- it { should have_role("anonymous".send(param_method), Forum.first) }
80
56
  end
81
57
 
82
58
  context "being instance scoped role to the user" do
83
59
  it { expect { subject.remove_role("moderator".send(param_method), Forum) }.to change { subject.roles.size }.by(-1) }
84
60
 
85
- it { should have_role("warrior") }
86
- it { should_not have_role("manager", Forum) }
87
- it { should have_role("player", Forum) }
88
61
  it { should_not have_role("moderator".send(param_method), Forum.last) }
89
62
  it { should have_role("moderator".send(param_method), Group.last) }
90
- it { should have_role("anonymous".send(param_method), Forum.first) }
91
63
  end
92
64
 
93
65
  context "not being a role of the user" do
@@ -107,10 +79,7 @@ shared_examples_for "#remove_role_examples" do |param_name, param_method|
107
79
  context "being instance scoped role to the user" do
108
80
  it { expect { subject.remove_role("moderator".send(param_method), Forum.first) }.to change { subject.roles.size }.by(-1) }
109
81
 
110
- it { should have_role("soldier") }
111
- it { should have_role("visitor", Forum) }
112
82
  it { should_not have_role("moderator", Forum.first) }
113
- it { should have_role("anonymous", Forum.last) }
114
83
  end
115
84
 
116
85
  context "not being a role of the user" do
@@ -93,10 +93,11 @@ shared_examples_for Rolify::Role do
93
93
 
94
94
  it { should have_role :admin }
95
95
  it { should have_role :moderator, Forum.first }
96
+ it { subject.has_any_role?(:admin).should be_true }
96
97
  end
97
98
 
98
99
  context "on the Class level ", :scope => :mixed do
99
100
  it_should_behave_like :finders, "String", :to_s
100
101
  it_should_behave_like :finders, "Symbol", :to_sym
101
102
  end
102
- end
103
+ end
@@ -3,7 +3,7 @@ require "bundler/setup"
3
3
 
4
4
  require 'rolify'
5
5
  require 'rolify/matchers'
6
- require 'rails/all'
6
+ require 'rails'
7
7
 
8
8
  require 'coveralls'
9
9
  Coveralls.wear_merged!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rolify
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florent Monbillard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-26 00:00:00.000000000 Z
11
+ date: 2014-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ammeter
@@ -94,34 +94,6 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: activerecord
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: 3.2.0
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: 3.2.0
111
- - !ruby/object:Gem::Dependency
112
- name: mongoid
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '3.1'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '3.1'
125
97
  description: Very simple Roles library without any authorization enforcement supporting
126
98
  scope on resource objects (instance or class). Supports ActiveRecord and Mongoid
127
99
  ORMs.
@@ -200,7 +172,8 @@ files:
200
172
  - spec/support/data.rb
201
173
  - spec/support/schema.rb
202
174
  homepage: http://eppo.github.com/rolify/
203
- licenses: []
175
+ licenses:
176
+ - MIT
204
177
  metadata: {}
205
178
  post_install_message:
206
179
  rdoc_options: []
@@ -218,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
191
  version: '0'
219
192
  requirements: []
220
193
  rubyforge_project: rolify
221
- rubygems_version: 2.0.3
194
+ rubygems_version: 2.2.0
222
195
  signing_key:
223
196
  specification_version: 4
224
197
  summary: Roles library with resource scoping
@@ -252,4 +225,3 @@ test_files:
252
225
  - spec/support/adapters/mongoid.yml
253
226
  - spec/support/data.rb
254
227
  - spec/support/schema.rb
255
- has_rdoc: