tb_core 1.3.10 → 1.4.beta1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -15,16 +15,20 @@ module TbCore::ApplicationHelper
|
|
15
15
|
|
16
16
|
def tb_form_errors(record, *fields_to_display)
|
17
17
|
if record.errors.any?
|
18
|
-
content_tag :div, :
|
19
|
-
concat(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
content_tag :div, class: 'form-errors test' do
|
19
|
+
concat(
|
20
|
+
tb_form_error_header(record) +
|
21
|
+
content_tag(:ul) do
|
22
|
+
if fields_to_display.any?
|
23
|
+
messages = fields_to_display.collect{ |field| record.errors.full_messages_for(field) }.flatten()
|
24
|
+
else
|
25
|
+
messages = record.errors.full_messages
|
26
|
+
end
|
27
|
+
messages.each do |msg|
|
28
|
+
concat content_tag(:li, msg)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
)
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|
@@ -32,22 +36,22 @@ module TbCore::ApplicationHelper
|
|
32
36
|
def tb_form_error_header(record)
|
33
37
|
if record.errors.any?
|
34
38
|
message = "Please correct the following #{'error'.pluralize(record.errors.size)}:"
|
35
|
-
return content_tag :h4, message, :
|
39
|
+
return content_tag :h4, message, class: 'form-field-error'
|
36
40
|
end
|
37
41
|
end
|
38
42
|
|
39
43
|
def tb_form_error_field(record, attribute)
|
40
44
|
message = record.errors[attribute].first
|
41
45
|
if message
|
42
|
-
return content_tag :p, message, :
|
46
|
+
return content_tag :p, message, class: 'help-block form-field-error'
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
46
50
|
def tb_form_field(attribute)
|
47
|
-
content_tag :div, :
|
48
|
-
concat label_tag attribute, attribute, :
|
49
|
-
concat(content_tag(:div, :
|
50
|
-
text_field_tag attribute, :
|
51
|
+
content_tag :div, class: 'form-group' do
|
52
|
+
concat label_tag attribute, attribute, class: 'col-sm-2 control-label'
|
53
|
+
concat(content_tag(:div, class: 'col-sm-10') do
|
54
|
+
text_field_tag attribute, placeholder: attribute, class: 'form-control'
|
51
55
|
end)
|
52
56
|
end
|
53
57
|
end
|
@@ -1,17 +1,23 @@
|
|
1
1
|
class TbCoreMailer < ActionMailer::Base
|
2
|
-
|
2
|
+
default from: Spud::Core.from_address
|
3
3
|
layout 'mailer'
|
4
4
|
|
5
5
|
def forgot_password_notification(user, url)
|
6
6
|
@user = user
|
7
7
|
@url = url
|
8
|
-
mail(
|
8
|
+
mail(
|
9
|
+
to: to_address_for_user(user),
|
10
|
+
subject: default_i18n_subject(site_name: Spud::Core.site_name)
|
11
|
+
)
|
9
12
|
end
|
10
13
|
|
11
14
|
def user_credentials(user, password)
|
12
15
|
@user = user
|
13
16
|
@password = password
|
14
|
-
mail(
|
17
|
+
mail(
|
18
|
+
to: to_address_for_user(user),
|
19
|
+
subject: default_i18n_subject(site_name: Spud::Core.site_name)
|
20
|
+
)
|
15
21
|
end
|
16
22
|
|
17
23
|
private
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class Spud::SpudUserModel < ActiveRecord::Base
|
2
2
|
self.table_name = 'spud_users'
|
3
3
|
self.abstract_class = true
|
4
|
-
|
4
|
+
|
5
5
|
acts_as_authentic do |c|
|
6
6
|
c.transition_from_crypto_providers = Authlogic::CryptoProviders::Sha512
|
7
7
|
c.crypto_provider = Authlogic::CryptoProviders::SCrypt
|
@@ -11,11 +11,11 @@ class Spud::SpudUserModel < ActiveRecord::Base
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
belongs_to :role, :
|
14
|
+
belongs_to :role, class_name: 'SpudRole', foreign_key: 'spud_role_id'
|
15
15
|
has_many :spud_user_settings
|
16
16
|
|
17
|
-
validates :first_name, :last_name, :
|
18
|
-
before_validation :set_login_to_email, :
|
17
|
+
validates :first_name, :last_name, presence: true
|
18
|
+
before_validation :set_login_to_email, if: ->{ Spud::Core.config.use_email_as_login }
|
19
19
|
before_update :unset_requires_password_change
|
20
20
|
|
21
21
|
scope :admins, ->{
|
@@ -36,12 +36,6 @@ class Spud::SpudUserModel < ActiveRecord::Base
|
|
36
36
|
return "#{self.first_name} #{self.last_name}"
|
37
37
|
end
|
38
38
|
|
39
|
-
def email_formatted
|
40
|
-
address = Mail::Address.new(email)
|
41
|
-
address.display_name = full_name
|
42
|
-
return address.format
|
43
|
-
end
|
44
|
-
|
45
39
|
def full_name_with_email
|
46
40
|
return "#{full_name} (#{email})"
|
47
41
|
end
|
@@ -110,11 +104,11 @@ class Spud::SpudUserModel < ActiveRecord::Base
|
|
110
104
|
# * tag - Desired permission tag string (required)
|
111
105
|
# * include_supers - Whether to include super user (default: true)
|
112
106
|
def self.with_permission(tag, include_supers:true)
|
113
|
-
role_ids = SpudRolePermission.where(:
|
107
|
+
role_ids = SpudRolePermission.where(spud_permission_tag: tag).pluck(:spud_role_id).uniq()
|
114
108
|
if include_supers
|
115
109
|
return SpudUser.where('super_admin = 1 OR spud_role_id IN (?)', role_ids)
|
116
110
|
else
|
117
|
-
return SpudUser.where(:
|
111
|
+
return SpudUser.where(spud_role_id: role_ids)
|
118
112
|
end
|
119
113
|
end
|
120
114
|
|
@@ -137,7 +131,7 @@ private
|
|
137
131
|
end
|
138
132
|
|
139
133
|
def unset_requires_password_change
|
140
|
-
if password_changed? && !requires_password_change_changed?(:
|
134
|
+
if password_changed? && !requires_password_change_changed?(to: true)
|
141
135
|
self.requires_password_change = false
|
142
136
|
end
|
143
137
|
return true
|
data/app/models/spud_role.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
class SpudRole < ActiveRecord::Base
|
2
2
|
|
3
|
-
has_many :spud_role_permissions, :
|
4
|
-
has_many :users, :
|
3
|
+
has_many :spud_role_permissions, dependent: :destroy
|
4
|
+
has_many :users, class_name: 'SpudUser'
|
5
5
|
|
6
|
-
validates :name, :
|
6
|
+
validates :name, presence: true, uniqueness: true
|
7
7
|
|
8
8
|
def permissions
|
9
9
|
self.spud_role_permissions.collect(&:permission).reject(&:blank?)
|
@@ -21,7 +21,7 @@ class SpudRole < ActiveRecord::Base
|
|
21
21
|
tags.delete(role_permission.permission.tag)
|
22
22
|
end
|
23
23
|
end
|
24
|
-
self.spud_role_permissions += tags.collect{ |tag| SpudRolePermission.new(:
|
24
|
+
self.spud_role_permissions += tags.collect{ |tag| SpudRolePermission.new(spud_permission_tag: tag) }
|
25
25
|
end
|
26
26
|
|
27
27
|
def permission_tags
|
data/config/routes.rb
CHANGED
@@ -11,7 +11,7 @@ Rails.application.routes.draw do
|
|
11
11
|
put 'settings' => 'settings#update'
|
12
12
|
put 'change_sort' => 'dashboard#change_sort'
|
13
13
|
|
14
|
-
root :to => "dashboard#index"
|
14
|
+
root :to => "dashboard#index", as: :root
|
15
15
|
resources :users do
|
16
16
|
get 'export', :on => :collection
|
17
17
|
end
|
@@ -20,8 +20,8 @@ Rails.application.routes.draw do
|
|
20
20
|
get 'setup' => 'setup#new'
|
21
21
|
post 'setup' => 'setup#create'
|
22
22
|
end
|
23
|
-
|
24
|
-
# Non-admin login paths
|
23
|
+
|
24
|
+
# Non-admin login paths
|
25
25
|
get 'login' => 'user_sessions#new', :as => 'login'
|
26
26
|
post 'login' => 'user_sessions#create'
|
27
27
|
match 'logout' => 'user_sessions#destroy', :as => 'logout', :via => [:get, :post]
|
@@ -1,9 +1,9 @@
|
|
1
1
|
class Spud::ControllerSpecGenerator < ::Rails::Generators::Base
|
2
2
|
source_root File.expand_path('../templates', __FILE__)
|
3
3
|
|
4
|
-
argument :name, :
|
5
|
-
argument :string_attribute, :
|
6
|
-
argument :editable, :
|
4
|
+
argument :name, type: :string
|
5
|
+
argument :string_attribute, type: :string
|
6
|
+
argument :editable, type: :numeric, default: 0
|
7
7
|
|
8
8
|
def controller
|
9
9
|
template 'controller_spec.rb.erb', "spec/controllers/#{name.downcase}_controller_spec.rb"
|
@@ -31,4 +31,7 @@ private
|
|
31
31
|
return editable == 1
|
32
32
|
end
|
33
33
|
|
34
|
+
def include_user_session?
|
35
|
+
return name.match('Admin/')
|
36
|
+
end
|
34
37
|
end
|
@@ -1,44 +1,53 @@
|
|
1
1
|
require 'rails/generators/migration'
|
2
2
|
|
3
3
|
class Spud::ModuleGenerator < ::Rails::Generators::Base
|
4
|
-
desc
|
5
|
-
argument :module_name, :
|
6
|
-
argument :attributes, :
|
4
|
+
desc 'Creates a new model, dashboard module, and frontend route'
|
5
|
+
argument :module_name, type: :string
|
6
|
+
argument :attributes, type: :array, default: [], banner: 'field[:type][:index] field[:type][:index]'
|
7
7
|
|
8
8
|
source_root File.expand_path('../templates', __FILE__)
|
9
9
|
|
10
10
|
def create_module
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
template "assets/admin/module.js.erb", "app/assets/javascripts/admin/#{module_name_formatted}.js"
|
15
|
-
create_file "app/assets/stylesheets/admin/#{module_name_formatted}.scss", "// Place #{module_name} admin styles here\n\n"
|
16
|
-
create_file "app/assets/stylesheets/#{module_name_formatted}.scss", "// Place #{module_name} styles here\n\n"
|
17
|
-
template "views/admin/index.html.erb", "app/views/admin/#{module_name_formatted}/index.html.erb"
|
18
|
-
template "views/admin/show.html.erb", "app/views/admin/#{module_name_formatted}/show.html.erb"
|
19
|
-
template "views/admin/new.html.erb", "app/views/admin/#{module_name_formatted}/new.html.erb"
|
20
|
-
template "views/admin/edit.html.erb", "app/views/admin/#{module_name_formatted}/edit.html.erb"
|
21
|
-
template "views/admin/_form.html.erb", "app/views/admin/#{module_name_formatted}/_form.html.erb"
|
22
|
-
template "views/frontend/index.html.erb", "app/views/#{module_name_formatted}/index.html.erb"
|
23
|
-
template "views/frontend/show.html.erb", "app/views/#{module_name_formatted}/show.html.erb"
|
24
|
-
environment("Spud::Core.config.admin_applications += [{:name => '#{module_name_formatted.humanize.titlecase}', :thumbnail => \"admin/module_icon.png\", :url => \"/admin/#{module_name_formatted}\"}]")
|
11
|
+
install_templates
|
12
|
+
install_assets
|
13
|
+
inject_code
|
25
14
|
create_routes
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
if defined?(RSpec)
|
31
|
-
string_attribute = find_first_string_attr()
|
32
|
-
Rails::Generators.invoke 'spud:controller_spec', ["#{module_name}", string_attribute, 0], :behavior => behavior
|
33
|
-
Rails::Generators.invoke 'spud:controller_spec', ["Admin/#{module_name}", string_attribute, 1], :behavior => behavior
|
34
|
-
end
|
15
|
+
create_specs if defined?(RSpec)
|
16
|
+
create_model_scopes() if self.behavior == :invoke
|
17
|
+
end
|
35
18
|
|
36
|
-
|
37
|
-
|
38
|
-
|
19
|
+
private
|
20
|
+
|
21
|
+
def install_templates
|
22
|
+
template 'admin_controller.rb.erb', "app/controllers/admin/#{module_name_formatted}_controller.rb"
|
23
|
+
template 'controller.rb.erb', "app/controllers/#{module_name_formatted}_controller.rb"
|
24
|
+
template 'assets/module.js.erb', "app/assets/javascripts/#{module_name_formatted}.js"
|
25
|
+
template 'assets/admin/module.js.erb', "app/assets/javascripts/admin/#{module_name_formatted}.js"
|
26
|
+
template 'views/admin/index.html.erb', "app/views/admin/#{module_name_formatted}/index.html.erb"
|
27
|
+
template 'views/admin/show.html.erb', "app/views/admin/#{module_name_formatted}/show.html.erb"
|
28
|
+
template 'views/admin/new.html.erb', "app/views/admin/#{module_name_formatted}/new.html.erb"
|
29
|
+
template 'views/admin/edit.html.erb', "app/views/admin/#{module_name_formatted}/edit.html.erb"
|
30
|
+
template 'views/admin/_form.html.erb', "app/views/admin/#{module_name_formatted}/_form.html.erb"
|
31
|
+
template 'views/frontend/index.html.erb', "app/views/#{module_name_formatted}/index.html.erb"
|
32
|
+
template 'views/frontend/show.html.erb', "app/views/#{module_name_formatted}/show.html.erb"
|
39
33
|
end
|
40
34
|
|
41
|
-
|
35
|
+
def install_assets
|
36
|
+
create_file "app/assets/stylesheets/admin/#{module_name_formatted}.scss",
|
37
|
+
"// Place #{module_name} admin styles here\n\n"
|
38
|
+
create_file "app/assets/stylesheets/#{module_name_formatted}.scss",
|
39
|
+
"// Place #{module_name} styles here\n\n"
|
40
|
+
end
|
41
|
+
|
42
|
+
def inject_code
|
43
|
+
environment(
|
44
|
+
"Spud::Core.config.admin_applications += [{name: '#{module_name_formatted.humanize.titlecase}',
|
45
|
+
thumbnail: \"admin/module_icon.png\", url: \"/admin/#{module_name_formatted}\"}]"
|
46
|
+
)
|
47
|
+
Rails::Generators.invoke 'model', [module_name_formatted.singularize] + attributes, behavior: behavior
|
48
|
+
Rails::Generators.invoke 'helper', [module_name], behavior: behavior
|
49
|
+
Rails::Generators.invoke 'helper', ["Admin/#{module_name}"], behavior: behavior
|
50
|
+
end
|
42
51
|
|
43
52
|
def module_name_formatted
|
44
53
|
module_name.pluralize.underscore
|
@@ -53,12 +62,18 @@ namespace :admin do
|
|
53
62
|
EOF
|
54
63
|
end
|
55
64
|
|
65
|
+
def create_specs
|
66
|
+
string_attribute = find_first_string_attr()
|
67
|
+
Rails::Generators.invoke 'spud:controller_spec', ["#{module_name}", string_attribute, 0], behavior: behavior
|
68
|
+
Rails::Generators.invoke 'spud:controller_spec', ["Admin/#{module_name}", string_attribute, 1], behavior: behavior
|
69
|
+
end
|
70
|
+
|
56
71
|
def field_for_attribute(type, name)
|
57
72
|
case type
|
58
73
|
when 'integer'
|
59
74
|
"<%= f.tb_number_field :#{name} %>"
|
60
75
|
when 'text'
|
61
|
-
"<%= f.tb_text_area :#{name}, :
|
76
|
+
"<%= f.tb_text_area :#{name}, rows: 4 %>"
|
62
77
|
when 'boolean'
|
63
78
|
"<%= f.tb_check_box :#{name} %>"
|
64
79
|
when 'date'
|
@@ -77,29 +92,29 @@ EOF
|
|
77
92
|
end
|
78
93
|
|
79
94
|
def create_model_scopes
|
80
|
-
sort_field = ask(
|
81
|
-
search_field = ask(
|
82
|
-
inject_into_file "app/models/#{module_name.singularize.underscore}.rb", after: "
|
83
|
-
scope :ordered, ->{ order(
|
84
|
-
scope :search, ->(term){ where('#{search_field} LIKE ?', "%\#{term}%") }
|
95
|
+
sort_field = ask('What field would you like to sort by?', default: 'created_at')
|
96
|
+
search_field = ask('What field would you like to search by?', default: attributes.first.split(':').first)
|
97
|
+
inject_into_file "app/models/#{module_name.singularize.underscore}.rb", after: "ApplicationRecord\n" do <<-RUBY
|
98
|
+
scope :ordered, -> { order(#{sort_field}: :desc) }
|
99
|
+
scope :search, ->(term) { where('#{search_field} LIKE ?', "%\#{term}%") }
|
85
100
|
RUBY
|
86
101
|
end
|
87
102
|
end
|
88
103
|
|
89
104
|
# NOT CURRENTLY USED
|
90
105
|
#
|
91
|
-
# Call this method from the create_module generator to automatically build length validators for string columns.
|
92
|
-
# database exceptions when long strings are entered by a user.
|
106
|
+
# Call this method from the create_module generator to automatically build length validators for string columns.
|
107
|
+
# The idea here is to protect against database exceptions when long strings are entered by a user.
|
93
108
|
#
|
94
|
-
#
|
109
|
+
# Assumes 255 as the default limit
|
95
110
|
#
|
96
111
|
#
|
97
112
|
def add_string_maximums
|
98
113
|
string_attrs = attributes.select{ |att| att.split(':')[1] == 'string' }.collect{ |att| att.split(':')[0] }
|
99
114
|
if string_attrs.any?
|
100
115
|
string_attrs_as_symbols = string_attrs.collect{ |att| ":#{att.to_s}" }.join(', ')
|
101
|
-
inject_into_file "app/models/#{module_name.singularize.underscore}.rb", :
|
102
|
-
|
116
|
+
inject_into_file "app/models/#{module_name.singularize.underscore}.rb", before: 'end' do <<-RUBY
|
117
|
+
|
103
118
|
validates #{string_attrs_as_symbols}, :length => {:maximum => 255}
|
104
119
|
|
105
120
|
RUBY
|
@@ -3,41 +3,45 @@ class Spud::SetupGenerator < ::Rails::Generators::Base
|
|
3
3
|
source_root File.expand_path('../templates', __FILE__)
|
4
4
|
|
5
5
|
def setup
|
6
|
-
if ask(
|
6
|
+
if ask(
|
7
|
+
'NOTICE: Setup will now attempt to delete and/or overwrite existing files. Continue?',
|
8
|
+
limited_to: ['y', 'n']
|
9
|
+
) == 'n'
|
7
10
|
return
|
8
11
|
end
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
template "application_controller.rb", "app/controllers/application_controller.rb"
|
14
|
-
template 'assets/admin.scss', 'app/assets/stylesheets/admin/application.scss'
|
15
|
-
|
16
|
-
remove_file 'app/assets/stylesheets/application.css'
|
17
|
-
template 'assets/application.scss', 'app/assets/stylesheets/application.scss'
|
18
|
-
template 'assets/application.js', 'app/assets/javascripts/application.js'
|
19
|
-
template 'assets/admin/application.js', 'app/assets/javascripts/admin/application.js'
|
20
|
-
|
21
|
-
if defined?(Bootstrap)
|
22
|
-
theme_file = Bootstrap::Rails::Engine.root.join('templates', 'project', '_bootstrap-variables.sass')
|
23
|
-
template theme_file, 'app/assets/stylesheets/imports/bootstrap_theme.scss' if File.exist?(theme_file)
|
24
|
-
|
25
|
-
modules_file = Bootstrap::Rails::Engine.root.join('assets', 'stylesheets', '_bootstrap.scss')
|
26
|
-
template modules_file, 'app/assets/stylesheets/imports/bootstrap_modules.scss' if File.exist?(modules_file)
|
27
|
-
|
28
|
-
template 'assets/bootstrap.js', 'app/assets/javascripts/bootstrap_modules.js'
|
29
|
-
end
|
13
|
+
install_templates()
|
14
|
+
install_bootstrap() if defined?(Bootstrap)
|
30
15
|
|
31
16
|
environment(spud_core_configs())
|
32
17
|
rake('railties:install:migrations')
|
33
18
|
|
34
|
-
if ask(
|
19
|
+
if ask('Migrate the database?', limited_to: ['y', 'n']).downcase == 'y'
|
35
20
|
rake('db:migrate')
|
36
21
|
end
|
37
22
|
end
|
38
23
|
|
39
24
|
private
|
40
25
|
|
26
|
+
def install_templates
|
27
|
+
template 'views/layouts/application.html.erb', 'app/views/layouts/application.html.erb'
|
28
|
+
template 'views/layouts/error_page.html.erb', 'app/views/layouts/error_page.html.erb'
|
29
|
+
template 'application_controller.rb', 'app/controllers/application_controller.rb'
|
30
|
+
template 'assets/admin.scss', 'app/assets/stylesheets/admin/application.scss'
|
31
|
+
remove_file 'app/assets/stylesheets/application.css'
|
32
|
+
template 'assets/application.scss', 'app/assets/stylesheets/application.scss'
|
33
|
+
template 'assets/application.js', 'app/assets/javascripts/application.js'
|
34
|
+
template 'assets/admin/application.js', 'app/assets/javascripts/admin/application.js'
|
35
|
+
end
|
36
|
+
|
37
|
+
def install_bootstrap
|
38
|
+
theme_file = Bootstrap::Rails::Engine.root.join('templates', 'project', '_bootstrap-variables.sass')
|
39
|
+
template theme_file, 'app/assets/stylesheets/imports/bootstrap_theme.scss' if File.exist?(theme_file)
|
40
|
+
modules_file = Bootstrap::Rails::Engine.root.join('assets', 'stylesheets', '_bootstrap.scss')
|
41
|
+
template modules_file, 'app/assets/stylesheets/imports/bootstrap_modules.scss' if File.exist?(modules_file)
|
42
|
+
template 'assets/bootstrap.js', 'app/assets/javascripts/bootstrap_modules.js'
|
43
|
+
end
|
44
|
+
|
41
45
|
def spud_core_configs
|
42
46
|
site_name = application_name().titleize
|
43
47
|
domain_name = application_name().dasherize
|
@@ -1,14 +1,11 @@
|
|
1
1
|
class Admin::<%= module_name_formatted.camelize%>Controller < Admin::ApplicationController
|
2
|
-
|
3
2
|
belongs_to_app :<%= module_name_formatted %>
|
4
|
-
add_breadcrumb
|
5
|
-
before_action :load_<%= module_name_formatted.singularize %>, :
|
3
|
+
add_breadcrumb '<%= module_name_formatted.humanize.titlecase %>', :admin_<%= module_name_formatted %>_path
|
4
|
+
before_action :load_<%= module_name_formatted.singularize %>, only: [:show, :edit, :update, :destroy]
|
6
5
|
|
7
6
|
def index
|
8
|
-
@<%= module_name_formatted %> = <%= module_name_formatted.singularize.camelize %>.ordered.paginate(:
|
9
|
-
if params[:search]
|
10
|
-
@<%= module_name_formatted %> = @<%= module_name_formatted %>.search(params[:search])
|
11
|
-
end
|
7
|
+
@<%= module_name_formatted %> = <%= module_name_formatted.singularize.camelize %>.ordered.paginate(page: params[:page])
|
8
|
+
@<%= module_name_formatted %> = @<%= module_name_formatted %>.search(params[:search]) if params[:search]
|
12
9
|
respond_with @<%= module_name_formatted %>
|
13
10
|
end
|
14
11
|
|
@@ -24,7 +21,7 @@ class Admin::<%= module_name_formatted.camelize%>Controller < Admin::Application
|
|
24
21
|
def create
|
25
22
|
@<%= module_name_formatted.singularize %> = <%= module_name_formatted.singularize.camelize %>.new(<%= module_name_formatted.singularize %>_params)
|
26
23
|
flash[:notice] = '<%= module_name_formatted.singularize.camelize %> created successfully' if @<%= module_name_formatted.singularize %>.save
|
27
|
-
respond_with @<%= module_name_formatted.singularize %>, :
|
24
|
+
respond_with @<%= module_name_formatted.singularize %>, location: admin_<%= module_name_formatted %>_path
|
28
25
|
end
|
29
26
|
|
30
27
|
def edit
|
@@ -35,22 +32,21 @@ class Admin::<%= module_name_formatted.camelize%>Controller < Admin::Application
|
|
35
32
|
if @<%= module_name_formatted.singularize%>.update_attributes(<%= module_name_formatted.singularize %>_params)
|
36
33
|
flash[:notice] = '<%= module_name_formatted.singularize.camelize %> updated successfully'
|
37
34
|
end
|
38
|
-
respond_with @<%= module_name_formatted.singularize %>, :
|
35
|
+
respond_with @<%= module_name_formatted.singularize %>, location: admin_<%= module_name_formatted %>_path
|
39
36
|
end
|
40
37
|
|
41
38
|
def destroy
|
42
39
|
flash[:notice] = '<%= module_name_formatted.singularize.camelize %> deleted successfully' if @<%= module_name_formatted.singularize %>.destroy
|
43
|
-
respond_with @<%= module_name_formatted.singularize %>, :
|
40
|
+
respond_with @<%= module_name_formatted.singularize %>, location: admin_<%= module_name_formatted %>_path
|
44
41
|
end
|
45
42
|
|
46
|
-
private
|
43
|
+
private
|
47
44
|
|
48
45
|
def load_<%= module_name_formatted.singularize %>
|
49
|
-
@<%= module_name_formatted.singularize %> = <%= module_name_formatted.singularize.camelize %>.find_by!(:
|
46
|
+
@<%= module_name_formatted.singularize %> = <%= module_name_formatted.singularize.camelize %>.find_by!(id: params[:id])
|
50
47
|
end
|
51
48
|
|
52
49
|
def <%= module_name_formatted.singularize %>_params
|
53
50
|
params.require(:<%= module_name_formatted.singularize %>).permit(<%= attribute_names.collect{ |att| ":#{att}" }.join(', ') %>)
|
54
51
|
end
|
55
|
-
|
56
52
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
class <%=module_name_formatted.camelize%>Controller < ApplicationController
|
2
|
-
|
3
2
|
respond_to :html, :json
|
4
|
-
before_action :load_<%=module_name_formatted.singularize%>, :
|
3
|
+
before_action :load_<%=module_name_formatted.singularize%>, only: [:show]
|
5
4
|
|
6
5
|
def index
|
7
|
-
@<%=module_name_formatted%> = <%=module_name_formatted.singularize.camelize%>.ordered.paginate(:
|
6
|
+
@<%=module_name_formatted%> = <%=module_name_formatted.singularize.camelize%>.ordered.paginate(page: params[:page])
|
8
7
|
respond_with @<%=module_name_formatted%>
|
9
8
|
end
|
10
9
|
|
@@ -12,10 +11,9 @@ class <%=module_name_formatted.camelize%>Controller < ApplicationController
|
|
12
11
|
respond_with @<%=module_name_formatted.singularize%>
|
13
12
|
end
|
14
13
|
|
15
|
-
private
|
14
|
+
private
|
16
15
|
|
17
16
|
def load_<%=module_name_formatted.singularize%>
|
18
|
-
@<%=module_name_formatted.singularize%> = <%=module_name_formatted.singularize.camelize%>.find_by!(:
|
17
|
+
@<%=module_name_formatted.singularize%> = <%=module_name_formatted.singularize.camelize%>.find_by!(id: params[:id])
|
19
18
|
end
|
20
|
-
|
21
19
|
end
|
@@ -1,56 +1,52 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
RSpec.describe <%= controller_class_name %>, :
|
4
|
-
|
3
|
+
RSpec.describe <%= controller_class_name %>, type: :controller do
|
5
4
|
before(:each) do
|
6
|
-
|
5
|
+
<%- if include_user_session? -%>
|
6
|
+
activate_session(admin: true)
|
7
|
+
<%- end -%>
|
7
8
|
end
|
8
9
|
|
9
10
|
describe 'index' do
|
10
11
|
it 'should render the index' do
|
11
12
|
get :index
|
12
13
|
expect(response).to have_http_status :success
|
13
|
-
expect(response).to render_template :index
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
describe 'show' do
|
18
18
|
it 'should render the show page' do
|
19
19
|
<%= model_variable_name %> = FactoryGirl.create(:<%= model_variable_name %>)
|
20
|
-
get :show, :
|
20
|
+
get :show, id: <%= model_variable_name %>.id
|
21
21
|
expect(response).to have_http_status :success
|
22
|
-
expect(response).to render_template :show
|
23
22
|
end
|
24
23
|
|
25
24
|
it 'should return a 404 error' do
|
26
|
-
get :show, :
|
25
|
+
get :show, id: 1
|
27
26
|
expect(response).to have_http_status :not_found
|
28
27
|
end
|
29
28
|
end
|
30
|
-
|
31
29
|
<%- if include_edit_actions? -%>
|
32
30
|
describe 'new' do
|
33
31
|
it 'should render the new page' do
|
34
32
|
get :new
|
35
33
|
expect(response).to have_http_status :success
|
36
|
-
expect(response).to render_template :new
|
37
34
|
end
|
38
35
|
end
|
39
36
|
|
40
37
|
describe 'edit' do
|
41
38
|
it 'should render the edit page' do
|
42
39
|
<%= model_variable_name %> = FactoryGirl.create(:<%= model_variable_name %>)
|
43
|
-
get :edit, :
|
40
|
+
get :edit, id: <%= model_variable_name %>.id
|
44
41
|
expect(response).to have_http_status :success
|
45
|
-
expect(response).to render_template :edit
|
46
42
|
end
|
47
43
|
end
|
48
44
|
|
49
45
|
describe 'create' do
|
50
46
|
it 'should create the record' do
|
51
|
-
expect
|
52
|
-
post :create,
|
53
|
-
|
47
|
+
expect do
|
48
|
+
post :create, <%= model_variable_name %>: FactoryGirl.attributes_for(:<%= model_variable_name %>)
|
49
|
+
end.to change(<%= model_class_name %>, :count).by(1)
|
54
50
|
end
|
55
51
|
end
|
56
52
|
|
@@ -59,21 +55,20 @@ RSpec.describe <%= controller_class_name %>, :type => :controller do
|
|
59
55
|
<%= model_variable_name %> = FactoryGirl.create(:<%= model_variable_name %>)
|
60
56
|
current_value = <%= model_variable_name %>.<%= model_string_attribute_name %>
|
61
57
|
new_value = current_value + '-Updated'
|
62
|
-
expect
|
63
|
-
patch :update, :
|
58
|
+
expect do
|
59
|
+
patch :update, id: <%= model_variable_name %>.id, <%= model_variable_name %>: { <%= model_string_attribute_name %>: new_value }
|
64
60
|
<%= model_variable_name %>.reload
|
65
|
-
|
61
|
+
end.to change(<%= model_variable_name %>, :<%= model_string_attribute_name %>).to(new_value)
|
66
62
|
end
|
67
63
|
end
|
68
64
|
|
69
65
|
describe 'destroy' do
|
70
66
|
it 'should destroy the record' do
|
71
67
|
<%= model_variable_name %> = FactoryGirl.create(:<%= model_variable_name %>)
|
72
|
-
expect
|
73
|
-
delete :destroy, :
|
74
|
-
|
68
|
+
expect do
|
69
|
+
delete :destroy, id: <%= model_variable_name %>.id
|
70
|
+
end.to change(<%= model_class_name %>, :count).by(-1)
|
75
71
|
end
|
76
72
|
end
|
77
73
|
<%- end -%>
|
78
|
-
|
79
74
|
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
7
7
|
<%%= tb_page_title() %>
|
8
8
|
<%%= stylesheet_link_tag "application", :media => "all" %>
|
9
|
-
<%%= javascript_include_tag "application" %>
|
9
|
+
<%%= javascript_include_tag "application", async: Rails.env.production? %>
|
10
10
|
<%%= csrf_meta_tags %>
|
11
11
|
<%%= yield :head %>
|
12
12
|
</head>
|