royce 1.0.1
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +32 -0
- data/lib/generators/royce/install_generator.rb +21 -0
- data/lib/generators/royce/templates/create_royce.rb +22 -0
- data/lib/royce.rb +7 -0
- data/lib/royce/class_methods.rb +32 -0
- data/lib/royce/connector.rb +9 -0
- data/lib/royce/macros.rb +39 -0
- data/lib/royce/methods.rb +39 -0
- data/lib/royce/role.rb +15 -0
- data/lib/royce/version.rb +3 -0
- data/lib/tasks/royce_tasks.rake +4 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/user.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +82 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/db/migrate/20140817214831_create_users.rb +8 -0
- data/test/dummy/db/migrate/20140821050450_create_royce.rb +22 -0
- data/test/dummy/db/schema.rb +39 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +73 -0
- data/test/dummy/log/test.log +36250 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/scopes_test.rb +67 -0
- data/test/roller_test.rb +107 -0
- data/test/scopes_test.rb +70 -0
- data/test/test_helper.rb +16 -0
- metadata +186 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
4
|
+
# ActiveRecord::Migration.create_table :employees
|
5
|
+
# ActiveRecord::Migration.create_table :baby_boomers
|
6
|
+
# load "dummy/db/schema.rb"
|
7
|
+
# ActiveRecord::Migrator.up "db/migrate"
|
8
|
+
|
9
|
+
# def human_roles
|
10
|
+
# %w( partier rocker )
|
11
|
+
# end
|
12
|
+
|
13
|
+
# class Employee < ActiveRecord::Base
|
14
|
+
# royce_roles human_roles
|
15
|
+
# end
|
16
|
+
|
17
|
+
# class BabyBoomer < ActiveRecord::Base
|
18
|
+
# royce_roles human_roles
|
19
|
+
# end
|
20
|
+
|
21
|
+
# describe "Testing class-level scopes" do
|
22
|
+
|
23
|
+
# before do
|
24
|
+
# Employee.delete_all
|
25
|
+
# BabyBoomer.delete_all
|
26
|
+
# User.delete_all
|
27
|
+
# end
|
28
|
+
|
29
|
+
# it "Has named scopes" do
|
30
|
+
# Employee.available_role_names.must_equal human_roles
|
31
|
+
# end
|
32
|
+
|
33
|
+
# it "Owner named scopes return owners with role" do
|
34
|
+
# employee = Employee.create
|
35
|
+
# Employee.partiers.include?(employee).must_equal false
|
36
|
+
# employee.add_role :partier
|
37
|
+
# Employee.partiers.include?(employee).must_equal true
|
38
|
+
# Employee.rockers.include?(employee).must_equal false
|
39
|
+
# end
|
40
|
+
|
41
|
+
# it "Named scope updates for tag removal deletion" do
|
42
|
+
# employee = Employee.create
|
43
|
+
# employee.add_role :rocker
|
44
|
+
# Employee.rockers.include?(employee).must_equal true
|
45
|
+
# employee.remove_role :rocker
|
46
|
+
# Employee.rockers.include?(employee).must_equal false
|
47
|
+
# Employee.rockers.count.must_equal 0
|
48
|
+
# end
|
49
|
+
|
50
|
+
|
51
|
+
# describe "Role to owning class relationships" do
|
52
|
+
|
53
|
+
# the_role = Royce::Role.find_by(name: 'partier')
|
54
|
+
# count = 20
|
55
|
+
|
56
|
+
# it "exist for single word models" do
|
57
|
+
# count.times{ Employee.create.add_role 'partier' }
|
58
|
+
# the_role.employees.count.must_equal count
|
59
|
+
# end
|
60
|
+
|
61
|
+
# it "exist for two word models" do
|
62
|
+
# count.times { BabyBoomer.create.add_role 'partier' }
|
63
|
+
# the_role.baby_boomers.count.must_equal count
|
64
|
+
# end
|
65
|
+
|
66
|
+
# end
|
67
|
+
# end
|
data/test/roller_test.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe "Basic tests" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
User.delete_all
|
7
|
+
end
|
8
|
+
|
9
|
+
def user
|
10
|
+
@user ||= User.create
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'can create role' do
|
14
|
+
role = Royce::Role.create(name: 'some_role')
|
15
|
+
role.wont_be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'Can create user' do
|
19
|
+
User.create.wont_be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'Creates roles automatically' do
|
23
|
+
Royce::Role.count.must_be :>, 0
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'adding roles' do
|
27
|
+
|
28
|
+
it 'can add with string' do
|
29
|
+
user.add_role 'user'
|
30
|
+
user.roles.count.must_equal 1
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'can add with symbol' do
|
34
|
+
user.add_role :user
|
35
|
+
user.roles.count.must_equal 1
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'can add with Role object' do
|
39
|
+
User.available_roles.each do |role|
|
40
|
+
user.add_role role
|
41
|
+
end
|
42
|
+
user.roles.count.must_equal User.available_roles.count
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
describe 'Removing roles' do
|
49
|
+
|
50
|
+
it 'can remove with string' do
|
51
|
+
user.add_role 'user'
|
52
|
+
user.remove_role 'user'
|
53
|
+
user.roles.count.must_equal 0
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'can remove with symbol' do
|
57
|
+
user.add_role :user
|
58
|
+
user.remove_role :user
|
59
|
+
user.roles.count.must_equal 0
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'Can query role name' do
|
65
|
+
user.has_role?('user').must_equal false
|
66
|
+
user.has_role?(:user).must_equal false
|
67
|
+
user_role = Royce::Role.find_by(name: 'user')
|
68
|
+
user.has_role?(user_role).must_equal false
|
69
|
+
|
70
|
+
user.add_role 'user'
|
71
|
+
|
72
|
+
user.has_role?('user').must_equal true
|
73
|
+
user.has_role?(:user).must_equal true
|
74
|
+
user.has_role?(user_role).must_equal true
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'Can tell acceptable roles' do
|
78
|
+
user.allowed_role?('zxcv').must_equal false
|
79
|
+
user.allowed_role?('user').must_equal true
|
80
|
+
user.allowed_role?(:zxcv).must_equal false
|
81
|
+
user.allowed_role?(:user).must_equal true
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'Has name methods' do
|
85
|
+
User.available_roles.each do |role|
|
86
|
+
method_name = "#{role}?"
|
87
|
+
user.send(method_name).must_equal false
|
88
|
+
user.add_role role
|
89
|
+
user.send(method_name).must_equal true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "knows allowed roles" do
|
94
|
+
User.available_roles.each do |role|
|
95
|
+
user.allowed_role?(role).must_equal true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
it "has named scopes for each role" do
|
100
|
+
User.available_roles.each do |role|
|
101
|
+
User.send role.name.pluralize.to_sym
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
end
|
107
|
+
|
data/test/scopes_test.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
4
|
+
ActiveRecord::Migration.create_table :employees
|
5
|
+
ActiveRecord::Migration.create_table :baby_boomers
|
6
|
+
load "dummy/db/schema.rb"
|
7
|
+
ActiveRecord::Migrator.up "db/migrate"
|
8
|
+
|
9
|
+
def human_roles
|
10
|
+
%w( partier rocker )
|
11
|
+
end
|
12
|
+
|
13
|
+
class Employee < ActiveRecord::Base
|
14
|
+
royce_roles human_roles
|
15
|
+
end
|
16
|
+
|
17
|
+
class BabyBoomer < ActiveRecord::Base
|
18
|
+
royce_roles human_roles
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "Testing class-level scopes" do
|
22
|
+
|
23
|
+
before do
|
24
|
+
Employee.delete_all
|
25
|
+
BabyBoomer.delete_all
|
26
|
+
User.delete_all
|
27
|
+
end
|
28
|
+
|
29
|
+
it "Has named scopes" do
|
30
|
+
Employee.available_role_names.must_equal human_roles
|
31
|
+
end
|
32
|
+
|
33
|
+
it "Owner named scopes return owners with role" do
|
34
|
+
employee = Employee.create
|
35
|
+
Employee.partiers.include?(employee).must_equal false
|
36
|
+
employee.add_role :partier
|
37
|
+
Employee.partiers.include?(employee).must_equal true
|
38
|
+
Employee.rockers.include?(employee).must_equal false
|
39
|
+
end
|
40
|
+
|
41
|
+
it "Named scope updates for tag removal deletion" do
|
42
|
+
employee = Employee.create
|
43
|
+
employee.add_role :rocker
|
44
|
+
Employee.rockers.include?(employee).must_equal true
|
45
|
+
employee.remove_role :rocker
|
46
|
+
Employee.rockers.include?(employee).must_equal false
|
47
|
+
Employee.rockers.count.must_equal 0
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
describe "Role to owning class relationships" do
|
52
|
+
|
53
|
+
the_role = Royce::Role.find_by(name: 'partier')
|
54
|
+
count = 20
|
55
|
+
|
56
|
+
it "exist for single word models" do
|
57
|
+
count.times{ Employee.create.add_role 'partier' }
|
58
|
+
the_role.employees.count.must_equal count
|
59
|
+
end
|
60
|
+
|
61
|
+
it "exist for two word models" do
|
62
|
+
count.times { BabyBoomer.create.add_role 'partier' }
|
63
|
+
the_role.baby_boomers.count.must_equal count
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
end
|