active_scaffold 3.3.2 → 3.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +9 -0
- data/app/assets/javascripts/active_scaffold.js.erb +5 -2
- data/app/assets/javascripts/jquery/active_scaffold.js +4 -6
- data/app/assets/javascripts/jquery/date_picker_bridge.js.erb +16 -14
- data/app/assets/javascripts/prototype/active_scaffold.js +0 -5
- data/app/assets/stylesheets/active_scaffold.css.scss +1 -1
- data/app/assets/stylesheets/active_scaffold_jquery_ui.css.erb +7 -0
- data/lib/active_scaffold.rb +1 -1
- data/lib/active_scaffold/actions/update.rb +2 -1
- data/lib/active_scaffold/attribute_params.rb +2 -2
- data/lib/active_scaffold/bridges/date_picker.rb +1 -1
- data/lib/active_scaffold/config/core.rb +0 -2
- data/lib/active_scaffold/config/nested.rb +6 -3
- data/lib/active_scaffold/constraints.rb +2 -2
- data/lib/active_scaffold/data_structures/action_columns.rb +68 -72
- data/lib/active_scaffold/data_structures/column.rb +7 -3
- data/lib/active_scaffold/data_structures/sorting.rb +2 -1
- data/lib/active_scaffold/finder.rb +2 -14
- data/lib/active_scaffold/helpers/form_column_helpers.rb +1 -0
- data/lib/active_scaffold/helpers/list_column_helpers.rb +1 -1
- data/lib/active_scaffold/helpers/pagination_helpers.rb +1 -1
- data/lib/active_scaffold/helpers/search_column_helpers.rb +2 -2
- data/lib/active_scaffold/helpers/view_helpers.rb +7 -5
- data/lib/active_scaffold/tableless.rb +2 -2
- data/lib/active_scaffold/version.rb +1 -1
- data/test/bridges/bridge_test.rb +22 -33
- data/test/bridges/date_picker_test.rb +29 -0
- data/test/bridges/paperclip_test.rb +10 -11
- data/test/bridges/tiny_mce_test.rb +7 -7
- data/test/{bridges/company.rb → company.rb} +14 -13
- data/test/config/base_test.rb +14 -12
- data/test/config/core_test.rb +59 -53
- data/test/config/create_test.rb +56 -54
- data/test/config/delete_test.rb +31 -29
- data/test/config/field_search_test.rb +45 -43
- data/test/config/list_test.rb +119 -117
- data/test/config/nested_test.rb +50 -58
- data/test/config/search_test.rb +58 -56
- data/test/config/show_test.rb +42 -40
- data/test/config/subform_test.rb +15 -13
- data/test/config/update_test.rb +40 -38
- data/test/const_mocker.rb +14 -18
- data/test/data_structures/action_columns_test.rb +3 -3
- data/test/data_structures/action_link_test.rb +1 -1
- data/test/data_structures/action_links_test.rb +3 -3
- data/test/data_structures/actions_test.rb +2 -2
- data/test/data_structures/association_column_test.rb +5 -6
- data/test/data_structures/column_test.rb +8 -4
- data/test/data_structures/columns_test.rb +2 -3
- data/test/data_structures/error_message_test.rb +2 -2
- data/test/data_structures/set_test.rb +2 -3
- data/test/data_structures/sorting_test.rb +1 -2
- data/test/data_structures/standard_column_test.rb +2 -3
- data/test/data_structures/validation_reflection_test.rb +51 -0
- data/test/data_structures/virtual_column_test.rb +1 -1
- data/test/extensions/active_record_test.rb +2 -3
- data/test/extensions/array_test.rb +2 -2
- data/test/helpers/form_column_helpers_test.rb +6 -6
- data/test/helpers/list_column_helpers_test.rb +4 -1
- data/test/helpers/pagination_helpers_test.rb +7 -3
- data/test/misc/active_record_permissions_test.rb +1 -1
- data/test/misc/attribute_params_test.rb +3 -4
- data/test/misc/configurable_test.rb +2 -2
- data/test/misc/constraints_test.rb +29 -29
- data/test/misc/finder_test.rb +13 -10
- data/test/misc/lang_test.rb +1 -1
- data/test/mock_app/Rakefile +7 -0
- data/test/mock_app/config.ru +4 -0
- data/test/mock_app/config/application.rb +11 -0
- data/test/mock_app/config/boot.rb +6 -109
- data/test/mock_app/config/database.yml +2 -2
- data/test/mock_app/config/environment.rb +4 -42
- data/test/mock_app/config/environments/development.rb +21 -13
- data/test/mock_app/config/environments/production.rb +41 -20
- data/test/mock_app/config/environments/test.rb +27 -22
- data/test/mock_app/config/initializers/backtrace_silencers.rb +2 -2
- data/test/mock_app/config/initializers/inflections.rb +1 -1
- data/test/mock_app/config/initializers/secret_token.rb +7 -0
- data/test/mock_app/config/initializers/session_store.rb +2 -9
- data/test/mock_app/config/initializers/wrap_parameters.rb +14 -0
- data/test/mock_app/config/routes.rb +2 -42
- data/test/model_stub.rb +2 -3
- data/test/test_helper.rb +13 -11
- data/vendor/assets/stylesheets/jquery-ui-theme.css.erb +47 -0
- data/vendor/assets/stylesheets/jquery-ui.css +2 -36
- metadata +92 -103
- data/test/bridges/active_scaffold_dependent_protect_test.rb +0 -34
- data/test/bridges/unobtrusive_date_picker_test.rb +0 -49
- data/test/bridges/validation_reflection_test.rb +0 -57
- data/test/mock_app/config/initializers/new_rails_defaults.rb +0 -19
@@ -175,7 +175,7 @@ module ActiveScaffold
|
|
175
175
|
|
176
176
|
def condition_value_for_numeric(column, value)
|
177
177
|
return value if value.nil?
|
178
|
-
value =
|
178
|
+
value = column.number_to_native(value) if column.options[:format] && column.search_ui != :number
|
179
179
|
case (column.search_ui || column.column.type)
|
180
180
|
when :integer then value.to_i rescue value ? 1 : 0
|
181
181
|
when :float then value.to_f
|
@@ -184,18 +184,6 @@ module ActiveScaffold
|
|
184
184
|
value
|
185
185
|
end
|
186
186
|
end
|
187
|
-
|
188
|
-
def i18n_number_to_native_format(value)
|
189
|
-
native = '.'
|
190
|
-
delimiter = I18n.t('number.format.delimiter')
|
191
|
-
separator = I18n.t('number.format.separator')
|
192
|
-
return value if value.blank? || !value.is_a?(String)
|
193
|
-
unless delimiter == native && !value.include?(separator) && value !~ /\.\d{3}$/
|
194
|
-
value.gsub(/[^0-9\-#{I18n.t('number.format.separator')}]/, '').gsub(I18n.t('number.format.separator'), native)
|
195
|
-
else
|
196
|
-
value
|
197
|
-
end
|
198
|
-
end
|
199
187
|
|
200
188
|
def datetime_conversion_for_condition(column)
|
201
189
|
if column.column
|
@@ -367,7 +355,7 @@ module ActiveScaffold
|
|
367
355
|
end
|
368
356
|
|
369
357
|
klass = beginning_of_chain
|
370
|
-
klass = klass.uniq if find_options[:outer_joins].present?
|
358
|
+
klass = klass.where(nil).uniq if find_options[:outer_joins].present? # HACK: call where(nil) because calling uniq on associations (nested scaffolds) send SQL to DB
|
371
359
|
# we build the paginator differently for method- and sql-based sorting
|
372
360
|
if options[:sorting] and options[:sorting].sorts_by_method?
|
373
361
|
pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page|
|
@@ -119,6 +119,7 @@ module ActiveScaffold
|
|
119
119
|
url_params = url_params.except(:parent_scaffold, :association, nested.param_name) if nested? && scope
|
120
120
|
url_params[:eid] = params[:eid] if params[:eid]
|
121
121
|
if scope
|
122
|
+
url_params[:parent_controller] ||= url_params[:controller]
|
122
123
|
url_params[:controller] = subform_controller.controller_path
|
123
124
|
url_params[:scope] = scope
|
124
125
|
url_params[:parent_id] = params[:parent_id] || params[:id]
|
@@ -160,7 +160,7 @@ module ActiveScaffold
|
|
160
160
|
if column.associated_limit == 0
|
161
161
|
size if column.associated_number?
|
162
162
|
else
|
163
|
-
joined_associated = firsts.join(active_scaffold_config.list.association_join_text)
|
163
|
+
joined_associated = firsts.join(h(active_scaffold_config.list.association_join_text)).html_safe
|
164
164
|
joined_associated << " (#{size})" if column.associated_number? and column.associated_limit and value.size > column.associated_limit
|
165
165
|
joined_associated
|
166
166
|
end
|
@@ -38,7 +38,7 @@ module ActiveScaffold
|
|
38
38
|
page = current_page.number - offset
|
39
39
|
if page < start_number && page > last_page
|
40
40
|
html << '..' if page > last_page + 1
|
41
|
-
html << pagination_ajax_link(page,
|
41
|
+
html << pagination_ajax_link(page, url_options, options)
|
42
42
|
last_page = page
|
43
43
|
end
|
44
44
|
end
|
@@ -82,7 +82,7 @@ module ActiveScaffold
|
|
82
82
|
active_scaffold_checkbox_list(column, select_options, associated, options)
|
83
83
|
end
|
84
84
|
|
85
|
-
def active_scaffold_search_select(column, html_options)
|
85
|
+
def active_scaffold_search_select(column, html_options, options = {})
|
86
86
|
associated = html_options.delete :value
|
87
87
|
if column.association
|
88
88
|
associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil?
|
@@ -95,7 +95,7 @@ module ActiveScaffold
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
options =
|
98
|
+
options = options.merge(:selected => associated).merge column.options
|
99
99
|
html_options.merge! column.options[:html_options] || {}
|
100
100
|
if html_options[:multiple]
|
101
101
|
html_options[:name] += '[]'
|
@@ -235,7 +235,12 @@ module ActiveScaffold
|
|
235
235
|
url_options = action_link_url_options(link, record)
|
236
236
|
if active_scaffold_config.cache_action_link_urls
|
237
237
|
url = url_for(url_options)
|
238
|
-
|
238
|
+
model = active_scaffold_config.model
|
239
|
+
is_sti_record = record && model.columns_hash.include?(model.inheritance_column) &&
|
240
|
+
record[model.inheritance_column].present?
|
241
|
+
unless link.dynamic_parameters.is_a?(Proc) || is_sti_record
|
242
|
+
@action_links_urls[link.name_to_cache_link_url] = url
|
243
|
+
end
|
239
244
|
url
|
240
245
|
else
|
241
246
|
url_for(params_for(url_options))
|
@@ -339,10 +344,7 @@ module ActiveScaffold
|
|
339
344
|
html_options[:data][:cancel_refresh] = true if link.refresh_on_close
|
340
345
|
html_options[:data][:keep_open] = true if link.keep_open?
|
341
346
|
end
|
342
|
-
if link.popup?
|
343
|
-
html_options[:data][:popup] = true
|
344
|
-
html_options[:target] = '_blank'
|
345
|
-
end
|
347
|
+
html_options[:target] = '_blank' if link.popup?
|
346
348
|
html_options[:id] = link_id
|
347
349
|
html_options[:remote] = true unless link.page? || link.popup?
|
348
350
|
if link.dhtml_confirm?
|
@@ -69,10 +69,10 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def self.execute_simple_calculation(relation, operation, column_name, distinct)
|
72
|
-
if operation == 'count' &&
|
72
|
+
if operation == 'count' && [relation.klass.primary_key, :all].include?(column_name)
|
73
73
|
find_all(relation).size
|
74
74
|
else
|
75
|
-
raise "self.execute_simple_calculation must be implemented in a Tableless model to support #{operation} #{column_name}
|
75
|
+
raise "self.execute_simple_calculation must be implemented in a Tableless model to support #{operation} #{column_name}#{' distinct' if distinct} columns"
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
data/test/bridges/bridge_test.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
class Bridges::BridgeTest < Test::Unit::TestCase
|
3
|
+
class BridgeTest < Test::Unit::TestCase
|
7
4
|
def setup
|
8
5
|
@const_store = {}
|
9
6
|
end
|
@@ -12,36 +9,29 @@ class Bridges::BridgeTest < Test::Unit::TestCase
|
|
12
9
|
end
|
13
10
|
|
14
11
|
def test__shouldnt_throw_errors
|
15
|
-
ActiveScaffold::
|
12
|
+
ActiveScaffold::Bridges.run_all
|
16
13
|
end
|
17
14
|
|
18
15
|
def test__cds_bridge
|
16
|
+
js, ActiveScaffold.js_framework = ActiveScaffold.js_framework, :prototype
|
19
17
|
ConstMocker.mock("CalendarDateSelect") do |cm|
|
20
18
|
cm.remove
|
21
19
|
assert(! bridge_will_be_installed("CalendarDateSelect"))
|
22
20
|
cm.declare
|
23
21
|
assert(bridge_will_be_installed("CalendarDateSelect"))
|
24
22
|
end
|
23
|
+
ActiveScaffold.js_framework = js
|
25
24
|
end
|
26
25
|
|
27
26
|
def test__file_column_bridge
|
28
27
|
ConstMocker.mock("FileColumn") do |cm|
|
29
|
-
|
30
|
-
|
28
|
+
cm.remove
|
29
|
+
assert(! bridge_will_be_installed("FileColumn"))
|
31
30
|
cm.declare
|
32
31
|
assert(bridge_will_be_installed("FileColumn"))
|
33
32
|
end
|
34
33
|
end
|
35
34
|
|
36
|
-
def test__dependent_protect_bridge
|
37
|
-
ConstMocker.mock("DependentProtect") do |cm|
|
38
|
-
cm.remove
|
39
|
-
assert(! bridge_will_be_installed("DependentProtect"))
|
40
|
-
cm.declare
|
41
|
-
assert(bridge_will_be_installed("DependentProtect"))
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
35
|
def test__paperclip_bridge
|
46
36
|
ConstMocker.mock("Paperclip") do |cm|
|
47
37
|
cm.remove
|
@@ -51,22 +41,21 @@ class Bridges::BridgeTest < Test::Unit::TestCase
|
|
51
41
|
end
|
52
42
|
end
|
53
43
|
|
54
|
-
def
|
55
|
-
ConstMocker.mock("
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
44
|
+
def test__date_picker_bridge
|
45
|
+
ConstMocker.mock("Jquery") do |jquery|
|
46
|
+
jquery.declare
|
47
|
+
ConstMocker.mock("Rails", jquery.const) do |rails|
|
48
|
+
rails.declare
|
49
|
+
ConstMocker.mock("Ui", jquery.const) do |cm|
|
50
|
+
cm.remove
|
51
|
+
assert(! bridge_will_be_installed("DatePicker"))
|
52
|
+
cm.declare
|
53
|
+
assert(bridge_will_be_installed("DatePicker"))
|
54
|
+
end
|
55
|
+
end
|
60
56
|
end
|
61
57
|
end
|
62
58
|
|
63
|
-
def test__validation_reflection_bridge
|
64
|
-
class << ActiveRecord::Base; undef_method :reflect_on_validations_for; end rescue nil
|
65
|
-
assert(! bridge_will_be_installed("ValidationReflection"))
|
66
|
-
class << ActiveRecord::Base; define_method :reflect_on_validations_for, lambda{}; end
|
67
|
-
assert(bridge_will_be_installed("ValidationReflection"))
|
68
|
-
end
|
69
|
-
|
70
59
|
def test__semantic_attributes_bridge
|
71
60
|
ConstMocker.mock("SemanticAttributes") do |cm|
|
72
61
|
cm.remove
|
@@ -79,12 +68,12 @@ class Bridges::BridgeTest < Test::Unit::TestCase
|
|
79
68
|
protected
|
80
69
|
|
81
70
|
def find_bridge(name)
|
82
|
-
ActiveScaffold::
|
71
|
+
ActiveScaffold::Bridges[name.to_s.underscore.to_sym]
|
83
72
|
end
|
84
73
|
|
85
74
|
def bridge_will_be_installed(name)
|
86
75
|
assert bridge=find_bridge(name), "No bridge found matching #{name}"
|
87
76
|
|
88
|
-
bridge.
|
77
|
+
bridge.install?
|
89
78
|
end
|
90
|
-
end
|
79
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/bridges/date_picker/ext')
|
3
|
+
#require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/bridges/date_picker/helper')
|
4
|
+
|
5
|
+
class DatePickerTest < ActionView::TestCase
|
6
|
+
include ActiveScaffold::Helpers::ViewHelpers
|
7
|
+
include ActiveScaffold::Bridges::DatePicker::Helper::FormColumnHelpers
|
8
|
+
include ActiveScaffold::Bridges::DatePicker::Helper::DatepickerColumnHelpers
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@controller.class.class_eval do
|
12
|
+
include ActiveScaffold::Finder
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_set_form_ui
|
17
|
+
config = ActiveScaffold::Config::Core.new(:company)
|
18
|
+
assert_equal nil, config.columns[:name].form_ui, 'form_ui for name'
|
19
|
+
assert_equal :date_picker, config.columns[:date].form_ui, 'form_ui for date'
|
20
|
+
assert_equal :datetime_picker, config.columns[:datetime].form_ui, 'form_ui for datetime'
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_form_ui
|
24
|
+
config = ActiveScaffold::Config::Core.new(:company)
|
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')
|
28
|
+
end
|
29
|
+
end
|
@@ -1,12 +1,11 @@
|
|
1
|
-
require '
|
2
|
-
require File.
|
3
|
-
require File.
|
4
|
-
require File.
|
5
|
-
require File.
|
6
|
-
require File.join(File.dirname(__FILE__), '../../lib/bridges/paperclip/lib/list_ui')
|
1
|
+
require 'test_helper'
|
2
|
+
require File.expand_path('../../../lib/active_scaffold/bridges/paperclip/paperclip_bridge', __FILE__)
|
3
|
+
require File.expand_path('../../../lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers', __FILE__)
|
4
|
+
require File.expand_path('../../../lib/active_scaffold/bridges/paperclip/form_ui', __FILE__)
|
5
|
+
require File.expand_path('../../../lib/active_scaffold/bridges/paperclip/list_ui', __FILE__)
|
7
6
|
|
8
7
|
class PaperclipCore < ActiveScaffold::Config::Core
|
9
|
-
include ActiveScaffold::PaperclipBridge
|
8
|
+
include ActiveScaffold::Bridges::Paperclip::PaperclipBridge
|
10
9
|
end
|
11
10
|
|
12
11
|
class PaperclipTest < ActionView::TestCase
|
@@ -49,10 +48,10 @@ class PaperclipTest < ActionView::TestCase
|
|
49
48
|
company = Company.new
|
50
49
|
|
51
50
|
company.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => Company.attachment_definitions[:logo]))
|
52
|
-
assert_dom_equal '<a href="/system/file"
|
51
|
+
assert_dom_equal '<a href="/system/file" data-popup="true" target="_blank">file</a>', active_scaffold_column_paperclip(company, config.columns[:logo])
|
53
52
|
|
54
53
|
company.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => {:thumbnail => '40x40'}))
|
55
|
-
assert_dom_equal '<a href="/system/file"
|
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])
|
56
55
|
end
|
57
56
|
|
58
57
|
def test_form_ui
|
@@ -60,9 +59,9 @@ class PaperclipTest < ActionView::TestCase
|
|
60
59
|
@record = Company.new
|
61
60
|
|
62
61
|
@record.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => Company.attachment_definitions[:logo]))
|
63
|
-
assert_dom_equal '<div><a href="/system/file"
|
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('true'); $(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')
|
64
63
|
|
65
64
|
@record.stubs(:logo).returns(stub(:file? => false))
|
66
|
-
assert_dom_equal '<input name="record[logo]"
|
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
66
|
end
|
68
67
|
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
require '
|
2
|
-
require File.join(File.dirname(__FILE__), '
|
3
|
-
require File.join(File.dirname(__FILE__), '../../lib/bridges/tiny_mce/lib/tiny_mce_bridge')
|
1
|
+
require 'test_helper'
|
2
|
+
require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/bridges/tiny_mce/helpers')
|
4
3
|
|
5
4
|
class TinyMceTest < ActionView::TestCase
|
6
5
|
include ActiveScaffold::Helpers::ViewHelpers
|
7
|
-
include ActiveScaffold::
|
6
|
+
include ActiveScaffold::Bridges::TinyMce::Helpers
|
8
7
|
|
9
8
|
def test_includes
|
10
|
-
|
9
|
+
ActiveScaffold::Bridges::TinyMce.expects(:install?).returns(true)
|
10
|
+
assert ActiveScaffold::Bridges.all_javascripts.include?("tinymce-jquery")
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_form_ui
|
14
|
-
config =
|
14
|
+
config = ActiveScaffold::Config::Core.new(:company)
|
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\"
|
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)
|
19
19
|
end
|
20
20
|
|
21
21
|
protected
|
@@ -1,14 +1,10 @@
|
|
1
|
-
|
2
|
-
require 'active_record'
|
3
|
-
require 'active_record/reflection'
|
4
|
-
require File.join(File.dirname(__FILE__), '../../lib/bridges/dependent_protect/lib/dependent_protect_bridge')
|
5
|
-
|
6
|
-
# Mocking everything necesary to test the plugin.
|
7
|
-
class Company
|
1
|
+
class Company < ActiveRecord::Base
|
8
2
|
def initialize(with_or_without = nil)
|
9
3
|
@with_companies = with_or_without == :with_companies
|
10
4
|
@with_company = with_or_without == :with_company
|
11
5
|
@with_main_company = with_or_without == :with_main_company
|
6
|
+
@attributes = {}
|
7
|
+
@attributes_cache = {}
|
12
8
|
end
|
13
9
|
|
14
10
|
def self.columns_hash
|
@@ -44,9 +40,6 @@ class Company
|
|
44
40
|
@@before = s
|
45
41
|
end
|
46
42
|
|
47
|
-
include ActiveRecord::Reflection
|
48
|
-
include DependentProtectSecurity
|
49
|
-
|
50
43
|
def self.has_many(association_id, options = {})
|
51
44
|
reflection = create_reflection(:has_many, association_id, options, self)
|
52
45
|
end
|
@@ -56,9 +49,9 @@ class Company
|
|
56
49
|
def self.belongs_to(association_id, options = {})
|
57
50
|
reflection = create_reflection(:belongs_to, association_id, options, self)
|
58
51
|
end
|
59
|
-
has_many :companies
|
60
|
-
has_one :company
|
61
|
-
belongs_to :main_company, :
|
52
|
+
has_many :companies
|
53
|
+
has_one :company
|
54
|
+
belongs_to :main_company, :class_name => 'Company'
|
62
55
|
|
63
56
|
def companies
|
64
57
|
if @with_companies
|
@@ -78,4 +71,12 @@ class Company
|
|
78
71
|
|
79
72
|
def name
|
80
73
|
end
|
74
|
+
|
75
|
+
def date
|
76
|
+
Date.today
|
77
|
+
end
|
78
|
+
|
79
|
+
def datetime
|
80
|
+
Time.now
|
81
|
+
end
|
81
82
|
end
|
data/test/config/base_test.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
module Config
|
4
|
+
class BaseTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@base = ActiveScaffold::Config::Base.new(ActiveScaffold::Config::Core.new(:model_stub))
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_formats
|
10
|
+
assert_equal [], @base.formats
|
11
|
+
@base.formats << :pdf
|
12
|
+
assert_equal [:pdf], @base.formats
|
13
|
+
@base.formats = [:html]
|
14
|
+
assert_equal [:html], @base.formats
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
data/test/config/core_test.rb
CHANGED
@@ -1,58 +1,64 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
assert !@config.sti_children
|
11
|
-
assert_equal [:create, :list, :search, :update, :delete, :show, :nested, :subform], @config.actions.to_a
|
12
|
-
assert_equal :default, @config.frontend
|
13
|
-
assert_equal :default, @config.theme
|
14
|
-
assert_equal 'ModelStub', @config.label(:count => 1)
|
15
|
-
assert_equal 'ModelStubs', @config.label
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_add_sti_children
|
19
|
-
@config.sti_create_links = true
|
20
|
-
assert !@config.add_sti_create_links?
|
21
|
-
@config.sti_children = [:a]
|
22
|
-
assert @config.add_sti_create_links?
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_sti_children
|
26
|
-
@config.sti_children = [:a]
|
27
|
-
assert_equal [:a], @config.sti_children
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_actions
|
31
|
-
assert @config.actions.include?(:create)
|
32
|
-
@config.actions = [:list]
|
33
|
-
assert !@config.actions.include?(:create)
|
34
|
-
assert_equal [:list], @config.actions.to_a
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_form_ui_in_sti
|
38
|
-
@config.columns << :type
|
3
|
+
module Config
|
4
|
+
class CoreTest < Test::Unit::TestCase
|
5
|
+
class ModelStubsController < ActionController::Base; end
|
6
|
+
def setup
|
7
|
+
@config = ActiveScaffold::Config::Core.new :model_stub
|
8
|
+
ModelStubsController.instance_variable_set :@active_scaffold_config, @config
|
9
|
+
end
|
39
10
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
11
|
+
def test_default_options
|
12
|
+
assert !@config.add_sti_create_links?
|
13
|
+
assert !@config.sti_children
|
14
|
+
assert_equal [:create, :list, :search, :update, :delete, :show, :nested, :subform], @config.actions.to_a
|
15
|
+
assert_equal :default, @config.frontend
|
16
|
+
assert_equal :default, @config.theme
|
17
|
+
assert_equal 'Model stub', @config.label(:count => 1)
|
18
|
+
assert_equal 'ModelStubs', @config.label
|
19
|
+
end
|
44
20
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
21
|
+
def test_add_sti_children
|
22
|
+
@config.sti_create_links = true
|
23
|
+
assert !@config.add_sti_create_links?
|
24
|
+
@config.sti_children = [:a]
|
25
|
+
assert @config.add_sti_create_links?
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_sti_children
|
29
|
+
@config.sti_children = [:a]
|
30
|
+
assert_equal [:a], @config.sti_children
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_actions
|
34
|
+
assert @config.actions.include?(:create)
|
35
|
+
@config.actions = [:list]
|
36
|
+
assert !@config.actions.include?(:create)
|
37
|
+
assert_equal [:list], @config.actions.to_a
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_form_ui_in_sti
|
41
|
+
@config.columns << :type
|
42
|
+
|
43
|
+
@config.sti_create_links = false
|
44
|
+
@config.sti_children = [:model_stub]
|
45
|
+
@config._configure_sti
|
46
|
+
assert_equal :select, @config.columns[:type].form_ui
|
47
|
+
assert_equal [['Model stub', 'ModelStub']], @config.columns[:type].options[:options]
|
48
|
+
|
49
|
+
@config.columns[:type].form_ui = nil
|
50
|
+
@config.sti_create_links = true
|
51
|
+
@config._configure_sti
|
52
|
+
assert_equal :hidden, @config.columns[:type].form_ui
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_sti_children_links
|
56
|
+
@config.sti_children = [:model_stub]
|
57
|
+
@config.sti_create_links = true
|
58
|
+
@config.action_links.add @config.create.link
|
59
|
+
ModelStubsController.send(:_add_sti_create_links)
|
60
|
+
assert_equal 'Create Model stub', @config.action_links[:new].label
|
61
|
+
assert_equal 'config/core_test/model_stubs', @config.action_links[:new].parameters[:parent_sti]
|
62
|
+
end
|
57
63
|
end
|
58
64
|
end
|