tb_core 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -2
  3. data/app/assets/javascripts/admin/core/dashboard.js +19 -16
  4. data/app/assets/libs/sortable/sortable.js +1481 -0
  5. data/app/controllers/admin/application_controller.rb +2 -1
  6. data/app/controllers/admin/users_controller.rb +5 -1
  7. data/app/controllers/concerns/tb_core/error_handling.rb +49 -0
  8. data/app/controllers/concerns/tb_core/redirection.rb +23 -0
  9. data/app/controllers/concerns/tb_core/sortable_params.rb +80 -0
  10. data/app/controllers/concerns/tb_core/user_authentication.rb +57 -0
  11. data/app/controllers/spud/application_controller.rb +8 -136
  12. data/app/controllers/tb_core/application_controller.rb +16 -0
  13. data/app/helpers/admin/application_helper.rb +3 -1
  14. data/app/helpers/tb_core/application_helper.rb +32 -0
  15. data/app/views/admin/users/index.html.erb +6 -6
  16. data/config/locales/en.yml +1 -0
  17. data/config/routes.rb +1 -1
  18. data/lib/generators/spud/templates/application_controller.rb +1 -1
  19. data/lib/spud_core/engine.rb +1 -1
  20. data/lib/spud_core/version.rb +1 -1
  21. data/lib/tb_core/form_builder.rb +1 -1
  22. data/lib/tb_core/table_header.rb +92 -0
  23. data/spec/controllers/admin/application_controller_spec.rb +1 -1
  24. data/spec/controllers/{spud → tb_core}/application_controller_spec.rb +1 -1
  25. data/spec/controllers/tb_core/sortable_params_spec.rb +64 -0
  26. data/spec/dummy/app/controllers/application_controller.rb +1 -1
  27. data/spec/helpers/tb_core/application_helper_spec.rb +39 -0
  28. data/spec/rails_helper.rb +3 -4
  29. data/spec/spec_helper.rb +2 -0
  30. metadata +18 -11
  31. data/app/assets/javascripts/admin/core/jquery_ui.js +0 -22
  32. data/app/assets/stylesheets/admin/core/jquery_ui.scss +0 -19
  33. data/app/controllers/spud/admin/application_controller.rb +0 -12
  34. data/app/helpers/spud/application_helper.rb +0 -36
@@ -0,0 +1,64 @@
1
+ require 'rails_helper'
2
+
3
+ describe TbCore::SortableParams, type: :controller do
4
+ controller do
5
+ include TbCore::SortableParams
6
+ sortable_by :first_name, :last_name, :email,
7
+ display_name: [:first_name, :last_name],
8
+ birth_date: 'user_birthdays.date :dir',
9
+ special: proc { |dir| "some_other_tables.whatever #{dir}" },
10
+ default: :last_name
11
+
12
+ def index; end
13
+ end
14
+
15
+ describe '#sort_direction' do
16
+ it 'returns asc' do
17
+ expect(controller.sort_direction).to eq(:asc)
18
+ end
19
+ it 'returns desc' do
20
+ controller.params[:dir] = 'desc'
21
+ expect(controller.sort_direction).to eq(:desc)
22
+ end
23
+ end
24
+
25
+ describe '#sort_attribute' do
26
+ it 'returns the default' do
27
+ expect(controller.sort_attribute).to eq(:last_name)
28
+ end
29
+ it 'returns the param' do
30
+ controller.params[:sort] = 'email'
31
+ expect(controller.sort_attribute).to eq(:email)
32
+ end
33
+ end
34
+
35
+ describe '#sortable_query' do
36
+ it 'returns the value as a hash' do
37
+ controller.params[:sort] = 'email'
38
+ expect(controller.sortable_query).to eq(email: :asc)
39
+ end
40
+
41
+ it 'returns a multi value hash' do
42
+ controller.params[:sort] = 'display_name'
43
+ controller.params[:dir] = 'desc'
44
+ expect(controller.sortable_query).to eq(first_name: :desc, last_name: :desc)
45
+ end
46
+
47
+ it 'returns a string with substitution' do
48
+ controller.params[:sort] = 'birth_date'
49
+ controller.params[:dir] = 'desc'
50
+ expect(controller.sortable_query).to eq('user_birthdays.date desc')
51
+ end
52
+
53
+ it 'returns a string by calling a proc' do
54
+ controller.params[:sort] = 'special'
55
+ controller.params[:dir] = 'desc'
56
+ expect(controller.sortable_query).to eq('some_other_tables.whatever desc')
57
+ end
58
+
59
+ it 'returns nothing' do
60
+ controller.params[:sort] = 'not_allowed'
61
+ expect(controller.sortable_query).to eq(nil)
62
+ end
63
+ end
64
+ end
@@ -1,3 +1,3 @@
1
- class ApplicationController < Spud::ApplicationController
1
+ class ApplicationController < TbCore::ApplicationController
2
2
  protect_from_forgery
3
3
  end
@@ -0,0 +1,39 @@
1
+ require 'rails_helper'
2
+
3
+ describe TbCore::ApplicationHelper, type: :helper do
4
+ describe '#tb_table_header' do
5
+
6
+ it 'returns a table header with rows' do
7
+ result = helper.tb_table_header(:admin_users_path)
8
+ expect(result).to include('<thead class="tb-table-header"><tr></tr></thead>')
9
+ expect(result).to include('</thead>')
10
+ end
11
+
12
+ it 'has some headers' do
13
+ result = helper.tb_table_header(:admin_users_path, model: SpudUser) do |t|
14
+ view.concat(t.header(:first_name))
15
+ view.concat(t.header(:email))
16
+ end
17
+ expect(result).to include('<th>First name</th>')
18
+ expect(result).to include('<th>Email</th>')
19
+ end
20
+
21
+ it 'generates links' do
22
+ result = helper.tb_table_header(:admin_users_path, model: SpudUser) do |t|
23
+ view.concat(t.sortable(:first_name))
24
+ view.concat(t.sortable(:email))
25
+ end
26
+ expect(result).to include('<a href="/admin/users?dir=asc&amp;sort=first_name">First name</a>')
27
+ expect(result).to include('<a href="/admin/users?dir=asc&amp;sort=email">Email</a>')
28
+ end
29
+
30
+ it 'sets the active class' do
31
+ helper.params[:sort] = 'first_name'
32
+ helper.params[:dir] = 'desc'
33
+ result = helper.tb_table_header(:admin_users_path, model: SpudUser) do |t|
34
+ view.concat(t.sortable(:first_name))
35
+ end
36
+ expect(result).to include('<th class="sortable sortable-active sortable-desc">')
37
+ end
38
+ end
39
+ end
data/spec/rails_helper.rb CHANGED
@@ -1,18 +1,17 @@
1
+ require 'simplecov'
2
+ SimpleCov.start 'rails'
3
+
1
4
  # This file is copied to spec/ when you run 'rails generate rspec:install'
2
5
  ENV['RAILS_ENV'] ||= 'test'
3
6
 
4
7
  require File.expand_path('../dummy/config/environment.rb', __FILE__)
5
8
  require 'spec_helper'
6
- # require 'session_helper'
7
9
  require 'tb_core/test_helper'
8
10
  require 'rails-controller-testing'
9
11
  require 'rspec/rails'
10
12
  require 'database_cleaner'
11
- require 'simplecov'
12
13
  require 'factory_girl_rails'
13
14
 
14
- SimpleCov.start 'rails'
15
-
16
15
  # Add additional requires below this line. Rails is not loaded until this point!
17
16
 
18
17
  # Requires supporting ruby files with custom matchers and macros, etc, in
data/spec/spec_helper.rb CHANGED
@@ -15,6 +15,8 @@
15
15
  #
16
16
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
17
  RSpec.configure do |config|
18
+ config.example_status_persistence_file_path = 'tmp/rspec.txt'
19
+
18
20
  # rspec-expectations config goes here. You can use an alternate
19
21
  # assertion/expectation library such as wrong or the stdlib/minitest
20
22
  # assertions if you prefer.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tb_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Woods
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-06 00:00:00.000000000 Z
11
+ date: 2017-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -67,19 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: jquery-ui-rails
70
+ name: jquery-rails
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '6.0'
75
+ version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '6.0'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: breadcrumbs_on_rails
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -281,7 +281,6 @@ files:
281
281
  - app/assets/javascripts/admin/core/dashboard.js
282
282
  - app/assets/javascripts/admin/core/date_picker.js
283
283
  - app/assets/javascripts/admin/core/editor.js
284
- - app/assets/javascripts/admin/core/jquery_ui.js
285
284
  - app/assets/javascripts/admin/core/modal.js
286
285
  - app/assets/javascripts/admin/core/preinit.js
287
286
  - app/assets/javascripts/admin/core/roles.js
@@ -295,9 +294,9 @@ files:
295
294
  - app/assets/libs/datepicker/js/bootstrap-datepicker.js
296
295
  - app/assets/libs/datepicker/less/datepicker.less
297
296
  - app/assets/libs/rails-ujs.js
297
+ - app/assets/libs/sortable/sortable.js
298
298
  - app/assets/stylesheets/admin/application.css
299
299
  - app/assets/stylesheets/admin/core/application.scss
300
- - app/assets/stylesheets/admin/core/jquery_ui.scss
301
300
  - app/assets/stylesheets/admin/core/login.scss
302
301
  - app/assets/stylesheets/admin/core/users.scss
303
302
  - app/controllers/admin/application_controller.rb
@@ -308,13 +307,16 @@ files:
308
307
  - app/controllers/admin/setup_controller.rb
309
308
  - app/controllers/admin/user_sessions_controller.rb
310
309
  - app/controllers/admin/users_controller.rb
310
+ - app/controllers/concerns/tb_core/error_handling.rb
311
+ - app/controllers/concerns/tb_core/redirection.rb
312
+ - app/controllers/concerns/tb_core/sortable_params.rb
313
+ - app/controllers/concerns/tb_core/user_authentication.rb
311
314
  - app/controllers/password_resets_controller.rb
312
- - app/controllers/spud/admin/application_controller.rb
313
315
  - app/controllers/spud/application_controller.rb
316
+ - app/controllers/tb_core/application_controller.rb
314
317
  - app/controllers/user_sessions_controller.rb
315
318
  - app/helpers/admin/application_helper.rb
316
319
  - app/helpers/admin/roles_helper.rb
317
- - app/helpers/spud/application_helper.rb
318
320
  - app/helpers/tb_core/application_helper.rb
319
321
  - app/mailers/tb_core_mailer.rb
320
322
  - app/models/spud/spud_user_model.rb
@@ -408,6 +410,7 @@ files:
408
410
  - lib/tb_core/belongs_to_app.rb
409
411
  - lib/tb_core/form_builder.rb
410
412
  - lib/tb_core/responder.rb
413
+ - lib/tb_core/table_header.rb
411
414
  - lib/tb_core/test_helper.rb
412
415
  - spec/controllers/admin/application_controller_spec.rb
413
416
  - spec/controllers/admin/dashboard_controller_spec.rb
@@ -416,7 +419,8 @@ files:
416
419
  - spec/controllers/admin/setup_controller_spec.rb
417
420
  - spec/controllers/admin/user_sessions_controller_spec.rb
418
421
  - spec/controllers/admin/users_controller_spec.rb
419
- - spec/controllers/spud/application_controller_spec.rb
422
+ - spec/controllers/tb_core/application_controller_spec.rb
423
+ - spec/controllers/tb_core/sortable_params_spec.rb
420
424
  - spec/dummy/README.rdoc
421
425
  - spec/dummy/Rakefile
422
426
  - spec/dummy/app/assets/javascripts/admin/application.js
@@ -452,6 +456,7 @@ files:
452
456
  - spec/factories/spud_role_factories.rb
453
457
  - spec/factories/spud_user_factories.rb
454
458
  - spec/helpers/spud/admin/application_helper_spec.rb
459
+ - spec/helpers/tb_core/application_helper_spec.rb
455
460
  - spec/lib/spud_core/configuration_spec.rb
456
461
  - spec/lib/tb_core/belongs_to_app_spec.rb
457
462
  - spec/models/spud_role_spec.rb
@@ -489,7 +494,8 @@ test_files:
489
494
  - spec/controllers/admin/setup_controller_spec.rb
490
495
  - spec/controllers/admin/user_sessions_controller_spec.rb
491
496
  - spec/controllers/admin/users_controller_spec.rb
492
- - spec/controllers/spud/application_controller_spec.rb
497
+ - spec/controllers/tb_core/application_controller_spec.rb
498
+ - spec/controllers/tb_core/sortable_params_spec.rb
493
499
  - spec/dummy/app/assets/javascripts/admin/application.js
494
500
  - spec/dummy/app/assets/javascripts/application.js
495
501
  - spec/dummy/app/assets/stylesheets/admin/application.scss
@@ -525,6 +531,7 @@ test_files:
525
531
  - spec/factories/spud_role_factories.rb
526
532
  - spec/factories/spud_user_factories.rb
527
533
  - spec/helpers/spud/admin/application_helper_spec.rb
534
+ - spec/helpers/tb_core/application_helper_spec.rb
528
535
  - spec/lib/spud_core/configuration_spec.rb
529
536
  - spec/lib/tb_core/belongs_to_app_spec.rb
530
537
  - spec/models/spud_role_spec.rb
@@ -1,22 +0,0 @@
1
- // Use this file to customize which jQuery UI JavaScript modules we include in the admin.
2
- //
3
- // https://github.com/joliss/jquery-ui-rails
4
- //
5
- // We primarily use UI for some interaction utilties and to fill in gaps
6
- // left by Bootstrap. As a general rule, we should try to use a Bootstrap
7
- // equivalent FIRST and then fall back to jQuery UI if necessary.
8
- //
9
- // For example, we prefer bootstrap-datepicker over jQuery UI Datepicker
10
- //
11
- // To see a full list of available modules (and their dependencies), see here:
12
- // http://jqueryui.com/download
13
- //
14
- // NOTE: Don't forget to also add the corresponding modules to jquery_ui.scss!
15
- //
16
- //= require jquery-ui/core
17
- //= require jquery-ui/widget
18
- //= require jquery-ui/widgets/mouse
19
- //= require jquery-ui/widgets/draggable
20
- //= require jquery-ui/widgets/droppable
21
- //= require jquery-ui/widgets/sortable
22
- //
@@ -1,19 +0,0 @@
1
- // Use this file to customize which jQuery UI CSS modules we include in the admin.
2
- //
3
- // https://github.com/joliss/jquery-ui-rails
4
- //
5
- // We primarily use UI for some interaction utilties and to fill in gaps
6
- // left by Bootstrap. As a general rule, we should try to use a Bootstrap
7
- // equivalent FIRST and then fall back to jQuery UI if necessary.
8
- //
9
- // For example, we prefer bootstrap-datepicker over jQuery UI Datepicker
10
- //
11
- // To see a full list of available modules (and their dependencies), see here:
12
- // http://jqueryui.com/download
13
- //
14
- // NOTE: Don't forget to also add the corresponding modules to jquery_ui.js!
15
- //
16
- //= require jquery-ui/core
17
- //= require jquery-ui/draggable
18
- //= require jquery-ui/sortable
19
- //
@@ -1,12 +0,0 @@
1
- class Spud::Admin::ApplicationController < Admin::ApplicationController
2
-
3
- def initialize
4
- ActiveSupport::Deprecation.warn(
5
- "Spud::Admin::ApplicationController is deprecated and may be removed from future releases,
6
- use Admin::ApplicationController instead.",
7
- caller
8
- )
9
- super
10
- end
11
-
12
- end
@@ -1,36 +0,0 @@
1
- module Spud::ApplicationHelper
2
-
3
- def tb_page_title
4
- if content_for?(:title)
5
- title = content_for(:title) + ' | ' + Spud::Core.site_name
6
- elsif @page_title
7
- title = @page_title + ' | ' + Spud::Core.site_name
8
- else
9
- title = Spud::Core.site_name
10
- end
11
- return content_tag :title, title
12
- end
13
-
14
- def current_site_name
15
- return Spud::Core.config.site_name
16
- end
17
-
18
- def cache_key_for_spud_collection(collection, key:'view', cache_params:[], for_user:false)
19
- cache_keys = [controller_name, action_name, key]
20
- cache_keys << collection.collect(&:updated_at).max().try(:utc).try(:to_i)
21
- if for_user
22
- cache_keys << current_user_id
23
- end
24
- if cache_params.any?
25
- cache_keys += cache_params.collect{ |cache_param| params[cache_param] || 'nil' }
26
- end
27
- cache_keys += collection.collect(&:id)
28
- cache_key = cache_keys.join('/')
29
- if cache_key.length > 250
30
- return Digest::SHA1.hexdigest(cache_key)
31
- else
32
- return cache_key
33
- end
34
- end
35
-
36
- end