simple_form 1.5.2 → 2.0.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 (108) hide show
  1. data/CHANGELOG.md +234 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +816 -0
  4. data/lib/generators/simple_form/install_generator.rb +15 -1
  5. data/lib/generators/simple_form/templates/README +12 -0
  6. data/lib/generators/simple_form/templates/_form.html.erb +2 -2
  7. data/lib/generators/simple_form/templates/_form.html.haml +2 -2
  8. data/lib/generators/simple_form/templates/_form.html.slim +4 -4
  9. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb.tt +176 -0
  10. data/lib/simple_form/action_view_extensions/builder.rb +206 -59
  11. data/lib/simple_form/action_view_extensions/form_helper.rb +30 -23
  12. data/lib/simple_form/components/errors.rb +6 -24
  13. data/lib/simple_form/components/hints.rb +7 -21
  14. data/lib/simple_form/components/html5.rb +26 -0
  15. data/lib/simple_form/components/labels.rb +22 -14
  16. data/lib/simple_form/components/maxlength.rb +41 -0
  17. data/lib/simple_form/components/min_max.rb +49 -0
  18. data/lib/simple_form/components/pattern.rb +34 -0
  19. data/lib/simple_form/components/placeholders.rb +5 -17
  20. data/lib/simple_form/components/readonly.rb +22 -0
  21. data/lib/simple_form/components.rb +11 -1
  22. data/lib/simple_form/core_ext/hash.rb +16 -0
  23. data/lib/simple_form/error_notification.rb +9 -3
  24. data/lib/simple_form/form_builder.rb +105 -28
  25. data/lib/simple_form/helpers/autofocus.rb +11 -0
  26. data/lib/simple_form/helpers/disabled.rb +15 -0
  27. data/lib/simple_form/helpers/readonly.rb +15 -0
  28. data/lib/simple_form/helpers/required.rb +10 -11
  29. data/lib/simple_form/helpers/validators.rb +4 -4
  30. data/lib/simple_form/helpers.rb +7 -4
  31. data/lib/simple_form/inputs/base.rb +53 -81
  32. data/lib/simple_form/inputs/boolean_input.rb +46 -4
  33. data/lib/simple_form/inputs/collection_check_boxes_input.rb +21 -0
  34. data/lib/simple_form/inputs/collection_input.rb +27 -13
  35. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +67 -0
  36. data/lib/simple_form/inputs/collection_select_input.rb +14 -0
  37. data/lib/simple_form/inputs/date_time_input.rb +10 -6
  38. data/lib/simple_form/inputs/grouped_collection_select_input.rb +41 -0
  39. data/lib/simple_form/inputs/hidden_input.rb +3 -6
  40. data/lib/simple_form/inputs/numeric_input.rb +3 -51
  41. data/lib/simple_form/inputs/password_input.rb +1 -2
  42. data/lib/simple_form/inputs/priority_input.rb +2 -2
  43. data/lib/simple_form/inputs/range_input.rb +1 -3
  44. data/lib/simple_form/inputs/string_input.rb +6 -8
  45. data/lib/simple_form/inputs/text_input.rb +1 -2
  46. data/lib/simple_form/inputs.rb +17 -13
  47. data/lib/simple_form/version.rb +1 -1
  48. data/lib/simple_form/wrappers/builder.rb +103 -0
  49. data/lib/simple_form/wrappers/many.rb +69 -0
  50. data/lib/simple_form/wrappers/root.rb +34 -0
  51. data/lib/simple_form/wrappers/single.rb +18 -0
  52. data/lib/simple_form/wrappers.rb +8 -0
  53. data/lib/simple_form.rb +118 -48
  54. data/test/action_view_extensions/builder_test.rb +285 -102
  55. data/test/action_view_extensions/form_helper_test.rb +32 -10
  56. data/test/components/label_test.rb +44 -5
  57. data/test/form_builder/association_test.rb +177 -0
  58. data/test/form_builder/button_test.rb +47 -0
  59. data/test/{error_notification_test.rb → form_builder/error_notification_test.rb} +18 -1
  60. data/test/form_builder/error_test.rb +121 -0
  61. data/test/form_builder/general_test.rb +356 -0
  62. data/test/form_builder/hint_test.rb +123 -0
  63. data/test/form_builder/input_field_test.rb +63 -0
  64. data/test/form_builder/label_test.rb +65 -0
  65. data/test/form_builder/wrapper_test.rb +149 -0
  66. data/test/generators/simple_form_generator_test.rb +32 -0
  67. data/test/inputs/boolean_input_test.rb +101 -0
  68. data/test/inputs/collection_check_boxes_input_test.rb +224 -0
  69. data/test/inputs/collection_radio_buttons_input_test.rb +326 -0
  70. data/test/inputs/collection_select_input_test.rb +241 -0
  71. data/test/inputs/datetime_input_test.rb +99 -0
  72. data/test/inputs/disabled_test.rb +38 -0
  73. data/test/inputs/discovery_test.rb +61 -0
  74. data/test/inputs/file_input_test.rb +16 -0
  75. data/test/inputs/general_test.rb +69 -0
  76. data/test/inputs/grouped_collection_select_input_test.rb +118 -0
  77. data/test/inputs/hidden_input_test.rb +30 -0
  78. data/test/inputs/numeric_input_test.rb +167 -0
  79. data/test/inputs/priority_input_test.rb +43 -0
  80. data/test/inputs/readonly_test.rb +61 -0
  81. data/test/inputs/required_test.rb +113 -0
  82. data/test/inputs/string_input_test.rb +140 -0
  83. data/test/inputs/text_input_test.rb +24 -0
  84. data/test/support/misc_helpers.rb +53 -12
  85. data/test/support/mock_controller.rb +2 -2
  86. data/test/support/models.rb +20 -5
  87. data/test/test_helper.rb +11 -12
  88. metadata +124 -96
  89. data/.gitignore +0 -3
  90. data/.gitmodules +0 -3
  91. data/.travis.yml +0 -15
  92. data/CHANGELOG.rdoc +0 -159
  93. data/Gemfile +0 -9
  94. data/README.rdoc +0 -466
  95. data/Rakefile +0 -27
  96. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +0 -93
  97. data/lib/simple_form/components/wrapper.rb +0 -38
  98. data/lib/simple_form/helpers/has_errors.rb +0 -15
  99. data/lib/simple_form/helpers/maxlength.rb +0 -24
  100. data/lib/simple_form/helpers/pattern.rb +0 -28
  101. data/simple_form.gemspec +0 -25
  102. data/test/components/error_test.rb +0 -56
  103. data/test/components/hint_test.rb +0 -74
  104. data/test/components/wrapper_test.rb +0 -63
  105. data/test/custom_components.rb +0 -7
  106. data/test/form_builder_test.rb +0 -930
  107. data/test/inputs_test.rb +0 -995
  108. /data/test/{discovery_inputs.rb → support/discovery_inputs.rb} +0 -0
@@ -0,0 +1,113 @@
1
+ require 'test_helper'
2
+
3
+ class RequiredTest < ActionView::TestCase
4
+ # REQUIRED AND PRESENCE VALIDATION
5
+ test 'builder input should obtain required from ActiveModel::Validations when it is included' do
6
+ with_form_for @validating_user, :name
7
+ assert_select 'input.required[required]#validating_user_name'
8
+ with_form_for @validating_user, :status
9
+ assert_select 'input.optional#validating_user_status'
10
+ end
11
+
12
+ test 'builder input should allow overriding required when ActiveModel::Validations is included' do
13
+ with_form_for @validating_user, :name, :required => false
14
+ assert_select 'input.optional#validating_user_name'
15
+ with_form_for @validating_user, :status, :required => true
16
+ assert_select 'input.required[required]#validating_user_status'
17
+ end
18
+
19
+ test 'builder input should be required by default when ActiveModel::Validations is not included' do
20
+ with_form_for @user, :name
21
+ assert_select 'input.required[required]#user_name'
22
+ end
23
+
24
+ test 'builder input should not be required by default when ActiveModel::Validations is not included if option is set to false' do
25
+ swap SimpleForm, :required_by_default => false do
26
+ with_form_for @user, :name
27
+ assert_select 'input.optional#user_name'
28
+ assert_no_select 'input[required]'
29
+ end
30
+ end
31
+
32
+ test 'when not using browser validations, input should not generate required html attribute' do
33
+ swap SimpleForm, :browser_validations => false do
34
+ with_input_for @user, :name, :string
35
+ assert_select 'input[type=text].required'
36
+ assert_no_select 'input[type=text][required]'
37
+ end
38
+ end
39
+
40
+ test 'builder input should allow disabling required when ActiveModel::Validations is not included' do
41
+ with_form_for @user, :name, :required => false
42
+ assert_no_select 'input.required'
43
+ assert_no_select 'input[required]'
44
+ assert_select 'input.optional#user_name'
45
+ end
46
+
47
+ test 'when not the required component the input does not have the required attribute but has the required class' do
48
+ swap_wrapper do
49
+ with_input_for @user, :name, :string
50
+ assert_select 'input[type=text].required'
51
+ assert_no_select 'input[type=text][required]'
52
+ end
53
+ end
54
+
55
+ # VALIDATORS :if :unless
56
+ test 'builder input should not be required when ActiveModel::Validations is included and if option is present' do
57
+ with_form_for @validating_user, :age
58
+ assert_no_select 'input.required'
59
+ assert_no_select 'input[required]'
60
+ assert_select 'input.optional#validating_user_age'
61
+ end
62
+
63
+ test 'builder input should not be required when ActiveModel::Validations is included and unless option is present' do
64
+ with_form_for @validating_user, :amount
65
+ assert_no_select 'input.required'
66
+ assert_no_select 'input[required]'
67
+ assert_select 'input.optional#validating_user_amount'
68
+ end
69
+
70
+ # VALIDATORS :on
71
+ test 'builder input should be required when validation is on create and is not persisted' do
72
+ @validating_user.new_record!
73
+ with_form_for @validating_user, :action
74
+ assert_select 'input.required'
75
+ assert_select 'input[required]'
76
+ assert_select 'input.required[required]#validating_user_action'
77
+ end
78
+
79
+ test 'builder input should not be required when validation is on create and is persisted' do
80
+ with_form_for @validating_user, :action
81
+ assert_no_select 'input.required'
82
+ assert_no_select 'input[required]'
83
+ assert_select 'input.optional#validating_user_action'
84
+ end
85
+
86
+ test 'builder input should be required when validation is on save' do
87
+ with_form_for @validating_user, :credit_limit
88
+ assert_select 'input.required'
89
+ assert_select 'input[required]'
90
+ assert_select 'input.required[required]#validating_user_credit_limit'
91
+
92
+ @validating_user.new_record!
93
+ with_form_for @validating_user, :credit_limit
94
+ assert_select 'input.required'
95
+ assert_select 'input[required]'
96
+ assert_select 'input.required[required]#validating_user_credit_limit'
97
+ end
98
+
99
+ test 'builder input should be required when validation is on update and is persisted' do
100
+ with_form_for @validating_user, :phone_number
101
+ assert_select 'input.required'
102
+ assert_select 'input[required]'
103
+ assert_select 'input.required[required]#validating_user_phone_number'
104
+ end
105
+
106
+ test 'builder input should not be required when validation is on update and is not persisted' do
107
+ @validating_user.new_record!
108
+ with_form_for @validating_user, :phone_number
109
+ assert_no_select 'input.required'
110
+ assert_no_select 'input[required]'
111
+ assert_select 'input.optional#validating_user_phone_number'
112
+ end
113
+ end
@@ -0,0 +1,140 @@
1
+ # encoding: UTF-8
2
+ require 'test_helper'
3
+
4
+ class StringInputTest < ActionView::TestCase
5
+ test 'input should map text field to string attribute' do
6
+ with_input_for @user, :name, :string
7
+ assert_select "input#user_name[type=text][name='user[name]'][value=New in SimpleForm!]"
8
+ end
9
+
10
+ test 'input should generate a password field for password attributes' do
11
+ with_input_for @user, :password, :password
12
+ assert_select "input#user_password.password[type=password][name='user[password]']"
13
+ end
14
+
15
+ test 'input should not use size attribute for decimal attributes' do
16
+ with_input_for @user, :credit_limit, :decimal
17
+ assert_no_select 'input.decimal[size]'
18
+ end
19
+
20
+ test 'input should get maxlength from column definition for string attributes' do
21
+ with_input_for @user, :name, :string
22
+ assert_select 'input.string[maxlength=100]'
23
+ end
24
+
25
+ test 'input should not get maxlength from column without size definition for string attributes' do
26
+ with_input_for @user, :action, :string
27
+ assert_no_select 'input.string[maxlength]'
28
+ end
29
+
30
+ test 'input should get size from column definition for string attributes respecting maximum value' do
31
+ with_input_for @user, :name, :string
32
+ assert_select 'input.string[size=50]'
33
+ end
34
+
35
+ test 'input should use default text size for password attributes' do
36
+ with_input_for @user, :password, :password
37
+ assert_select 'input.password[type=password][size=50]'
38
+ end
39
+
40
+ test 'input should get maxlength from column definition for password attributes' do
41
+ with_input_for @user, :password, :password
42
+ assert_select 'input.password[type=password][maxlength=100]'
43
+ end
44
+
45
+ test 'input should infer maxlength column definition from validation when present' do
46
+ with_input_for @validating_user, :name, :string
47
+ assert_select 'input.string[maxlength=25]'
48
+ end
49
+
50
+ test 'input should not get maxlength from validation when tokenizer present' do
51
+ with_input_for @validating_user, :action, :string
52
+ assert_no_select 'input.string[maxlength]'
53
+ end
54
+
55
+ test 'input should get maxlength from validation when :is option present' do
56
+ with_input_for @validating_user, :home_picture, :string
57
+ assert_select 'input.string[maxlength=12]'
58
+ end
59
+
60
+ test 'input should not generate placeholder by default' do
61
+ with_input_for @user, :name, :string
62
+ assert_no_select 'input[placeholder]'
63
+ end
64
+
65
+ test 'input should accept the placeholder option' do
66
+ with_input_for @user, :name, :string, :placeholder => 'Put in some text'
67
+ assert_select 'input.string[placeholder=Put in some text]'
68
+ end
69
+
70
+ test 'input should generate a password field for password attributes that accept placeholder' do
71
+ with_input_for @user, :password, :password, :placeholder => 'Password Confirmation'
72
+ assert_select 'input[type=password].password[placeholder=Password Confirmation]#user_password'
73
+ end
74
+
75
+ test 'input should not infer pattern from attributes by default' do
76
+ with_input_for @other_validating_user, :country, :string
77
+ assert_no_select 'input[pattern="\w+"]'
78
+ end
79
+
80
+ test 'input should infer pattern from attributes' do
81
+ with_input_for @other_validating_user, :country, :string, :pattern => true
82
+ assert_select 'input[pattern="\w+"]'
83
+ end
84
+
85
+ test 'input should infer pattern from attributes using proc' do
86
+ with_input_for @other_validating_user, :name, :string, :pattern => true
87
+ assert_select 'input[pattern="\w+"]'
88
+ end
89
+
90
+ test 'input should not infer pattern from attributes if root default is false' do
91
+ swap_wrapper do
92
+ with_input_for @other_validating_user, :country, :string
93
+ assert_no_select 'input[pattern="\w+"]'
94
+ end
95
+ end
96
+
97
+ test 'input should use given pattern from attributes' do
98
+ with_input_for @other_validating_user, :country, :string, :input_html => { :pattern => "\\d+" }
99
+ assert_select 'input[pattern="\d+"]'
100
+ end
101
+
102
+ test 'input should use i18n to translate placeholder text' do
103
+ store_translations(:en, :simple_form => { :placeholders => { :user => {
104
+ :name => 'Name goes here'
105
+ } } }) do
106
+ with_input_for @user, :name, :string
107
+ assert_select 'input.string[placeholder=Name goes here]'
108
+ end
109
+ end
110
+
111
+ [:email, :url, :search, :tel].each do |type|
112
+ test "input should allow type #{type}" do
113
+ with_input_for @user, :name, type
114
+ assert_select "input.string.#{type}"
115
+ assert_select "input[type=#{type}]"
116
+ end
117
+
118
+ test "input should not allow type #{type} if HTML5 compatibility is disabled" do
119
+ swap_wrapper do
120
+ with_input_for @user, :name, type
121
+ assert_select "input[type=text]"
122
+ assert_no_select "input[type=#{type}]"
123
+ end
124
+ end
125
+ end
126
+
127
+ test 'input strips extra spaces from class html attribute with default classes' do
128
+ with_input_for @user, :name, :string
129
+ assert_select "input[class='string required']"
130
+ assert_no_select "input[class='string required ']"
131
+ assert_no_select "input[class=' string required']"
132
+ end
133
+
134
+ test 'input strips extra spaces from class html attribute when giving a custom class' do
135
+ with_input_for @user, :name, :string, :input_html => { :class => "my_input" }
136
+ assert_select "input[class='string required my_input']"
137
+ assert_no_select "input[class='string required my_input ']"
138
+ assert_no_select "input[class=' string required my_input']"
139
+ end
140
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: UTF-8
2
+ require 'test_helper'
3
+
4
+ class TextInputTest < ActionView::TestCase
5
+ test 'input should generate a text area for text attributes' do
6
+ with_input_for @user, :description, :text
7
+ assert_select 'textarea.text#user_description'
8
+ end
9
+
10
+ test 'input should generate a text area for text attributes that accept placeholder' do
11
+ with_input_for @user, :description, :text, :placeholder => 'Put in some text'
12
+ assert_select 'textarea.text[placeholder=Put in some text]'
13
+ end
14
+
15
+ test 'input should get maxlength from column definition for text attributes' do
16
+ with_input_for @user, :description, :text
17
+ assert_select 'textarea.text[maxlength=200]'
18
+ end
19
+
20
+ test 'input should infer maxlength column definition from validation when present for text attributes' do
21
+ with_input_for @validating_user, :description, :text
22
+ assert_select 'textarea.text[maxlength=50]'
23
+ end
24
+ end
@@ -1,11 +1,10 @@
1
1
  module MiscHelpers
2
2
  def store_translations(locale, translations, &block)
3
- begin
4
- I18n.backend.store_translations locale, translations
5
- yield
6
- ensure
7
- I18n.reload!
8
- end
3
+ I18n.backend.store_translations locale, translations
4
+ yield
5
+ ensure
6
+ I18n.reload!
7
+ I18n.backend.send :init_translations
9
8
  end
10
9
 
11
10
  def assert_no_select(selector, value = nil)
@@ -25,12 +24,34 @@ module MiscHelpers
25
24
  end
26
25
  end
27
26
 
28
- def with_concat_form_for(object, &block)
29
- concat simple_form_for(object, &block)
27
+ def swap_wrapper(name=:default, wrapper=self.custom_wrapper)
28
+ old = SimpleForm.wrappers[name]
29
+ SimpleForm.wrappers[name] = wrapper
30
+ yield
31
+ ensure
32
+ SimpleForm.wrappers[name] = old
33
+ end
34
+
35
+ def custom_wrapper
36
+ SimpleForm.build :tag => :section, :class => "custom_wrapper", :pattern => false do |b|
37
+ b.use :pattern
38
+ b.wrapper :another, :class => "another_wrapper" do |ba|
39
+ ba.use :label
40
+ ba.use :input
41
+ end
42
+ b.wrapper :error_wrapper, :tag => :div, :class => "error_wrapper" do |be|
43
+ be.use :error, :wrap_with => { :tag => :span, :class => "omg_error" }
44
+ end
45
+ b.use :hint, :wrap_with => { :class => "omg_hint" }
46
+ end
30
47
  end
31
48
 
32
- def with_concat_custom_form_for(object, &block)
33
- concat custom_form_for(object, &block)
49
+ def custom_wrapper_without_top_level
50
+ SimpleForm.build :tag => false, :class => 'custom_wrapper_without_top_level' do |b|
51
+ b.use :label_input
52
+ b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
53
+ b.use :error, :wrap_with => { :tag => :span, :class => :error }
54
+ end
34
55
  end
35
56
 
36
57
  def custom_form_for(object, *args, &block)
@@ -41,8 +62,28 @@ module MiscHelpers
41
62
  simple_form_for(object, *(args << { :builder => CustomMapTypeFormBuilder }), &block)
42
63
  end
43
64
 
44
- def with_concat_custom_mapping_form_for(object, &block)
45
- concat custom_mapping_form_for(object, &block)
65
+ def with_concat_form_for(*args, &block)
66
+ concat simple_form_for(*args, &block)
67
+ end
68
+
69
+ def with_concat_custom_form_for(*args, &block)
70
+ concat custom_form_for(*args, &block)
71
+ end
72
+
73
+ def with_concat_custom_mapping_form_for(*args, &block)
74
+ concat custom_mapping_form_for(*args, &block)
75
+ end
76
+
77
+ def with_form_for(object, *args, &block)
78
+ with_concat_form_for(object) do |f|
79
+ f.input(*args, &block)
80
+ end
81
+ end
82
+
83
+ def with_input_for(object, attribute_name, type, options={})
84
+ with_concat_form_for(object) do |f|
85
+ f.input(attribute_name, options.merge(:as => type))
86
+ end
46
87
  end
47
88
  end
48
89
 
@@ -1,12 +1,12 @@
1
1
  class MockController
2
- attr_accessor :action_name
2
+ attr_writer :action_name
3
3
 
4
4
  def _routes
5
5
  self
6
6
  end
7
7
 
8
8
  def action_name
9
- @action_name || "edit"
9
+ defined?(@action_name) ? @action_name : "edit"
10
10
  end
11
11
 
12
12
  def url_for(*args)
@@ -26,14 +26,14 @@ class Company < Struct.new(:id, :name)
26
26
  end
27
27
 
28
28
  class Tag < Company
29
- extend ActiveModel::Naming
30
- include ActiveModel::Conversion
31
-
32
29
  def self.all(options={})
33
30
  (1..3).map{|i| Tag.new(i, "Tag #{i}")}
34
31
  end
35
32
  end
36
33
 
34
+ class TagGroup < Struct.new(:id, :name, :tags)
35
+ end
36
+
37
37
  class User
38
38
  extend ActiveModel::Naming
39
39
  include ActiveModel::Conversion
@@ -42,9 +42,10 @@ class User
42
42
  :description, :created_at, :updated_at, :credit_limit, :password, :url,
43
43
  :delivery_time, :born_at, :special_company_id, :country, :tags, :tag_ids,
44
44
  :avatar, :home_picture, :email, :status, :residence_country, :phone_number,
45
- :post_count, :lock_version, :amount, :attempts, :action
45
+ :post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender
46
46
 
47
47
  def initialize(options={})
48
+ @new_record = false
48
49
  options.each do |key, value|
49
50
  send("#{key}=", value)
50
51
  end if options
@@ -55,7 +56,7 @@ class User
55
56
  end
56
57
 
57
58
  def persisted?
58
- !(@new_record || false)
59
+ !@new_record
59
60
  end
60
61
 
61
62
  def company_attributes=(*)
@@ -80,6 +81,7 @@ class User
80
81
  when :amount then :integer
81
82
  when :attempts then :integer
82
83
  when :action then :string
84
+ when :credit_card then :string
83
85
  end
84
86
  Column.new(attribute, column_type, limit)
85
87
  end
@@ -122,6 +124,10 @@ class User
122
124
  )
123
125
  end
124
126
  end
127
+
128
+ def self.readonly_attributes
129
+ [:credit_card]
130
+ end
125
131
  end
126
132
 
127
133
  class ValidatingUser < User
@@ -149,6 +155,8 @@ class ValidatingUser < User
149
155
  :only_integer => true
150
156
  validates_length_of :name, :maximum => 25
151
157
  validates_length_of :description, :maximum => 50
158
+ validates_length_of :action, :maximum => 10, :tokenizer => lambda { |str| str.scan(/\w+/) }
159
+ validates_length_of :home_picture, :is => 12
152
160
 
153
161
  def min_amount
154
162
  10
@@ -183,6 +191,13 @@ class OtherValidatingUser < User
183
191
  :only_integer => true
184
192
 
185
193
  validates_format_of :country, :with => /\w+/
194
+
195
+ # TODO: Remove this check when we drop Rails 3.0 support
196
+ if ActiveModel::VERSION::MAJOR == 3 && ActiveModel::VERSION::MINOR >= 1
197
+ validates_format_of :name, :with => Proc.new { /\w+/ }
198
+ else
199
+ validates_format_of :name, :with => /\w+/
200
+ end
186
201
  end
187
202
 
188
203
  class HashBackedAuthor < Hash
data/test/test_helper.rb CHANGED
@@ -22,17 +22,15 @@ end
22
22
  $:.unshift File.expand_path("../../lib", __FILE__)
23
23
  require 'simple_form'
24
24
 
25
- Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
26
- I18n.default_locale = :en
27
-
28
- country_select = "#{File.dirname(__FILE__)}/support/country_select/lib"
25
+ require "rails/generators/test_case"
26
+ require 'generators/simple_form/install_generator'
29
27
 
30
- if File.exists?(country_select)
31
- $:.unshift country_select
32
- require 'country_select'
33
- else
34
- raise "Could not find country_select plugin in test/support. Please execute git submodule update --init."
28
+ Dir["#{File.dirname(__FILE__)}/support/*.rb"].each do |file|
29
+ require file unless file.end_with?('discovery_inputs.rb')
35
30
  end
31
+ I18n.default_locale = :en
32
+
33
+ require 'country_select'
36
34
 
37
35
  class ActionView::TestCase
38
36
  include MiscHelpers
@@ -53,15 +51,16 @@ class ActionView::TestCase
53
51
  def setup_new_user(options={})
54
52
  @user = User.new({
55
53
  :id => 1,
56
- :name => 'New in Simple Form!',
54
+ :name => 'New in SimpleForm!',
57
55
  :description => 'Hello!',
58
56
  :created_at => Time.now
59
57
  }.merge(options))
60
58
 
61
59
  @validating_user = ValidatingUser.new({
62
60
  :id => 1,
63
- :name => 'New in Simple Form!',
61
+ :name => 'New in SimpleForm!',
64
62
  :description => 'Hello!',
63
+ :home_picture => 'Home picture',
65
64
  :created_at => Time.now,
66
65
  :age => 19,
67
66
  :amount => 15,
@@ -71,7 +70,7 @@ class ActionView::TestCase
71
70
 
72
71
  @other_validating_user = OtherValidatingUser.new({
73
72
  :id => 1,
74
- :name => 'New in Simple Form!',
73
+ :name => 'New in SimpleForm!',
75
74
  :description => 'Hello!',
76
75
  :created_at => Time.now,
77
76
  :age => 19,