active_scaffold 3.4.17 → 3.4.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +12 -1
  3. data/README.md +8 -4
  4. data/app/assets/javascripts/jquery/active_scaffold.js +82 -67
  5. data/app/assets/stylesheets/active_scaffold.scss +1 -1
  6. data/app/assets/stylesheets/active_scaffold_colors.scss +1 -1
  7. data/app/assets/stylesheets/blue-theme.css +1 -1
  8. data/app/views/active_scaffold_overrides/_form_association.html.erb +3 -3
  9. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +3 -3
  10. data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
  11. data/lib/active_scaffold.rb +16 -16
  12. data/lib/active_scaffold/actions/common_search.rb +13 -11
  13. data/lib/active_scaffold/actions/core.rb +85 -78
  14. data/lib/active_scaffold/actions/create.rb +29 -28
  15. data/lib/active_scaffold/actions/delete.rb +17 -17
  16. data/lib/active_scaffold/actions/field_search.rb +18 -19
  17. data/lib/active_scaffold/actions/list.rb +30 -22
  18. data/lib/active_scaffold/actions/mark.rb +1 -1
  19. data/lib/active_scaffold/actions/nested.rb +78 -65
  20. data/lib/active_scaffold/actions/search.rb +13 -10
  21. data/lib/active_scaffold/actions/show.rb +10 -6
  22. data/lib/active_scaffold/actions/subform.rb +1 -2
  23. data/lib/active_scaffold/actions/update.rb +39 -31
  24. data/lib/active_scaffold/active_record_permissions.rb +14 -15
  25. data/lib/active_scaffold/attribute_params.rb +42 -43
  26. data/lib/active_scaffold/bridges.rb +22 -12
  27. data/lib/active_scaffold/bridges/ancestry.rb +1 -1
  28. data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +6 -6
  29. data/lib/active_scaffold/bridges/bitfields.rb +1 -1
  30. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +12 -13
  31. data/lib/active_scaffold/bridges/calendar_date_select.rb +5 -5
  32. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +17 -20
  33. data/lib/active_scaffold/bridges/cancan.rb +1 -1
  34. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +8 -9
  35. data/lib/active_scaffold/bridges/carrierwave.rb +4 -4
  36. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +9 -8
  37. data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +11 -10
  38. data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +7 -6
  39. data/lib/active_scaffold/bridges/chosen.rb +1 -1
  40. data/lib/active_scaffold/bridges/chosen/helpers.rb +4 -4
  41. data/lib/active_scaffold/bridges/country_helper.rb +1 -1
  42. data/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb +259 -260
  43. data/lib/active_scaffold/bridges/date_picker.rb +2 -2
  44. data/lib/active_scaffold/bridges/date_picker/ext.rb +9 -11
  45. data/lib/active_scaffold/bridges/date_picker/helper.rb +61 -67
  46. data/lib/active_scaffold/bridges/dragonfly.rb +4 -4
  47. data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +9 -8
  48. data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +11 -10
  49. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +6 -5
  50. data/lib/active_scaffold/bridges/file_column.rb +5 -5
  51. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +20 -23
  52. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +20 -23
  53. data/lib/active_scaffold/bridges/file_column/form_ui.rb +13 -14
  54. data/lib/active_scaffold/bridges/file_column/list_ui.rb +7 -8
  55. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +18 -22
  56. data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +5 -4
  57. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +2 -10
  58. data/lib/active_scaffold/bridges/paper_trail.rb +7 -5
  59. data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +4 -3
  60. data/lib/active_scaffold/bridges/paperclip.rb +5 -5
  61. data/lib/active_scaffold/bridges/paperclip/form_ui.rb +11 -10
  62. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +6 -5
  63. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +10 -9
  64. data/lib/active_scaffold/bridges/record_select.rb +1 -1
  65. data/lib/active_scaffold/bridges/record_select/helpers.rb +28 -28
  66. data/lib/active_scaffold/bridges/semantic_attributes.rb +1 -1
  67. data/lib/active_scaffold/bridges/semantic_attributes/column.rb +1 -1
  68. data/lib/active_scaffold/bridges/shared/date_bridge.rb +58 -52
  69. data/lib/active_scaffold/bridges/tiny_mce.rb +2 -2
  70. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -3
  71. data/lib/active_scaffold/config/base.rb +9 -10
  72. data/lib/active_scaffold/config/core.rb +24 -29
  73. data/lib/active_scaffold/config/create.rb +0 -1
  74. data/lib/active_scaffold/config/field_search.rb +8 -10
  75. data/lib/active_scaffold/config/form.rb +5 -5
  76. data/lib/active_scaffold/config/list.rb +21 -20
  77. data/lib/active_scaffold/config/mark.rb +3 -3
  78. data/lib/active_scaffold/config/nested.rb +11 -10
  79. data/lib/active_scaffold/config/search.rb +2 -3
  80. data/lib/active_scaffold/config/show.rb +1 -1
  81. data/lib/active_scaffold/config/update.rb +1 -2
  82. data/lib/active_scaffold/configurable.rb +9 -11
  83. data/lib/active_scaffold/constraints.rb +9 -8
  84. data/lib/active_scaffold/core.rb +72 -84
  85. data/lib/active_scaffold/data_structures/action_columns.rb +26 -25
  86. data/lib/active_scaffold/data_structures/action_link.rb +43 -43
  87. data/lib/active_scaffold/data_structures/action_links.rb +17 -15
  88. data/lib/active_scaffold/data_structures/actions.rb +5 -5
  89. data/lib/active_scaffold/data_structures/bridge.rb +6 -3
  90. data/lib/active_scaffold/data_structures/column.rb +110 -89
  91. data/lib/active_scaffold/data_structures/columns.rb +3 -3
  92. data/lib/active_scaffold/data_structures/error_message.rb +4 -6
  93. data/lib/active_scaffold/data_structures/nested_info.rb +43 -48
  94. data/lib/active_scaffold/data_structures/set.rb +7 -8
  95. data/lib/active_scaffold/data_structures/sorting.rb +38 -33
  96. data/lib/active_scaffold/delayed_setup.rb +5 -6
  97. data/lib/active_scaffold/engine.rb +4 -4
  98. data/lib/active_scaffold/extensions/action_controller_rendering.rb +3 -4
  99. data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -1
  100. data/lib/active_scaffold/extensions/action_view_rendering.rb +5 -6
  101. data/lib/active_scaffold/extensions/left_outer_joins.rb +11 -11
  102. data/lib/active_scaffold/extensions/localize.rb +1 -1
  103. data/lib/active_scaffold/extensions/name_option_for_datetime.rb +1 -1
  104. data/lib/active_scaffold/extensions/paginator_extensions.rb +2 -5
  105. data/lib/active_scaffold/extensions/reverse_associations.rb +13 -13
  106. data/lib/active_scaffold/extensions/routing_mapper.rb +9 -9
  107. data/lib/active_scaffold/extensions/unsaved_associated.rb +9 -9
  108. data/lib/active_scaffold/finder.rb +90 -93
  109. data/lib/active_scaffold/helpers/association_helpers.rb +5 -5
  110. data/lib/active_scaffold/helpers/controller_helpers.rb +22 -19
  111. data/lib/active_scaffold/helpers/form_column_helpers.rb +115 -105
  112. data/lib/active_scaffold/helpers/human_condition_helpers.rb +62 -35
  113. data/lib/active_scaffold/helpers/id_helpers.rb +6 -6
  114. data/lib/active_scaffold/helpers/list_column_helpers.rb +89 -94
  115. data/lib/active_scaffold/helpers/pagination_helpers.rb +9 -9
  116. data/lib/active_scaffold/helpers/search_column_helpers.rb +47 -44
  117. data/lib/active_scaffold/helpers/show_column_helpers.rb +2 -2
  118. data/lib/active_scaffold/helpers/view_helpers.rb +86 -91
  119. data/lib/active_scaffold/marked_model.rb +10 -10
  120. data/lib/active_scaffold/paginator.rb +30 -34
  121. data/lib/active_scaffold/responds_to_parent.rb +27 -28
  122. data/lib/active_scaffold/tableless.rb +20 -15
  123. data/lib/active_scaffold/version.rb +1 -1
  124. data/lib/generators/active_scaffold/active_scaffold_generator.rb +8 -8
  125. data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +9 -9
  126. data/shoulda_macros/macros.rb +27 -22
  127. data/test/bridges/bridge_test.rb +38 -29
  128. data/test/bridges/date_picker_test.rb +1 -1
  129. data/test/bridges/paper_trail_test.rb +17 -0
  130. data/test/bridges/paperclip_test.rb +3 -2
  131. data/test/bridges/tiny_mce_test.rb +5 -2
  132. data/test/company.rb +25 -30
  133. data/test/config/base_test.rb +1 -1
  134. data/test/config/core_test.rb +9 -9
  135. data/test/config/create_test.rb +14 -8
  136. data/test/config/delete_test.rb +4 -4
  137. data/test/config/field_search_test.rb +6 -6
  138. data/test/config/list_test.rb +16 -16
  139. data/test/config/nested_test.rb +4 -4
  140. data/test/config/search_test.rb +8 -8
  141. data/test/config/show_test.rb +6 -6
  142. data/test/config/subform_test.rb +1 -1
  143. data/test/config/update_test.rb +5 -5
  144. data/test/const_mocker.rb +4 -4
  145. data/test/data_structures/action_columns_test.rb +4 -5
  146. data/test/data_structures/action_link_test.rb +1 -0
  147. data/test/data_structures/action_links_test.rb +5 -5
  148. data/test/data_structures/column_test.rb +9 -9
  149. data/test/data_structures/columns_test.rb +2 -2
  150. data/test/data_structures/error_message_test.rb +4 -5
  151. data/test/data_structures/set_test.rb +1 -2
  152. data/test/data_structures/sorting_test.rb +10 -10
  153. data/test/data_structures/validation_reflection_test.rb +8 -0
  154. data/test/extensions/routing_mapper_test.rb +2 -2
  155. data/test/helpers/list_column_helpers_test.rb +3 -2
  156. data/test/helpers/pagination_helpers_test.rb +5 -4
  157. data/test/helpers/search_column_helpers_test.rb +1 -1
  158. data/test/misc/active_record_permissions_test.rb +63 -50
  159. data/test/misc/attribute_params_test.rb +28 -26
  160. data/test/misc/calculation_test.rb +10 -3
  161. data/test/misc/configurable_test.rb +12 -13
  162. data/test/misc/constraints_test.rb +6 -6
  163. data/test/misc/convert_numbers_format_test.rb +7 -6
  164. data/test/misc/finder_test.rb +17 -12
  165. data/test/misc/lang_test.rb +3 -4
  166. data/test/misc/tableless_test.rb +2 -3
  167. data/test/mock_app/app/controllers/addresses_controller.rb +1 -1
  168. data/test/mock_app/app/controllers/buildings_controller.rb +1 -1
  169. data/test/mock_app/app/controllers/cars_controller.rb +1 -1
  170. data/test/mock_app/app/controllers/contacts_controller.rb +1 -1
  171. data/test/mock_app/app/controllers/people_controller.rb +1 -1
  172. data/test/mock_app/app/models/file_model.rb +2 -2
  173. data/test/mock_app/app/models/person.rb +1 -1
  174. data/test/mock_app/config/application.rb +3 -3
  175. data/test/mock_app/config/boot.rb +1 -1
  176. data/test/mock_app/config/environment.rb +1 -0
  177. data/test/mock_app/config/environments/development.rb +0 -1
  178. data/test/mock_app/config/environments/production.rb +1 -1
  179. data/test/mock_app/db/schema.rb +14 -15
  180. data/test/model_stub.rb +13 -16
  181. data/test/run_all.rb +5 -7
  182. data/test/test_helper.rb +12 -9
  183. metadata +19 -3
@@ -9,25 +9,25 @@ module ActiveScaffold::DataStructures
9
9
 
10
10
  def set_values(*args)
11
11
  @set = []
12
- self.add *args
12
+ add *args
13
13
  end
14
14
 
15
15
  # the way to add items to the set.
16
16
  def add(*args)
17
17
  args.flatten! # allow [] as a param
18
- args.each { |arg|
18
+ args.each do |arg|
19
19
  arg = arg.to_sym if arg.is_a? String
20
20
  @set << arg unless @set.include? arg # avoid duplicates
21
- }
21
+ end
22
22
  end
23
23
  alias_method :<<, :add
24
24
 
25
25
  # the way to remove items from the set.
26
26
  def exclude(*args)
27
27
  args.flatten! # allow [] as a param
28
- args.collect! { |a| a.to_sym } # symbolize the args
28
+ args.collect!(&:to_sym) # symbolize the args
29
29
  # check respond_to? :to_sym, ActionColumns doesn't respond to to_sym
30
- @set.reject! { |c| c.respond_to? :to_sym and args.include? c.to_sym } # reject all items specified
30
+ @set.reject! { |c| c.respond_to?(:to_sym) && args.include?(c.to_sym) } # reject all items specified
31
31
  end
32
32
  alias_method :remove, :exclude
33
33
 
@@ -45,17 +45,16 @@ module ActiveScaffold::DataStructures
45
45
  alias_method :[], :find_by_name
46
46
 
47
47
  def each
48
- @set.each {|i| yield i }
48
+ @set.each { |i| yield i }
49
49
  end
50
50
 
51
51
  # returns the number of items in the set
52
52
  def length
53
53
  @set.length
54
54
  end
55
-
55
+
56
56
  def empty?
57
57
  @set.empty?
58
58
  end
59
-
60
59
  end
61
60
  end
@@ -4,43 +4,37 @@ module ActiveScaffold::DataStructures
4
4
  include Enumerable
5
5
 
6
6
  attr_accessor :constraint_columns
7
- attr_accessor :sorting_by_primary_key
7
+ attr_accessor :sorting_by_primary_key # enabled by default for postgres
8
8
 
9
9
  def initialize(columns)
10
10
  @columns = columns
11
11
  @clauses = []
12
12
  @constraint_columns = []
13
13
  end
14
-
15
- def set_default_sorting(model)
16
- model_scope = model.send(:build_default_scope)
17
- order_clause = model_scope.order_values.join(",") if model_scope
18
14
 
15
+ def set_default_sorting(model)
19
16
  # fallback to setting primary key ordering
20
- if model.column_names.include?(model.primary_key)
21
- set([model.primary_key, 'ASC'])
22
- @primary_key_clause = clause
23
- @sorting_by_primary_key = model.connection.try(:adapter_name) == 'PostgreSQL' # mandatory for postgres, so enabled by default
24
- end
17
+ setup_primary_key_order_clause(model)
18
+ model_scope = model.send(:build_default_scope)
19
+ order_clause = model_scope.order_values.join(',') if model_scope
20
+ return unless order_clause
25
21
  # If an ORDER BY clause is found set default sorting according to it
26
- if order_clause
27
- set_sorting_from_order_clause(order_clause, model.table_name)
28
- @default_sorting = true
29
- end
22
+ set_sorting_from_order_clause(order_clause, model.table_name)
23
+ @default_sorting = true
30
24
  end
31
25
 
32
26
  def set_nested_sorting(table_name, order_clause)
33
27
  clear
34
28
  set_sorting_from_order_clause(order_clause, table_name)
35
29
  end
36
-
30
+
37
31
  # add a clause to the sorting, assuming the column is sortable
38
32
  def add(column_name, direction = nil)
39
33
  direction ||= 'ASC'
40
34
  direction = direction.to_s.upcase
41
35
  column = get_column(column_name)
42
36
  raise ArgumentError, "Could not find column #{column_name}" if column.nil?
43
- raise ArgumentError, "Sorting direction unknown" unless [:ASC, :DESC].include? direction.to_sym
37
+ raise ArgumentError, 'Sorting direction unknown' unless [:ASC, :DESC].include? direction.to_sym
44
38
  @clauses << [column, direction.untaint] if column.sortable?
45
39
  raise ArgumentError, "Can't mix :method- and :sql-based sorting" if mixed_sorting?
46
40
  end
@@ -59,7 +53,7 @@ module ActiveScaffold::DataStructures
59
53
  clear
60
54
  if args.first.is_a?(Enumerable)
61
55
  args.each do |h|
62
- h.is_a?(Hash) ? h.each { |c,d| add(c,d) } : add(*h)
56
+ h.is_a?(Hash) ? h.each { |c, d| add(c, d) } : add(*h)
63
57
  end
64
58
  else
65
59
  add(*args)
@@ -83,8 +77,8 @@ module ActiveScaffold::DataStructures
83
77
  clause[1]
84
78
  end
85
79
 
86
- SORTING_STAGES = Hash[%w(reset ASC DESC reset).each_cons(2).map{|a|a}].freeze
87
- DEFAULT_SORTING_STAGES = Hash[%w(ASC DESC ASC).each_cons(2).map{|a|a}].freeze
80
+ SORTING_STAGES = Hash[%w(reset ASC DESC reset).each_cons(2).to_a].freeze
81
+ DEFAULT_SORTING_STAGES = Hash[%w(ASC DESC ASC).each_cons(2).to_a].freeze
88
82
  def next_sorting_of(column, sorted_by_default)
89
83
  stages = sorted_by_default ? DEFAULT_SORTING_STAGES : SORTING_STAGES
90
84
  stages[direction_of(column)] || 'ASC'
@@ -92,11 +86,11 @@ module ActiveScaffold::DataStructures
92
86
 
93
87
  # checks whether any column is configured to sort by method (using a proc)
94
88
  def sorts_by_method?
95
- @clauses.any? { |sorting| sorting[0].sort.is_a? Hash and sorting[0].sort.has_key? :method }
89
+ @clauses.any? { |sorting| sorting[0].sort.is_a?(Hash) && sorting[0].sort.key?(:method) }
96
90
  end
97
91
 
98
92
  def sorts_by_sql?
99
- @clauses.any? { |sorting| sorting[0].sort.is_a? Hash and sorting[0].sort.has_key? :sql }
93
+ @clauses.any? { |sorting| sorting[0].sort.is_a?(Hash) && sorting[0].sort.key?(:sql) }
100
94
  end
101
95
 
102
96
  # iterate over the clauses
@@ -118,12 +112,12 @@ module ActiveScaffold::DataStructures
118
112
  each do |sort_column, sort_direction|
119
113
  next if constraint_columns.include? sort_column.name
120
114
  sql = sort_column.sort[:sql]
121
- next if sql.nil? or sql.empty?
115
+ next if sql.nil? || sql.empty?
122
116
 
123
- order << Array(sql).map {|column| "#{column} #{sort_direction}"}.join(', ')
117
+ order << Array(sql).map { |column| "#{column} #{sort_direction}" }.join(', ')
124
118
  end
125
119
 
126
- order << @primary_key_clause if @sorting_by_primary_key
120
+ order << @primary_key_order_clause if @sorting_by_primary_key
127
121
  order unless order.empty?
128
122
  end
129
123
 
@@ -132,7 +126,7 @@ module ActiveScaffold::DataStructures
132
126
  # retrieves the sorting clause for the given column
133
127
  def get_clause(column)
134
128
  column = get_column(column)
135
- @clauses.find{ |clause| clause[0] == column}
129
+ @clauses.find { |clause| clause[0] == column }
136
130
  end
137
131
 
138
132
  # possibly converts the given argument into a column object from @columns (if it's not already)
@@ -141,13 +135,13 @@ module ActiveScaffold::DataStructures
141
135
  return name_or_column if name_or_column.is_a? ActiveScaffold::DataStructures::Column
142
136
  # it's a name
143
137
  name_or_column = name_or_column.to_s.split('.').last if name_or_column.to_s.include? '.'
144
- return @columns[name_or_column]
138
+ @columns[name_or_column]
145
139
  end
146
140
 
147
141
  def mixed_sorting?
148
- sorts_by_method? and sorts_by_sql?
142
+ sorts_by_method? && sorts_by_sql?
149
143
  end
150
-
144
+
151
145
  def default_sorting?
152
146
  @default_sorting
153
147
  end
@@ -161,20 +155,20 @@ module ActiveScaffold::DataStructures
161
155
  end
162
156
  end
163
157
  end
164
-
158
+
165
159
  def extract_order_parts(criterion_parts)
166
160
  column_name_part, direction_part = criterion_parts.strip.split(' ')
167
161
  column_name_parts = column_name_part.split('.')
168
162
  order = {:direction => extract_direction(direction_part),
169
- :column_name => remove_quotes(column_name_parts.last)}
163
+ :column_name => remove_quotes(column_name_parts.last)}
170
164
  order[:table_name] = remove_quotes(column_name_parts[-2]) if column_name_parts.length >= 2
171
165
  order
172
166
  end
173
-
167
+
174
168
  def different_table?(model_table_name, order_table_name)
175
169
  !order_table_name.nil? && model_table_name != order_table_name
176
170
  end
177
-
171
+
178
172
  def remove_quotes(sql_name)
179
173
  if sql_name.starts_with?('"') || sql_name.starts_with?('`')
180
174
  sql_name[1, (sql_name.length - 2)]
@@ -182,7 +176,7 @@ module ActiveScaffold::DataStructures
182
176
  sql_name
183
177
  end
184
178
  end
185
-
179
+
186
180
  def extract_direction(direction_part)
187
181
  if direction_part.to_s.upcase == 'DESC'
188
182
  'DESC'
@@ -190,5 +184,16 @@ module ActiveScaffold::DataStructures
190
184
  'ASC'
191
185
  end
192
186
  end
187
+
188
+ def postgres?(model)
189
+ model.connection.try(:adapter_name) == 'PostgreSQL'
190
+ end
191
+
192
+ def setup_primary_key_order_clause(model)
193
+ return unless model.column_names.include?(model.primary_key)
194
+ set([model.primary_key, 'ASC'])
195
+ @primary_key_order_clause = clause
196
+ @sorting_by_primary_key = postgres?(model) # mandatory for postgres, so enabled by default
197
+ end
193
198
  end
194
199
  end
@@ -8,17 +8,16 @@ module ActiveScaffold
8
8
  self.class.config_active_scaffold_delayed
9
9
  super
10
10
  end
11
-
11
+
12
12
  module ClassMethods
13
13
  def active_scaffold(model_id = nil, &block)
14
- @active_scaffold_delayed = proc{ super(model_id, &block) }
14
+ @active_scaffold_delayed = proc { super(model_id, &block) }
15
15
  end
16
16
 
17
17
  def config_active_scaffold_delayed
18
- if @active_scaffold_delayed
19
- block, @active_scaffold_delayed = @active_scaffold_delayed, nil
20
- block.call
21
- end
18
+ return unless @active_scaffold_delayed
19
+ block, @active_scaffold_delayed = @active_scaffold_delayed, nil
20
+ block.call
22
21
  end
23
22
 
24
23
  def active_scaffold_config
@@ -1,22 +1,23 @@
1
1
  module ActiveScaffold
2
2
  class Engine < ::Rails::Engine
3
- initializer "active_scaffold.action_controller" do |app|
3
+ initializer 'active_scaffold.action_controller' do
4
4
  ActiveSupport.on_load :action_controller do
5
5
  include ActiveScaffold::Core
6
6
  include ActiveScaffold::DelayedSetup if ActiveScaffold.delayed_setup
7
7
  include ActiveScaffold::RespondsToParent
8
8
  include ActiveScaffold::Helpers::ControllerHelpers
9
9
  include ActiveScaffold::ActiveRecordPermissions::ModelUserAccess::Controller
10
+ ActiveScaffold::Bridges.prepare_all
10
11
  end
11
12
  end
12
13
 
13
- initializer "active_scaffold.action_view" do |app|
14
+ initializer 'active_scaffold.action_view' do
14
15
  ActiveSupport.on_load :action_view do
15
16
  include ActiveScaffold::Helpers::ViewHelpers
16
17
  end
17
18
  end
18
19
 
19
- initializer "active_scaffold.active_record" do |app|
20
+ initializer 'active_scaffold.active_record' do
20
21
  ActiveSupport.on_load :active_record do
21
22
  include ActiveScaffold::ActiveRecordPermissions::ModelUserAccess::Model
22
23
  ActiveRecord::Associations::Association.send :include, ActiveScaffold::Tableless::Association
@@ -24,6 +25,5 @@ module ActiveScaffold
24
25
  ActiveRecord::Associations::SingularAssociation.send :include, ActiveScaffold::Tableless::SingularAssociation
25
26
  end
26
27
  end
27
-
28
28
  end
29
29
  end
@@ -2,12 +2,12 @@
2
2
  module ActionController #:nodoc:
3
3
  class Base
4
4
  def render_with_active_scaffold(*args, &block)
5
- if self.class.uses_active_scaffold? and params[:adapter] and @rendering_adapter.nil? and request.xhr?
5
+ if self.class.uses_active_scaffold? && params[:adapter] && @rendering_adapter.nil? && request.xhr?
6
6
  @rendering_adapter = true # recursion control
7
7
  # if we need an adapter, then we render the actual stuff to a string and insert it into the adapter template
8
- opts = args.blank? ? Hash.new : args.first
8
+ opts = args.blank? ? {} : args.first
9
9
  render :partial => params[:adapter][1..-1],
10
- :locals => {:payload => render_to_string(opts.merge(:layout => false), &block).html_safe},
10
+ :locals => {:payload => render_to_string(opts.merge(:layout => false), &block).html_safe},
11
11
  :use_full_path => true, :layout => false, :content_type => :html
12
12
  @rendering_adapter = nil # recursion control
13
13
  else
@@ -17,4 +17,3 @@ module ActionController #:nodoc:
17
17
  alias_method_chain :render, :active_scaffold
18
18
  end
19
19
  end
20
-
@@ -2,7 +2,7 @@ module ActionController #:nodoc:
2
2
  class Base
3
3
  # adding to ActionController::Base so it can overrided in ApplicationController
4
4
  def deny_access
5
- head :unauthorized
5
+ head :forbidden # better for action or record not allowed, according to RFC 7231
6
6
  end
7
7
  end
8
8
  end
@@ -1,7 +1,7 @@
1
1
  module ActionView
2
2
  class LookupContext
3
3
  attr_accessor :last_template
4
-
4
+
5
5
  def find_template_with_last_template(name, prefixes = [], partial = false, keys = [], options = {})
6
6
  self.last_template = find_template_without_last_template(name, prefixes, partial, keys, options)
7
7
  end
@@ -35,7 +35,7 @@ module ActionView::Helpers #:nodoc:
35
35
  # Defining options[:label] lets you completely customize the list title for the embedded scaffold.
36
36
  #
37
37
  def render_with_active_scaffold(*args, &block)
38
- if args.first.is_a? Hash and args.first[:active_scaffold]
38
+ if args.first.is_a?(Hash) && args.first[:active_scaffold]
39
39
  require 'digest/md5'
40
40
  options = args.first
41
41
 
@@ -45,7 +45,7 @@ module ActionView::Helpers #:nodoc:
45
45
  eid = Digest::MD5.hexdigest(params[:controller] + remote_controller.to_s + constraints.to_s + conditions.to_s)
46
46
  eid_info = session["as:#{eid}"] ||= {}
47
47
  if constraints
48
- eid_info['constraints'] = constraints
48
+ eid_info['constraints'] = constraints
49
49
  else
50
50
  eid_info.delete 'constraints'
51
51
  end
@@ -99,7 +99,7 @@ module ActionView::Helpers #:nodoc:
99
99
  else
100
100
  options[:prefixes] = ['active_scaffold_overrides']
101
101
  last_view_path = File.expand_path(File.dirname(File.dirname(lookup_context.last_template.inspect)), Rails.root)
102
- lookup_context.view_paths = view_paths.drop(view_paths.find_index {|path| path.to_s == last_view_path} + 1)
102
+ lookup_context.view_paths = view_paths.drop(view_paths.find_index { |path| path.to_s == last_view_path } + 1)
103
103
  end
104
104
  result = render_without_active_scaffold options
105
105
  lookup_context.view_paths = @_view_paths if @_view_paths
@@ -121,10 +121,9 @@ module ActionView::Helpers #:nodoc:
121
121
  end
122
122
  end
123
123
  alias_method_chain :render, :active_scaffold
124
-
124
+
125
125
  def view_stack
126
126
  @_view_stack ||= []
127
127
  end
128
-
129
128
  end
130
129
  end
@@ -14,7 +14,7 @@ module ActiveScaffold
14
14
  relation = clone
15
15
 
16
16
  args.flatten!
17
- relation.joins_values += [''] # HACK for using outer_joins in update_all/delete_all
17
+ relation.joins_values += [''] # HACK: for using outer_joins in update_all/delete_all
18
18
  relation.outer_joins_values += args
19
19
 
20
20
  relation
@@ -30,12 +30,12 @@ module ActiveScaffold
30
30
  end
31
31
 
32
32
  def outer_joins(*args)
33
- check_if_method_has_arguments!("outer_joins", args)
33
+ check_if_method_has_arguments!('outer_joins', args)
34
34
  spawn.outer_joins!(*args.compact.flatten)
35
35
  end
36
36
 
37
37
  def outer_joins!(*args)
38
- self.joins_values += [''] # HACK for using outer_joins in update_all/delete_all
38
+ self.joins_values += [''] # HACK: for using outer_joins in update_all/delete_all
39
39
  self.outer_joins_values += args
40
40
  self
41
41
  end
@@ -43,25 +43,25 @@ module ActiveScaffold
43
43
 
44
44
  if Rails.version < '4.1'
45
45
  def build_arel
46
- unless outer_joins_values.empty?
47
- relation = self.except(:outer_joins)
46
+ if outer_joins_values.empty?
47
+ super
48
+ else
49
+ relation = except(:outer_joins)
48
50
  join_dependency = ActiveRecord::Associations::JoinDependency.new(@klass, outer_joins_values, [])
49
51
  join_dependency.join_associations.each do |association|
50
52
  relation = association.join_relation(relation)
51
53
  end
52
54
  relation.build_arel
53
- else
54
- super
55
55
  end
56
56
  end
57
57
  else
58
58
  def build_arel
59
- unless outer_joins_values.empty?
60
- relation = self.except(:outer_joins)
59
+ if outer_joins_values.empty?
60
+ super
61
+ else
62
+ relation = except(:outer_joins)
61
63
  relation.joins! ActiveRecord::Associations::JoinDependency.new(@klass, outer_joins_values, [])
62
64
  relation.build_arel
63
- else
64
- super
65
65
  end
66
66
  end
67
67
  end
@@ -4,7 +4,7 @@ class Object
4
4
  text = I18n.translate("#{key}", {:scope => [:active_scaffold, *options.delete(:scope)], :default => key.is_a?(String) ? key : key.to_s.titleize}.merge(options)).html_safe
5
5
  # text = nil if text.include?('translation missing:')
6
6
  end
7
- text ||= key
7
+ text ||= key
8
8
  text
9
9
  end
10
10
  end
@@ -1,7 +1,7 @@
1
1
  module ActiveScaffold
2
2
  module DateSelectExtension
3
3
  def datetime_selector_with_name(options, html_options)
4
- options.merge!(:prefix => options[:name].gsub(/\[[^\[]*\]$/,'')) if options[:name]
4
+ options.merge!(:prefix => options[:name].gsub(/\[[^\[]*\]$/, '')) if options[:name]
5
5
  datetime_selector_without_name(options, html_options)
6
6
  end
7
7
  def self.included(base)
@@ -1,13 +1,12 @@
1
1
  require 'active_scaffold/paginator'
2
2
 
3
3
  class Paginator
4
-
5
4
  # Total number of pages
6
5
  def number_of_pages_with_infinite
7
6
  number_of_pages_without_infinite if @count
8
7
  end
9
8
  alias_method_chain :number_of_pages, :infinite
10
-
9
+
11
10
  # Is this an "infinite" paginator
12
11
  def infinite?
13
12
  @count.nil?
@@ -16,7 +15,7 @@ class Paginator
16
15
  def count
17
16
  @count || first.items.size
18
17
  end
19
-
18
+
20
19
  class Page
21
20
  # Checks to see if there's a page after this one
22
21
  def next_with_infinite?
@@ -33,6 +32,4 @@ class Paginator
33
32
  end
34
33
  end
35
34
  end
36
-
37
35
  end
38
-