roles-spec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format nested
2
+ --color
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Kristian Mandrup
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.
data/README.markdown ADDED
@@ -0,0 +1,51 @@
1
+ # Roles spec
2
+
3
+ RSpec matchers to spec your User models to make sure they apply certain Role strategies. To be used with the Roles gems - see [Roles generic](http://github.com/kristianmandrup/**roles_generic**)
4
+
5
+ ## Install
6
+
7
+ <code>gem install roles-spec</code>
8
+
9
+ ## Usage
10
+
11
+ Teaser:
12
+ <pre>
13
+ root_dir.should have_model :user do |clazz|
14
+ clazz.should have_valid_roles :admin, :guest
15
+ clazz.should have_roles_strategy :one_role
16
+ clazz.should have_roles_orm :active_record
17
+ clazz.should have_roles_class :role
18
+ end
19
+ </pre>
20
+
21
+ Full RSpec example:
22
+ <pre>
23
+ root_dir = Rails3::Assist::Directory.rails_root
24
+
25
+ describe 'User model applies role strategy' do
26
+ use_orm :active_record
27
+
28
+ it "should have valid roles :user and :admin and the role strategy :admin_flag" do
29
+ root_dir.should have_model :user do |clazz|
30
+ clazz.should have_valid_roles :admin, :guest
31
+ clazz.should have_roles_strategy :one_role, :default
32
+ clazz.should have_roles_orm :active_record
33
+ clazz.should have_roles_class :role
34
+ end
35
+ end
36
+ end
37
+ </pre>
38
+
39
+ ## Note on Patches/Pull Requests
40
+
41
+ * Fork the project.
42
+ * Make your feature addition or bug fix.
43
+ * Add tests for it. This is important so I don't break it in a
44
+ future version unintentionally.
45
+ * Commit, do not mess with rakefile, version, or history.
46
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
47
+ * Send me a pull request. Bonus points for topic branches.
48
+
49
+ ## Copyright
50
+
51
+ Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ gem.name = "roles-spec"
5
+ gem.summary = %Q{RSpec matchers for roles}
6
+ gem.description = %Q{Spec that your User model files apply role strategies as expected}
7
+ gem.email = "kmandrup@gmail.com"
8
+ gem.homepage = "http://github.com/kristianmandrup/roles-spec"
9
+ gem.authors = ["Kristian Mandrup"]
10
+ gem.add_dependency "rspec", "~> 2.0.0.beta.22"
11
+ gem.add_dependency "require_all", "~> 1.1.0"
12
+ gem.add_dependency "rails-app-spec", "~> 0.2.9"
13
+ gem.add_dependency "rails3_artifactor", "~> 0.2.2"
14
+ gem.add_dependency "code-spec", "~> 0.2.3"
15
+ gem.add_dependency "activesupport", "~> 3.0.0"
16
+
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,28 @@
1
+ require 'code-spec'
2
+ require 'active_support/inflector'
3
+
4
+ module RSpec::RubyContentMatchers
5
+ module Roles
6
+ def have_default_roles
7
+ have_call :valid_roles_are, :args => [:admin, :guest]
8
+ end
9
+
10
+ def have_valid_roles *names
11
+ have_call :valid_roles, :args => names
12
+ end
13
+
14
+ def have_roles_strategy strategy, options = nil
15
+ return have_call :strategy, strategy.to_sym if !options
16
+ have_call :strategy, :args => [strategy.to_sym, options]
17
+ end
18
+
19
+ def have_roles_orm orm_name
20
+ include_module "Roles::#{orm_name.to_s.camelize}"
21
+ end
22
+
23
+ def have_roles_class clazz
24
+ have_call :role_class, clazz.to_sym
25
+ end
26
+ end
27
+ end
28
+
data/lib/roles-spec.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'require_all'
2
+ require_all File.dirname(__FILE__) + '/matchers'
3
+ require_all File.dirname(__FILE__) + '/rspec'
@@ -0,0 +1,7 @@
1
+ require 'rspec/core'
2
+
3
+ RSpec.configure do |config|
4
+ config.include RSpec::RubyContentMatchers::Roles
5
+ end
6
+
7
+
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ root_dir = Rails3::Assist::Directory.rails_root
4
+
5
+ describe 'RSpec matcher to spec that your User model is configured with a Role strategy' do
6
+ use_orm :none
7
+
8
+ before :each do
9
+ create_model :user do
10
+ %q{
11
+ include Roles::ActiveRecord
12
+
13
+ strategy :one_role, :default
14
+ valid_roles_are :admin, :guest
15
+ role_class :role
16
+ }
17
+ end
18
+
19
+ create_model :admin do
20
+ %q{
21
+ include Roles::ActiveRecord
22
+
23
+ strategy :many_roles, :default
24
+ valid_roles_are :admin, :guest, :special
25
+ role_class :role
26
+ }
27
+ end
28
+
29
+ puts read_model :user
30
+ end
31
+
32
+ after :each do
33
+ remove_models :user, :admin
34
+ end
35
+
36
+ it "should have the User model setup with :one_role default strategy" do
37
+ root_dir.should have_model :user do |clazz|
38
+ clazz.should have_default_roles
39
+ clazz.should have_roles_strategy :one_role
40
+ clazz.should have_roles_orm :active_record
41
+ clazz.should have_roles_class :role
42
+ end
43
+ end
44
+
45
+ it "should have the Admin model setup with :many_roles strategy" do
46
+ root_dir.should have_model :admin do |clazz|
47
+ clazz.should have_valid_roles :admin, :guest, :special
48
+ clazz.should have_roles_strategy :many_roles, :default
49
+ clazz.should have_roles_orm :active_record
50
+ clazz.should have_roles_class :role
51
+ end
52
+ end
53
+ end
54
+
@@ -0,0 +1,31 @@
1
+ require 'rspec/core'
2
+ require 'roles-spec'
3
+ require 'rails-app-spec'
4
+
5
+ RSpec.configure do |config|
6
+ config.mock_with :mocha
7
+ config.before do
8
+ Rails3::Assist::Directory.rails_root = temp_dir('tmp_rails')
9
+ end
10
+
11
+ config.after do
12
+ remove_temp_dir 'tmp_rails'
13
+ end
14
+ end
15
+
16
+ def project_dir
17
+ File.dirname(__FILE__) + '/..'
18
+ end
19
+
20
+ def temp_dir name
21
+ File.join(project_dir, name)
22
+ end
23
+
24
+ def make_temp_dir name
25
+ FileUtils.mkdir_p temp_dir(name)
26
+ temp_dir(name)
27
+ end
28
+
29
+ def remove_temp_dir name
30
+ FileUtils.rm_rf temp_dir(name)
31
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roles-spec
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Kristian Mandrup
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-16 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 0
32
+ - beta
33
+ - 22
34
+ version: 2.0.0.beta.22
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: require_all
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 1
47
+ - 1
48
+ - 0
49
+ version: 1.1.0
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rails-app-spec
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ - 2
63
+ - 9
64
+ version: 0.2.9
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: rails3_artifactor
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ - 2
78
+ - 2
79
+ version: 0.2.2
80
+ type: :runtime
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ name: code-spec
84
+ prerelease: false
85
+ requirement: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
92
+ - 2
93
+ - 3
94
+ version: 0.2.3
95
+ type: :runtime
96
+ version_requirements: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ name: activesupport
99
+ prerelease: false
100
+ requirement: &id006 !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ~>
104
+ - !ruby/object:Gem::Version
105
+ segments:
106
+ - 3
107
+ - 0
108
+ - 0
109
+ version: 3.0.0
110
+ type: :runtime
111
+ version_requirements: *id006
112
+ description: Spec that your User model files apply role strategies as expected
113
+ email: kmandrup@gmail.com
114
+ executables: []
115
+
116
+ extensions: []
117
+
118
+ extra_rdoc_files:
119
+ - LICENSE
120
+ - README.markdown
121
+ files:
122
+ - .document
123
+ - .gitignore
124
+ - .rspec
125
+ - LICENSE
126
+ - README.markdown
127
+ - Rakefile
128
+ - VERSION
129
+ - lib/matchers/have_roles.rb
130
+ - lib/roles-spec.rb
131
+ - lib/rspec/configure.rb
132
+ - spec/matchers/have_roles_spec.rb
133
+ - spec/spec_helper.rb
134
+ has_rdoc: true
135
+ homepage: http://github.com/kristianmandrup/roles-spec
136
+ licenses: []
137
+
138
+ post_install_message:
139
+ rdoc_options:
140
+ - --charset=UTF-8
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ segments:
149
+ - 0
150
+ version: "0"
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ requirements: []
160
+
161
+ rubyforge_project:
162
+ rubygems_version: 1.3.7
163
+ signing_key:
164
+ specification_version: 3
165
+ summary: RSpec matchers for roles
166
+ test_files:
167
+ - spec/matchers/have_roles_spec.rb
168
+ - spec/spec_helper.rb