tb_core 1.3.10 → 1.4.beta1
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 +4 -4
- data/Rakefile +5 -20
- data/app/controllers/admin/application_controller.rb +2 -2
- data/app/controllers/admin/dashboard_controller.rb +4 -4
- data/app/controllers/admin/password_resets_controller.rb +9 -9
- data/app/controllers/admin/roles_controller.rb +8 -8
- data/app/controllers/admin/settings_controller.rb +11 -9
- data/app/controllers/admin/setup_controller.rb +5 -5
- data/app/controllers/admin/user_sessions_controller.rb +2 -2
- data/app/controllers/admin/users_controller.rb +13 -13
- data/app/controllers/password_resets_controller.rb +7 -7
- data/app/controllers/spud/admin/application_controller.rb +5 -1
- data/app/controllers/spud/application_controller.rb +15 -11
- data/app/controllers/user_sessions_controller.rb +11 -5
- data/app/helpers/admin/application_helper.rb +20 -14
- data/app/helpers/tb_core/application_helper.rb +20 -16
- data/app/mailers/tb_core_mailer.rb +9 -3
- data/app/models/spud/spud_user_model.rb +7 -13
- data/app/models/spud_role.rb +4 -4
- data/app/models/spud_user_setting.rb +2 -2
- data/config/routes.rb +3 -3
- data/lib/generators/spud/controller_spec_generator.rb +6 -3
- data/lib/generators/spud/module_generator.rb +56 -41
- data/lib/generators/spud/setup_generator.rb +26 -22
- data/lib/generators/spud/templates/admin_controller.rb.erb +9 -13
- data/lib/generators/spud/templates/controller.rb.erb +4 -6
- data/lib/generators/spud/templates/controller_spec.rb.erb +16 -21
- data/lib/generators/spud/templates/views/layouts/application.html.erb +1 -1
- data/lib/spud_core/catch_all_route.rb +1 -1
- data/lib/spud_core/configuration.rb +7 -3
- data/lib/spud_core/engine.rb +5 -18
- data/lib/spud_core/errors.rb +3 -4
- data/lib/spud_core/test_files.rb +3 -3
- data/lib/spud_core/version.rb +1 -1
- data/lib/tb_core/belongs_to_app.rb +6 -3
- data/lib/tb_core/form_builder.rb +40 -33
- data/lib/tb_core/responder.rb +2 -2
- data/lib/tb_core/test_helper.rb +2 -2
- data/spec/controllers/admin/application_controller_spec.rb +14 -14
- data/spec/controllers/admin/dashboard_controller_spec.rb +26 -23
- data/spec/controllers/admin/password_reset_controller_spec.rb +29 -30
- data/spec/controllers/admin/settings_controller_spec.rb +13 -13
- data/spec/controllers/admin/setup_controller_spec.rb +12 -12
- data/spec/controllers/admin/user_sessions_controller_spec.rb +3 -3
- data/spec/controllers/admin/users_controller_spec.rb +68 -65
- data/spec/controllers/spud/application_controller_spec.rb +1 -1
- data/spec/dummy/config/application.rb +6 -7
- data/spec/dummy/config/database.yml +7 -16
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/environments/test.rb +5 -2
- data/spec/dummy/config/routes.rb +1 -1
- data/spec/dummy/db/schema.rb +53 -54
- data/spec/factories/spud_user_factories.rb +2 -2
- data/spec/helpers/spud/admin/application_helper_spec.rb +4 -4
- data/spec/lib/spud_core/configuration_spec.rb +2 -2
- data/spec/lib/tb_core/belongs_to_app_spec.rb +4 -4
- data/spec/models/spud_role_spec.rb +9 -9
- data/spec/models/spud_user_spec.rb +19 -32
- data/spec/rails_helper.rb +5 -6
- metadata +67 -77
- data/lib/responds_to_parent.rb +0 -69
- data/lib/tb_core/mysql2_extensions.rb +0 -45
- data/spec/dummy/db/migrate/20141214200804_create_spud_admin_permissions.tb_core.rb +0 -12
- data/spec/dummy/db/migrate/20141214200805_create_spud_users.tb_core.rb +0 -30
- data/spec/dummy/db/migrate/20141214200806_add_time_zone_to_spud_user.tb_core.rb +0 -7
- data/spec/dummy/db/migrate/20141214200807_add_scope_to_spud_admin_permissions.tb_core.rb +0 -7
- data/spec/dummy/db/migrate/20141214200808_create_spud_user_settings.tb_core.rb +0 -12
- data/spec/dummy/db/migrate/20141214200809_create_spud_roles.tb_core.rb +0 -11
- data/spec/dummy/db/migrate/20141214200810_create_spud_permissions.tb_core.rb +0 -11
- data/spec/dummy/db/migrate/20141214200811_create_spud_role_permissions.tb_core.rb +0 -12
- data/spec/dummy/db/migrate/20141214200812_drop_spud_admin_permissions.tb_core.rb +0 -16
- data/spec/dummy/db/migrate/20150610180845_add_requires_password_change_to_spud_users.tb_core.rb +0 -6
- data/spec/lib/tb_core/mysql2_extensions_spec.rb +0 -59
@@ -5,12 +5,12 @@ module Spud
|
|
5
5
|
:javascripts, :stylesheets, :admin_javascripts, :admin_stylesheets,
|
6
6
|
:permissions, :production_alert_domain, :use_email_as_login
|
7
7
|
self.admin_applications = []
|
8
|
-
self.site_name =
|
8
|
+
self.site_name = 'Company Name'
|
9
9
|
self.site_id = 0
|
10
10
|
self.short_name = 'default'
|
11
11
|
self.javascripts = []
|
12
12
|
self.stylesheets = []
|
13
|
-
self.from_address =
|
13
|
+
self.from_address = 'no-reply@companyname.com'
|
14
14
|
self.permissions = []
|
15
15
|
self.admin_javascripts = ['admin/core/application', 'admin/application']
|
16
16
|
self.admin_stylesheets = ['admin/core/application', 'admin/application']
|
@@ -29,7 +29,11 @@ module Spud
|
|
29
29
|
|
30
30
|
def self.default_site_config
|
31
31
|
ActiveSupport::Deprecation.warn 'Spud::Core.default_site_config is deprecated and will be removed in the future'
|
32
|
-
return {
|
32
|
+
return {
|
33
|
+
site_id: Spud::Core.config.site_id,
|
34
|
+
site_name: Spud::Core.config.site_name,
|
35
|
+
short_name: Spud::Core.config.short_name
|
36
|
+
}
|
33
37
|
end
|
34
38
|
|
35
39
|
def self.append_admin_javascripts(*args)
|
data/lib/spud_core/engine.rb
CHANGED
@@ -17,7 +17,6 @@ module Spud
|
|
17
17
|
class Engine < ::Rails::Engine
|
18
18
|
require "#{root}/lib/spud_core/errors"
|
19
19
|
require "#{root}/lib/spud_core/searchable"
|
20
|
-
require "#{root}/lib/responds_to_parent"
|
21
20
|
|
22
21
|
engine_name :tb_core
|
23
22
|
config.autoload_paths << "#{root}/lib"
|
@@ -34,7 +33,7 @@ module Spud
|
|
34
33
|
end
|
35
34
|
end
|
36
35
|
|
37
|
-
initializer 'tb_core.admin', :
|
36
|
+
initializer 'tb_core.admin', after: :admin do |config|
|
38
37
|
# Translate Hash configured permissions into SpudPermission objects
|
39
38
|
Spud::Core.permissions.collect! do |p|
|
40
39
|
if p.class == Hash
|
@@ -43,12 +42,10 @@ module Spud
|
|
43
42
|
p
|
44
43
|
end
|
45
44
|
# Append Users admin module
|
46
|
-
Spud::Core.config.admin_applications.unshift(
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
:order => 100
|
51
|
-
})
|
45
|
+
Spud::Core.config.admin_applications.unshift(name: 'Users',
|
46
|
+
thumbnail: 'admin/users_thumb.png',
|
47
|
+
url: '/admin/users',
|
48
|
+
order: 100)
|
52
49
|
# Create default permissions for modules
|
53
50
|
Spud::Core.admin_applications.each do |admin_application|
|
54
51
|
admin_application[:key] ||= admin_application[:name].gsub(' ', '_').downcase.to_sym
|
@@ -66,16 +63,6 @@ module Spud
|
|
66
63
|
end
|
67
64
|
end
|
68
65
|
|
69
|
-
initializer 'tb_core.mysql2_extensions' do
|
70
|
-
ActiveSupport.on_load(:active_record) do
|
71
|
-
if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
|
72
|
-
ActiveRecord::ConnectionAdapters::Mysql2Adapter.class_eval do
|
73
|
-
include TbCore::Mysql2Extensions
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
66
|
initializer 'tb_core.assets' do
|
80
67
|
Rails.application.config.assets.precompile += ['admin/users_thumb.png', 'admin/module_icon.png']
|
81
68
|
end
|
data/lib/spud_core/errors.rb
CHANGED
@@ -4,13 +4,12 @@ class Spud::RequestError < StandardError
|
|
4
4
|
|
5
5
|
# For compatability reasons, this method accepts multiple styles of inputs
|
6
6
|
# Going forward the expected input will be:
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# * item: The item that could not be found. String. (default = page)
|
9
9
|
# * template (named): ERB template you wish to render
|
10
10
|
#
|
11
11
|
def initialize(item_or_opts='page', opts={})
|
12
12
|
if item_or_opts.is_a?(Hash)
|
13
|
-
# ActiveSupport::Deprecation.warn("Passing the :item as a key/value pair to #{self.class.to_s} is deprecated; Pass it as the first argument instead.")
|
14
13
|
@item = item_or_opts[:item]
|
15
14
|
@template = item_or_opts[:template]
|
16
15
|
else
|
@@ -18,8 +17,8 @@ class Spud::RequestError < StandardError
|
|
18
17
|
@template = opts[:template]
|
19
18
|
end
|
20
19
|
@template ||= 'layouts/error_page'
|
21
|
-
@title = I18n.t(:title, :
|
22
|
-
super(I18n.t(:message, :
|
20
|
+
@title = I18n.t(:title, scope: [:tb_core, :errors, @i18n])
|
21
|
+
super(I18n.t(:message, scope: [:tb_core, :errors, @i18n], item: @item))
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
data/lib/spud_core/test_files.rb
CHANGED
@@ -9,15 +9,15 @@ module Spud
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def load_specs
|
12
|
-
Dir[File.join(File.expand_path('../../../', __FILE__),
|
12
|
+
Dir[File.join(File.expand_path('../../../', __FILE__), 'spec/**/*_spec.rb')].each {|f| require f}
|
13
13
|
end
|
14
14
|
|
15
15
|
def load_factories
|
16
|
-
Dir[File.join(File.expand_path('../../../', __FILE__),
|
16
|
+
Dir[File.join(File.expand_path('../../../', __FILE__), 'factories/*')].each {|f| require f}
|
17
17
|
end
|
18
18
|
|
19
19
|
def load_support
|
20
|
-
Dir[File.join(File.expand_path('../../../', __FILE__),
|
20
|
+
Dir[File.join(File.expand_path('../../../', __FILE__), 'spec/support/**/*.rb')].each {|f| require f}
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/spud_core/version.rb
CHANGED
@@ -3,7 +3,10 @@ module TbCore::BelongsToApp
|
|
3
3
|
|
4
4
|
module ClassMethods
|
5
5
|
def belongs_to_spud_app(name, options={})
|
6
|
-
ActiveSupport::Deprecation.warn
|
6
|
+
ActiveSupport::Deprecation.warn(
|
7
|
+
'ApplicationController#belongs_to_spud_app is deprecated. Please use #belongs_to_app instead.',
|
8
|
+
caller
|
9
|
+
)
|
7
10
|
belongs_to_app(name, page_title: options[:page_title])
|
8
11
|
end
|
9
12
|
|
@@ -16,7 +19,7 @@ module TbCore::BelongsToApp
|
|
16
19
|
def belongs_to_app(name, page_title: nil, only: nil)
|
17
20
|
before_action ->(){
|
18
21
|
act_as_app(name, page_title: page_title)
|
19
|
-
}, :
|
22
|
+
}, only: only
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
@@ -32,7 +35,7 @@ private
|
|
32
35
|
if @page_application.blank?
|
33
36
|
raise "Requested application '#{symbol}' could not be found"
|
34
37
|
elsif !current_user.can_view_app?(@page_application)
|
35
|
-
raise Spud::AccessDeniedError.new(:
|
38
|
+
raise Spud::AccessDeniedError.new(item: 'module', template: '/layouts/admin/error_page')
|
36
39
|
end
|
37
40
|
@page_thumbnail = @page_application[:thumbnail]
|
38
41
|
@page_name = determine_page_name(page_title || @page_application[:name], action_name)
|
data/lib/tb_core/form_builder.rb
CHANGED
@@ -9,7 +9,7 @@ class TbCore::FormBuilder < ActionView::Helpers::FormBuilder
|
|
9
9
|
# Build a form group
|
10
10
|
#
|
11
11
|
def tb_form_group(content=nil, options={})
|
12
|
-
content_tag :div, options.merge(:
|
12
|
+
content_tag :div, options.merge(class: 'form-group') do
|
13
13
|
if block_given?
|
14
14
|
yield
|
15
15
|
else
|
@@ -24,15 +24,15 @@ class TbCore::FormBuilder < ActionView::Helpers::FormBuilder
|
|
24
24
|
if options[:label_text] != nil
|
25
25
|
text = options[:label_text]
|
26
26
|
else
|
27
|
-
text = @object.class.human_attribute_name(attribute)
|
27
|
+
text = @object.class.human_attribute_name(attribute)
|
28
28
|
end
|
29
|
-
label(attribute, text, :
|
29
|
+
label(attribute, text, class: 'col-sm-2 control-label')
|
30
30
|
end
|
31
31
|
|
32
32
|
# Builds an input field with error message
|
33
33
|
#
|
34
34
|
def tb_input_field_tag(attribute, input_type=nil, options={})
|
35
|
-
content_tag(:div, :
|
35
|
+
content_tag(:div, class: 'col-sm-10') do
|
36
36
|
if block_given?
|
37
37
|
concat(yield(attribute))
|
38
38
|
else
|
@@ -42,10 +42,10 @@ class TbCore::FormBuilder < ActionView::Helpers::FormBuilder
|
|
42
42
|
end
|
43
43
|
error_message = @object.errors[attribute].first
|
44
44
|
if options[:help_text]
|
45
|
-
concat content_tag(:p, @template.raw(options[:help_text]), :
|
45
|
+
concat content_tag(:p, @template.raw(options[:help_text]), class: 'help-block')
|
46
46
|
end
|
47
47
|
if error_message
|
48
|
-
concat content_tag(:p, error_message, :
|
48
|
+
concat content_tag(:p, error_message, class: 'form-error form-error-inline')
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -84,7 +84,7 @@ class TbCore::FormBuilder < ActionView::Helpers::FormBuilder
|
|
84
84
|
#
|
85
85
|
def tb_select_tag(attribute, option_tags, options={}, html_options={})
|
86
86
|
tb_input_field_tag(attribute) do
|
87
|
-
select(attribute, option_tags, objectify_options(options), html_options.merge(:
|
87
|
+
select(attribute, option_tags, objectify_options(options), html_options.merge(class: 'form-control'))
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -93,16 +93,16 @@ class TbCore::FormBuilder < ActionView::Helpers::FormBuilder
|
|
93
93
|
def tb_date_select_tag(attribute, options={}, html_options={})
|
94
94
|
options[:with_css_classes] = true
|
95
95
|
tb_input_field_tag(attribute) do
|
96
|
-
date_select(attribute, objectify_options(options), html_options.merge(:
|
96
|
+
date_select(attribute, objectify_options(options), html_options.merge(class: 'form-control date-select'))
|
97
97
|
end
|
98
|
-
end
|
98
|
+
end
|
99
99
|
|
100
100
|
# Builds a date select tag
|
101
101
|
#
|
102
102
|
def tb_datetime_select_tag(attribute, options={}, html_options={})
|
103
103
|
options[:with_css_classes] = true
|
104
104
|
tb_input_field_tag(attribute) do
|
105
|
-
datetime_select(attribute, objectify_options(options), html_options.merge(:
|
105
|
+
datetime_select(attribute, objectify_options(options), html_options.merge(class: 'form-control datetime-select'))
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
@@ -111,21 +111,26 @@ class TbCore::FormBuilder < ActionView::Helpers::FormBuilder
|
|
111
111
|
def tb_time_select_tag(attribute, options={}, html_options={})
|
112
112
|
options[:with_css_classes] = true
|
113
113
|
tb_input_field_tag(attribute) do
|
114
|
-
time_select(attribute, objectify_options(options), html_options.merge(:
|
114
|
+
time_select(attribute, objectify_options(options), html_options.merge(class: 'form-control datetime-select'))
|
115
115
|
end
|
116
|
-
end
|
116
|
+
end
|
117
117
|
|
118
118
|
# Builds a row of save/cancel buttons
|
119
119
|
#
|
120
120
|
def tb_save_buttons(model_name, cancel_path, delete_path=nil)
|
121
|
-
content_tag :div, :
|
122
|
-
content_tag :div, :
|
123
|
-
concat submit "Save #{model_name}",
|
121
|
+
content_tag :div, class: 'form-group' do
|
122
|
+
content_tag :div, class: 'col-sm-offset-2 col-sm-10' do
|
123
|
+
concat submit "Save #{model_name}",
|
124
|
+
class: 'btn btn-primary',
|
125
|
+
data: { disable_with: "Saving #{model_name}...", enable_with: 'Saved!' }
|
124
126
|
concat ' '
|
125
|
-
concat @template.link_to 'Cancel', cancel_path, :
|
127
|
+
concat @template.link_to 'Cancel', cancel_path, class: 'btn btn-default', data: {dismiss: :modal}
|
126
128
|
if delete_path != nil
|
127
129
|
concat ' '
|
128
|
-
concat @template.link_to 'Delete', delete_path,
|
130
|
+
concat @template.link_to 'Delete', delete_path,
|
131
|
+
class: 'btn btn-danger',
|
132
|
+
data: {confirm: "This action can't be undone. Would you like to delete the #{model_name.downcase}?"},
|
133
|
+
method: :delete
|
129
134
|
end
|
130
135
|
end
|
131
136
|
end
|
@@ -139,9 +144,9 @@ class TbCore::FormBuilder < ActionView::Helpers::FormBuilder
|
|
139
144
|
#
|
140
145
|
|
141
146
|
def tb_sub_title(text)
|
142
|
-
content_tag :div, options.merge(:
|
143
|
-
content_tag :div, :
|
144
|
-
content_tag :h4, text, :
|
147
|
+
content_tag :div, options.merge(class: 'form-group') do
|
148
|
+
content_tag :div, class: 'col-sm-offset-2 col-sm-10' do
|
149
|
+
content_tag :h4, text, class: 'form-sub-title'
|
145
150
|
end
|
146
151
|
end
|
147
152
|
end
|
@@ -223,7 +228,7 @@ class TbCore::FormBuilder < ActionView::Helpers::FormBuilder
|
|
223
228
|
#
|
224
229
|
def tb_select(attribute, option_tags, options={}, html_options={})
|
225
230
|
tb_input_field(attribute) do
|
226
|
-
select(attribute, option_tags, objectify_options(options), html_options.merge(:
|
231
|
+
select(attribute, option_tags, objectify_options(options), html_options.merge(class: 'form-control'))
|
227
232
|
end
|
228
233
|
end
|
229
234
|
|
@@ -232,7 +237,7 @@ class TbCore::FormBuilder < ActionView::Helpers::FormBuilder
|
|
232
237
|
def tb_date_select(attribute, options={}, html_options={})
|
233
238
|
options[:with_css_classes] = true
|
234
239
|
tb_input_field(attribute) do
|
235
|
-
date_select(attribute, objectify_options(options), html_options.merge(:
|
240
|
+
date_select(attribute, objectify_options(options), html_options.merge(class: 'form-control date-select'))
|
236
241
|
end
|
237
242
|
end
|
238
243
|
|
@@ -241,7 +246,7 @@ class TbCore::FormBuilder < ActionView::Helpers::FormBuilder
|
|
241
246
|
def tb_datetime_select(attribute, options={}, html_options={})
|
242
247
|
options[:with_css_classes] = true
|
243
248
|
tb_input_field(attribute) do
|
244
|
-
datetime_select(attribute, objectify_options(options), html_options.merge(:
|
249
|
+
datetime_select(attribute, objectify_options(options), html_options.merge(class: 'form-control datetime-select'))
|
245
250
|
end
|
246
251
|
end
|
247
252
|
|
@@ -250,15 +255,15 @@ class TbCore::FormBuilder < ActionView::Helpers::FormBuilder
|
|
250
255
|
def tb_time_select(attribute, options={}, html_options={})
|
251
256
|
options[:with_css_classes] = true
|
252
257
|
tb_input_field(attribute) do
|
253
|
-
time_select(attribute, objectify_options(options), html_options.merge(:
|
258
|
+
time_select(attribute, objectify_options(options), html_options.merge(class: 'form-control datetime-select'))
|
254
259
|
end
|
255
|
-
end
|
260
|
+
end
|
256
261
|
|
257
262
|
# Builds a time zone select group
|
258
263
|
#
|
259
264
|
def tb_time_zone_select(attribute, priority_zones, options={}, html_options={})
|
260
265
|
tb_input_field(attribute) do
|
261
|
-
time_zone_select(attribute, priority_zones, objectify_options(options), html_options.merge(:
|
266
|
+
time_zone_select(attribute, priority_zones, objectify_options(options), html_options.merge(class: 'form-control'))
|
262
267
|
end
|
263
268
|
end
|
264
269
|
|
@@ -271,17 +276,19 @@ class TbCore::FormBuilder < ActionView::Helpers::FormBuilder
|
|
271
276
|
#
|
272
277
|
def tb_user_select(attribute = :spud_user_id, users: SpudUser.ordered, selected: nil, default_text: 'Select User')
|
273
278
|
selected = @object[attribute] if selected.nil?
|
274
|
-
return content_tag :div, :
|
275
|
-
concat label attribute, :
|
276
|
-
concat content_tag(:div, :
|
279
|
+
return content_tag :div, class: 'form-group' do
|
280
|
+
concat label attribute, class: 'control-label col-sm-2'
|
281
|
+
concat content_tag(:div, class: 'col-sm-10'){
|
277
282
|
concat select(
|
278
283
|
attribute,
|
279
284
|
@template.options_from_collection_for_select(users, :id, :full_name_with_email, selected),
|
280
|
-
{:
|
281
|
-
|
285
|
+
{include_blank: default_text},
|
286
|
+
class: 'form-control tb-user-select'
|
282
287
|
)
|
283
|
-
concat @template.link_to 'Edit User', @template.edit_admin_user_path(':id'),
|
284
|
-
|
288
|
+
concat @template.link_to 'Edit User', @template.edit_admin_user_path(':id'),
|
289
|
+
class: 'btn btn-default tb-user-select-btn tb-user-select-edit'
|
290
|
+
concat @template.link_to 'New User', @template.new_admin_user_path,
|
291
|
+
class: 'btn btn-default tb-user-select-btn tb-user-select-add'
|
285
292
|
}
|
286
293
|
end
|
287
294
|
end
|
data/lib/tb_core/responder.rb
CHANGED
@@ -4,7 +4,7 @@ class TbCore::Responder < ActionController::Responder
|
|
4
4
|
super
|
5
5
|
|
6
6
|
# Don't require a :location parameter for redirecting
|
7
|
-
if !@options.
|
7
|
+
if !@options.key?(:location)
|
8
8
|
@options[:location] = nil
|
9
9
|
end
|
10
10
|
end
|
@@ -16,7 +16,7 @@ class TbCore::Responder < ActionController::Responder
|
|
16
16
|
if get?
|
17
17
|
display resource
|
18
18
|
elsif post? || patch?
|
19
|
-
display resource, :
|
19
|
+
display resource, status: :created, location: api_location
|
20
20
|
else
|
21
21
|
head :no_content
|
22
22
|
end
|
data/lib/tb_core/test_helper.rb
CHANGED
@@ -11,11 +11,11 @@ module TbCore::SessionHelper
|
|
11
11
|
activate_authlogic()
|
12
12
|
if permissions
|
13
13
|
permissions = [permissions] unless permissions.is_a?(Array)
|
14
|
-
role = SpudRole.create(:
|
14
|
+
role = SpudRole.create(name: 'New Role', permission_tags: permissions)
|
15
15
|
else
|
16
16
|
role = nil
|
17
17
|
end
|
18
|
-
@user = FactoryGirl.create(:spud_user,
|
18
|
+
@user = FactoryGirl.create(:spud_user, super_admin: admin, role: role)
|
19
19
|
SpudUserSession.create(@user)
|
20
20
|
return @user
|
21
21
|
end
|
@@ -1,27 +1,27 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
RSpec.describe Admin::ApplicationController, :
|
4
|
-
|
3
|
+
RSpec.describe Admin::ApplicationController, type: :controller do
|
4
|
+
|
5
5
|
before :each do
|
6
6
|
activate_authlogic
|
7
7
|
@user = FactoryGirl.create(:spud_user)
|
8
8
|
@role = FactoryGirl.create(:spud_role)
|
9
9
|
@session = SpudUserSession.create(@user)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
describe 'require_user' do
|
13
13
|
controller(Admin::ApplicationController) do
|
14
14
|
def index
|
15
|
-
|
15
|
+
head :ok
|
16
16
|
end
|
17
17
|
end
|
18
|
-
it
|
18
|
+
it 'should respond successfully if the current user is a super admin' do
|
19
19
|
@user.update_attribute(:super_admin, true)
|
20
20
|
get :index
|
21
21
|
expect(response).to be_success
|
22
22
|
end
|
23
|
-
|
24
|
-
it
|
23
|
+
|
24
|
+
it 'should respond successfully if the current user has admin permissions' do
|
25
25
|
@role.permission_tags = ['admin.users.full_access']
|
26
26
|
@role.save()
|
27
27
|
@user.role = @role
|
@@ -29,14 +29,14 @@ RSpec.describe Admin::ApplicationController, :type => :controller do
|
|
29
29
|
get :index
|
30
30
|
expect(response).to be_success
|
31
31
|
end
|
32
|
-
|
33
|
-
it
|
32
|
+
|
33
|
+
it 'should redirect to the login if the current user is not logged in' do
|
34
34
|
@session.destroy
|
35
35
|
get :index
|
36
|
-
expect(response).to redirect_to(admin_login_path(:
|
36
|
+
expect(response).to redirect_to(admin_login_path(return_to: '/admin/application'))
|
37
37
|
end
|
38
|
-
|
39
|
-
it
|
38
|
+
|
39
|
+
it 'should redirect to the root for a user without administrative priviledges' do
|
40
40
|
@user.super_admin = false
|
41
41
|
@user.role = nil
|
42
42
|
@user.save
|
@@ -44,6 +44,6 @@ RSpec.describe Admin::ApplicationController, :type => :controller do
|
|
44
44
|
expect(response.code).to eq('403')
|
45
45
|
expect(response).to render_template('layouts/admin/error_page')
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
end
|
49
|
-
end
|
49
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
RSpec.describe Admin::DashboardController, :
|
3
|
+
RSpec.describe Admin::DashboardController, type: :controller do
|
4
4
|
|
5
5
|
before(:all) do
|
6
6
|
Spud::Core.admin_applications += [{
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
7
|
+
name: 'Test App',
|
8
|
+
url: '/test/app',
|
9
|
+
permissions: ['admin.test_app.full_access']
|
10
10
|
},
|
11
11
|
{
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
12
|
+
name: 'dash app',
|
13
|
+
key: 'dash_app',
|
14
|
+
badge: ->(user){ 1 }
|
15
15
|
}]
|
16
16
|
end
|
17
17
|
|
@@ -20,67 +20,70 @@ RSpec.describe Admin::DashboardController, :type => :controller do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe 'index' do
|
23
|
-
it
|
23
|
+
it 'should display applications the current user has access to given that the current user is not a super admin' do
|
24
24
|
@user.super_admin = false
|
25
|
-
@user.role = FactoryGirl.create(:spud_role, :
|
25
|
+
@user.role = FactoryGirl.create(:spud_role, permission_tags: ['admin.users.full_access'])
|
26
26
|
@user.save()
|
27
27
|
get :index
|
28
28
|
|
29
29
|
expect(assigns(:admin_applications).collect{|app| app[:name] }).to include('Users')
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it 'should not display applications the current user does not have access
|
33
|
+
to given that the current user is not a super admin' do
|
33
34
|
@user.super_admin = false
|
34
|
-
@user.role = FactoryGirl.create(:spud_role, :
|
35
|
+
@user.role = FactoryGirl.create(:spud_role, permission_tags: ['admin.users.full_access'])
|
35
36
|
@user.save()
|
36
37
|
get :index
|
37
38
|
|
38
39
|
expect(assigns(:admin_applications).collect{|app| app[:name] }).to_not include('Test App')
|
39
40
|
end
|
40
41
|
|
41
|
-
it
|
42
|
+
it 'should display all the applications despite the users permissions given
|
43
|
+
the current user is a super admin' do
|
42
44
|
@user.super_admin = true
|
43
45
|
@user.role = nil
|
44
46
|
@user.save
|
45
47
|
get :index
|
46
48
|
|
47
|
-
|
49
|
+
excectation = Spud::Core.admin_applications.collect{|app| app[:name] }
|
50
|
+
expect(assigns(:admin_applications).collect{|app| app[:name] }).to eq(excectation)
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
51
54
|
describe 'badges' do
|
52
55
|
before(:each) do
|
53
|
-
request.accept =
|
56
|
+
request.accept = 'application/json'
|
54
57
|
Spud::Core.configure do |config|
|
55
|
-
config.site_name =
|
58
|
+
config.site_name = 'Test Site'
|
56
59
|
end
|
57
60
|
@user.super_admin = true
|
58
61
|
@user.save
|
59
62
|
end
|
60
63
|
|
61
|
-
it
|
64
|
+
it 'should respond with a json content type' do
|
62
65
|
get :badges
|
63
|
-
|
66
|
+
|
64
67
|
end
|
65
68
|
|
66
|
-
it
|
69
|
+
it 'should contain data array in reponse' do
|
67
70
|
get :badges
|
68
71
|
json = JSON.parse(response.body)
|
69
|
-
expect(response.content_type).to eq(
|
72
|
+
expect(response.content_type).to eq('application/json')
|
70
73
|
expect(json).to have_key('data')
|
71
74
|
end
|
72
75
|
|
73
|
-
it
|
76
|
+
it 'should have badge count 1 for dash app' do
|
74
77
|
get :badges
|
75
78
|
json = JSON.parse(response.body)
|
76
|
-
data = json[
|
79
|
+
data = json['data']
|
77
80
|
assert data.size == 1
|
78
81
|
app_found = false
|
79
82
|
badge_count = 0
|
80
83
|
data.each do |app|
|
81
|
-
if app[
|
84
|
+
if app['key'] == 'dash_app'
|
82
85
|
app_found = true
|
83
|
-
badge_count = app[
|
86
|
+
badge_count = app['badge_count']
|
84
87
|
end
|
85
88
|
end
|
86
89
|
assert app_found && badge_count == 1
|