strongbolt 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +33 -0
  3. data/.gitignore +18 -0
  4. data/.rspec +1 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/Gemfile +4 -0
  8. data/Gemfile.lock +130 -0
  9. data/LICENSE.txt +22 -0
  10. data/README.md +182 -0
  11. data/Rakefile +1 -0
  12. data/app/assets/javascripts/strongbolt.js +1 -0
  13. data/app/assets/javascripts/strongbolt/role-capabilities.js +80 -0
  14. data/app/controllers/strongbolt/capabilities_controller.rb +77 -0
  15. data/app/controllers/strongbolt/roles_controller.rb +92 -0
  16. data/app/controllers/strongbolt/security_controller.rb +8 -0
  17. data/app/controllers/strongbolt/user_groups_controller.rb +76 -0
  18. data/app/controllers/strongbolt/user_groups_users_controller.rb +35 -0
  19. data/app/controllers/strongbolt_controller.rb +2 -0
  20. data/app/views/strongbolt/_menu.html.erb +13 -0
  21. data/app/views/strongbolt/capabilities/index.html.erb +53 -0
  22. data/app/views/strongbolt/capabilities/show.html.erb +53 -0
  23. data/app/views/strongbolt/roles/_capabilities.html.erb +47 -0
  24. data/app/views/strongbolt/roles/_capability.html.erb +21 -0
  25. data/app/views/strongbolt/roles/_form.html.erb +12 -0
  26. data/app/views/strongbolt/roles/edit.html.erb +14 -0
  27. data/app/views/strongbolt/roles/index.html.erb +54 -0
  28. data/app/views/strongbolt/roles/new.html.erb +11 -0
  29. data/app/views/strongbolt/roles/show.html.erb +52 -0
  30. data/app/views/strongbolt/user_groups/_form.html.erb +12 -0
  31. data/app/views/strongbolt/user_groups/edit.html.erb +14 -0
  32. data/app/views/strongbolt/user_groups/index.html.erb +46 -0
  33. data/app/views/strongbolt/user_groups/new.html.erb +13 -0
  34. data/app/views/strongbolt/user_groups/show.html.erb +88 -0
  35. data/lib/generators/strongbolt/fix_generator.rb +23 -0
  36. data/lib/generators/strongbolt/indexes_generator.rb +19 -0
  37. data/lib/generators/strongbolt/install_generator.rb +29 -0
  38. data/lib/generators/strongbolt/templates/fix.rb +5 -0
  39. data/lib/generators/strongbolt/templates/indexes.rb +21 -0
  40. data/lib/generators/strongbolt/templates/migration.rb +73 -0
  41. data/lib/generators/strongbolt/templates/strongbolt.rb +45 -0
  42. data/lib/generators/strongbolt/views_generator.rb +26 -0
  43. data/lib/strongbolt.rb +219 -0
  44. data/lib/strongbolt/base.rb +7 -0
  45. data/lib/strongbolt/bolted.rb +125 -0
  46. data/lib/strongbolt/bolted_controller.rb +297 -0
  47. data/lib/strongbolt/capabilities_role.rb +15 -0
  48. data/lib/strongbolt/capability.rb +165 -0
  49. data/lib/strongbolt/configuration.rb +111 -0
  50. data/lib/strongbolt/controllers/url_helpers.rb +37 -0
  51. data/lib/strongbolt/engine.rb +44 -0
  52. data/lib/strongbolt/errors.rb +38 -0
  53. data/lib/strongbolt/generators/migration.rb +35 -0
  54. data/lib/strongbolt/helpers.rb +18 -0
  55. data/lib/strongbolt/rails/routes.rb +20 -0
  56. data/lib/strongbolt/role.rb +46 -0
  57. data/lib/strongbolt/roles_user_group.rb +15 -0
  58. data/lib/strongbolt/rspec.rb +29 -0
  59. data/lib/strongbolt/rspec/user.rb +90 -0
  60. data/lib/strongbolt/tenantable.rb +304 -0
  61. data/lib/strongbolt/user_abilities.rb +292 -0
  62. data/lib/strongbolt/user_group.rb +24 -0
  63. data/lib/strongbolt/user_groups_user.rb +16 -0
  64. data/lib/strongbolt/users_tenant.rb +12 -0
  65. data/lib/strongbolt/version.rb +3 -0
  66. data/lib/tasks/strongbolt_tasks.rake +29 -0
  67. data/spec/controllers/strongbolt/capabilities_controller_spec.rb +254 -0
  68. data/spec/controllers/strongbolt/roles_controller_spec.rb +228 -0
  69. data/spec/controllers/strongbolt/user_groups_controller_spec.rb +216 -0
  70. data/spec/controllers/strongbolt/user_groups_users_controller_spec.rb +69 -0
  71. data/spec/controllers/without_authorization_controller_spec.rb +20 -0
  72. data/spec/dummy/.rspec +2 -0
  73. data/spec/dummy/README.rdoc +28 -0
  74. data/spec/dummy/Rakefile +6 -0
  75. data/spec/dummy/app/assets/images/.keep +0 -0
  76. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  77. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  78. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  79. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  80. data/spec/dummy/app/controllers/posts_controller.rb +18 -0
  81. data/spec/dummy/app/controllers/test_controller.rb +3 -0
  82. data/spec/dummy/app/controllers/without_authorization_controller.rb +5 -0
  83. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  84. data/spec/dummy/app/mailers/.keep +0 -0
  85. data/spec/dummy/app/models/.keep +0 -0
  86. data/spec/dummy/app/models/concerns/.keep +0 -0
  87. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  88. data/spec/dummy/bin/bundle +3 -0
  89. data/spec/dummy/bin/rails +4 -0
  90. data/spec/dummy/bin/rake +4 -0
  91. data/spec/dummy/config.ru +4 -0
  92. data/spec/dummy/config/application.rb +29 -0
  93. data/spec/dummy/config/boot.rb +5 -0
  94. data/spec/dummy/config/database.yml +25 -0
  95. data/spec/dummy/config/environment.rb +5 -0
  96. data/spec/dummy/config/environments/development.rb +37 -0
  97. data/spec/dummy/config/environments/production.rb +78 -0
  98. data/spec/dummy/config/environments/test.rb +39 -0
  99. data/spec/dummy/config/initializers/assets.rb +8 -0
  100. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  101. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  102. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  103. data/spec/dummy/config/initializers/inflections.rb +16 -0
  104. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  105. data/spec/dummy/config/initializers/session_store.rb +3 -0
  106. data/spec/dummy/config/initializers/strongbolt.rb +32 -0
  107. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  108. data/spec/dummy/config/locales/en.yml +23 -0
  109. data/spec/dummy/config/routes.rb +12 -0
  110. data/spec/dummy/config/secrets.yml +22 -0
  111. data/spec/dummy/db/development.sqlite3 +0 -0
  112. data/spec/dummy/db/migrate/20150630212236_create_strongbolt_tables.rb +54 -0
  113. data/spec/dummy/db/migrate/20150630212251_create_strongbolt_tables_indexes.rb +21 -0
  114. data/spec/dummy/db/schema.rb +84 -0
  115. data/spec/dummy/db/test.sqlite3 +0 -0
  116. data/spec/dummy/lib/assets/.keep +0 -0
  117. data/spec/dummy/public/404.html +67 -0
  118. data/spec/dummy/public/422.html +67 -0
  119. data/spec/dummy/public/500.html +66 -0
  120. data/spec/dummy/public/favicon.ico +0 -0
  121. data/spec/fabricators/capability_fabricator.rb +4 -0
  122. data/spec/fabricators/role_fabricator.rb +9 -0
  123. data/spec/fabricators/user_fabricator.rb +3 -0
  124. data/spec/fabricators/user_group_fabricator.rb +9 -0
  125. data/spec/fixtures/application.rb +28 -0
  126. data/spec/fixtures/controllers.rb +5 -0
  127. data/spec/spec_helper.rb +89 -0
  128. data/spec/strongbolt/bolted_controller_spec.rb +706 -0
  129. data/spec/strongbolt/bolted_spec.rb +136 -0
  130. data/spec/strongbolt/capability_spec.rb +251 -0
  131. data/spec/strongbolt/configuration_spec.rb +119 -0
  132. data/spec/strongbolt/controllers/url_helpers_spec.rb +34 -0
  133. data/spec/strongbolt/helpers_spec.rb +43 -0
  134. data/spec/strongbolt/role_spec.rb +90 -0
  135. data/spec/strongbolt/tenantable_spec.rb +281 -0
  136. data/spec/strongbolt/user_abilities_spec.rb +509 -0
  137. data/spec/strongbolt/user_group_spec.rb +37 -0
  138. data/spec/strongbolt/users_tenant_spec.rb +36 -0
  139. data/spec/strongbolt_spec.rb +274 -0
  140. data/spec/support/controller_macros.rb +11 -0
  141. data/spec/support/db_setup.rb +134 -0
  142. data/spec/support/helpers.rb +62 -0
  143. data/spec/support/transactional_specs.rb +17 -0
  144. data/strongbolt.gemspec +32 -0
  145. metadata +407 -0
@@ -0,0 +1,216 @@
1
+ require 'spec_helper'
2
+
3
+ module Strongbolt
4
+ describe UserGroupsController do
5
+
6
+ let!(:user_group) { Fabricate :user_group }
7
+
8
+ let(:valid_attributes) { Fabricate.attributes_for :user_group }
9
+
10
+ subject { response }
11
+
12
+ #
13
+ # GET #index
14
+ #
15
+ describe "GET #index" do
16
+
17
+ before { get :index }
18
+
19
+ it { should be_success }
20
+
21
+ it { should render_template :index }
22
+
23
+ it "should assign user groups" do
24
+ expect(assigns :user_groups).to eq [user_group]
25
+ end
26
+
27
+ end
28
+
29
+ #
30
+ # GET #new
31
+ #
32
+ describe "GET #new" do
33
+
34
+ before { get :new }
35
+
36
+ it { should be_success }
37
+
38
+ it { should render_template :new }
39
+
40
+ end
41
+
42
+
43
+ #
44
+ # GET #show
45
+ #
46
+ describe "GET #show" do
47
+
48
+ before { get :show, id: user_group.id }
49
+
50
+ it { should be_success }
51
+
52
+ it "should assign user group" do
53
+ expect(assigns :user_group).to eq user_group
54
+ end
55
+
56
+ it { should render_template :show }
57
+
58
+ end
59
+
60
+ #
61
+ # GET #edit
62
+ #
63
+ describe "GET #edit" do
64
+
65
+ before { get :edit, id: user_group.id }
66
+
67
+ it { should be_success }
68
+
69
+ it "should assign user group" do
70
+ expect(assigns :user_group).to eq user_group
71
+ end
72
+
73
+ it { should render_template :edit }
74
+
75
+ end
76
+
77
+ #
78
+ # POST #create
79
+ #
80
+ describe "POST #create" do
81
+
82
+ let(:create) { post :create, user_group: attributes }
83
+
84
+ context 'when valid attributes' do
85
+
86
+ let(:attributes) { valid_attributes }
87
+
88
+ it "should redirect to show" do
89
+ create
90
+ expect(response).to redirect_to user_group_path(UserGroup.last)
91
+ end
92
+
93
+ it "should create an user group" do
94
+ expect do
95
+ create
96
+ end.to change(UserGroup, :count).by 1
97
+ end
98
+
99
+ end
100
+
101
+ context "when invalid attributes" do
102
+
103
+ let(:attributes) { {} }
104
+
105
+ it "should redirect_to new" do
106
+ create
107
+ expect(response).to redirect_to new_user_group_path
108
+ end
109
+
110
+ it "should not create an user group" do
111
+ expect do
112
+ create
113
+ end.not_to change(UserGroup, :count)
114
+ end
115
+
116
+ it "should set flash danger" do
117
+ create
118
+ expect(flash[:danger]).to be_present
119
+ end
120
+
121
+ end
122
+
123
+ end
124
+
125
+
126
+ #
127
+ # PUT #update
128
+ #
129
+ describe "PUT #update" do
130
+
131
+ before { put :update, id: user_group.id, user_group: attributes }
132
+
133
+ context 'when valid attributes' do
134
+
135
+ let(:attributes) { valid_attributes }
136
+
137
+ it { should redirect_to user_group_path(user_group) }
138
+
139
+ it "should update attributes" do
140
+ expect(user_group.reload.name).to eq valid_attributes[:name]
141
+ end
142
+
143
+ end
144
+
145
+ context 'when invalid attributes' do
146
+
147
+ let(:attributes) { {name: ""} }
148
+
149
+ it { should redirect_to edit_user_group_path(user_group) }
150
+
151
+ it "should not update attributes" do
152
+ expect(user_group.reload.name).not_to eq ""
153
+ end
154
+
155
+ it "should set flash danger" do
156
+ expect(flash[:danger]).to be_present
157
+ end
158
+
159
+ end
160
+
161
+ end
162
+
163
+
164
+ #
165
+ # DELETE #destroy
166
+ #
167
+ describe "DELETE #destroy" do
168
+
169
+ let(:destroy) { delete :destroy, id: user_group.id }
170
+
171
+ context "when no user" do
172
+
173
+ it "should redirect to index" do
174
+ destroy
175
+ expect(response).to redirect_to user_groups_path
176
+ end
177
+
178
+ it "should set flash success" do
179
+ destroy
180
+ expect(flash[:success]).to be_present
181
+ end
182
+
183
+ it "should delete a user group" do
184
+ expect do
185
+ destroy
186
+ end.to change(UserGroup, :count).by -1
187
+ end
188
+
189
+ end
190
+
191
+ context "when has users" do
192
+
193
+ before { user_group.users << Fabricate(:user) }
194
+
195
+ it "should redirect to show" do
196
+ destroy
197
+ expect(response).to redirect_to user_group_path(user_group)
198
+ end
199
+
200
+ it "should set flash danger" do
201
+ destroy
202
+ expect(flash[:danger]).to be_present
203
+ end
204
+
205
+ it "should not delete a user group" do
206
+ expect do
207
+ destroy
208
+ end.not_to change(UserGroup, :count)
209
+ end
210
+
211
+ end
212
+
213
+ end
214
+
215
+ end
216
+ end
@@ -0,0 +1,69 @@
1
+ require "spec_helper"
2
+
3
+ module Strongbolt
4
+ describe UserGroupsUsersController do
5
+
6
+ let(:user_group) { Fabricate :user_group }
7
+ let(:user) { Fabricate :user }
8
+
9
+ subject { response }
10
+
11
+ #
12
+ # POST #create
13
+ #
14
+ describe "POST #create" do
15
+
16
+ context "when valid user group and user" do
17
+
18
+ before { post :create, user_group_id: user_group.id, id: user.id }
19
+
20
+ it { should redirect_to user_group_path(user_group) }
21
+
22
+ it "should have add user to group" do
23
+ user_group.reload
24
+ expect(user_group.users).to include user
25
+ end
26
+
27
+ context "when redoing" do
28
+ before { post :create, user_group_id: user_group.id, id: user.id }
29
+
30
+ it { should redirect_to user_group_path(user_group) }
31
+
32
+ it "should not have added it twice" do
33
+ expect(user_group.users.count).to eq 1
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ #
42
+ # DELETE #destroy
43
+ #
44
+ describe "DELETE #destroy" do
45
+ context "when valid user group and user" do
46
+
47
+ before do
48
+ user_group.users << user
49
+ delete :destroy, user_group_id: user_group.id, id: user.id
50
+ end
51
+
52
+ it { should redirect_to user_group_path(user_group) }
53
+
54
+ it "should have removed user" do
55
+ user_group.reload
56
+ expect(user_group.users).not_to include user
57
+ end
58
+
59
+ context "when redoing" do
60
+ before { delete :destroy, user_group_id: user_group.id, id: user.id }
61
+
62
+ it { should redirect_to user_group_path(user_group) }
63
+ end
64
+
65
+ end
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ describe WithoutAuthorizationController do
4
+ before do
5
+ # Returns an user
6
+ allow(Strongbolt).to receive(:current_user)
7
+ .and_return User.new
8
+ end
9
+
10
+ describe "GET #show" do
11
+ it "should not raise error" do
12
+ expect { get :show }.not_to raise_error
13
+ end
14
+
15
+ it "should be success" do
16
+ get :show
17
+ expect(response).to be_success
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
File without changes
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,18 @@
1
+ #
2
+ # We create the controller we'll be using in our tests
3
+ #
4
+ RESTFUL_ACTIONS = [:index, :show, :new, :create, :update, :edit, :destroy]
5
+
6
+ class PostsController < TestController
7
+ include Strongbolt::BoltedController
8
+
9
+ # Some actions
10
+ RESTFUL_ACTIONS.each do |action|
11
+ define_method action do
12
+ end
13
+ end
14
+
15
+ def custom; end
16
+
17
+ def current_user; end
18
+ end
@@ -0,0 +1,3 @@
1
+ class TestController < ActionController::Base
2
+ def render(*attributes); end
3
+ end
@@ -0,0 +1,5 @@
1
+ class WithoutAuthorizationController < ApplicationController
2
+ def show
3
+ head :ok
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>