active_scaffold 3.4.43 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (216) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +39 -0
  3. data/{LICENSE → LICENSE.md} +1 -1
  4. data/README.md +27 -19
  5. data/app/assets/javascripts/active_scaffold.js.erb +1 -1
  6. data/app/assets/javascripts/jquery/active_scaffold.js +95 -43
  7. data/app/assets/javascripts/jquery/tiny_mce_bridge.js +30 -6
  8. data/app/assets/javascripts/prototype/tiny_mce_bridge.js +11 -1
  9. data/app/assets/stylesheets/active_scaffold_colors.scss +2 -2
  10. data/app/assets/stylesheets/active_scaffold_layout.css +36 -28
  11. data/app/views/active_scaffold_overrides/_base_form.html.erb +2 -3
  12. data/app/views/active_scaffold_overrides/_field_search.html.erb +8 -7
  13. data/app/views/active_scaffold_overrides/_form_association.html.erb +9 -9
  14. data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +6 -6
  15. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +52 -50
  16. data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +1 -1
  17. data/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +1 -1
  18. data/app/views/active_scaffold_overrides/_human_conditions.html.erb +3 -1
  19. data/app/views/active_scaffold_overrides/_list_calculations.html.erb +1 -1
  20. data/app/views/active_scaffold_overrides/_list_column_headings.html.erb +2 -0
  21. data/app/views/active_scaffold_overrides/_list_messages.html.erb +5 -3
  22. data/app/views/active_scaffold_overrides/_list_record.html.erb +3 -1
  23. data/app/views/active_scaffold_overrides/_list_with_header.html.erb +9 -9
  24. data/app/views/active_scaffold_overrides/_messages.html.erb +1 -1
  25. data/app/views/active_scaffold_overrides/_refresh_list.js.erb +18 -10
  26. data/app/views/active_scaffold_overrides/_render_field.js.erb +3 -3
  27. data/app/views/active_scaffold_overrides/_search.html.erb +7 -6
  28. data/app/views/active_scaffold_overrides/_show_actions.html.erb +14 -0
  29. data/app/views/active_scaffold_overrides/_show_association.html.erb +1 -1
  30. data/app/views/active_scaffold_overrides/_update_actions.html.erb +6 -2
  31. data/app/views/active_scaffold_overrides/_update_column.js.erb +1 -1
  32. data/app/views/active_scaffold_overrides/_update_form.html.erb +1 -1
  33. data/app/views/active_scaffold_overrides/destroy.js.erb +2 -3
  34. data/app/views/active_scaffold_overrides/edit_associated.js.erb +4 -3
  35. data/app/views/active_scaffold_overrides/on_action_update.js.erb +5 -3
  36. data/app/views/active_scaffold_overrides/on_create.js.erb +4 -4
  37. data/app/views/active_scaffold_overrides/on_update.js.erb +6 -6
  38. data/app/views/active_scaffold_overrides/show.html.erb +6 -0
  39. data/app/views/active_scaffold_overrides/update.html.erb +1 -1
  40. data/app/views/active_scaffold_overrides/update_column.js.erb +1 -1
  41. data/config/brakeman.ignore +26 -0
  42. data/config/brakeman.yml +3 -0
  43. data/config/i18n-tasks.yml +121 -0
  44. data/config/locales/de.yml +81 -70
  45. data/config/locales/en.yml +83 -74
  46. data/config/locales/es.yml +82 -73
  47. data/config/locales/fr.yml +86 -75
  48. data/config/locales/hu.yml +81 -70
  49. data/config/locales/ja.yml +71 -60
  50. data/config/locales/ru.yml +85 -74
  51. data/lib/active_scaffold.rb +3 -0
  52. data/lib/active_scaffold/actions/common_search.rb +11 -7
  53. data/lib/active_scaffold/actions/core.rb +119 -47
  54. data/lib/active_scaffold/actions/create.rb +1 -1
  55. data/lib/active_scaffold/actions/delete.rb +11 -8
  56. data/lib/active_scaffold/actions/field_search.rb +104 -6
  57. data/lib/active_scaffold/actions/list.rb +25 -21
  58. data/lib/active_scaffold/actions/mark.rb +12 -4
  59. data/lib/active_scaffold/actions/nested.rb +26 -26
  60. data/lib/active_scaffold/actions/search.rb +2 -2
  61. data/lib/active_scaffold/actions/show.rb +4 -5
  62. data/lib/active_scaffold/actions/subform.rb +9 -7
  63. data/lib/active_scaffold/actions/update.rb +20 -13
  64. data/lib/active_scaffold/active_record_permissions.rb +24 -5
  65. data/lib/active_scaffold/attribute_params.rb +68 -49
  66. data/lib/active_scaffold/bridges.rb +1 -1
  67. data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +15 -19
  68. data/lib/active_scaffold/bridges/bitfields.rb +1 -1
  69. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +10 -14
  70. data/lib/active_scaffold/bridges/calendar_date_select.rb +0 -7
  71. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +19 -22
  72. data/lib/active_scaffold/bridges/cancan.rb +4 -3
  73. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +11 -21
  74. data/lib/active_scaffold/bridges/carrierwave.rb +2 -1
  75. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +2 -6
  76. data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +6 -39
  77. data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +1 -1
  78. data/lib/active_scaffold/bridges/chosen.rb +4 -1
  79. data/lib/active_scaffold/bridges/chosen/helpers.rb +3 -2
  80. data/lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb +2 -2
  81. data/lib/active_scaffold/bridges/date_picker.rb +3 -0
  82. data/lib/active_scaffold/bridges/date_picker/ext.rb +43 -38
  83. data/lib/active_scaffold/bridges/date_picker/helper.rb +24 -23
  84. data/lib/active_scaffold/bridges/dragonfly.rb +1 -1
  85. data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +3 -7
  86. data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +3 -25
  87. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +2 -2
  88. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +6 -8
  89. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +1 -1
  90. data/lib/active_scaffold/bridges/file_column/form_ui.rb +0 -2
  91. data/lib/active_scaffold/bridges/file_column/list_ui.rb +2 -1
  92. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +1 -1
  93. data/lib/active_scaffold/bridges/paper_trail/actions.rb +1 -1
  94. data/lib/active_scaffold/bridges/paper_trail/helper.rb +1 -2
  95. data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +3 -7
  96. data/lib/active_scaffold/bridges/paperclip.rb +1 -1
  97. data/lib/active_scaffold/bridges/paperclip/form_ui.rb +3 -28
  98. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
  99. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +3 -7
  100. data/lib/active_scaffold/bridges/record_select.rb +2 -0
  101. data/lib/active_scaffold/bridges/record_select/helpers.rb +14 -18
  102. data/lib/active_scaffold/bridges/semantic_attributes/column.rb +4 -8
  103. data/lib/active_scaffold/bridges/shared/date_bridge.rb +20 -20
  104. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +7 -22
  105. data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +14 -14
  106. data/lib/active_scaffold/config/base.rb +9 -6
  107. data/lib/active_scaffold/config/core.rb +30 -21
  108. data/lib/active_scaffold/config/create.rb +2 -1
  109. data/lib/active_scaffold/config/delete.rb +2 -2
  110. data/lib/active_scaffold/config/field_search.rb +9 -3
  111. data/lib/active_scaffold/config/form.rb +4 -4
  112. data/lib/active_scaffold/config/list.rb +27 -23
  113. data/lib/active_scaffold/config/nested.rb +4 -4
  114. data/lib/active_scaffold/config/search.rb +6 -6
  115. data/lib/active_scaffold/config/show.rb +11 -1
  116. data/lib/active_scaffold/config/subform.rb +1 -1
  117. data/lib/active_scaffold/config/update.rb +4 -2
  118. data/lib/active_scaffold/constraints.rb +39 -36
  119. data/lib/active_scaffold/core.rb +36 -15
  120. data/lib/active_scaffold/data_structures/action_columns.rb +14 -9
  121. data/lib/active_scaffold/data_structures/action_link.rb +4 -5
  122. data/lib/active_scaffold/data_structures/action_links.rb +5 -4
  123. data/lib/active_scaffold/data_structures/actions.rb +2 -2
  124. data/lib/active_scaffold/data_structures/association.rb +8 -0
  125. data/lib/active_scaffold/data_structures/association/abstract.rb +147 -0
  126. data/lib/active_scaffold/data_structures/association/active_mongoid.rb +42 -0
  127. data/lib/active_scaffold/data_structures/association/active_record.rb +94 -0
  128. data/lib/active_scaffold/data_structures/association/mongoid.rb +45 -0
  129. data/lib/active_scaffold/data_structures/bridge.rb +3 -6
  130. data/lib/active_scaffold/data_structures/column.rb +100 -82
  131. data/lib/active_scaffold/data_structures/columns.rb +21 -3
  132. data/lib/active_scaffold/data_structures/nested_info.rb +22 -37
  133. data/lib/active_scaffold/data_structures/set.rb +4 -4
  134. data/lib/active_scaffold/data_structures/sorting.rb +29 -15
  135. data/lib/active_scaffold/engine.rb +3 -1
  136. data/lib/active_scaffold/extensions/action_controller_rendering.rb +10 -5
  137. data/lib/active_scaffold/extensions/action_view_rendering.rb +65 -59
  138. data/lib/active_scaffold/extensions/left_outer_joins.rb +48 -53
  139. data/lib/active_scaffold/extensions/localize.rb +3 -4
  140. data/lib/active_scaffold/extensions/name_option_for_datetime.rb +7 -11
  141. data/lib/active_scaffold/extensions/paginator_extensions.rb +20 -18
  142. data/lib/active_scaffold/extensions/routing_mapper.rb +104 -40
  143. data/lib/active_scaffold/extensions/to_label.rb +1 -1
  144. data/lib/active_scaffold/extensions/unsaved_associated.rb +4 -13
  145. data/lib/active_scaffold/extensions/unsaved_record.rb +12 -1
  146. data/lib/active_scaffold/finder.rb +200 -134
  147. data/lib/active_scaffold/helpers/action_link_helpers.rb +398 -0
  148. data/lib/active_scaffold/helpers/association_helpers.rb +12 -30
  149. data/lib/active_scaffold/helpers/controller_helpers.rb +74 -24
  150. data/lib/active_scaffold/helpers/form_column_helpers.rb +205 -112
  151. data/lib/active_scaffold/helpers/human_condition_helpers.rb +21 -11
  152. data/lib/active_scaffold/helpers/id_helpers.rb +1 -1
  153. data/lib/active_scaffold/helpers/list_column_helpers.rb +117 -39
  154. data/lib/active_scaffold/helpers/pagination_helpers.rb +11 -14
  155. data/lib/active_scaffold/helpers/search_column_helpers.rb +69 -32
  156. data/lib/active_scaffold/helpers/show_column_helpers.rb +9 -3
  157. data/lib/active_scaffold/helpers/view_helpers.rb +41 -426
  158. data/lib/active_scaffold/orm_checks.rb +109 -0
  159. data/lib/active_scaffold/paginator.rb +1 -1
  160. data/lib/active_scaffold/responds_to_parent.rb +12 -10
  161. data/lib/active_scaffold/tableless.rb +81 -43
  162. data/lib/active_scaffold/version.rb +2 -2
  163. data/lib/generators/active_scaffold/controller_generator.rb +49 -0
  164. data/lib/generators/active_scaffold/install_generator.rb +45 -0
  165. data/lib/generators/active_scaffold/resource_generator.rb +56 -0
  166. data/lib/generators/{active_scaffold_controller/templates → templates}/controller.rb +0 -0
  167. data/lib/generators/{active_scaffold_controller/templates → templates}/helper.rb +0 -0
  168. data/shoulda_macros/macros.rb +3 -3
  169. data/test/active_scaffold_config_mock.rb +33 -0
  170. data/test/bridges/bridge_test.rb +9 -9
  171. data/test/bridges/date_picker_test.rb +3 -1
  172. data/test/bridges/paper_trail_test.rb +2 -3
  173. data/test/bridges/paperclip_test.rb +21 -10
  174. data/test/bridges/tiny_mce_test.rb +20 -21
  175. data/test/class_with_finder.rb +42 -0
  176. data/test/company.rb +6 -4
  177. data/test/config/core_test.rb +1 -1
  178. data/test/config/create_test.rb +1 -1
  179. data/test/config/list_test.rb +3 -3
  180. data/test/config/update_test.rb +3 -3
  181. data/test/data_structures/action_columns_test.rb +3 -3
  182. data/test/data_structures/association_column_test.rb +5 -5
  183. data/test/data_structures/column_test.rb +14 -14
  184. data/test/data_structures/columns_test.rb +2 -2
  185. data/test/data_structures/set_test.rb +2 -2
  186. data/test/data_structures/sorting_test.rb +6 -4
  187. data/test/extensions/active_record_test.rb +1 -1
  188. data/test/extensions/routing_mapper_test.rb +64 -13
  189. data/test/helpers/form_column_helpers_test.rb +6 -6
  190. data/test/helpers/list_column_helpers_test.rb +9 -5
  191. data/test/helpers/pagination_helpers_test.rb +1 -0
  192. data/test/misc/active_record_permissions_test.rb +18 -1
  193. data/test/misc/attribute_params_test.rb +26 -17
  194. data/test/misc/calculation_test.rb +8 -31
  195. data/test/misc/configurable_test.rb +3 -2
  196. data/test/misc/constraints_test.rb +33 -22
  197. data/test/misc/convert_numbers_format_test.rb +28 -10
  198. data/test/misc/finder_test.rb +6 -29
  199. data/test/misc/parse_datetime_test.rb +160 -0
  200. data/test/misc/render_test.rb +1 -1
  201. data/test/misc/tableless_test.rb +24 -0
  202. data/test/mock_app/app/models/building.rb +2 -1
  203. data/test/mock_app/config.ru +1 -1
  204. data/test/mock_app/config/environments/test.rb +1 -1
  205. data/test/mock_app/config/routes.rb +11 -3
  206. data/test/model_stub.rb +11 -6
  207. data/test/run_all.rb +1 -1
  208. data/test/test_helper.rb +19 -4
  209. metadata +42 -23
  210. data/lib/active_scaffold/data_structures/error_message.rb +0 -22
  211. data/lib/active_scaffold/extensions/reverse_associations.rb +0 -119
  212. data/lib/generators/active_scaffold/USAGE +0 -29
  213. data/lib/generators/active_scaffold/active_scaffold_generator.rb +0 -21
  214. data/lib/generators/active_scaffold_controller/USAGE +0 -19
  215. data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +0 -29
  216. data/test/data_structures/error_message_test.rb +0 -25
@@ -0,0 +1,56 @@
1
+ require 'rails/generators/rails/resource/resource_generator'
2
+ # require 'generators/active_scaffold_controller/active_scaffold_controller_generator'
3
+
4
+ module ActiveScaffold
5
+ module Generators
6
+ class ResourceGenerator < Rails::Generators::ResourceGenerator # metagenerator
7
+ remove_hook_for :resource_controller
8
+ remove_hook_for :resource_route
9
+ remove_class_option :actions
10
+
11
+ desc <<-DESC.strip_heredoc
12
+ Description:
13
+ Scaffolds an entire resource, from model and migration to controller,
14
+ along with a full test suite and configured to use active_scaffold.
15
+ The resource is ready to use as a starting point for your RESTful,
16
+ resource-oriented application.
17
+
18
+ Pass the name of the model (in singular form), either CamelCased or
19
+ under_scored, as the first argument, and an optional list of attribute
20
+ pairs.
21
+
22
+ Attribute pairs are field:type arguments specifying the
23
+ model's attributes. Timestamps are added by default, so you don't have to
24
+ specify them by hand as 'created_at:datetime updated_at:datetime'.
25
+
26
+ You don't have to think up every attribute up front, but it helps to
27
+ sketch out a few so you can start working with the resource immediately.
28
+
29
+ For example, 'active_scaffold post title:string body:text published:boolean'
30
+ gives you a model with those three attributes, a controller configured to use active_scaffold,
31
+ as well as a resources :posts with additional active_scaffold routes
32
+ declaration in config/routes.rb.
33
+
34
+ If you want to remove all the generated files, run
35
+ 'rails destroy active_scaffold ModelName'.
36
+
37
+ Examples:
38
+ `rails generate active_scaffold:resource post`
39
+ `rails generate active_scaffold:resource post title:string body:text published:boolean`
40
+ `rails generate active_scaffold:resource purchase order_id:integer amount:decimal`
41
+ DESC
42
+
43
+ def add_resource_route
44
+ routing_code = class_path.collect { |namespace| "namespace :#{namespace} do " }.join(' ')
45
+ routing_code << "resources :#{file_name.pluralize}, concerns: :active_scaffold"
46
+ routing_code << ' end' * class_path.size
47
+ log :route, routing_code
48
+ in_root do
49
+ inject_into_file 'config/routes.rb', " #{routing_code}\n", {after: /^[ ]*concern :active_scaffold,.*\n/, verbose: false, force: true}
50
+ end
51
+ end
52
+
53
+ invoke 'active_scaffold:controller'
54
+ end
55
+ end
56
+ end
@@ -61,7 +61,7 @@ class ActiveSupport::TestCase
61
61
  def self.should_render_as_form_hidden(column_name)
62
62
  before_block = lambda do
63
63
  @rendered_columns = []
64
- @controller.view_context_class.any_instance.expects(:"hidden_field").at_least_once.with do |_, method, _|
64
+ @controller.view_context_class.any_instance.expects(:hidden_field).at_least_once.with do |_, method, _|
65
65
  @rendered_columns << method
66
66
  true
67
67
  end
@@ -125,8 +125,8 @@ class ActiveSupport::TestCase
125
125
  script = block ? instance_eval(&block) : /.*/
126
126
  script = script.is_a?(Regexp) ? script.source : Regexp.quote(script)
127
127
  script = script.gsub('\n', '\\\\\\n')
128
- .gsub(/['"]/, '\\\\\\\\\&')
129
- .gsub('</script>', '</scr"+"ipt>')
128
+ .gsub(/['"]/, '\\\\\\\\\&')
129
+ .gsub('</script>', '</scr"+"ipt>')
130
130
  assert_select 'script[type=text/javascript]', Regexp.new('.*' + Regexp.quote("with(window.parent) { setTimeout(function() { window.eval('") + script + Regexp.quote("'); if (typeof(loc) !== 'undefined') loc.replace('about:blank'); }, 1) };") + '.*')
131
131
  end
132
132
  end
@@ -0,0 +1,33 @@
1
+ module ActiveScaffoldConfigMock
2
+ module ClassMethods
3
+ class Config
4
+ def active_record?
5
+ @type == :active_record
6
+ end
7
+
8
+ def mongoid?
9
+ @type == :mongoid
10
+ end
11
+
12
+ def initialize(type = :active_record)
13
+ @type = type
14
+ end
15
+
16
+ def primary_key
17
+ mongoid? ? '_id' : 'id'
18
+ end
19
+ end
20
+
21
+ def active_scaffold_config
22
+ @active_scaffold_config ||= Config.new
23
+ end
24
+ end
25
+
26
+ def self.included(klass)
27
+ klass.extend ClassMethods
28
+ end
29
+
30
+ def active_scaffold_config
31
+ self.class.active_scaffold_config
32
+ end
33
+ end
@@ -5,22 +5,21 @@ class BridgeTest < MiniTest::Test
5
5
  @const_store = {}
6
6
  end
7
7
 
8
- def teardown
9
- end
8
+ def teardown; end
10
9
 
11
10
  def test__shouldnt_throw_errors
12
11
  ActiveScaffold::Bridges.run_all
13
12
  end
14
13
 
15
14
  def test__cds_bridge
16
- js, ActiveScaffold.js_framework = ActiveScaffold.js_framework, :prototype
17
- ConstMocker.mock('CalendarDateSelect') do |cm|
18
- cm.remove
19
- assert(!bridge_will_be_installed('CalendarDateSelect'))
20
- cm.declare
21
- assert(bridge_will_be_installed('CalendarDateSelect'))
15
+ with_js_framework :prototype do
16
+ ConstMocker.mock('CalendarDateSelect') do |cm|
17
+ cm.remove
18
+ assert(!bridge_will_be_installed('CalendarDateSelect'))
19
+ cm.declare
20
+ assert(bridge_will_be_installed('CalendarDateSelect'))
21
+ end
22
22
  end
23
- ActiveScaffold.js_framework = js
24
23
  end
25
24
 
26
25
  def test__file_column_bridge
@@ -54,6 +53,7 @@ class BridgeTest < MiniTest::Test
54
53
  end
55
54
  end
56
55
  end
56
+ ActiveScaffold.js_framework = nil
57
57
  end
58
58
 
59
59
  def test__semantic_attributes_bridge
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
+ require 'active_scaffold_config_mock'
2
3
  require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/bridges/date_picker/ext')
3
4
  # require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/bridges/date_picker/helper')
4
5
 
@@ -9,13 +10,14 @@ class DatePickerTest < ActionView::TestCase
9
10
 
10
11
  def setup
11
12
  @controller.class.class_eval do
13
+ include ActiveScaffoldConfigMock
12
14
  include ActiveScaffold::Finder
13
15
  end
14
16
  end
15
17
 
16
18
  def test_set_form_ui
17
19
  config = ActiveScaffold::Config::Core.new(:company)
18
- assert_equal nil, config.columns[:name].form_ui, 'form_ui for name'
20
+ assert_nil config.columns[:name].form_ui, 'form_ui for name'
19
21
  assert_equal :date_picker, config.columns[:date].form_ui, 'form_ui for date'
20
22
  assert_equal :datetime_picker, config.columns[:datetime].form_ui, 'form_ui for datetime'
21
23
  end
@@ -7,9 +7,8 @@ class PaperTrailTest < ActionController::TestCase
7
7
  def test_deleted_route
8
8
  with_routing do |map|
9
9
  map.draw do
10
- resources :addresses do
11
- as_routes
12
- end
10
+ concern :active_scaffold, ActiveScaffold::Routing::Basic.new
11
+ resources :addresses, concerns: :active_scaffold
13
12
  end
14
13
  assert_routing '/addresses/deleted', :controller => 'addresses', :action => 'deleted'
15
14
  end
@@ -25,7 +25,7 @@ class PaperclipTest < ActionView::TestCase
25
25
  assert config.update.multipart?
26
26
  assert_equal :paperclip, config.columns[:logo].form_ui
27
27
  assert_equal [:delete_logo], config.columns[:logo].params.to_a
28
- %w(logo_file_name logo_file_size logo_updated_at logo_content_type).each do |attr|
28
+ %w[logo_file_name logo_file_size logo_updated_at logo_content_type].each do |attr|
29
29
  refute config.columns._inheritable.include?(attr.to_sym)
30
30
  end
31
31
  assert Company.method_defined?(:delete_logo)
@@ -55,16 +55,27 @@ class PaperclipTest < ActionView::TestCase
55
55
  end
56
56
 
57
57
  def test_form_ui
58
- js, ActiveScaffold.js_framework = ActiveScaffold.js_framework, :jquery
59
- config = PaperclipCore.new(:company)
60
- @record = Company.new
58
+ with_js_framework :jquery do
59
+ config = PaperclipCore.new(:company)
60
+ @record = Company.new
61
61
 
62
- @record.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => Company.attachment_definitions[:logo]))
63
- escaped_quote = Rails::VERSION::MAJOR < 4 ? '&#x27;' : '&#39;'
64
- assert_dom_equal %{<div><a href="/system/file" target="_blank">file</a> | <input name="record[delete_logo]" type="hidden" id="record_delete_logo" value="false" /><a href="#" onclick="jQuery(this).prev().val(#{escaped_quote}true#{escaped_quote}); jQuery(this).parent().hide().next().show(); return false;">Remove or Replace file</a></div><div style="display: none"><input name="record[logo]" class="text-input" autocomplete="off" type="file" id="record_logo" /></div>}, active_scaffold_input_paperclip(config.columns[:logo], :name => 'record[logo]', :id => 'record_logo', :object => @record)
62
+ @record.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => Company.attachment_definitions[:logo]))
63
+ quote = '&#39;'
64
+ click_js = "jQuery(this).prev().val(#{quote}true#{quote}); jQuery(this).parent().hide().next().show(); return false;"
65
+ change_js = "jQuery(this).parents(#{quote}div.paperclip_controls#{quote}).find(#{quote}input.remove_file#{quote}).val(#{quote}false#{quote}); return false;"
66
+ template = [
67
+ '<div class="paperclip_controls"><div>',
68
+ '<a href="/system/file" target="_blank">file</a> | ',
69
+ '<input name="record[delete_logo]" type="hidden" class="remove_file" id="record_delete_logo" value="false" />',
70
+ %(<a href="#" onclick="#{click_js}">Remove or Replace file</a>),
71
+ '</div><div style="display: none">',
72
+ %(<input name="record[logo]" class="text-input" autocomplete="off" type="file" id="record_logo" onchange="#{change_js}" />),
73
+ '</div></div>'
74
+ ].join
75
+ assert_dom_equal template, active_scaffold_input_paperclip(config.columns[:logo], :name => 'record[logo]', :id => 'record_logo', :object => @record)
65
76
 
66
- @record.stubs(:logo).returns(stub(:file? => false))
67
- assert_dom_equal '<input name="record[logo]" class="text-input" autocomplete="off" type="file" id="record_logo" />', active_scaffold_input_paperclip(config.columns[:logo], :name => 'record[logo]', :id => 'record_logo', :object => @record)
68
- ActiveScaffold.js_framework = js
77
+ @record.stubs(:logo).returns(stub(:file? => false))
78
+ assert_dom_equal '<input name="record[logo]" class="text-input" autocomplete="off" type="file" id="record_logo" />', active_scaffold_input_paperclip(config.columns[:logo], :name => 'record[logo]', :id => 'record_logo', :object => @record)
79
+ end
69
80
  end
70
81
  end
@@ -8,44 +8,43 @@ class TinyMceTest < ActionView::TestCase
8
8
  # configuration options from tinymce.yml
9
9
  #
10
10
  # [1]: https://github.com/spohlenz/tinymce-rails/blob/master/lib/tinymce/rails/helper.rb#L37
11
- def tinymce_configuration(config=:default)
12
- return case config
13
- when :default
14
- Class.new do
15
- def options
16
- {theme: 'modern'}
17
- end
18
- end.new
19
- when :alternate
20
- Class.new do
21
- def options
22
- {theme: 'alternate', toolbar: 'undo redo | format'}
23
- end
24
- end.new
25
- end
11
+ def tinymce_configuration(config = :default)
12
+ case config
13
+ when :default
14
+ Class.new do
15
+ def options
16
+ {theme: 'modern'}
17
+ end
18
+ end.new
19
+ when :alternate
20
+ Class.new do
21
+ def options
22
+ {theme: 'alternate', toolbar: 'undo redo | format'}
23
+ end
24
+ end.new
25
+ end
26
26
  end
27
27
 
28
28
  def test_includes
29
29
  ActiveScaffold::Bridges::TinyMce.expects(:install?).returns(true)
30
- ActiveScaffold.js_framework = :jquery
31
- assert ActiveScaffold::Bridges.all_javascripts.include?('tinymce-jquery')
30
+ with_js_framework :jquery do
31
+ assert ActiveScaffold::Bridges.all_javascripts.include?('tinymce-jquery')
32
+ end
32
33
  end
33
34
 
34
35
  def test_form_ui
35
36
  config = ActiveScaffold::Config::Core.new(:company)
36
37
  record = Company.new
37
- expects(:request).returns(stub(:xhr? => true))
38
38
 
39
- assert_dom_equal %{<textarea name=\"record[name]\" class=\"name-input mceEditor\" id=\"record_name\">\n</textarea>\n<script#{' type="text/javascript"' if Rails::VERSION::MAJOR < 4}>\n//<![CDATA[\ntinyMCE.settings = {\"theme\":\"modern\"};tinyMCE.execCommand('mceAddEditor', false, 'record_name');\n//]]>\n</script>}, active_scaffold_input_text_editor(config.columns[:name], :name => 'record[name]', :id => 'record_name', :class => 'name-input', :object => record)
39
+ assert_dom_equal %(<textarea name=\"record[name]\" class=\"name-input mceEditor\" id=\"record_name\" data-tinymce=\"{&quot;theme&quot;:&quot;modern&quot;}\">\n</textarea>), active_scaffold_input_text_editor(config.columns[:name], :name => 'record[name]', :id => 'record_name', :class => 'name-input', :object => record)
40
40
  end
41
41
 
42
42
  def test_form_ui_alternate
43
43
  config = ActiveScaffold::Config::Core.new(:company)
44
44
  record = Company.new
45
- expects(:request).returns(stub(:xhr? => true))
46
45
  config.columns[:name].options[:tinymce_config] = :alternate
47
46
 
48
- assert_dom_equal %{<textarea name=\"record[name]\" class=\"name-input mceEditor\" id=\"record_name\">\n</textarea>\n<script#{' type="text/javascript"' if Rails::VERSION::MAJOR < 4}>\n//<![CDATA[\ntinyMCE.settings = {\"theme\":\"alternate\",\"toolbar\":\"undo redo | format\"};tinyMCE.execCommand('mceAddEditor', false, 'record_name');\n//]]>\n</script>}, active_scaffold_input_tinymce(config.columns[:name], :name => 'record[name]', :id => 'record_name', :class => 'name-input', :object => record)
47
+ assert_dom_equal %(<textarea name=\"record[name]\" class=\"name-input mceEditor\" id=\"record_name\" data-tinymce=\"{&quot;theme&quot;:&quot;alternate&quot;,&quot;toolbar&quot;:&quot;undo redo | format&quot;}\">\n</textarea>), active_scaffold_input_tinymce(config.columns[:name], :name => 'record[name]', :id => 'record_name', :class => 'name-input', :object => record)
49
48
  end
50
49
 
51
50
  protected
@@ -0,0 +1,42 @@
1
+ require 'active_scaffold_config_mock'
2
+
3
+ class ClassWithFinder
4
+ include ActiveScaffoldConfigMock
5
+ include ActiveScaffold::Finder
6
+
7
+ def active_scaffold_config
8
+ self.class.active_scaffold_config
9
+ end
10
+
11
+ def conditions_for_collection; end
12
+
13
+ def conditions_from_params; end
14
+
15
+ def conditions_from_constraints; end
16
+
17
+ def active_scaffold_embedded_params
18
+ {}
19
+ end
20
+
21
+ def params_hash(v)
22
+ v
23
+ end
24
+
25
+ def joins_for_collection; end
26
+
27
+ def custom_finder_options
28
+ {}
29
+ end
30
+
31
+ def beginning_of_chain
32
+ active_scaffold_config.model
33
+ end
34
+
35
+ def conditional_get_support?; end
36
+
37
+ def params; {}; end
38
+
39
+ def grouped_search?
40
+ false
41
+ end
42
+ end
@@ -9,7 +9,7 @@ class Company < ActiveRecord::Base
9
9
  end
10
10
 
11
11
  def self.columns_hash
12
- {
12
+ @columns_hash ||= {
13
13
  'name' => ColumnMock.new('name', nil, 'varchar(255)'),
14
14
  'date' => ColumnMock.new('date', nil, 'date'),
15
15
  'datetime' => ColumnMock.new('datetime', nil, 'datetime'),
@@ -49,16 +49,18 @@ class Company < ActiveRecord::Base
49
49
  end
50
50
  else
51
51
  def self.create_reflection(*args)
52
- ActiveRecord::Reflection.create *args
52
+ ActiveRecord::Reflection.create(*args)
53
53
  end
54
54
  end
55
55
 
56
56
  def self.has_many(association_id, options = {})
57
57
  create_reflection(:has_many, association_id, nil, options, self)
58
58
  end
59
+
59
60
  def self.has_one(association_id, options = {})
60
61
  create_reflection(:has_one, association_id, nil, options, self)
61
62
  end
63
+
62
64
  def self.belongs_to(association_id, options = {})
63
65
  create_reflection(:belongs_to, association_id, nil, options, self)
64
66
  end
@@ -86,10 +88,10 @@ class Company < ActiveRecord::Base
86
88
  def name_came_from_user?; end
87
89
 
88
90
  def date
89
- Date.today
91
+ Time.zone.today
90
92
  end
91
93
 
92
94
  def datetime
93
- Time.now
95
+ Time.zone.now
94
96
  end
95
97
  end
@@ -13,7 +13,7 @@ module Config
13
13
  def test_default_options
14
14
  refute @config.add_sti_create_links?
15
15
  refute @config.sti_children
16
- assert_equal [:create, :list, :search, :update, :delete, :show, :nested, :subform], @config.actions.to_a
16
+ assert_equal %i[create list search update delete show nested subform], @config.actions.to_a
17
17
  assert_equal :default, @config.frontend
18
18
  assert_equal :default, @config.theme
19
19
  assert_equal 'Model stub', @config.label(:count => 1)
@@ -12,7 +12,7 @@ module Config
12
12
  end
13
13
 
14
14
  def test_default_columns
15
- assert_equal [:a, :d, :other_model, :other_models], @config.create.columns.names
15
+ assert_equal %i[a d other_model other_models], @config.create.columns.names
16
16
  end
17
17
 
18
18
  def test_default_options
@@ -21,7 +21,7 @@ module Config
21
21
  assert_equal '-', @config.list.empty_field_text
22
22
  assert_equal ', ', @config.list.association_join_text
23
23
  assert_equal true, @config.list.pagination
24
- assert_equal nil, @config.list.search_partial
24
+ assert_nil @config.list.search_partial
25
25
  assert_equal :no_entries, @config.list.no_entries_message
26
26
  assert_equal :filtered, @config.list.filtered_message
27
27
  refute @config.list.always_show_create
@@ -127,8 +127,8 @@ module Config
127
127
  end
128
128
 
129
129
  def test_count_includes
130
- @config.list.count_includes = [:assoc_1, :assoc_2]
131
- assert_equal [:assoc_1, :assoc_2], @config.list.count_includes
130
+ @config.list.count_includes = %i[assoc_1 assoc_2]
131
+ assert_equal %i[assoc_1 assoc_2], @config.list.count_includes
132
132
  end
133
133
  end
134
134
  end
@@ -7,11 +7,11 @@ module Config
7
7
  end
8
8
 
9
9
  def test_copy_columns_from_create
10
- @config.create.columns = [:a, :c, :d]
11
- assert_equal [:a, :d], @config.create.columns.names
10
+ @config.create.columns = %i[a c d]
11
+ assert_equal %i[a d], @config.create.columns.names
12
12
  @config.update.columns = @config.create.columns
13
13
  @config._load_action_columns
14
- assert_equal [:a, :c, :d], @config.update.columns.names
14
+ assert_equal %i[a c d], @config.update.columns.names
15
15
  end
16
16
 
17
17
  def test__params_for_columns__returns_all_params
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
 
5
5
  class ActionColumnsTest < MiniTest::Test
6
6
  def setup
7
- @columns = ActiveScaffold::DataStructures::ActionColumns.new([:a, :b])
7
+ @columns = ActiveScaffold::DataStructures::ActionColumns.new(%i[a b])
8
8
  @columns.action = stub(:core => stub(:model_id => 'model_stub'))
9
9
  end
10
10
 
@@ -35,7 +35,7 @@ class ActionColumnsTest < MiniTest::Test
35
35
  def test_exclude_array
36
36
  # exclude with a symbol
37
37
  assert @columns.include?(:b)
38
- @columns.exclude [:a, :b]
38
+ @columns.exclude %i[a b]
39
39
  refute @columns.include?(:b)
40
40
  refute @columns.include?(:a)
41
41
  end
@@ -58,7 +58,7 @@ class ActionColumnsTest < MiniTest::Test
58
58
 
59
59
  # try adding an array of columns
60
60
  refute @columns.include?(:f)
61
- @columns.add [:f, :g]
61
+ @columns.add %i[f g]
62
62
  assert @columns.include?(:f)
63
63
  assert @columns.include?(:g)
64
64
  end