role_play 1.0.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
- pkg/*
1
+ pkg/*
2
+ .rvmrc
@@ -1,11 +1,11 @@
1
1
  Install
2
2
  =======
3
+
4
+ From gemcutter
5
+ $ gem install role_play
3
6
 
4
- $ gem source -a http://gems.github.com/
5
- $ sudo gem install mintdigital-has_roles
6
-
7
- # environment.rb
8
- config.gem 'mintdigital-has_roles', :lib => 'has_roles'
7
+ # or in your Gemfile
8
+ gem 'role_play'
9
9
 
10
10
  Example
11
11
  =======
@@ -16,7 +16,7 @@ In an ActiveRecord class:
16
16
 
17
17
  Then run:
18
18
 
19
- ./script/generate has_roles && rake db:migrate
19
+ rails generate role_play_migration && rake db:migrate
20
20
 
21
21
  Now your model has these instance methods:
22
22
 
@@ -32,4 +32,6 @@ Now your model has these instance methods:
32
32
 
33
33
  ---
34
34
 
35
+ Tested in Ruby 1.9.2 and Rails 3.0.3
36
+
35
37
  Copyright (c) 2008 Krzysztof Zylawy, released under the MIT license
data/Rakefile CHANGED
@@ -1,44 +1,17 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'rake/rdoctask'
4
- require File.join(File.dirname(__FILE__), %w[lib/role_play])
5
-
6
- # begin
7
- # require 'echoe'
8
- # Echoe.new('has_roles') do |a|
9
- # a.version = HasRoles::Version::STRING
10
- # a.summary = "Simple roles for ActiveRecord"
11
- # a.author = "Krzysztof Zylawy"
12
- # a.email = "krzysztof@mintdigital.com"
13
- # a.runtime_dependencies = ['activerecord']
14
- # a.development_dependencies = ['echoe']
15
- # a.has_rdoc = false
16
- # a.retain_gemspec = true
17
- # end
18
- # rescue LoadError
19
- # puts "Install 'echoe' if you want gem building-ness."
20
- # end
21
-
22
- begin
23
- require 'jeweler'
24
- Jeweler::Tasks.new do |s|
25
- s.name = "role_play"
26
- s.summary = "Simple roles for ActiveRecord"
27
- s.email = "philnash@gmail.com"
28
- s.homepage = "http://github.com/mintdigital/has_roles"
29
- s.authors = ["Krzysztof Zylawy", "Mint Digital"]
30
- s.add_dependency 'activerecord'
31
- end
32
- Jeweler::GemcutterTasks.new
33
- rescue LoadError
34
- puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
35
- end
36
4
 
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
37
7
 
38
8
  desc 'Default: Run Tests'
39
9
  Rake::TestTask.new do |t|
40
10
  t.warning = true
41
11
  t.pattern = 'test/**/*_test.rb'
12
+ t.libs << 'test'
13
+ t.libs << 'lib'
14
+ t.verbose = true
42
15
  end
43
16
 
44
17
  desc 'Generate documentation for the role_play plugin.'
@@ -49,3 +22,4 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
49
22
  rdoc.rdoc_files.include('README')
50
23
  rdoc.rdoc_files.include('lib/**/*.rb')
51
24
  end
25
+
@@ -0,0 +1,12 @@
1
+ class RolePlayMigrationGenerator < Rails::Generators::Base
2
+ include Rails::Generators::Migration
3
+ source_root File.expand_path("../templates", __FILE__)
4
+
5
+ def self.next_migration_number(path)
6
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
7
+ end
8
+
9
+ def create_model_file
10
+ migration_template "migration.rb", "db/migrate/create_roles.rb"
11
+ end
12
+ end
data/lib/role_play.rb CHANGED
@@ -1,35 +1,29 @@
1
- module RolePlay
1
+ require 'role'
2
+ require 'role_assignment'
3
+ require 'active_support/concern'
2
4
 
3
- def self.included(base)
4
- base.extend HasMethods
5
- end
5
+ module RolePlay
6
+ extend ActiveSupport::Concern
6
7
 
7
- module HasMethods
8
+ module ClassMethods
8
9
  def has_roles(*roles)
9
10
  roles.flatten!
10
11
  write_inheritable_attribute(:available_roles, roles)
11
12
  class_inheritable_reader :available_roles
12
13
 
13
- unless included_modules.include? InstanceMethods
14
- has_many :role_assignments, :as => :roleable, :dependent => :destroy
15
- has_many :roles, :through => :role_assignments
16
-
17
- extend ClassMethods
18
- include InstanceMethods
19
- available_roles.each do |role|
20
- self.class_eval do
21
- define_method "#{role}?".to_sym do
22
- has_role?(role)
23
- end
14
+ has_many :role_assignments, :as => :roleable, :dependent => :destroy
15
+ has_many :roles, :through => :role_assignments
16
+
17
+ available_roles.each do |role|
18
+ self.class_eval do
19
+ define_method "#{role}?".to_sym do
20
+ has_role?(role)
24
21
  end
25
22
  end
26
23
  end
27
24
  end
28
25
  end
29
26
 
30
- module ClassMethods
31
- end
32
-
33
27
  module InstanceMethods
34
28
  def can_have_role?(role_name)
35
29
  available_roles.include?(role_name)
@@ -55,6 +49,8 @@ module RolePlay
55
49
  def clear_roles
56
50
  role_assignments.clear
57
51
  end
58
-
52
+
59
53
  end
60
54
  end
55
+
56
+ ActiveRecord::Base.send(:include, RolePlay) if defined?(ActiveRecord)
data/rails/init.rb CHANGED
@@ -1,4 +1 @@
1
- require File.join(File.dirname(__FILE__), %w[.. lib role_play])
2
-
3
- ActiveRecord::Base.send(:include, RolePlay)
4
-
1
+ require 'role_play'
data/role_play.gemspec CHANGED
@@ -1,63 +1,17 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
3
  Gem::Specification.new do |s|
7
- s.name = %q{role_play}
8
- s.version = "1.0.1"
4
+ s.version = "1.1.2"
9
5
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.name = 'role_play'
7
+ s.summary = %q{Simple roles for ActiveRecord}
8
+ s.description = 'Rails 3-ified version of the beloved plugin'
11
9
  s.authors = ["Krzysztof Zylawy", "Mint Digital"]
12
- s.date = %q{2009-12-04}
13
- s.email = %q{philnash@gmail.com}
14
- s.extra_rdoc_files = [
15
- "README"
16
- ]
17
- s.files = [
18
- ".gitignore",
19
- "MIT-LICENSE",
20
- "Manifest",
21
- "README",
22
- "Rakefile",
23
- "VERSION",
24
- "generators/role_play/USAGE",
25
- "generators/role_play/role_play_generator.rb",
26
- "generators/role_play/templates/migration.rb",
27
- "install.rb",
28
- "lib/role.rb",
29
- "lib/role_assignment.rb",
30
- "lib/role_play.rb",
31
- "rails/init.rb",
32
- "role_play.gemspec",
33
- "tasks/has_roles_tasks.rake",
34
- "test/assertions.rb",
35
- "test/role_play_test.rb",
36
- "test/test_helper.rb",
37
- "uninstall.rb"
38
- ]
39
- s.homepage = %q{http://github.com/mintdigital/has_roles}
40
- s.rdoc_options = ["--charset=UTF-8"]
10
+ s.email = 'hello@mintdigital.com'
11
+ s.homepage = %q{https://github.com/mintdigital/role_play}
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test}/*`.split("\n")
41
14
  s.require_paths = ["lib"]
42
- s.rubygems_version = %q{1.3.5}
43
- s.summary = %q{Simple roles for ActiveRecord}
44
- s.test_files = [
45
- "test/assertions.rb",
46
- "test/role_play_test.rb",
47
- "test/test_helper.rb"
48
- ]
49
-
50
- if s.respond_to? :specification_version then
51
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
- s.specification_version = 3
53
-
54
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
55
- s.add_runtime_dependency(%q<activerecord>, [">= 0"])
56
- else
57
- s.add_dependency(%q<activerecord>, [">= 0"])
58
- end
59
- else
60
- s.add_dependency(%q<activerecord>, [">= 0"])
61
- end
15
+ s.platform = Gem::Platform::RUBY
16
+ s.add_dependency('activerecord', '3.0.3')
62
17
  end
63
-
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+ require 'generators/role_play_migration/role_play_migration_generator'
3
+
4
+ class MigrationGeneratorTest < Rails::Generators::TestCase
5
+ tests RolePlayMigrationGenerator
6
+ destination File.expand_path("../tmp", File.dirname(__FILE__))
7
+ setup :prepare_destination
8
+
9
+ test "migration file is created" do
10
+ run_generator
11
+ assert_migration "db/migrate/create_roles.rb" do |mig|
12
+ assert_class_method :up, mig do |upmeth|
13
+ assert_match(/create_table/, upmeth)
14
+ end
15
+ assert_class_method :down, mig do |downmeth|
16
+ assert_match(/drop_table/, downmeth)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
1
+ require 'test_helper'
2
2
 
3
3
  class RoleableSample < ActiveRecord::Base
4
4
  has_roles [:sample_role_1, :sample_role_2]
@@ -8,7 +8,7 @@ class AnotherRoleable < ActiveRecord::Base
8
8
  has_roles :another1, :another2
9
9
  end
10
10
 
11
- class RolePlayTest < Test::Unit::TestCase
11
+ class RolePlayTest < ActiveSupport::TestCase
12
12
 
13
13
  def setup
14
14
  @roleable_sample = RoleableSample.create
data/test/test_helper.rb CHANGED
@@ -1,14 +1,16 @@
1
+ #require 'rails/generators'
2
+ #require 'rails/generators/test_case'
1
3
  require 'test/unit'
2
4
  require 'rubygems'
3
5
  require 'active_record'
4
- require File.join(File.dirname(__FILE__), 'assertions')
6
+
7
+ ENV['RAILS_ENV'] = 'test'
8
+
9
+ require 'rails/generators/test_case'
5
10
  require File.join(File.dirname(__FILE__), %w[.. rails init.rb])
6
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
7
11
  require 'role'
8
12
  require 'role_assignment'
9
13
 
10
- Test::Unit::TestCase.send :include, ActiveSupport::Testing::Assertions
11
-
12
14
  ActiveRecord::Base.establish_connection(
13
15
  :adapter => 'sqlite3', :database => ':memory:'
14
16
  )
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: role_play
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 1
8
+ - 2
9
+ version: 1.1.2
5
10
  platform: ruby
6
11
  authors:
7
12
  - Krzysztof Zylawy
@@ -10,77 +15,82 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2009-12-04 00:00:00 +00:00
18
+ date: 2011-01-31 00:00:00 +00:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: activerecord
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
21
26
  requirements:
22
- - - ">="
27
+ - - "="
23
28
  - !ruby/object:Gem::Version
24
- version: "0"
25
- version:
26
- description:
27
- email: philnash@gmail.com
29
+ segments:
30
+ - 3
31
+ - 0
32
+ - 3
33
+ version: 3.0.3
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: Rails 3-ified version of the beloved plugin
37
+ email: hello@mintdigital.com
28
38
  executables: []
29
39
 
30
40
  extensions: []
31
41
 
32
- extra_rdoc_files:
33
- - README
42
+ extra_rdoc_files: []
43
+
34
44
  files:
35
45
  - .gitignore
36
46
  - MIT-LICENSE
37
- - Manifest
38
- - README
47
+ - README.markdown
39
48
  - Rakefile
40
- - VERSION
41
- - generators/role_play/USAGE
42
- - generators/role_play/role_play_generator.rb
43
- - generators/role_play/templates/migration.rb
44
49
  - install.rb
50
+ - lib/generators/role_play_migration/USAGE
51
+ - lib/generators/role_play_migration/role_play_migration_generator.rb
52
+ - lib/generators/role_play_migration/templates/migration.rb
45
53
  - lib/role.rb
46
54
  - lib/role_assignment.rb
47
55
  - lib/role_play.rb
48
56
  - rails/init.rb
49
57
  - role_play.gemspec
50
58
  - tasks/has_roles_tasks.rake
51
- - test/assertions.rb
59
+ - test/migration_generator_test.rb
52
60
  - test/role_play_test.rb
53
61
  - test/test_helper.rb
54
62
  - uninstall.rb
55
63
  has_rdoc: true
56
- homepage: http://github.com/mintdigital/has_roles
64
+ homepage: https://github.com/mintdigital/role_play
57
65
  licenses: []
58
66
 
59
67
  post_install_message:
60
- rdoc_options:
61
- - --charset=UTF-8
68
+ rdoc_options: []
69
+
62
70
  require_paths:
63
71
  - lib
64
72
  required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ">="
67
76
  - !ruby/object:Gem::Version
77
+ segments:
78
+ - 0
68
79
  version: "0"
69
- version:
70
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
71
82
  requirements:
72
83
  - - ">="
73
84
  - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
74
87
  version: "0"
75
- version:
76
88
  requirements: []
77
89
 
78
90
  rubyforge_project:
79
- rubygems_version: 1.3.5
91
+ rubygems_version: 1.3.7
80
92
  signing_key:
81
93
  specification_version: 3
82
94
  summary: Simple roles for ActiveRecord
83
- test_files:
84
- - test/assertions.rb
85
- - test/role_play_test.rb
86
- - test/test_helper.rb
95
+ test_files: []
96
+
data/Manifest DELETED
@@ -1,18 +0,0 @@
1
- generators/has_roles/has_roles_generator.rb
2
- generators/has_roles/templates/migration.rb
3
- generators/has_roles/USAGE
4
- has_roles.gemspec
5
- install.rb
6
- lib/has_roles.rb
7
- lib/role.rb
8
- lib/role_assignment.rb
9
- Manifest
10
- MIT-LICENSE
11
- rails/init.rb
12
- Rakefile
13
- README
14
- tasks/has_roles_tasks.rake
15
- test/assertions.rb
16
- test/has_roles_test.rb
17
- test/test_helper.rb
18
- uninstall.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.1
@@ -1,10 +0,0 @@
1
- class RolePlayGenerator < Rails::Generator::Base
2
- def manifest
3
- recorded_session = record do |m|
4
- unless options[:skip_migration]
5
- m.migration_template "migration.rb", "db/migrate",
6
- :migration_file_name => 'create_roles'
7
- end
8
- end
9
- end
10
- end
data/test/assertions.rb DELETED
@@ -1,82 +0,0 @@
1
- # Copyright (c) 2005-2009 David Heinemeier Hansson
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining
4
- # a copy of this software and associated documentation files (the
5
- # "Software"), to deal in the Software without restriction, including
6
- # without limitation the rights to use, copy, modify, merge, publish,
7
- # distribute, sublicense, and/or sell copies of the Software, and to
8
- # permit persons to whom the Software is furnished to do so, subject to
9
- # the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be
12
- # included in all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
-
22
- module ActiveSupport
23
- module Testing
24
- module Assertions
25
- # Test numeric difference between the return value of an expression as a result of what is evaluated
26
- # in the yielded block.
27
- #
28
- # assert_difference 'Article.count' do
29
- # post :create, :article => {...}
30
- # end
31
- #
32
- # An arbitrary expression is passed in and evaluated.
33
- #
34
- # assert_difference 'assigns(:article).comments(:reload).size' do
35
- # post :create, :comment => {...}
36
- # end
37
- #
38
- # An arbitrary positive or negative difference can be specified. The default is +1.
39
- #
40
- # assert_difference 'Article.count', -1 do
41
- # post :delete, :id => ...
42
- # end
43
- #
44
- # An array of expressions can also be passed in and evaluated.
45
- #
46
- # assert_difference [ 'Article.count', 'Post.count' ], +2 do
47
- # post :create, :article => {...}
48
- # end
49
- #
50
- # A error message can be specified.
51
- #
52
- # assert_difference 'Article.count', -1, "An Article should be destroyed" do
53
- # post :delete, :id => ...
54
- # end
55
- def assert_difference(expressions, difference = 1, message = nil, &block)
56
- expression_evaluations = Array(expressions).collect{ |expression| lambda { eval(expression, block.send(:binding)) } }
57
-
58
- original_values = expression_evaluations.inject([]) { |memo, expression| memo << expression.call }
59
- yield
60
- expression_evaluations.each_with_index do |expression, i|
61
- assert_equal original_values[i] + difference, expression.call, message
62
- end
63
- end
64
-
65
- # Assertion that the numeric result of evaluating an expression is not changed before and after
66
- # invoking the passed in block.
67
- #
68
- # assert_no_difference 'Article.count' do
69
- # post :create, :article => invalid_attributes
70
- # end
71
- #
72
- # A error message can be specified.
73
- #
74
- # assert_no_difference 'Article.count', "An Article should not be destroyed" do
75
- # post :create, :article => invalid_attributes
76
- # end
77
- def assert_no_difference(expressions, message = nil, &block)
78
- assert_difference expressions, 0, message, &block
79
- end
80
- end
81
- end
82
- end