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.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +9 -0
  3. data/app/assets/javascripts/active_scaffold.js.erb +5 -2
  4. data/app/assets/javascripts/jquery/active_scaffold.js +4 -6
  5. data/app/assets/javascripts/jquery/date_picker_bridge.js.erb +16 -14
  6. data/app/assets/javascripts/prototype/active_scaffold.js +0 -5
  7. data/app/assets/stylesheets/active_scaffold.css.scss +1 -1
  8. data/app/assets/stylesheets/active_scaffold_jquery_ui.css.erb +7 -0
  9. data/lib/active_scaffold.rb +1 -1
  10. data/lib/active_scaffold/actions/update.rb +2 -1
  11. data/lib/active_scaffold/attribute_params.rb +2 -2
  12. data/lib/active_scaffold/bridges/date_picker.rb +1 -1
  13. data/lib/active_scaffold/config/core.rb +0 -2
  14. data/lib/active_scaffold/config/nested.rb +6 -3
  15. data/lib/active_scaffold/constraints.rb +2 -2
  16. data/lib/active_scaffold/data_structures/action_columns.rb +68 -72
  17. data/lib/active_scaffold/data_structures/column.rb +7 -3
  18. data/lib/active_scaffold/data_structures/sorting.rb +2 -1
  19. data/lib/active_scaffold/finder.rb +2 -14
  20. data/lib/active_scaffold/helpers/form_column_helpers.rb +1 -0
  21. data/lib/active_scaffold/helpers/list_column_helpers.rb +1 -1
  22. data/lib/active_scaffold/helpers/pagination_helpers.rb +1 -1
  23. data/lib/active_scaffold/helpers/search_column_helpers.rb +2 -2
  24. data/lib/active_scaffold/helpers/view_helpers.rb +7 -5
  25. data/lib/active_scaffold/tableless.rb +2 -2
  26. data/lib/active_scaffold/version.rb +1 -1
  27. data/test/bridges/bridge_test.rb +22 -33
  28. data/test/bridges/date_picker_test.rb +29 -0
  29. data/test/bridges/paperclip_test.rb +10 -11
  30. data/test/bridges/tiny_mce_test.rb +7 -7
  31. data/test/{bridges/company.rb → company.rb} +14 -13
  32. data/test/config/base_test.rb +14 -12
  33. data/test/config/core_test.rb +59 -53
  34. data/test/config/create_test.rb +56 -54
  35. data/test/config/delete_test.rb +31 -29
  36. data/test/config/field_search_test.rb +45 -43
  37. data/test/config/list_test.rb +119 -117
  38. data/test/config/nested_test.rb +50 -58
  39. data/test/config/search_test.rb +58 -56
  40. data/test/config/show_test.rb +42 -40
  41. data/test/config/subform_test.rb +15 -13
  42. data/test/config/update_test.rb +40 -38
  43. data/test/const_mocker.rb +14 -18
  44. data/test/data_structures/action_columns_test.rb +3 -3
  45. data/test/data_structures/action_link_test.rb +1 -1
  46. data/test/data_structures/action_links_test.rb +3 -3
  47. data/test/data_structures/actions_test.rb +2 -2
  48. data/test/data_structures/association_column_test.rb +5 -6
  49. data/test/data_structures/column_test.rb +8 -4
  50. data/test/data_structures/columns_test.rb +2 -3
  51. data/test/data_structures/error_message_test.rb +2 -2
  52. data/test/data_structures/set_test.rb +2 -3
  53. data/test/data_structures/sorting_test.rb +1 -2
  54. data/test/data_structures/standard_column_test.rb +2 -3
  55. data/test/data_structures/validation_reflection_test.rb +51 -0
  56. data/test/data_structures/virtual_column_test.rb +1 -1
  57. data/test/extensions/active_record_test.rb +2 -3
  58. data/test/extensions/array_test.rb +2 -2
  59. data/test/helpers/form_column_helpers_test.rb +6 -6
  60. data/test/helpers/list_column_helpers_test.rb +4 -1
  61. data/test/helpers/pagination_helpers_test.rb +7 -3
  62. data/test/misc/active_record_permissions_test.rb +1 -1
  63. data/test/misc/attribute_params_test.rb +3 -4
  64. data/test/misc/configurable_test.rb +2 -2
  65. data/test/misc/constraints_test.rb +29 -29
  66. data/test/misc/finder_test.rb +13 -10
  67. data/test/misc/lang_test.rb +1 -1
  68. data/test/mock_app/Rakefile +7 -0
  69. data/test/mock_app/config.ru +4 -0
  70. data/test/mock_app/config/application.rb +11 -0
  71. data/test/mock_app/config/boot.rb +6 -109
  72. data/test/mock_app/config/database.yml +2 -2
  73. data/test/mock_app/config/environment.rb +4 -42
  74. data/test/mock_app/config/environments/development.rb +21 -13
  75. data/test/mock_app/config/environments/production.rb +41 -20
  76. data/test/mock_app/config/environments/test.rb +27 -22
  77. data/test/mock_app/config/initializers/backtrace_silencers.rb +2 -2
  78. data/test/mock_app/config/initializers/inflections.rb +1 -1
  79. data/test/mock_app/config/initializers/secret_token.rb +7 -0
  80. data/test/mock_app/config/initializers/session_store.rb +2 -9
  81. data/test/mock_app/config/initializers/wrap_parameters.rb +14 -0
  82. data/test/mock_app/config/routes.rb +2 -42
  83. data/test/model_stub.rb +2 -3
  84. data/test/test_helper.rb +13 -11
  85. data/vendor/assets/stylesheets/jquery-ui-theme.css.erb +47 -0
  86. data/vendor/assets/stylesheets/jquery-ui.css +2 -36
  87. metadata +92 -103
  88. data/test/bridges/active_scaffold_dependent_protect_test.rb +0 -34
  89. data/test/bridges/unobtrusive_date_picker_test.rb +0 -49
  90. data/test/bridges/validation_reflection_test.rb +0 -57
  91. data/test/mock_app/config/initializers/new_rails_defaults.rb +0 -19
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
1
+ require 'test_helper'
2
2
  # require 'test/model_stub'
3
- require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/data_structures/set.rb')
3
+ #require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/data_structures/set.rb')
4
4
 
5
5
  class ActionColumnsTest < Test::Unit::TestCase
6
6
  def setup
@@ -110,4 +110,4 @@ class ActionColumnsTest < Test::Unit::TestCase
110
110
  assert @columns.include?(:c)
111
111
  assert !@columns.include?(:d)
112
112
  end
113
- end
113
+ end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
1
+ require 'test_helper'
2
2
 
3
3
  class ActionLinkTest < Test::Unit::TestCase
4
4
  def setup
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
1
+ require 'test_helper'
2
2
 
3
3
  class ActionLinksTest < Test::Unit::TestCase
4
4
  def setup
@@ -53,10 +53,10 @@ class ActionLinksTest < Test::Unit::TestCase
53
53
  @links.add 'foo', :type => :collection
54
54
  @links.add 'bar', :type => :member
55
55
 
56
- @links.each :collection do |link|
56
+ @links.collection.each do |link|
57
57
  assert_equal 'foo', link.action
58
58
  end
59
- @links.each :member do |link|
59
+ @links.member.each do |link|
60
60
  assert_equal 'bar', link.action
61
61
  end
62
62
  end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
1
+ require 'test_helper'
2
2
 
3
3
  class ActionsTest < Test::Unit::TestCase
4
4
  def setup
@@ -22,4 +22,4 @@ class ActionsTest < Test::Unit::TestCase
22
22
  @actions.add 'c'
23
23
  assert @actions.include?('c')
24
24
  end
25
- end
25
+ end
@@ -1,5 +1,5 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
- require File.join(File.dirname(__FILE__), '../model_stub')
1
+ require 'test_helper'
2
+ require 'model_stub'
3
3
 
4
4
  class AssociationColumnTest < Test::Unit::TestCase
5
5
  def setup
@@ -12,15 +12,14 @@ class AssociationColumnTest < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_sorting
15
- # sorting on association columns is method-based
16
- hash = {:method => "other_model.to_s"}
17
- assert_equal hash, @association_column.sort
15
+ # sorting on association columns is not defined
16
+ assert_equal false, @association_column.sort
18
17
  end
19
18
 
20
19
  def test_searching
21
20
  # by default searching on association columns uses primary key
22
21
  assert @association_column.searchable?
23
- assert_equal '"model_stubs"."id"', @association_column.search_sql
22
+ assert_equal ['"model_stubs"."id"'], @association_column.search_sql
24
23
  end
25
24
 
26
25
  def test_association
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
1
+ require 'test_helper'
2
2
 
3
3
  class ColumnTest < Test::Unit::TestCase
4
4
  def setup
@@ -121,9 +121,9 @@ class ColumnTest < Test::Unit::TestCase
121
121
 
122
122
  def test_custom_search
123
123
  @column.search_sql = true
124
- assert_equal '"model_stubs"."a"', @column.search_sql
124
+ assert_equal ['"model_stubs"."a"'], @column.search_sql
125
125
  @column.search_sql = 'foobar'
126
- assert_equal 'foobar', @column.search_sql
126
+ assert_equal ['foobar'], @column.search_sql
127
127
  assert @column.searchable?
128
128
  end
129
129
 
@@ -172,7 +172,7 @@ class ColumnTest < Test::Unit::TestCase
172
172
  end
173
173
 
174
174
  def test_includes
175
- assert_equal [], @column.includes
175
+ assert_equal nil, @column.includes
176
176
 
177
177
  # make sure that when a non-array comes in, an array comes out
178
178
  @column.includes = :column_name
@@ -181,5 +181,9 @@ class ColumnTest < Test::Unit::TestCase
181
181
  # make sure that when a non-array comes in, an array comes out
182
182
  @column.includes = [:column_name]
183
183
  assert_equal([:column_name], @column.includes)
184
+
185
+ # make sure that when a non-array comes in, an array comes out
186
+ @column.includes = nil
187
+ assert_nil @column.includes
184
188
  end
185
189
  end
@@ -1,5 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
- # require 'test/model_stub'
1
+ require 'test_helper'
3
2
 
4
3
  class ColumnsTest < Test::Unit::TestCase
5
4
  def setup
@@ -66,4 +65,4 @@ class ColumnsTest < Test::Unit::TestCase
66
65
  assert @columns.include?(:d)
67
66
  assert @columns.include?(:c)
68
67
  end
69
- end
68
+ end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
1
+ require 'test_helper'
2
2
 
3
3
  class ErrorMessageTest < Test::Unit::TestCase
4
4
  def setup
@@ -25,4 +25,4 @@ class ErrorMessageTest < Test::Unit::TestCase
25
25
  assert yml.has_key?(:error)
26
26
  assert_equal 'foo', yml[:error]
27
27
  end
28
- end
28
+ end
@@ -1,5 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
- # require 'test/model_stub'
1
+ require 'test_helper'
3
2
 
4
3
  class SetTest < Test::Unit::TestCase
5
4
  def setup
@@ -83,4 +82,4 @@ class SetTest < Test::Unit::TestCase
83
82
  assert @items.include?(:b)
84
83
  assert !@items.include?(:d)
85
84
  end
86
- end
85
+ end
@@ -1,5 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
- # require 'test/model_stub'
1
+ require 'test_helper'
3
2
 
4
3
  class SortingTest < Test::Unit::TestCase
5
4
  def setup
@@ -1,5 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
- # require 'test/model_stub'
1
+ require 'test_helper'
3
2
 
4
3
  class StandardColumnTest < Test::Unit::TestCase
5
4
  def setup
@@ -19,6 +18,6 @@ class StandardColumnTest < Test::Unit::TestCase
19
18
 
20
19
  def test_searching
21
20
  assert @standard_column.searchable?
22
- assert_equal '"model_stubs"."a"', @standard_column.search_sql # check default
21
+ assert_equal ['"model_stubs"."a"'], @standard_column.search_sql # check default
23
22
  end
24
23
  end
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+ class ValidationReflectionTest < Test::Unit::TestCase
4
+ def test_set_required_for_validates_presence_of
5
+ column = ActiveScaffold::DataStructures::Column.new(:name, Company)
6
+ assert !column.required?
7
+ Company.expects(:validators_on).with(:name).returns([ActiveModel::Validations::PresenceValidator.new(:attributes => :name)])
8
+ column = ActiveScaffold::DataStructures::Column.new(:name, Company)
9
+ assert column.required?
10
+ end
11
+
12
+ def test_set_required_for_validates_inclusion_of
13
+ column = ActiveScaffold::DataStructures::Column.new(:name, Company)
14
+ assert !column.required?
15
+ Company.expects(:validators_on).with(:name).returns([ActiveModel::Validations::InclusionValidator.new(:attributes => :name, :in => [])])
16
+ column = ActiveScaffold::DataStructures::Column.new(:name, Company)
17
+ assert column.required?
18
+ end
19
+
20
+ def test_not_set_required_for_validates_inclusion_of_and_allow_nil
21
+ Company.expects(:validators_on).with(:name).returns([ActiveModel::Validations::InclusionValidator.new(:attributes => :name, :in => [], :allow_nil => true)])
22
+ column = ActiveScaffold::DataStructures::Column.new(:name, Company)
23
+ assert !column.required?
24
+ end
25
+
26
+ def test_not_set_required_for_validates_inclusion_of_and_allow_blank
27
+ Company.expects(:validators_on).with(:name).returns([ActiveModel::Validations::InclusionValidator.new(:attributes => :name, :in => [], :allow_blank => true)])
28
+ column = ActiveScaffold::DataStructures::Column.new(:name, Company)
29
+ assert !column.required?
30
+ end
31
+
32
+ def test_not_set_required_for_no_validation
33
+ Company.expects(:validators_on).with(:name).returns([])
34
+ column = ActiveScaffold::DataStructures::Column.new(:name, Company)
35
+ assert !column.required?
36
+ end
37
+
38
+ def test_set_required_for_validates_presence_of_in_association
39
+ column = ActiveScaffold::DataStructures::Column.new(:main_company, Company)
40
+ assert !column.required?
41
+ Company.expects(:validators_on).with(:main_company).returns([ActiveModel::Validations::PresenceValidator.new(:attributes => :main_company)])
42
+ column = ActiveScaffold::DataStructures::Column.new(:main_company, Company)
43
+ assert column.required?
44
+ end
45
+
46
+ def test_not_set_required_for_no_validation_in_association_neither_foreign_key
47
+ Company.expects(:validators_on).returns([])
48
+ column = ActiveScaffold::DataStructures::Column.new(:main_company, Company)
49
+ assert !column.required?
50
+ end
51
+ end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
1
+ require 'test_helper'
2
2
 
3
3
  class VirtualColumnTest < Test::Unit::TestCase
4
4
  def setup
@@ -1,5 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
- #require 'test/model_stub'
1
+ require 'test_helper'
3
2
 
4
3
  class ActiveRecordTest < Test::Unit::TestCase
5
4
  def setup
@@ -42,4 +41,4 @@ class ActiveRecordTest < Test::Unit::TestCase
42
41
 
43
42
  assert_equal 'name', @record.to_label
44
43
  end
45
- end
44
+ end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
1
+ require 'test_helper'
2
2
 
3
3
  class ArrayTest < Test::Unit::TestCase
4
4
  def test_after
@@ -9,4 +9,4 @@ class ArrayTest < Test::Unit::TestCase
9
9
  assert_equal 'a', @sequence.after('c')
10
10
  assert_equal nil, @sequence.after('d')
11
11
  end
12
- end
12
+ end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
1
+ require 'test_helper'
2
2
 
3
3
  class FormColumnHelpersTest < ActionView::TestCase
4
4
  include ActiveScaffold::Helpers::FormColumnHelpers
@@ -10,22 +10,22 @@ class FormColumnHelpersTest < ActionView::TestCase
10
10
 
11
11
  def test_choices_for_select_form_ui_for_simple_column
12
12
  @column.options[:options] = [:value_1, :value_2, :value_3]
13
- assert_dom_equal '<select name="record[a]" id="record_a"><option value="value_1">Value 1</option><option value="value_2">Value 2</option><option value="value_3">Value 3</option></select>', active_scaffold_input_select(@column, {})
13
+ assert_dom_equal "<select name=\"record[a]\" id=\"record_a\"><option value=\"value_1\">Value 1</option>\n<option value=\"value_2\">Value 2</option>\n<option value=\"value_3\">Value 3</option></select>", active_scaffold_input_select(@column, {})
14
14
 
15
15
  @column.options[:options] = %w(value_1 value_2 value_3)
16
- assert_dom_equal '<select name="record[a]" id="record_a"><option value="value_1">value_1</option><option value="value_2">value_2</option><option value="value_3">value_3</option></select>', active_scaffold_input_select(@column, {})
16
+ assert_dom_equal "<select name=\"record[a]\" id=\"record_a\"><option value=\"value_1\">value_1</option>\n<option value=\"value_2\">value_2</option>\n<option value=\"value_3\">value_3</option></select>", active_scaffold_input_select(@column, {})
17
17
 
18
18
  @column.options[:options] = [%w(text_1 value_1), %w(text_2 value_2), %w(text_3 value_3)]
19
- assert_dom_equal '<select name="record[a]" id="record_a"><option value="value_1">text_1</option><option value="value_2">text_2</option><option value="value_3">text_3</option></select>', active_scaffold_input_select(@column, {})
19
+ assert_dom_equal "<select name=\"record[a]\" id=\"record_a\"><option value=\"value_1\">text_1</option>\n<option value=\"value_2\">text_2</option>\n<option value=\"value_3\">text_3</option></select>", active_scaffold_input_select(@column, {})
20
20
 
21
21
  @column.options[:options] = [[:text_1, :value_1], [:text_2, :value_2], [:text_3, :value_3]]
22
- assert_dom_equal '<select name="record[a]" id="record_a"><option value="value_1">Text 1</option><option value="value_2">Text 2</option><option value="value_3">Text 3</option></select>', active_scaffold_input_select(@column, {})
22
+ assert_dom_equal "<select name=\"record[a]\" id=\"record_a\"><option value=\"value_1\">Text 1</option>\n<option value=\"value_2\">Text 2</option>\n<option value=\"value_3\">Text 3</option></select>", active_scaffold_input_select(@column, {})
23
23
  end
24
24
 
25
25
  def test_options_for_select_form_ui_for_simple_column
26
26
  @column.options = {:include_blank => 'None', :selected => 'value_2', :disabled => %w(value_1 value_3)}
27
27
  @column.options[:options] = %w(value_1 value_2 value_3)
28
28
  @column.options[:html_options] = {:class => 'big'}
29
- assert_dom_equal '<select name="record[a]" class="big" id="record_a"><option value="">None</option><option disabled="disabled" value="value_1">value_1</option><option selected="selected" value="value_2">value_2</option><option disabled="disabled" value="value_3">value_3</option></select>', active_scaffold_input_select(@column, {})
29
+ assert_dom_equal "<select name=\"record[a]\" class=\"big\" id=\"record_a\"><option value=\"\">None</option>\n<option disabled=\"disabled\" value=\"value_1\">value_1</option>\n<option selected=\"selected\" value=\"value_2\">value_2</option>\n<option disabled=\"disabled\" value=\"value_3\">value_3</option></select>", active_scaffold_input_select(@column, {})
30
30
  end
31
31
  end
@@ -1,8 +1,9 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
1
+ require 'test_helper'
2
2
 
3
3
  class ListColumnHelpersTest < ActionView::TestCase
4
4
  include ActiveScaffold::Helpers::ListColumnHelpers
5
5
  include ActiveScaffold::Helpers::ViewHelpers
6
+ include ::ERB::Util
6
7
 
7
8
  def setup
8
9
  @column = ActiveScaffold::DataStructures::Column.new(:a, ModelStub)
@@ -32,6 +33,8 @@ class ListColumnHelpersTest < ActionView::TestCase
32
33
  value.each {|v| v.stubs(:to_label).returns(v)}
33
34
  assert_equal '1, 2, 3, … (4)', format_association_value(value, @association_column, value.size)
34
35
  @config.list.stubs(:association_join_text => ',<br/>')
36
+ assert_equal '1,&lt;br/&gt;2,&lt;br/&gt;3,&lt;br/&gt;… (4)', format_association_value(value, @association_column, value.size)
37
+ @config.list.stubs(:association_join_text => ',<br/>'.html_safe)
35
38
  assert_equal '1,<br/>2,<br/>3,<br/>… (4)', format_association_value(value, @association_column, value.size)
36
39
  end
37
40
 
@@ -1,8 +1,12 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
1
+ require 'test_helper'
2
2
 
3
3
  class PaginationHelpersTest < Test::Unit::TestCase
4
4
  include ActiveScaffold::Helpers::PaginationHelpers
5
5
 
6
+ def active_scaffold_config
7
+ @config ||= config_for('model_stub')
8
+ end
9
+
6
10
  def test_links
7
11
  self.stubs(:pagination_ajax_link).returns('l')
8
12
 
@@ -50,10 +54,10 @@ class PaginationHelpersTest < Test::Unit::TestCase
50
54
  def links(current, last_page, window_size = 2, infinite = false)
51
55
  paginator = stub(:last => last_page = stub(:number => last_page), :infinite? => infinite)
52
56
  current_page = stub(:number => current, :pager => paginator)
53
- pagination_ajax_links(current_page, {}, window_size)
57
+ pagination_ajax_links(current_page, {}, {}, window_size, 0)
54
58
  end
55
59
 
56
- def content_tag(tag, text)
60
+ def content_tag(tag, text, *args)
57
61
  text
58
62
  end
59
63
  end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
1
+ require 'test_helper'
2
2
 
3
3
  class PermissionModel < ActiveRecord::Base
4
4
  def self.columns; [] end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
1
+ require 'test_helper'
2
2
 
3
3
  class NumberModel < ActiveRecord::Base
4
4
  abstract_class = true
@@ -9,6 +9,7 @@ end
9
9
 
10
10
  class AttributeParamsTest < Test::Unit::TestCase
11
11
  include ActiveScaffold::AttributeParams
12
+ include ActiveScaffold::Finder
12
13
 
13
14
  def setup
14
15
  I18n.backend.store_translations :en, :number => {:format => {
@@ -27,9 +28,7 @@ class AttributeParamsTest < Test::Unit::TestCase
27
28
  }}
28
29
 
29
30
  @config = config_for('number_model')
30
- class << @config.list.columns
31
- include ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration
32
- end
31
+ @config.columns[:number].form_ui = nil
33
32
  @config.list.columns.set_columns @config.columns
34
33
  end
35
34
 
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
1
+ require 'test_helper'
2
2
 
3
3
  class ConfigurableClass
4
4
  FOO = 'bar'
@@ -93,4 +93,4 @@ class ConfigurableTest < Test::Unit::TestCase
93
93
  # but we want to let people accept the configurable class as the first argument, too
94
94
  assert_equal 'bar', ConfigurableClass.configure {|a| a.foo}
95
95
  end
96
- end
96
+ end
@@ -1,11 +1,11 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper.rb')
1
+ require 'test_helper'
2
2
 
3
3
  module ModelStubs
4
4
  class ModelStub < ActiveRecord::Base
5
5
  abstract_class = true
6
6
  def self.columns; [ActiveRecord::ConnectionAdapters::Column.new('foo', '')] end
7
7
  def self.table_name
8
- to_s.split('::').last.underscore.pluralize
8
+ @table_name || to_s.split('::').last.underscore.pluralize
9
9
  end
10
10
  self.store_full_sti_class = false
11
11
  end
@@ -43,31 +43,31 @@ module ModelStubs
43
43
  ##
44
44
 
45
45
  class OtherAddress < ModelStub
46
- set_table_name 'addresses'
46
+ self.table_name = 'addresses'
47
47
  belongs_to :other_addressable, :polymorphic => true
48
48
  end
49
49
 
50
50
  class OtherUser < ModelStub
51
- set_table_name 'users'
51
+ self.table_name = 'users'
52
52
  has_and_belongs_to_many :other_roles, :class_name => 'ModelStubs::OtherRole', :foreign_key => 'user_id', :association_foreign_key => 'role_id', :join_table => 'roles_users'
53
53
  has_one :other_subscription, :class_name => 'ModelStubs::OtherSubscription', :foreign_key => 'user_id'
54
54
  has_one :other_address, :as => :other_addressable, :class_name => 'ModelStubs::OtherAddress', :foreign_key => 'addressable_id'
55
55
  end
56
56
 
57
57
  class OtherService < ModelStub
58
- set_table_name 'services'
58
+ self.table_name = 'services'
59
59
  has_many :other_subscriptions, :class_name => 'ModelStubs::OtherSubscription', :foreign_key => 'service_id'
60
60
  has_many :other_users, :through => :other_subscriptions # :class_name and :foreign_key are ignored for :through
61
61
  end
62
62
 
63
63
  class OtherSubscription < ModelStub
64
- set_table_name 'subscriptions'
64
+ self.table_name = 'subscriptions'
65
65
  belongs_to :other_service, :class_name => 'ModelStubs::OtherService', :foreign_key => 'service_id'
66
66
  belongs_to :other_user, :class_name => 'ModelStubs::OtherUser', :foreign_key => 'user_id'
67
67
  end
68
68
 
69
69
  class OtherRole < ModelStub
70
- set_table_name 'roles'
70
+ self.table_name = 'roles'
71
71
  has_and_belongs_to_many :other_users, :class_name => 'ModelStubs::OtherUser', :foreign_key => 'role_id', :association_foreign_key => 'user_id', :join_table => 'roles_users'
72
72
  end
73
73
 
@@ -112,72 +112,72 @@ class ConstraintsTest < Test::Unit::TestCase
112
112
  def test_constraint_conditions_for_default_associations
113
113
  @test_object.active_scaffold_config = config_for('user')
114
114
  # has_one (vs belongs_to)
115
- assert_constraint_condition({:subscription => 5}, ['subscriptions.id = ?', 5], 'find the user with subscription #5')
115
+ assert_constraint_condition({:subscription => 5}, [{'subscriptions.id' => 5}], 'find the user with subscription #5')
116
116
  # habtm (vs habtm)
117
- assert_constraint_condition({:roles => 4}, ['roles_users.role_id = ?', 4], 'find all users with role #4')
117
+ assert_constraint_condition({:roles => 4}, [{'roles_users.role_id' => 4}], 'find all users with role #4')
118
118
  # has_one (vs polymorphic)
119
- assert_constraint_condition({:address => 11}, ['addresses.id = ?', 11], 'find the user with address #11')
119
+ assert_constraint_condition({:address => 11}, [{'addresses.id' => 11}], 'find the user with address #11')
120
120
  # reverse of a has_many :through
121
- assert_constraint_condition({:subscription => {:service => 5}}, ['services.id = ?', 5], 'find all users subscribed to service #5')
121
+ assert_constraint_condition({:subscription => {:service => 5}}, [{'services.id' => 5}], 'find all users subscribed to service #5')
122
122
  assert(@test_object.active_scaffold_includes.include?({:subscription => :service}), 'multi-level association include')
123
123
 
124
124
  @test_object.active_scaffold_config = config_for('subscription')
125
125
  # belongs_to (vs has_one)
126
- assert_constraint_condition({:user => 2}, ['subscriptions.user_id = ?', 2], 'find the subscription for user #2')
126
+ assert_constraint_condition({:user => 2}, [{'subscriptions.user_id' => 2}], 'find the subscription for user #2')
127
127
  # belongs_to (vs has_many)
128
- assert_constraint_condition({:service => 1}, ['subscriptions.service_id = ?', 1], 'find all subscriptions for service #1')
128
+ assert_constraint_condition({:service => 1}, [{'subscriptions.service_id' => 1}], 'find all subscriptions for service #1')
129
129
 
130
130
  @test_object.active_scaffold_config = config_for('service')
131
131
  # has_many (vs belongs_to)
132
- assert_constraint_condition({:subscriptions => 10}, ['subscriptions.id = ?', 10], 'find the service with subscription #10')
132
+ assert_constraint_condition({:subscriptions => 10}, [{'subscriptions.id' => 10}], 'find the service with subscription #10')
133
133
  # has_many :through (through has_many)
134
- assert_constraint_condition({:users => 7}, ['users.id = ?', 7], 'find the service with user #7')
134
+ assert_constraint_condition({:users => 7}, [{'users.id' => 7}], 'find the service with user #7')
135
135
 
136
136
  @test_object.active_scaffold_config = config_for('address')
137
137
  # belongs_to :polymorphic => true
138
- @test_object.params[:parent_model] = 'User'
139
- assert_constraint_condition({:addressable => 14}, ['addresses.addressable_id = ?', 14, 'addresses.addressable_type = ?', 'User'], 'find all addresses for user #14')
138
+ @test_object.params[:parent_model] = 'ModelStubs::User'
139
+ assert_constraint_condition({:addressable => 14}, [{'addresses.addressable_id' => 14, 'addresses.addressable_type' => 'ModelStubs::User'}], 'find all addresses for user #14')
140
140
  end
141
141
 
142
142
  def test_constraint_conditions_for_configured_associations
143
143
  @test_object.active_scaffold_config = config_for('other_user')
144
144
  # has_one (vs belongs_to)
145
- assert_constraint_condition({:other_subscription => 5}, ['subscriptions.id = ?', 5], 'find the user with subscription #5')
145
+ assert_constraint_condition({:other_subscription => 5}, [{'subscriptions.id' => 5}], 'find the user with subscription #5')
146
146
  # habtm (vs habtm)
147
- assert_constraint_condition({:other_roles => 4}, ['roles_users.role_id = ?', 4], 'find all users with role #4')
147
+ assert_constraint_condition({:other_roles => 4}, [{'roles_users.role_id' => 4}], 'find all users with role #4')
148
148
  # has_one (vs polymorphic)
149
- assert_constraint_condition({:other_address => 11}, ['addresses.id = ?', 11], 'find the user with address #11')
149
+ assert_constraint_condition({:other_address => 11}, [{'addresses.id' => 11}], 'find the user with address #11')
150
150
  # reverse of a has_many :through
151
- assert_constraint_condition({:other_subscription => {:other_service => 5}}, ['services.id = ?', 5], 'find all users subscribed to service #5')
151
+ assert_constraint_condition({:other_subscription => {:other_service => 5}}, [{'services.id' => 5}], 'find all users subscribed to service #5')
152
152
 
153
153
  @test_object.active_scaffold_config = config_for('other_subscription')
154
154
  # belongs_to (vs has_one)
155
- assert_constraint_condition({:other_user => 2}, ['subscriptions.user_id = ?', 2], 'find the subscription for user #2')
155
+ assert_constraint_condition({:other_user => 2}, [{'subscriptions.user_id' => 2}], 'find the subscription for user #2')
156
156
  # belongs_to (vs has_many)
157
- assert_constraint_condition({:other_service => 1}, ['subscriptions.service_id = ?', 1], 'find all subscriptions for service #1')
157
+ assert_constraint_condition({:other_service => 1}, [{'subscriptions.service_id' => 1}], 'find all subscriptions for service #1')
158
158
 
159
159
  @test_object.active_scaffold_config = config_for('other_service')
160
160
  # has_many (vs belongs_to)
161
- assert_constraint_condition({:other_subscriptions => 10}, ['subscriptions.id = ?', 10], 'find the service with subscription #10')
161
+ assert_constraint_condition({:other_subscriptions => 10}, [{'subscriptions.id' => 10}], 'find the service with subscription #10')
162
162
  # has_many :through (through has_many)
163
- assert_constraint_condition({:other_users => 7}, ['users.id = ?', 7], 'find the service with user #7')
163
+ assert_constraint_condition({:other_users => 7}, [{'users.id' => 7}], 'find the service with user #7')
164
164
 
165
165
  @test_object.active_scaffold_config = config_for('other_address')
166
166
  # belongs_to :polymorphic => true
167
- @test_object.params[:parent_model] = 'OtherUser'
168
- assert_constraint_condition({:other_addressable => 14}, ['addresses.other_addressable_id = ?', 14, 'addresses.other_addressable_type = ?', 'OtherUser'], 'find all addresses for user #14')
167
+ @test_object.params[:parent_model] = 'ModelStubs::OtherUser'
168
+ assert_constraint_condition({:other_addressable => 14}, [{'addresses.other_addressable_id' => 14, 'addresses.other_addressable_type' => 'ModelStubs::OtherUser'}], 'find all addresses for user #14')
169
169
  end
170
170
 
171
171
  def test_constraint_conditions_for_normal_attributes
172
172
  @test_object.active_scaffold_config = config_for('user')
173
- assert_constraint_condition({'foo' => 'bar'}, ['"users"."foo" = ?', 'bar'], 'normal column-based constraint')
173
+ assert_constraint_condition({'foo' => 'bar'}, [['"users"."foo" = ?', 'bar']], 'normal column-based constraint')
174
174
  end
175
175
 
176
176
  def test_constraint_conditions_for_associations_with_primary_key_option
177
177
  @test_object.active_scaffold_config = config_for('primary_key_location')
178
178
  #user = ModelStubs::PrimaryKeyUser.new(:id => 1, :name => 'User Name')
179
179
  ModelStubs::PrimaryKeyUser.expects(:find).with(1).returns(stub(:id => 1, :name => 'User Name'))
180
- assert_constraint_condition({'user' => 1}, ['primary_key_locations.username = ?', 'User Name'], 'association with primary-key constraint')
180
+ assert_constraint_condition({'user' => 1}, [{'primary_key_locations.username' => 'User Name'}], 'association with primary-key constraint')
181
181
  end
182
182
 
183
183
  protected