core_models 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +34 -0
  4. data/lib/core_models.rb +4 -0
  5. data/lib/core_models/models/concerns/group_concerns.rb +31 -0
  6. data/lib/core_models/models/concerns/role_concerns.rb +31 -0
  7. data/lib/core_models/models/concerns/user_concerns.rb +102 -0
  8. data/lib/core_models/models/group.rb +25 -0
  9. data/lib/core_models/models/group_membership.rb +16 -0
  10. data/lib/core_models/models/groups_role.rb +15 -0
  11. data/lib/core_models/models/permission.rb +24 -0
  12. data/lib/core_models/models/role.rb +33 -0
  13. data/lib/core_models/models/roles_permission.rb +15 -0
  14. data/lib/core_models/models/user.rb +63 -0
  15. data/lib/core_models/version.rb +3 -0
  16. data/lib/generators/core_models_setup_generator.rb +19 -0
  17. data/lib/tasks/core_models_tasks.rake +4 -0
  18. data/spec/dummy/README.rdoc +28 -0
  19. data/spec/dummy/Rakefile +6 -0
  20. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  21. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  22. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  23. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  24. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  25. data/spec/dummy/bin/bundle +3 -0
  26. data/spec/dummy/bin/rails +4 -0
  27. data/spec/dummy/bin/rake +4 -0
  28. data/spec/dummy/bin/setup +29 -0
  29. data/spec/dummy/config.ru +4 -0
  30. data/spec/dummy/config/application.rb +26 -0
  31. data/spec/dummy/config/boot.rb +5 -0
  32. data/spec/dummy/config/database.yml +23 -0
  33. data/spec/dummy/config/environment.rb +5 -0
  34. data/spec/dummy/config/environments/development.rb +41 -0
  35. data/spec/dummy/config/environments/production.rb +79 -0
  36. data/spec/dummy/config/environments/test.rb +42 -0
  37. data/spec/dummy/config/initializers/assets.rb +11 -0
  38. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  40. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  41. data/spec/dummy/config/initializers/friendly_id.rb +88 -0
  42. data/spec/dummy/config/initializers/inflections.rb +16 -0
  43. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  44. data/spec/dummy/config/initializers/session_store.rb +3 -0
  45. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  46. data/spec/dummy/config/locales/en.yml +23 -0
  47. data/spec/dummy/config/routes.rb +56 -0
  48. data/spec/dummy/config/secrets.yml +22 -0
  49. data/spec/dummy/db/development.sqlite3 +0 -0
  50. data/spec/dummy/db/migrate/20150220064247_create_friendly_id_slugs.rb +15 -0
  51. data/spec/dummy/db/schema.rb +93 -0
  52. data/spec/dummy/db/test.sqlite3 +0 -0
  53. data/spec/dummy/log/development.log +256 -0
  54. data/spec/dummy/log/test.log +21878 -0
  55. data/spec/dummy/public/404.html +67 -0
  56. data/spec/dummy/public/422.html +67 -0
  57. data/spec/dummy/public/500.html +66 -0
  58. data/spec/dummy/public/favicon.ico +0 -0
  59. data/spec/dummy/test.sqlite3 +0 -0
  60. data/spec/models/group_spec.rb +94 -0
  61. data/spec/models/permission_spec.rb +49 -0
  62. data/spec/models/role_spec.rb +113 -0
  63. data/spec/models/user_spec.rb +139 -0
  64. data/spec/rails_helper.rb +57 -0
  65. data/spec/schema.rb +103 -0
  66. data/spec/spec_helper.rb +85 -0
  67. data/spec/support/factories.rb +54 -0
  68. data/spec/support/model_classes.rb +36 -0
  69. data/spec/support/setup.rb +48 -0
  70. data/spec/test.sqlite3 +0 -0
  71. metadata +294 -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
Binary file
@@ -0,0 +1,94 @@
1
+ require 'rails_helper'
2
+ require 'support/model_classes'
3
+ require 'support/factories'
4
+ require 'support/setup'
5
+ require 'pry'
6
+
7
+
8
+ describe "group model mixin" do
9
+
10
+ context "Fail to find a group" do
11
+ it "should raise an error on trying to find non existent group" do
12
+ expect{
13
+ Group.find(1)
14
+ }.to raise_error ActiveRecord::RecordNotFound
15
+ end
16
+ end
17
+
18
+ context "Validation checks" do
19
+ it "validates a group object" do
20
+ FactoryGirl.build(:member_group).should be_valid
21
+ end
22
+
23
+ it "should not validate a group object, based on an empty name" do
24
+ FactoryGirl.build(:member_group, group_name: '').should_not be_valid
25
+ end
26
+ end
27
+
28
+ context "Friendly ID" do
29
+ it "should find based on name" do
30
+ @group = FactoryGirl.create(:member_group)
31
+ Group.find(@group.group_name.parameterize).should_not eql nil
32
+ end
33
+ end
34
+
35
+ context "Create role relationship" do
36
+ it "create a relationship and check that it exists" do
37
+ @group = FactoryGirl.create(:member_group)
38
+ @role = FactoryGirl.create(:admin_role)
39
+ @group.add_role = @role.role_name
40
+ @group.has_role?(@role.role_name).should eql true
41
+ end
42
+
43
+ it "should return an array of roles for a group" do
44
+ @group = FactoryGirl.create(:member_group)
45
+ @role = FactoryGirl.create(:admin_role)
46
+ @group.add_role = @role.role_name
47
+ @group.roles.empty?.should eql false
48
+ end
49
+
50
+ it "should return false for a group that cannot be altered" do
51
+ @group = FactoryGirl.create(:member_group, can_alter: false)
52
+ group = Group.find(@group.group_name.parameterize)
53
+ group.can_alter?.should eql false
54
+ end
55
+
56
+ it "should return false for a group that cannot be deleted" do
57
+ @group = FactoryGirl.create(:member_group, can_delete: false)
58
+ group = Group.find(@group.group_name.parameterize)
59
+ group.can_delete?.should eql false
60
+ end
61
+ end
62
+
63
+ describe "Roles" do
64
+ it "should get all roles for a group" do
65
+ @group = FactoryGirl.create(:member_group)
66
+ @role = FactoryGirl.create(:admin_role)
67
+ @group.add_role = @role.role_name
68
+ @group.role_names.empty?.should_not eql true
69
+ end
70
+ end
71
+
72
+ describe "Concerns" do
73
+ before(:each) do
74
+ no_user_member_roles_relation
75
+ end
76
+
77
+ it "should have a role" do
78
+ @group.has_role?(@role.role_name).should eql true
79
+ end
80
+
81
+ it "should get a role" do
82
+ @group.get_role(@role.role_name).should_not eql nil
83
+ end
84
+
85
+ it "should get a set of roles" do
86
+ @group.role_names.empty?.should_not eql true
87
+ end
88
+
89
+ it "should get a remove a role" do
90
+ @group.remove_role = @role.role_name
91
+ @group.has_role?(@role.role_name).should eql false
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,49 @@
1
+ require 'rails_helper'
2
+ require 'support/model_classes'
3
+ require 'support/factories'
4
+ require 'support/setup'
5
+ require 'pry'
6
+
7
+ describe "permission model mixin" do
8
+ before(:each) do
9
+ @permission = FactoryGirl.build(:can_read)
10
+ end
11
+
12
+ context "Validation checks" do
13
+ it "should be valid" do
14
+ expect(FactoryGirl.build(:can_read)).to be_valid
15
+ end
16
+
17
+ it "should not be valid" do
18
+ FactoryGirl.build(:can_read, permission_name: '').should_not be_valid
19
+ end
20
+ end
21
+
22
+ context "Fiendly ID" do
23
+ it "should find by name" do
24
+ permission = FactoryGirl.create(:can_read)
25
+ Permission.find(permission.permission_name.parameterize).should_not eql nil
26
+ end
27
+ end
28
+
29
+ context "Model specific methods" do
30
+ it "should be able to alter a permission" do
31
+ @permission.can_alter?.should eql true
32
+ end
33
+
34
+ it "should be able to delete a permission" do
35
+ @permission.can_delete?.should eql true
36
+ end
37
+ end
38
+
39
+ context "Roles" do
40
+ it "should return roles for a permission" do
41
+ permission = FactoryGirl.create(:can_read)
42
+ admin = FactoryGirl.create(:admin_role)
43
+
44
+ admin.add_permission = permission.permission_name
45
+
46
+ expect(permission.roles).to_not be nil
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+ require 'pry'
3
+
4
+ describe "role model mixin" do
5
+
6
+ context "Fail to find a role" do
7
+ it "should raise an error on trying to find non existent role" do
8
+ expect{
9
+ Role.find(1)
10
+ }.to raise_error ActiveRecord::RecordNotFound
11
+ end
12
+ end
13
+
14
+ context "Validation checks" do
15
+ it "validates a role object" do
16
+ FactoryGirl.build(:admin_role).should be_valid
17
+ end
18
+
19
+ it "should not validate a role object, based on an empty name" do
20
+ FactoryGirl.build(:admin_role, role_name: '').should_not be_valid
21
+ end
22
+ end
23
+
24
+ context "Friendly ID" do
25
+ it "should find based on name" do
26
+ @role = FactoryGirl.create(:admin_role)
27
+ Role.find(@role.role_name.parameterize).should_not eql nil
28
+ end
29
+ end
30
+
31
+ context "Belongs to a Group?" do
32
+ before(:each) do
33
+ @role = FactoryGirl.create(:admin_role)
34
+ @group = FactoryGirl.create(:member_group, group_name: 'Administrator')
35
+ end
36
+
37
+ it "Should belong to a group" do
38
+ @group.add_role = @role.role_name
39
+ @role.has_group?(@group.group_name).should eql true
40
+ end
41
+
42
+ it "should not belong to a group" do
43
+ @role.has_group?(@group.group_name).should eql false
44
+ end
45
+ end
46
+
47
+ context "Create permission relationship" do
48
+ it "create a relationship and check that it exists" do
49
+ @role = FactoryGirl.create(:admin_role)
50
+ @permission = FactoryGirl.create(:can_read)
51
+ @role.add_permission = @permission.permission_name
52
+ @role.has_permission?(@permission.permission_name).should eql true
53
+ end
54
+
55
+ it "should not return false for permissions added to a role" do
56
+ @role = FactoryGirl.create(:admin_role)
57
+ @permission = FactoryGirl.create(:can_read)
58
+ @role.add_permission = @permission.permission_name
59
+ @role.permissions.empty?.should eql false
60
+ end
61
+
62
+ it "should return an array of permissions for a role" do
63
+ @role = FactoryGirl.create(:admin_role)
64
+ @permission = FactoryGirl.create(:can_read)
65
+ @role.add_permission = @permission.permission_name
66
+ @role.permissions.empty?.should eql false
67
+ end
68
+
69
+ it "should return false for a role that cannot be altered" do
70
+ @role = FactoryGirl.create(:admin_role, can_alter: false)
71
+ role = Role.find(@role.role_name.parameterize)
72
+ role.can_alter?.should eql false
73
+ end
74
+
75
+ it "should return false for a role that cannot be deleted" do
76
+ @role = FactoryGirl.create(:admin_role, can_delete: false)
77
+ role = Role.find(@role.role_name.parameterize)
78
+ role.can_delete?.should eql false
79
+ end
80
+ end
81
+
82
+ describe "Permissions" do
83
+ it "should get a set of permissions for a role" do
84
+ @role = FactoryGirl.create(:admin_role)
85
+ @permission = FactoryGirl.create(:can_read)
86
+ @role.add_permission = @permission.permission_name
87
+ @role.permission_names.empty?.should_not eql true
88
+ end
89
+ end
90
+
91
+ describe "Concerns" do
92
+ before(:each) do
93
+ no_user_member_roles_relation
94
+ end
95
+
96
+ it "should belong to the member group" do
97
+ @role.has_group?('Member').should eql true
98
+ end
99
+
100
+ it "should have permissions" do
101
+ @role.permissions.nil?.should eql false
102
+ end
103
+
104
+ it "should get permission names" do
105
+ @role.permission_names.empty?.should_not be true
106
+ end
107
+
108
+ it "should delete a permission" do
109
+ @role.remove_permission = @permission.permission_name
110
+ @role.has_permission?(@permission.permission_name).should eql false
111
+ end
112
+ end
113
+ end