active_scaffold 3.3.3 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +39 -0
  3. data/README.md +5 -3
  4. data/app/assets/images/active_scaffold/refresh.png +0 -0
  5. data/app/assets/javascripts/jquery/active_scaffold.js +182 -91
  6. data/app/assets/javascripts/jquery/date_picker_bridge.js.erb +14 -16
  7. data/app/assets/javascripts/jquery/draggable_lists.js +33 -26
  8. data/app/assets/javascripts/jquery/jquery.editinplace.js +3 -3
  9. data/app/assets/javascripts/prototype/active_scaffold.js +61 -19
  10. data/app/assets/stylesheets/active_scaffold_colors.css.scss +4 -0
  11. data/app/assets/stylesheets/active_scaffold_images.css.scss +3 -0
  12. data/app/assets/stylesheets/active_scaffold_layout.css +23 -2
  13. data/app/views/active_scaffold_overrides/_add_existing_form.html.erb +1 -3
  14. data/app/views/active_scaffold_overrides/_base_form.html.erb +7 -5
  15. data/app/views/active_scaffold_overrides/_field_search.html.erb +1 -2
  16. data/app/views/active_scaffold_overrides/_form.html.erb +6 -4
  17. data/app/views/active_scaffold_overrides/_form_association.html.erb +4 -3
  18. data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +5 -5
  19. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +8 -6
  20. data/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +3 -2
  21. data/app/views/active_scaffold_overrides/_list.html.erb +8 -6
  22. data/app/views/active_scaffold_overrides/_list_column_headings.html.erb +1 -4
  23. data/app/views/active_scaffold_overrides/_list_pagination.html.erb +4 -4
  24. data/app/views/active_scaffold_overrides/_list_pagination_links.html.erb +1 -1
  25. data/app/views/active_scaffold_overrides/_list_record.html.erb +3 -3
  26. data/app/views/active_scaffold_overrides/_refresh_list.js.erb +8 -1
  27. data/app/views/active_scaffold_overrides/_search.html.erb +7 -13
  28. data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
  29. data/app/views/active_scaffold_overrides/on_create.js.erb +4 -4
  30. data/app/views/active_scaffold_overrides/render_field_inplace.html.erb +1 -1
  31. data/app/views/active_scaffold_overrides/row.js.erb +1 -1
  32. data/config/locales/de.yml +106 -95
  33. data/config/locales/en.yml +108 -97
  34. data/config/locales/es.yml +109 -98
  35. data/config/locales/fr.yml +108 -97
  36. data/config/locales/hu.yml +109 -98
  37. data/config/locales/ja.yml +100 -89
  38. data/config/locales/ru.yml +115 -104
  39. data/lib/active_scaffold.rb +18 -294
  40. data/lib/active_scaffold/actions/common_search.rb +50 -17
  41. data/lib/active_scaffold/actions/core.rb +93 -22
  42. data/lib/active_scaffold/actions/create.rb +15 -6
  43. data/lib/active_scaffold/actions/field_search.rb +68 -60
  44. data/lib/active_scaffold/actions/list.rb +49 -28
  45. data/lib/active_scaffold/actions/nested.rb +14 -6
  46. data/lib/active_scaffold/actions/search.rb +36 -35
  47. data/lib/active_scaffold/actions/show.rb +9 -4
  48. data/lib/active_scaffold/actions/subform.rb +1 -1
  49. data/lib/active_scaffold/actions/update.rb +22 -7
  50. data/lib/active_scaffold/active_record_permissions.rb +125 -118
  51. data/lib/active_scaffold/attribute_params.rb +84 -66
  52. data/lib/active_scaffold/bridges.rb +3 -3
  53. data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +10 -5
  54. data/lib/active_scaffold/bridges/cancan.rb +2 -1
  55. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +13 -2
  56. data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +11 -6
  57. data/lib/active_scaffold/bridges/chosen/helpers.rb +2 -2
  58. data/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb +45 -29
  59. data/lib/active_scaffold/bridges/date_picker/ext.rb +11 -6
  60. data/lib/active_scaffold/bridges/date_picker/helper.rb +5 -1
  61. data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +10 -5
  62. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +6 -1
  63. data/lib/active_scaffold/bridges/file_column/form_ui.rb +12 -11
  64. data/lib/active_scaffold/bridges/paperclip/form_ui.rb +14 -6
  65. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
  66. data/lib/active_scaffold/bridges/record_select/helpers.rb +15 -12
  67. data/lib/active_scaffold/bridges/shared/date_bridge.rb +7 -8
  68. data/lib/active_scaffold/bridges/tiny_mce.rb +5 -3
  69. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +4 -5
  70. data/lib/active_scaffold/config/base.rb +4 -0
  71. data/lib/active_scaffold/config/core.rb +12 -5
  72. data/lib/active_scaffold/config/delete.rb +0 -2
  73. data/lib/active_scaffold/config/field_search.rb +1 -4
  74. data/lib/active_scaffold/config/form.rb +0 -2
  75. data/lib/active_scaffold/config/list.rb +31 -1
  76. data/lib/active_scaffold/config/search.rb +0 -3
  77. data/lib/active_scaffold/config/show.rb +0 -6
  78. data/lib/active_scaffold/config/subform.rb +1 -0
  79. data/lib/active_scaffold/configurable.rb +2 -2
  80. data/lib/active_scaffold/constraints.rb +11 -14
  81. data/lib/active_scaffold/core.rb +277 -0
  82. data/lib/active_scaffold/data_structures/action_columns.rb +18 -2
  83. data/lib/active_scaffold/data_structures/action_link.rb +25 -6
  84. data/lib/active_scaffold/data_structures/action_links.rb +9 -4
  85. data/lib/active_scaffold/data_structures/actions.rb +1 -1
  86. data/lib/active_scaffold/data_structures/column.rb +6 -6
  87. data/lib/active_scaffold/data_structures/columns.rb +2 -2
  88. data/lib/active_scaffold/data_structures/nested_info.rb +5 -1
  89. data/lib/active_scaffold/data_structures/sorting.rb +15 -5
  90. data/lib/active_scaffold/delayed_setup.rb +30 -0
  91. data/lib/active_scaffold/engine.rb +25 -0
  92. data/lib/active_scaffold/extensions/action_view_rendering.rb +1 -1
  93. data/lib/active_scaffold/extensions/left_outer_joins.rb +61 -21
  94. data/lib/active_scaffold/extensions/localize.rb +1 -1
  95. data/lib/active_scaffold/extensions/name_option_for_datetime.rb +13 -8
  96. data/lib/active_scaffold/extensions/paginator_extensions.rb +5 -1
  97. data/lib/active_scaffold/extensions/reverse_associations.rb +1 -0
  98. data/lib/active_scaffold/extensions/routing_mapper.rb +1 -1
  99. data/lib/active_scaffold/extensions/unsaved_record.rb +4 -6
  100. data/lib/active_scaffold/finder.rb +79 -27
  101. data/lib/active_scaffold/helpers/association_helpers.rb +48 -18
  102. data/lib/active_scaffold/helpers/controller_helpers.rb +19 -10
  103. data/lib/active_scaffold/helpers/form_column_helpers.rb +185 -87
  104. data/lib/active_scaffold/helpers/human_condition_helpers.rb +2 -1
  105. data/lib/active_scaffold/helpers/id_helpers.rb +14 -8
  106. data/lib/active_scaffold/helpers/list_column_helpers.rb +65 -56
  107. data/lib/active_scaffold/helpers/pagination_helpers.rb +5 -1
  108. data/lib/active_scaffold/helpers/search_column_helpers.rb +21 -18
  109. data/lib/active_scaffold/helpers/view_helpers.rb +102 -64
  110. data/lib/active_scaffold/responds_to_parent.rb +39 -64
  111. data/lib/active_scaffold/tableless.rb +129 -10
  112. data/lib/active_scaffold/version.rb +2 -2
  113. data/test/bridges/bridge_test.rb +1 -1
  114. data/test/bridges/date_picker_test.rb +2 -2
  115. data/test/bridges/paperclip_test.rb +10 -8
  116. data/test/bridges/tiny_mce_test.rb +2 -2
  117. data/test/company.rb +22 -10
  118. data/test/config/base_test.rb +1 -1
  119. data/test/config/core_test.rb +8 -6
  120. data/test/config/create_test.rb +6 -6
  121. data/test/config/delete_test.rb +4 -4
  122. data/test/config/field_search_test.rb +6 -6
  123. data/test/config/list_test.rb +7 -7
  124. data/test/config/nested_test.rb +8 -7
  125. data/test/config/search_test.rb +7 -7
  126. data/test/config/show_test.rb +5 -5
  127. data/test/config/subform_test.rb +1 -1
  128. data/test/config/update_test.rb +5 -4
  129. data/test/data_structures/action_columns_test.rb +15 -16
  130. data/test/data_structures/action_link_test.rb +10 -10
  131. data/test/data_structures/action_links_test.rb +6 -6
  132. data/test/data_structures/actions_test.rb +4 -4
  133. data/test/data_structures/association_column_test.rb +4 -4
  134. data/test/data_structures/column_test.rb +9 -9
  135. data/test/data_structures/columns_test.rb +7 -7
  136. data/test/data_structures/error_message_test.rb +2 -4
  137. data/test/data_structures/set_test.rb +13 -13
  138. data/test/data_structures/sorting_test.rb +8 -8
  139. data/test/data_structures/standard_column_test.rb +2 -2
  140. data/test/data_structures/validation_reflection_test.rb +8 -8
  141. data/test/data_structures/virtual_column_test.rb +5 -5
  142. data/test/extensions/active_record_test.rb +1 -1
  143. data/test/helpers/form_column_helpers_test.rb +5 -5
  144. data/test/helpers/list_column_helpers_test.rb +2 -1
  145. data/test/helpers/pagination_helpers_test.rb +1 -1
  146. data/test/misc/active_record_permissions_test.rb +23 -4
  147. data/test/misc/attribute_params_test.rb +304 -136
  148. data/test/misc/calculation_test.rb +55 -0
  149. data/test/misc/configurable_test.rb +22 -21
  150. data/test/misc/constraints_test.rb +10 -7
  151. data/test/misc/convert_numbers_format_test.rb +149 -0
  152. data/test/misc/finder_test.rb +17 -13
  153. data/test/misc/lang_test.rb +1 -1
  154. data/test/misc/tableless_test.rb +18 -0
  155. data/test/mock_app/app/controllers/addresses_controller.rb +4 -0
  156. data/test/mock_app/app/controllers/buildings_controller.rb +4 -0
  157. data/test/mock_app/app/controllers/cars_controller.rb +4 -0
  158. data/test/mock_app/app/controllers/contacts_controller.rb +4 -0
  159. data/test/mock_app/app/controllers/floors_controller.rb +6 -0
  160. data/test/mock_app/app/controllers/people_controller.rb +4 -0
  161. data/test/mock_app/app/models/address.rb +3 -0
  162. data/test/mock_app/app/models/building.rb +8 -0
  163. data/test/mock_app/app/models/car.rb +3 -0
  164. data/test/mock_app/app/models/contact.rb +3 -0
  165. data/test/mock_app/app/models/file_model.rb +19 -0
  166. data/test/mock_app/app/models/floor.rb +8 -0
  167. data/test/mock_app/app/models/person.rb +11 -0
  168. data/test/mock_app/config/application.rb +2 -0
  169. data/test/mock_app/config/environments/test.rb +1 -1
  170. data/test/mock_app/config/initializers/secret_token.rb +5 -1
  171. data/test/mock_app/config/routes.rb +1 -1
  172. data/test/mock_app/db/schema.rb +51 -0
  173. data/test/model_stub.rb +3 -3
  174. data/test/test_helper.rb +15 -12
  175. metadata +51 -50
  176. data/lib/active_scaffold/extensions/array.rb +0 -7
  177. data/lib/active_scaffold/extensions/cache_association.rb +0 -16
  178. data/lib/active_scaffold/extensions/usa_state.rb +0 -46
  179. data/lib/active_scaffold_env.rb +0 -13
  180. data/test/extensions/array_test.rb +0 -12
  181. data/test/mock_app/public/blank.html +0 -33
  182. data/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT +0 -2
  183. data/test/mock_app/public/images/active_scaffold/default/add.gif +0 -0
  184. data/test/mock_app/public/images/active_scaffold/default/arrow_down.gif +0 -0
  185. data/test/mock_app/public/images/active_scaffold/default/arrow_up.gif +0 -0
  186. data/test/mock_app/public/images/active_scaffold/default/close.gif +0 -0
  187. data/test/mock_app/public/images/active_scaffold/default/cross.png +0 -0
  188. data/test/mock_app/public/images/active_scaffold/default/indicator-small.gif +0 -0
  189. data/test/mock_app/public/images/active_scaffold/default/indicator.gif +0 -0
  190. data/test/mock_app/public/images/active_scaffold/default/magnifier.png +0 -0
  191. data/test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT +0 -2
  192. data/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +0 -532
  193. data/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +0 -867
  194. data/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js +0 -117
  195. data/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js +0 -370
  196. data/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT +0 -2
  197. data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css +0 -35
  198. data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +0 -848
@@ -1,70 +1,45 @@
1
- # Copyright (c) 2006 Sean Treadway
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining
4
- # a copy of this software and associated documentation files (the
5
- # "Software"), to deal in the Software without restriction, including
6
- # without limitation the rights to use, copy, modify, merge, publish,
7
- # distribute, sublicense, and/or sell copies of the Software, and to
8
- # permit persons to whom the Software is furnished to do so, subject to
9
- # the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be
12
- # included in all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ module ActiveScaffold
2
+ # Module containing the methods useful for child IFRAME to parent window communication
3
+ module RespondsToParent
4
+ # Executes the response body as JavaScript in the context of the parent window.
5
+ # Use this method of you are posting a form to a hidden IFRAME or if you would like
6
+ # to use IFRAME base RPC.
7
+ def responds_to_parent(&block)
8
+ yield
21
9
 
10
+ if performed?
11
+ # Either pull out a redirect or the request body
12
+ script = if response.headers['Location']
13
+ #TODO: erase_redirect_results is missing in rails 3.0
14
+ "document.location.href = '#{self.class.helpers.escape_javascript location.to_s}'"
15
+ else
16
+ response.body || ''
17
+ end
22
18
 
23
- # Module containing the methods useful for child IFRAME to parent window communication
24
- module RespondsToParent
25
-
26
- # Executes the response body as JavaScript in the context of the parent window.
27
- # Use this method of you are posting a form to a hidden IFRAME or if you would like
28
- # to use IFRAME base RPC.
29
- def responds_to_parent(&block)
30
- yield
31
-
32
- if performed?
33
- # We're returning HTML instead of JS or XML now
34
- response.headers['Content-Type'] = 'text/html; charset=UTF-8'
35
-
36
- # Either pull out a redirect or the request body
37
- script = if response.headers['Location']
38
- #TODO: erase_redirect_results is missing in rails 3.0 has to be implemented
39
- #erase redirect
40
- "document.location.href = #{location.to_s.inspect}"
41
- else
42
- response.body
43
- end
44
-
45
- # Escape quotes, linebreaks and slashes, maintaining previously escaped slashes
46
- # Suggestions for improvement?
47
- script = (script || '').
48
- gsub('\\', '\\\\\\').
49
- gsub(/\r\n|\r|\n/, '\\n').
50
- gsub(/['"]/, '\\\\\&').
51
- gsub('</script>','</scr"+"ipt>')
19
+ # Eval in parent scope and replace document location of this frame
20
+ # so back button doesn't replay action on targeted forms
21
+ # loc = document.location to be set after parent is updated for IE
22
+ # with(window.parent) - pull in variables from parent window
23
+ # setTimeout - scope the execution in the windows parent for safari
24
+ # window.eval - legal eval for Opera
25
+ script = "<html><body><script type='text/javascript' charset='utf-8'>
26
+ var loc = document.location;
27
+ with(window.parent) { setTimeout(function() { window.eval('#{self.class.helpers.escape_javascript script}'); window.loc && loc.replace('about:blank'); }, 1) }
28
+ </script></body></html>"
52
29
 
53
- # Clear out the previous render to prevent double render
54
- response.request.env['action_controller.instance'].instance_variable_set(:@_response_body, nil)
55
-
56
- # Eval in parent scope and replace document location of this frame
57
- # so back button doesn't replay action on targeted forms
58
- # loc = document.location to be set after parent is updated for IE
59
- # with(window.parent) - pull in variables from parent window
60
- # setTimeout - scope the execution in the windows parent for safari
61
- # window.eval - legal eval for Opera
62
- render :text => "<html><body><script type='text/javascript' charset='utf-8'>
63
- var loc = document.location;
64
- with(window.parent) { setTimeout(function() { window.eval('#{script}'); if (typeof(loc) !== 'undefined') loc.replace('about:blank'); }, 1) };
65
- </script></body></html>".html_safe
30
+ # We're returning HTML instead of JS or XML now
31
+ response.headers['Content-Type'] = 'text/html; charset=UTF-8'
32
+
33
+ # Clear out the previous render to prevent double render and then render
34
+ if respond_to?(:erase_results, true)
35
+ erase_results
36
+ else
37
+ instance_variable_set(:@_response_body, nil)
38
+ end
39
+
40
+ render :text => script
41
+ end
66
42
  end
43
+ alias respond_to_parent responds_to_parent
67
44
  end
68
- alias respond_to_parent responds_to_parent
69
45
  end
70
-
@@ -1,13 +1,99 @@
1
1
  class ActiveScaffold::Tableless < ActiveRecord::Base
2
- class Relation < ActiveRecord::Relation
3
- attr_reader :conditions
2
+ class AssociationScope < ActiveRecord::Associations::AssociationScope
3
+ def column_for(table_name, column_name, alias_tracker = nil)
4
+ klass = alias_tracker ? alias_tracker.connection.klass : self.klass
5
+ if table_name == klass.table_name
6
+ klass.columns_hash[column_name]
7
+ else
8
+ super
9
+ end
10
+ end
11
+
12
+ if defined?(ActiveRecord::Associations::AssociationScope::INSTANCE) # rails >= 4.1
13
+ INSTANCE = respond_to?(:create) ? create : new # create for rails >= 4.2
14
+ def self.scope(association, connection)
15
+ INSTANCE.scope association, connection
16
+ end
17
+ end
18
+ end
19
+
20
+ class Connection < ActiveRecord::ConnectionAdapters::AbstractAdapter
21
+ attr_reader :klass
22
+ def initialize(klass, *args)
23
+ super(nil, *args)
24
+ @klass = klass
25
+ end
26
+ end
27
+
28
+ class Column < ActiveRecord::ConnectionAdapters::Column
29
+ def initialize(name, default, sql_type = nil, null = true)
30
+ if defined?(ActiveRecord::ConnectionAdapters::Type) # rails >= 4.2
31
+ cast_type = ActiveRecord::Base.connection.send :lookup_cast_type, sql_type
32
+ super(name, default, cast_type, sql_type, null)
33
+ else # rails < 4.2
34
+ super
35
+ end
36
+ end
37
+ end
38
+
39
+ module Association
40
+ def self.included(base)
41
+ base.alias_method_chain :association_scope, :tableless
42
+ base.alias_method_chain :target_scope, :tableless
43
+ end
44
+
45
+ def association_scope_with_tableless
46
+ @association_scope ||= overrided_association_scope if klass < ActiveScaffold::Tableless
47
+ association_scope_without_tableless
48
+ end
49
+
50
+ def overrided_association_scope
51
+ if AssociationScope.respond_to?(:scope) # rails >= 4.1
52
+ AssociationScope.scope(self, klass.connection)
53
+ else # rails < 4.1
54
+ AssociationScope.new(self).scope
55
+ end
56
+ end
57
+
58
+ def target_scope_with_tableless
59
+ target_scope_without_tableless.tap do |scope|
60
+ if klass < ActiveScaffold::Tableless
61
+ class << scope; include RelationExtension; end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ module CollectionAssociation
68
+ def self.included(base)
69
+ base.alias_method_chain :get_records, :tableless if Rails.version >= '4.2'
70
+ end
71
+ def get_records_with_tableless
72
+ klass < ActiveScaffold::Tableless ? scope.to_a : get_records_without_tableless
73
+ end
74
+ end
75
+
76
+ module SingularAssociation
77
+ def self.included(base)
78
+ base.alias_method_chain :get_records, :tableless if Rails.version >= '4.2'
79
+ end
80
+ def get_records_with_tableless
81
+ klass < ActiveScaffold::Tableless ? scope.limit(1).to_a : get_records_without_tableless
82
+ end
83
+ end
84
+
85
+ module RelationExtension
86
+ def conditions
87
+ @conditions
88
+ end
89
+
4
90
  def initialize(klass, table)
5
91
  super
6
92
  @conditions ||= []
7
93
  end
8
94
 
9
95
  def initialize_copy(other)
10
- @conditions = @conditions.dup
96
+ @conditions = @conditions.try(:dup) || []
11
97
  super
12
98
  end
13
99
 
@@ -44,10 +130,9 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
44
130
  end
45
131
  end
46
132
 
47
- def self.columns; @columns ||= []; end
48
- def self.table_name; @table_name ||= ActiveModel::Naming.plural(self); end
49
- def self.table_exists?; true; end
50
- self.abstract_class = true
133
+ class Relation < ActiveRecord::Relation
134
+ include RelationExtension
135
+ end
51
136
  class << self
52
137
  private
53
138
  def relation
@@ -55,8 +140,40 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
55
140
  end
56
141
  end
57
142
 
143
+ class StatementCache
144
+ def initialize(key)
145
+ @key = key
146
+ end
147
+
148
+ def execute(values, model, connection)
149
+ model.where(@key => values)
150
+ end
151
+ end
152
+
153
+ unless Rails.version < '4.2'
154
+ def self.columns_hash
155
+ if self < ActiveScaffold::Tableless
156
+ @columns_hash ||= Hash[self.columns.map { |c| [c.name, c] }]
157
+ else
158
+ super
159
+ end
160
+ end
161
+ def self.initialize_find_by_cache
162
+ self.find_by_statement_cache = Hash.new { |h, k| h[k] = StatementCache.new(k) }
163
+ end
164
+ end
165
+
166
+ def self.columns; @columns ||= []; end
167
+ def self.table_name; @table_name ||= ActiveModel::Naming.plural(self); end
168
+ def self.table_exists?; true; end
169
+ self.abstract_class = true
170
+
171
+ def self.connection
172
+ @connection ||= Connection.new(self)
173
+ end
174
+
58
175
  def self.column(name, sql_type = nil, options = {})
59
- column = ActiveRecord::ConnectionAdapters::Column.new(name.to_s, options[:default], sql_type.to_s, options.has_key?(:null) ? options[:null] : true)
176
+ column = Column.new(name.to_s, options[:default], sql_type.to_s, options.has_key?(:null) ? options[:null] : true)
60
177
  column.tap { columns << column }
61
178
  end
62
179
 
@@ -80,11 +197,13 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
80
197
  raise 'destroy must be implemented in a Tableless model'
81
198
  end
82
199
 
83
- def create #:nodoc:
200
+ def create_record #:nodoc:
84
201
  run_callbacks(:create) {}
85
202
  end
203
+ alias_method :create, :create_record # for rails3
86
204
 
87
- def update(*) #:nodoc:
205
+ def update_record(*) #:nodoc:
88
206
  run_callbacks(:update) {}
89
207
  end
208
+ alias_method :update, :update_record # for rails3
90
209
  end
@@ -1,8 +1,8 @@
1
1
  module ActiveScaffold
2
2
  module Version
3
3
  MAJOR = 3
4
- MINOR = 3
5
- PATCH = 3
4
+ MINOR = 4
5
+ PATCH = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class BridgeTest < Test::Unit::TestCase
3
+ class BridgeTest < MiniTest::Test
4
4
  def setup
5
5
  @const_store = {}
6
6
  end
@@ -23,7 +23,7 @@ class DatePickerTest < ActionView::TestCase
23
23
  def test_form_ui
24
24
  config = ActiveScaffold::Config::Core.new(:company)
25
25
  @record = Company.new
26
- assert active_scaffold_input_date_picker(config.columns[:date], :name => 'record[date]', :id => 'record_date')
27
- assert active_scaffold_input_date_picker(config.columns[:datetime], :name => 'record[datetime]', :id => 'record_datetime')
26
+ assert active_scaffold_input_date_picker(config.columns[:date], :name => 'record[date]', :id => 'record_date', :object => @record)
27
+ assert active_scaffold_input_date_picker(config.columns[:datetime], :name => 'record[datetime]', :id => 'record_datetime', :object => @record)
28
28
  end
29
29
  end
@@ -14,9 +14,9 @@ class PaperclipTest < ActionView::TestCase
14
14
  def test_initialization_without_paperclip
15
15
  Company.expects(:attachment_definitions)
16
16
  config = PaperclipCore.new(:company)
17
- assert !config.create.multipart?
18
- assert !config.update.multipart?
19
- assert !config.columns.any? {|column| column.form_ui == :paperclip}
17
+ refute config.create.multipart?
18
+ refute config.update.multipart?
19
+ refute config.columns.any? {|column| column.form_ui == :paperclip}
20
20
  end
21
21
 
22
22
  def test_initialization
@@ -26,7 +26,7 @@ class PaperclipTest < ActionView::TestCase
26
26
  assert_equal :paperclip, config.columns[:logo].form_ui
27
27
  assert_equal [:delete_logo], config.columns[:logo].params.to_a
28
28
  %w(logo_file_name logo_file_size logo_updated_at logo_content_type).each do |attr|
29
- assert !config.columns._inheritable.include?(attr.to_sym)
29
+ refute config.columns._inheritable.include?(attr.to_sym)
30
30
  end
31
31
  assert Company.method_defined?(:delete_logo)
32
32
  assert Company.method_defined?(:'delete_logo=')
@@ -48,20 +48,22 @@ class PaperclipTest < ActionView::TestCase
48
48
  company = Company.new
49
49
 
50
50
  company.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => Company.attachment_definitions[:logo]))
51
- assert_dom_equal '<a href="/system/file" data-popup="true" target="_blank">file</a>', active_scaffold_column_paperclip(company, config.columns[:logo])
51
+ assert_dom_equal '<a href="/system/file" target="_blank">file</a>', active_scaffold_column_paperclip(company, config.columns[:logo])
52
52
 
53
53
  company.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => {:thumbnail => '40x40'}))
54
- assert_dom_equal '<a href="/system/file" data-popup="true" target="_blank"><img src="/system/file" border="0" alt="File"/></a>', active_scaffold_column_paperclip(company, config.columns[:logo])
54
+ assert_dom_equal '<a href="/system/file" target="_blank"><img src="/system/file" border="0" alt="File"/></a>', active_scaffold_column_paperclip(company, config.columns[:logo])
55
55
  end
56
56
 
57
57
  def test_form_ui
58
+ js, ActiveScaffold.js_framework = ActiveScaffold.js_framework, :jquery
58
59
  config = PaperclipCore.new(:company)
59
60
  @record = Company.new
60
61
 
61
62
  @record.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => Company.attachment_definitions[:logo]))
62
- assert_dom_equal '<div><a href="/system/file" data-popup="true" target="_blank">file</a> | <input name="record[delete_logo]" type="hidden" id="record_delete_logo" value="false" /><a href="#" onclick="$(this).prev().val(&#x27;true&#x27;); $(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')
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)
63
65
 
64
66
  @record.stubs(:logo).returns(stub(:file? => false))
65
- 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')
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)
66
68
  end
67
69
  end
@@ -1,5 +1,4 @@
1
1
  require 'test_helper'
2
- require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/bridges/tiny_mce/helpers')
3
2
 
4
3
  class TinyMceTest < ActionView::TestCase
5
4
  include ActiveScaffold::Helpers::ViewHelpers
@@ -7,6 +6,7 @@ class TinyMceTest < ActionView::TestCase
7
6
 
8
7
  def test_includes
9
8
  ActiveScaffold::Bridges::TinyMce.expects(:install?).returns(true)
9
+ ActiveScaffold.js_framework = :jquery
10
10
  assert ActiveScaffold::Bridges.all_javascripts.include?("tinymce-jquery")
11
11
  end
12
12
 
@@ -15,7 +15,7 @@ class TinyMceTest < ActionView::TestCase
15
15
  @record = Company.new
16
16
  self.expects(:request).returns(stub(:xhr? => true))
17
17
 
18
- assert_dom_equal "<textarea name=\"record[name]\" class=\"name-input mceEditor\" id=\"record_name\">\n</textarea>\n<script type=\"text/javascript\">\n//<![CDATA[\ntinyMCE.settings = {\"theme\":\"simple\"};tinyMCE.execCommand('mceAddControl', 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)
18
+ 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\":\"simple\"};tinyMCE.execCommand('mceAddControl', 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)
19
19
  end
20
20
 
21
21
  protected
@@ -9,13 +9,13 @@ class Company < ActiveRecord::Base
9
9
 
10
10
  def self.columns_hash
11
11
  {
12
- 'name' => ActiveRecord::ConnectionAdapters::Column.new('name', nil, 'varchar(255)'),
13
- 'date' => ActiveRecord::ConnectionAdapters::Column.new('date', nil, 'date'),
14
- 'datetime' => ActiveRecord::ConnectionAdapters::Column.new('datetime', nil, 'datetime'),
15
- 'logo_file_name' => ActiveRecord::ConnectionAdapters::Column.new('logo_file_name', nil, 'varchar(255)'),
16
- 'logo_content_type' => ActiveRecord::ConnectionAdapters::Column.new('logo_content_type', nil, 'varchar(255)'),
17
- 'logo_file_size' => ActiveRecord::ConnectionAdapters::Column.new('logo_file_size', nil, 'int(11)'),
18
- 'logo_updated_at' => ActiveRecord::ConnectionAdapters::Column.new('logo_updated_at', nil, 'datetime'),
12
+ 'name' => ColumnMock.new('name', nil, 'varchar(255)'),
13
+ 'date' => ColumnMock.new('date', nil, 'date'),
14
+ 'datetime' => ColumnMock.new('datetime', nil, 'datetime'),
15
+ 'logo_file_name' => ColumnMock.new('logo_file_name', nil, 'varchar(255)'),
16
+ 'logo_content_type' => ColumnMock.new('logo_content_type', nil, 'varchar(255)'),
17
+ 'logo_file_size' => ColumnMock.new('logo_file_size', nil, 'int(11)'),
18
+ 'logo_updated_at' => ColumnMock.new('logo_updated_at', nil, 'datetime'),
19
19
  }
20
20
  end
21
21
 
@@ -39,15 +39,27 @@ class Company < ActiveRecord::Base
39
39
  def self.before_destroy(s=nil)
40
40
  @@before = s
41
41
  end
42
+
43
+ if respond_to?(:create_reflection)
44
+ if method(:create_reflection).arity == 4
45
+ def self.create_reflection(macro, name, scope, options, active_record)
46
+ super(macro, name, options, active_record)
47
+ end
48
+ end
49
+ else
50
+ def self.create_reflection(*args)
51
+ ActiveRecord::Reflection.create *args
52
+ end
53
+ end
42
54
 
43
55
  def self.has_many(association_id, options = {})
44
- reflection = create_reflection(:has_many, association_id, options, self)
56
+ reflection = create_reflection(:has_many, association_id, nil, options, self)
45
57
  end
46
58
  def self.has_one(association_id, options = {})
47
- reflection = create_reflection(:has_one, association_id, options, self)
59
+ reflection = create_reflection(:has_one, association_id, nil, options, self)
48
60
  end
49
61
  def self.belongs_to(association_id, options = {})
50
- reflection = create_reflection(:belongs_to, association_id, options, self)
62
+ reflection = create_reflection(:belongs_to, association_id, nil, options, self)
51
63
  end
52
64
  has_many :companies
53
65
  has_one :company
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Config
4
- class BaseTest < Test::Unit::TestCase
4
+ class BaseTest < MiniTest::Test
5
5
  def setup
6
6
  @base = ActiveScaffold::Config::Base.new(ActiveScaffold::Config::Core.new(:model_stub))
7
7
  end
@@ -1,16 +1,18 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Config
4
- class CoreTest < Test::Unit::TestCase
5
- class ModelStubsController < ActionController::Base; end
4
+ class CoreTest < MiniTest::Test
5
+ class ModelStubsController < ActionController::Base
6
+ include ActiveScaffold::Core
7
+ end
6
8
  def setup
7
9
  @config = ActiveScaffold::Config::Core.new :model_stub
8
10
  ModelStubsController.instance_variable_set :@active_scaffold_config, @config
9
11
  end
10
12
 
11
13
  def test_default_options
12
- assert !@config.add_sti_create_links?
13
- assert !@config.sti_children
14
+ refute @config.add_sti_create_links?
15
+ refute @config.sti_children
14
16
  assert_equal [:create, :list, :search, :update, :delete, :show, :nested, :subform], @config.actions.to_a
15
17
  assert_equal :default, @config.frontend
16
18
  assert_equal :default, @config.theme
@@ -20,7 +22,7 @@ module Config
20
22
 
21
23
  def test_add_sti_children
22
24
  @config.sti_create_links = true
23
- assert !@config.add_sti_create_links?
25
+ refute @config.add_sti_create_links?
24
26
  @config.sti_children = [:a]
25
27
  assert @config.add_sti_create_links?
26
28
  end
@@ -33,7 +35,7 @@ module Config
33
35
  def test_actions
34
36
  assert @config.actions.include?(:create)
35
37
  @config.actions = [:list]
36
- assert !@config.actions.include?(:create)
38
+ refute @config.actions.include?(:create)
37
39
  assert_equal [:list], @config.actions.to_a
38
40
  end
39
41