redmine_extensions 0.3.00 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +16 -40
- data/lib/generators/redmine_extensions/entity/entity_generator.rb +77 -24
- data/lib/generators/redmine_extensions/entity/templates/_%model_name_underscored%.api.rsb.tt +18 -0
- data/lib/generators/redmine_extensions/entity/templates/controller.rb.erb +14 -20
- data/lib/generators/redmine_extensions/entity/templates/controller_spec.rb.erb +19 -22
- data/lib/generators/redmine_extensions/entity/templates/easy_query.rb.erb +1 -3
- data/lib/generators/redmine_extensions/entity/templates/factories.rb.erb +5 -6
- data/lib/generators/redmine_extensions/entity/templates/helper.rb.erb +0 -21
- data/lib/generators/redmine_extensions/entity/templates/index.api.rsb.erb +2 -4
- data/lib/generators/redmine_extensions/entity/templates/migration.rb.erb +4 -3
- data/lib/generators/redmine_extensions/entity/templates/model.rb.erb +1 -1
- data/lib/generators/redmine_extensions/entity/templates/show.api.rsb.erb +1 -1
- data/lib/generators/redmine_extensions/entity/templates/spec/requests/%model_name_underscored%_spec.rb.tt +19 -0
- data/lib/redmine_extensions/engine.rb +1 -0
- data/lib/redmine_extensions/redmine_patches/models/custom_field_patch.rb +11 -0
- data/lib/redmine_extensions/tags/autocomplete_field.rb +1 -1
- data/lib/redmine_extensions/version.rb +1 -1
- data/spec/factories/easy_settings.rb +5 -4
- data/spec/features/autocomplete_spec.rb +1 -3
- data/spec/features/jasmine_spec.rb +1 -3
- data/spec/init_rails.rb +13 -0
- data/spec/models/easy_setting_spec.rb +0 -2
- data/spec/presenters/easy_settings/params_wrapper_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -69
- data/spec/support/plugin_generator.rb +1 -10
- metadata +12 -126
- data/spec/factories/easy_queries.rb +0 -8
- data/spec/factories/issues.rb +0 -96
- data/spec/factories/projects.rb +0 -84
- data/spec/factories/time_entries.rb +0 -38
- data/spec/factories/trackers.rb +0 -15
- data/spec/factories/users.rb +0 -23
- data/spec/rails_helper.rb +0 -119
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e5bdd71d9b581303878b289c07e4fa88fec0f319ee9c94b310db8ffe9bcf71a
|
4
|
+
data.tar.gz: 5c8d77bc0b82467bbb10a2429a984efdeece83f62372ce83f39c51f5977a7f89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a46dc0c10ebbd8e95257516d22e49d4bef13c02fbc2564ad000dfc48f67e960c66ac9a5e4bc2e141bf4697ee3d33eae8a6abf127cd3fa56c1e99ce64a5354f2
|
7
|
+
data.tar.gz: 20a9d5f7e2bc0dabf8465297965b5497bbd5f06b6c3991405ee5d5d66eaab09cb1d110f60ae37a7346bcbe5b6afd1aca70595aeb177d998c342afe40c60a8851
|
data/Rakefile
CHANGED
@@ -1,49 +1,25 @@
|
|
1
|
-
|
2
|
-
begin
|
3
|
-
require 'bundler/setup'
|
4
|
-
rescue LoadError
|
5
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
-
end
|
1
|
+
require 'bundler/setup'
|
7
2
|
|
8
|
-
|
9
|
-
|
3
|
+
possible_app_dirs = [
|
4
|
+
ENV['DUMMY_PATH'],
|
5
|
+
File.join(Dir.pwd, 'test/dummy')
|
6
|
+
]
|
7
|
+
dir = possible_app_dirs.compact.first
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
rdoc.rdoc_dir = "rdoc"
|
14
|
-
rdoc.title = "RedmineExtensions #{RedmineExtensions::VERSION}"
|
15
|
-
rdoc.rdoc_files.include("README*")
|
16
|
-
rdoc.rdoc_files.include("lib/**/*.rb")
|
17
|
-
end
|
18
|
-
rescue LoadError
|
19
|
-
puts 'RDocTask is not supported for this platform'
|
9
|
+
if !File.directory?(dir)
|
10
|
+
abort("Directory '#{dir}' does not exists")
|
20
11
|
end
|
21
12
|
|
22
|
-
APP_RAKEFILE = File.expand_path(
|
13
|
+
APP_RAKEFILE = File.expand_path(File.join(dir, 'Rakefile'), __dir__)
|
23
14
|
load 'rails/tasks/engine.rake'
|
24
|
-
|
25
|
-
# load 'rails/tasks/statistics.rake'
|
15
|
+
load 'rails/tasks/statistics.rake'
|
26
16
|
|
27
17
|
Bundler::GemHelper.install_tasks
|
28
18
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
require '
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
task :generate_test_plugin do
|
37
|
-
require RedmineExtensions::Engine.root.join('spec', 'support', 'plugin_generator').to_s
|
38
|
-
PluginGenerator.generate_test_plugin!
|
39
|
-
end
|
40
|
-
RSpec::Core::RakeTask.new(spec: [:generate_test_plugin, 'app:redmine:plugins:migrate']) do |spec|
|
41
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
42
|
-
spec.exclude_pattern = 'spec/redmine/**/*_spec.rb'
|
19
|
+
namespace :redmine_extensions do
|
20
|
+
task :generate_test_plugin do
|
21
|
+
require_relative 'spec/init_rails'
|
22
|
+
require RedmineExtensions::Engine.root.join('spec', 'support', 'plugin_generator').to_s
|
23
|
+
PluginGenerator.generate_test_plugin!
|
24
|
+
end
|
43
25
|
end
|
44
|
-
|
45
|
-
# task :redmine_test do |rake|
|
46
|
-
# Rake::Task['app:test'].invoke
|
47
|
-
# end
|
48
|
-
|
49
|
-
task :default => :spec
|
@@ -6,6 +6,8 @@ module RedmineExtensions
|
|
6
6
|
argument :model_name, type: :string, required: true, banner: 'Post'
|
7
7
|
argument :attributes, type: :array, required: true, banner: 'field[:type][:index] field[:type][:index]'
|
8
8
|
|
9
|
+
class_option :rys, type: :boolean, default: false, required: false, desc: "Use in case of RYS"
|
10
|
+
|
9
11
|
class_option :associations, type: :array, required: false, banner: '--associations association_type[:association_name][:association_class]'
|
10
12
|
|
11
13
|
class_option :project, type: :boolean, default: true, banner: '', :desc => 'make model depends on project'
|
@@ -25,12 +27,14 @@ module RedmineExtensions
|
|
25
27
|
attr_reader :controller_class, :model_name_underscored, :model_name_pluralize_underscored
|
26
28
|
attr_reader :db_columns
|
27
29
|
attr_reader :associations
|
28
|
-
|
30
|
+
attr_reader :rys
|
29
31
|
def initialize(*args)
|
30
32
|
super
|
33
|
+
@rys = !!options["rys"]
|
31
34
|
@plugin_name_underscored = plugin_name.underscore
|
32
35
|
@plugin_pretty_name = @plugin_name_underscored.titleize
|
33
|
-
|
36
|
+
|
37
|
+
@plugin_path = rys ? "." : "plugins/#{@plugin_name_underscored}"
|
34
38
|
@plugin_title = @plugin_name_underscored.camelize
|
35
39
|
|
36
40
|
@model_name_underscored = model_name.underscore
|
@@ -49,8 +53,10 @@ module RedmineExtensions
|
|
49
53
|
template 'edit.html.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/edit.html.erb"
|
50
54
|
template 'edit.js.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/edit.js.erb"
|
51
55
|
|
52
|
-
|
53
|
-
template '
|
56
|
+
tests_root = rys ? "./spec" : "#{plugin_path}/test"
|
57
|
+
template 'controller_spec.rb.erb', "#{tests_root + (!rys && "/spec" || "")}/controllers/#{model_name_pluralize_underscored}_controller_spec.rb"
|
58
|
+
template 'factories.rb.erb', "#{tests_root}/factories/#{model_name_underscored}.rb"
|
59
|
+
template 'spec/requests/%model_name_underscored%_spec.rb.tt', "#{tests_root}/requests/#{model_name_underscored}.rb"
|
54
60
|
|
55
61
|
if File.exists?("#{plugin_path}/config/locales/en.yml")
|
56
62
|
original_langfile = YAML.load_file("#{plugin_path}/config/locales/en.yml")
|
@@ -95,31 +101,32 @@ module RedmineExtensions
|
|
95
101
|
if File.exists?("#{plugin_path}/extra/easy_patch/easy_extensions/helpers/entity_attribute_helper_patch.rb")
|
96
102
|
|
97
103
|
inject_into_file "#{plugin_path}/extra/easy_patch/easy_extensions/helpers/entity_attribute_helper_patch.rb",
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
104
|
+
"\n def format_html_#{model_name_underscored}_attribute(entity_class, attribute, unformatted_value, options={})" +
|
105
|
+
"\n value = format_entity_attribute(entity_class, attribute, unformatted_value, options)" +
|
106
|
+
"\n case attribute.name" +
|
107
|
+
"\n when :name" +
|
108
|
+
"\n link_to(value, #{model_name_underscored.singularize}_path(options[:entity].id))" +
|
109
|
+
"\n else" +
|
110
|
+
"\n h(value)" +
|
111
|
+
"\n end" +
|
112
|
+
"\n end" +
|
113
|
+
"\n", after: "base.class_eval do"
|
108
114
|
|
109
115
|
end
|
110
116
|
else
|
111
117
|
template 'query.rb.erb', "#{plugin_path}/app/models/#{model_name_underscored}_query.rb"
|
112
118
|
end
|
113
119
|
|
114
|
-
|
120
|
+
routes_file = "#{plugin_path}/config/routes.rb"
|
121
|
+
if File.exists?(routes_file)
|
115
122
|
if project?
|
116
|
-
|
123
|
+
insert_into_file routes_file, before: (rys ? /end\z/ : /\z/) do
|
117
124
|
"\nresources :projects do " +
|
118
125
|
"\n resources :#{model_name_pluralize_underscored}" +
|
119
126
|
"\nend\n"
|
120
127
|
end
|
121
128
|
end
|
122
|
-
|
129
|
+
insert_into_file routes_file, before: (rys ? /end\z/ : /\z/) do
|
123
130
|
"\nresources :#{model_name_pluralize_underscored} do" +
|
124
131
|
"\n collection do " +
|
125
132
|
"\n get 'autocomplete'" +
|
@@ -166,10 +173,56 @@ module RedmineExtensions
|
|
166
173
|
s << "\nend"
|
167
174
|
|
168
175
|
append_to_file "#{plugin_path}/after_init.rb", s
|
176
|
+
elsif rys
|
177
|
+
s = ""
|
178
|
+
s << "\n Redmine::AccessControl.map do |map|"
|
179
|
+
s << "\n map.easy_category :#{model_name_pluralize_underscored} do |pmap|"
|
180
|
+
s << "\n pmap.permission :view_#{model_name_pluralize_underscored}, { #{model_name_pluralize_underscored}: [:index, :show, :autocomplete, :context_menu] }, read: true"
|
181
|
+
s << "\n pmap.permission :manage_#{model_name_pluralize_underscored}, { #{model_name_pluralize_underscored}: [:new, :create, :edit, :update, :destroy, :bulk_edit, :bulk_update] }"
|
182
|
+
s << "\n end "
|
183
|
+
s << "\n end\n"
|
184
|
+
append_to_file "./config/initializers/01_access_control.rb", s
|
185
|
+
|
186
|
+
s = ""
|
187
|
+
s << "\n Redmine::MenuManager.map :top_menu do |menu|"
|
188
|
+
s << "\n menu.push :#{model_name_pluralize_underscored}, { controller: '#{model_name_pluralize_underscored}', action: 'index', project_id: nil }, caption: :label_#{model_name_pluralize_underscored}"
|
189
|
+
s << "\n end\n"
|
190
|
+
if project?
|
191
|
+
s << "\n Redmine::MenuManager.map :project_menu do |menu|"
|
192
|
+
s << "\n menu.push :#{model_name_pluralize_underscored}, { controller: '#{model_name_pluralize_underscored}', action: 'index' }, param: :project_id, caption: :label_#{model_name_pluralize_underscored}"
|
193
|
+
s << "\n end\n"
|
194
|
+
end
|
195
|
+
append_to_file "./config/initializers/02_menu_manager.rb", s
|
196
|
+
s = ""
|
197
|
+
if acts_as_customizable?
|
198
|
+
s << "\n CustomFieldsHelper::CUSTOM_FIELDS_TABS << {name: '#{model_name}CustomField', partial: 'custom_fields/index', label: :label_#{model_name_pluralize_underscored}}\n"
|
199
|
+
end
|
200
|
+
if acts_as_searchable?
|
201
|
+
s << "\n Redmine::Search.map do |search|"
|
202
|
+
s << "\n search.register :#{model_name_pluralize_underscored}"
|
203
|
+
s << "\n end\n"
|
204
|
+
end
|
205
|
+
if acts_as_activity_provider?
|
206
|
+
s << "\n Redmine::Activity.map do |activity|"
|
207
|
+
s << "\n activity.register :#{model_name_pluralize_underscored}, {class_name: %w(#{model_name}), default: false}"
|
208
|
+
s << "\n end\n"
|
209
|
+
end
|
210
|
+
other_initializer = "./config/initializers/06_others.rb"
|
211
|
+
if File.exist?(other_initializer)
|
212
|
+
append_file other_initializer do
|
213
|
+
s
|
214
|
+
end
|
215
|
+
else
|
216
|
+
create_file other_initializer do
|
217
|
+
s
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
169
221
|
end
|
170
222
|
|
171
223
|
|
172
224
|
template 'show.api.rsb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/show.api.rsb"
|
225
|
+
template '_%model_name_underscored%.api.rsb.tt', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/_#{model_name_underscored}.api.rsb"
|
173
226
|
template 'show.html.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/show.html.erb"
|
174
227
|
template 'show.js.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/show.js.erb"
|
175
228
|
end
|
@@ -239,15 +292,15 @@ module RedmineExtensions
|
|
239
292
|
if attr_type == 'timestamp'
|
240
293
|
@timestamp_exist = true
|
241
294
|
else
|
242
|
-
@db_columns[attr_name] = {type: attr_type || 'string', idx: attr_idx, null: true, safe: true, query_type: attr_type || 'string', lang_key: lang_key}
|
295
|
+
@db_columns[attr_name] = { type: attr_type || 'string', idx: attr_idx, null: true, safe: true, query_type: attr_type || 'string', lang_key: lang_key }
|
243
296
|
end
|
244
297
|
end
|
245
298
|
|
246
|
-
@db_columns['project_id'] = {type: 'integer', idx: nil, null: false, safe: false, class: 'Project', list_class_name: 'name', query_type: 'list_optional', query_column_name: 'project', lang_key: "field_#{model_name_underscored}_project"} if project? && !@db_columns.key?('project_id')
|
247
|
-
@db_columns['author_id'] = {type: 'integer', idx: nil, null: false, safe: true, class: 'User', list_class_name: 'name', query_type: 'list', query_column_name: 'author', lang_key: "field_#{model_name_underscored}_author"} if author? && !@db_columns.key?('author_id')
|
299
|
+
@db_columns['project_id'] = { type: 'integer', idx: nil, null: false, safe: false, class: 'Project', list_class_name: 'name', query_type: 'list_optional', query_column_name: 'project', lang_key: "field_#{model_name_underscored}_project" } if project? && !@db_columns.key?('project_id')
|
300
|
+
@db_columns['author_id'] = { type: 'integer', idx: nil, null: false, safe: true, class: 'User', list_class_name: 'name', query_type: 'list', query_column_name: 'author', lang_key: "field_#{model_name_underscored}_author" } if author? && !@db_columns.key?('author_id')
|
248
301
|
|
249
|
-
@db_columns['created_at'] = {type: 'datetime', idx: nil, null: false, safe: false, query_type: 'date', lang_key: "field_#{model_name_underscored}_created_at"}
|
250
|
-
@db_columns['updated_at'] = {type: 'datetime', idx: nil, null: false, safe: false, query_type: 'date', lang_key: "field_#{model_name_underscored}_updated_at"}
|
302
|
+
@db_columns['created_at'] = { type: 'datetime', idx: nil, null: false, safe: false, query_type: 'date', lang_key: "field_#{model_name_underscored}_created_at" }
|
303
|
+
@db_columns['updated_at'] = { type: 'datetime', idx: nil, null: false, safe: false, query_type: 'date', lang_key: "field_#{model_name_underscored}_updated_at" }
|
251
304
|
end
|
252
305
|
|
253
306
|
def prepare_associations
|
@@ -259,7 +312,7 @@ module RedmineExtensions
|
|
259
312
|
assoc_type, assoc_name, assoc_class = assoc.split(':')
|
260
313
|
next if assoc_type.blank? || assoc_name.blank?
|
261
314
|
|
262
|
-
@associations[assoc_name] = {type: assoc_type, class: assoc_class}
|
315
|
+
@associations[assoc_name] = { type: assoc_type, class: assoc_class }
|
263
316
|
|
264
317
|
assoc_model_class = assoc_class.presence || assoc_name.singularize.camelize
|
265
318
|
assoc_model_filename = assoc_model_class.underscore
|
@@ -283,7 +336,7 @@ module RedmineExtensions
|
|
283
336
|
end
|
284
337
|
end
|
285
338
|
|
286
|
-
@db_columns["#{assoc_model_class.underscore.singularize}_id"] = {type: 'integer', idx: true, lang_key: assoc_model_class.underscore, query_type: 'list_optional', null: true}
|
339
|
+
@db_columns["#{assoc_model_class.underscore.singularize}_id"] = { type: 'integer', idx: true, lang_key: assoc_model_class.underscore, query_type: 'list_optional', null: true }
|
287
340
|
end
|
288
341
|
end
|
289
342
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
local_assigns[:api].<%= model_name_underscored %> do
|
2
|
+
local_assigns[:api].id <%= model_name_underscored %>.id
|
3
|
+
<%- db_columns.keys.each do |column_name| -%>
|
4
|
+
local_assigns[:api].<%= column_name %> <%= model_name_underscored %>.<%= column_name %>
|
5
|
+
<%- end -%>
|
6
|
+
<%- if acts_as_customizable? -%>
|
7
|
+
render_api_custom_values <%= model_name_underscored %>.visible_custom_field_values, local_assigns[:api]
|
8
|
+
<%- end -%>
|
9
|
+
<%- if acts_as_attachable? -%>
|
10
|
+
local_assigns[:api].array :attachments do
|
11
|
+
<%= model_name_underscored %>.attachments.each do |attachment|
|
12
|
+
render_api_attachment attachment, local_assigns[:api]
|
13
|
+
end
|
14
|
+
end if include_in_api_response?('attachments')
|
15
|
+
<%- end -%>
|
16
|
+
|
17
|
+
call_hook :helper_render_api_<%= model_name_underscored %>, { api: local_assigns[:api], <%= model_name_underscored %>: <%= model_name_underscored %> }
|
18
|
+
end
|
@@ -48,7 +48,7 @@ class <%= controller_class %>Controller < ApplicationController
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def create
|
51
|
-
@<%= model_name_underscored %> = <%= model_name %>.new
|
51
|
+
@<%= model_name_underscored %> = <%= model_name %>.new<%= "author: User.current" if author? %>
|
52
52
|
<%- if project? -%>
|
53
53
|
@<%= model_name_underscored %>.project = @project
|
54
54
|
<%- end -%>
|
@@ -57,17 +57,15 @@ class <%= controller_class %>Controller < ApplicationController
|
|
57
57
|
@<%= model_name_underscored %>.save_attachments(params[:attachments] || (params[:<%= model_name_underscored %>] && params[:<%= model_name_underscored %>][:uploads]))
|
58
58
|
<%- end -%>
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
format.html
|
60
|
+
respond_to do |format|
|
61
|
+
if @<%= model_name_underscored %>.save
|
62
|
+
format.html do
|
63
63
|
flash[:notice] = l(:notice_successful_create)
|
64
64
|
redirect_back_or_default <%= model_name_underscored %>_path(@<%= model_name_underscored %>)
|
65
|
-
|
65
|
+
end
|
66
66
|
format.api { render action: 'show', status: :created, location: <%= model_name_underscored %>_url(@<%= model_name_underscored %>) }
|
67
67
|
format.js { render template: 'common/close_modal' }
|
68
|
-
|
69
|
-
else
|
70
|
-
respond_to do |format|
|
68
|
+
else
|
71
69
|
format.html { render action: 'new' }
|
72
70
|
format.api { render_validation_errors(@<%= model_name_underscored %>) }
|
73
71
|
format.js { render action: 'new' }
|
@@ -90,17 +88,15 @@ class <%= controller_class %>Controller < ApplicationController
|
|
90
88
|
@<%= model_name_underscored %>.save_attachments(params[:attachments] || (params[:<%= model_name_underscored %>] && params[:<%= model_name_underscored %>][:uploads]))
|
91
89
|
<%- end -%>
|
92
90
|
|
93
|
-
|
94
|
-
|
95
|
-
format.html
|
91
|
+
respond_to do |format|
|
92
|
+
if @<%= model_name_underscored %>.save
|
93
|
+
format.html do
|
96
94
|
flash[:notice] = l(:notice_successful_update)
|
97
95
|
redirect_back_or_default <%= model_name_underscored %>_path(@<%= model_name_underscored %>)
|
98
|
-
|
96
|
+
end
|
99
97
|
format.api { render_api_ok }
|
100
98
|
format.js { render template: 'common/close_modal' }
|
101
|
-
|
102
|
-
else
|
103
|
-
respond_to do |format|
|
99
|
+
else
|
104
100
|
format.html { render action: 'edit' }
|
105
101
|
format.api { render_validation_errors(@<%= model_name_underscored %>) }
|
106
102
|
format.js { render action: 'edit' }
|
@@ -109,15 +105,13 @@ class <%= controller_class %>Controller < ApplicationController
|
|
109
105
|
end
|
110
106
|
|
111
107
|
def destroy
|
112
|
-
@<%= model_name_pluralize_underscored %>.each
|
113
|
-
<%= model_name_underscored %>.destroy
|
114
|
-
end
|
108
|
+
@<%= model_name_pluralize_underscored %>.each(&:destroy)
|
115
109
|
|
116
110
|
respond_to do |format|
|
117
|
-
format.html
|
111
|
+
format.html do
|
118
112
|
flash[:notice] = l(:notice_successful_delete)
|
119
113
|
redirect_back_or_default <%= model_name_pluralize_underscored %>_path
|
120
|
-
|
114
|
+
end
|
121
115
|
format.api { render_api_ok }
|
122
116
|
end
|
123
117
|
end
|
@@ -1,8 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
<% unless rys %>
|
2
|
+
require "easy_extensions/spec_helper"
|
3
|
+
<% end %>
|
4
|
+
RSpec.describe <%= controller_class %>Controller, logged: true do
|
4
5
|
let(:<%= model_name_underscored %>) { FactoryBot.create(:<%= model_name_underscored %>) }
|
5
|
-
let(:<%= model_name_pluralize_underscored %>) { FactoryBot.create_list(:<%= model_name_underscored %>,
|
6
|
+
let(:<%= model_name_pluralize_underscored %>) { FactoryBot.create_list(:<%= model_name_underscored %>, 2) }
|
6
7
|
|
7
8
|
before(:each) do
|
8
9
|
role = Role.non_member
|
@@ -21,7 +22,7 @@ describe <%= controller_class %>Controller, logged: true do
|
|
21
22
|
end
|
22
23
|
|
23
24
|
it 'show' do
|
24
|
-
get :show, {id: <%= model_name_underscored %>}
|
25
|
+
get :show, params: { id: <%= model_name_underscored %> }
|
25
26
|
expect(response).to have_http_status(:success)
|
26
27
|
expect(response).to render_template('<%= model_name_pluralize_underscored %>/show')
|
27
28
|
end
|
@@ -33,45 +34,41 @@ describe <%= controller_class %>Controller, logged: true do
|
|
33
34
|
end
|
34
35
|
|
35
36
|
it 'create with invalid' do
|
36
|
-
post :create, {<%= model_name_underscored %>: {}}
|
37
|
-
expect(response).to have_http_status(:success)
|
38
|
-
expect(assigns[:<%= model_name_underscored %>]).to be_a_new(<%= model_name %>)
|
37
|
+
post :create, params: { <%= model_name_underscored %>: { } }
|
39
38
|
expect(response).to render_template('<%= model_name_pluralize_underscored %>/new')
|
39
|
+
expect(assigns[:<%= model_name_underscored %>]).to be_a_new(<%= model_name %>)
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'create with valid' do
|
43
|
-
post :create, {<%= model_name_underscored %>: FactoryBot.attributes_for(:<%= model_name_underscored %>)}
|
44
|
-
expect(response).to have_http_status(:success)
|
45
|
-
expect(assigns[:<%= model_name_underscored %>]).not_to be_a_new(<%= model_name %>)
|
43
|
+
post :create, params: { <%= model_name_underscored %>: FactoryBot.attributes_for(:<%= model_name_underscored %>) }
|
46
44
|
expect(response).to redirect_to(<%= model_name_underscored %>_path(assigns[:<%= model_name_underscored %>]))
|
45
|
+
expect(assigns[:<%= model_name_underscored %>]).not_to be_a_new(<%= model_name %>)
|
47
46
|
end
|
48
47
|
|
49
48
|
it 'edit' do
|
50
|
-
get :edit, {id: <%= model_name_underscored %>}
|
49
|
+
get :edit, params: { id: <%= model_name_underscored %> }
|
51
50
|
expect(response).to have_http_status(:success)
|
52
51
|
expect(response).to render_template('<%= model_name_pluralize_underscored %>/edit')
|
53
52
|
end
|
54
53
|
|
55
54
|
it 'update with invalid' do
|
56
|
-
put :update, {id: <%= model_name_underscored %>, <%= model_name_underscored %>: {<%= safe_columns.first %>: ''}}
|
57
|
-
expect(response).to have_http_status(:success)
|
58
|
-
expect(assigns[:<%= model_name_underscored %>].valid?).to be false
|
55
|
+
put :update, params: { id: <%= model_name_underscored %>, <%= model_name_underscored %>: { <%= safe_columns.first[0] %>: '' } }
|
59
56
|
expect(response).to render_template('<%= model_name_pluralize_underscored %>/edit')
|
57
|
+
expect(assigns[:<%= model_name_underscored %>].valid?).to be false
|
60
58
|
end
|
61
59
|
|
62
60
|
it 'update with valid' do
|
63
|
-
put :update, {id: <%= model_name_underscored %>, <%= model_name_underscored %>: {<%= safe_columns.first %>: 'Tralalala'}}
|
64
|
-
expect(response).to have_http_status(:success)
|
65
|
-
expect(assigns[:<%= model_name_underscored %>].valid?).to be true
|
61
|
+
put :update, params: { id: <%= model_name_underscored %>, <%= model_name_underscored %>: { <%= safe_columns.first[0] %>: 'Tralalala' } }
|
66
62
|
expect(response).to redirect_to(<%= model_name_underscored %>_path(assigns[:<%= model_name_underscored %>]))
|
63
|
+
expect(assigns[ :<%= model_name_underscored %>].valid?).to be true
|
67
64
|
end
|
68
65
|
|
69
66
|
it 'destroy' do
|
70
|
-
|
71
|
-
|
67
|
+
<%= model_name_underscored %>
|
68
|
+
<%= model_name_pluralize_underscored %>
|
72
69
|
|
73
|
-
expect(<%= model_name %>.count).to eq(
|
74
|
-
expect {delete :destroy, {id: <%= model_name_underscored %>}}.to change(<%= model_name %>, :count).by(-1)
|
70
|
+
expect(<%= model_name %>.count).to eq(3)
|
71
|
+
expect { delete :destroy, params: { id: <%= model_name_underscored %> } }.to change(<%= model_name %>, :count).by(-1)
|
75
72
|
expect(response).to redirect_to(<%= model_name_pluralize_underscored %>_path)
|
76
73
|
expect(response).to redirect_to(<%= model_name_pluralize_underscored %>_path)
|
77
74
|
end
|
@@ -18,17 +18,15 @@ class <%= model_name %>Query < EasyQuery
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def initialize_available_columns
|
21
|
-
return @available_columns if @available_columns
|
22
21
|
group = l("label_filter_group_#{self.class.name.underscore}")
|
23
22
|
|
24
23
|
<%- db_columns.each do |column_name, column_options| -%>
|
25
24
|
add_available_column '<%= column_options[:query_column_name] || column_name %>', caption: <%= model_name %>.human_attribute_name(:<%= column_name %>), title: <%= model_name %>.human_attribute_name(:<%= column_name %>), group: group
|
26
25
|
<%- end -%>
|
27
26
|
<%- if acts_as_customizable? -%>
|
28
|
-
|
27
|
+
add_available_columns <%= model_name %>CustomField.sorted.visible.collect { |cf| EasyQueryCustomFieldColumn.new(cf, group: l(:label_filter_group_custom_fields))}
|
29
28
|
<%- end -%>
|
30
29
|
|
31
|
-
@available_columns
|
32
30
|
end
|
33
31
|
|
34
32
|
def default_list_columns
|