simple_form 3.0.0.rc → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of simple_form might be problematic. Click here for more details.

@@ -65,6 +65,10 @@ module SimpleForm
65
65
  @html_classes = SimpleForm.additional_classes_for(:input) { additional_classes }
66
66
 
67
67
  @input_html_classes = @html_classes.dup
68
+ if SimpleForm.input_class && !input_html_classes.empty?
69
+ input_html_classes << SimpleForm.input_class
70
+ end
71
+
68
72
  @input_html_options = html_options_for(:input, input_html_classes).tap do |o|
69
73
  o[:readonly] = true if has_readonly?
70
74
  o[:disabled] = true if has_disabled?
@@ -17,6 +17,7 @@ module SimpleForm
17
17
  input
18
18
  elsif nested_boolean_style?
19
19
  html_options = label_html_options.dup
20
+ html_options[:class] ||= []
20
21
  html_options[:class].push(:checkbox)
21
22
 
22
23
  build_hidden_field_for_checkbox +
@@ -66,7 +66,7 @@ module SimpleForm
66
66
  collection_translated = translate_collection if collection_classes == [Symbol]
67
67
 
68
68
  if collection_translated || collection_classes.include?(Array)
69
- { label: :first, value: :last }
69
+ { label: :first, value: :second }
70
70
  elsif collection_includes_basic_objects?(collection_classes)
71
71
  { label: :to_s, value: :to_s }
72
72
  else
@@ -11,7 +11,7 @@ module SimpleForm
11
11
  position = case input_type
12
12
  when :date, :datetime
13
13
  date_order = input_options[:order] || I18n.t('date.order')
14
- date_order.first
14
+ date_order.first.to_sym
15
15
  else
16
16
  :hour
17
17
  end
@@ -11,8 +11,9 @@ module SimpleForm
11
11
  value = value_for_collection(item, @value_method)
12
12
  text = value_for_collection(item, @text_method)
13
13
  default_html_options = default_html_options_for_collection(item, value)
14
+ additional_html_options = option_html_attributes(item)
14
15
 
15
- rendered_item = yield item, value, text, default_html_options
16
+ rendered_item = yield item, value, text, default_html_options.merge(additional_html_options)
16
17
 
17
18
  item_wrapper_tag ? @template_object.content_tag(item_wrapper_tag, rendered_item, class: item_wrapper_class) : rendered_item
18
19
  end.join.html_safe
@@ -1,3 +1,3 @@
1
1
  module SimpleForm
2
- VERSION = "3.0.0.rc".freeze
2
+ VERSION = "3.0.0".freeze
3
3
  end
@@ -0,0 +1,7 @@
1
+ module SimpleForm
2
+ <<<<<<< HEAD
3
+ VERSION = "2.0.4".freeze
4
+ =======
5
+ VERSION = "2.1.0.dev".freeze
6
+ >>>>>>> issue-720
7
+ end
@@ -49,8 +49,7 @@ class BuilderTest < ActionView::TestCase
49
49
  end
50
50
 
51
51
  test "collection radio checks the correct value to local variables" do
52
- user = User.new
53
- user.active = false
52
+ user = User.build(active: false)
54
53
  with_collection_radio_buttons user, :active, [true, false], :to_s, :to_s
55
54
 
56
55
  assert_select 'form input[type=radio][value=true]'
@@ -297,9 +296,9 @@ class BuilderTest < ActionView::TestCase
297
296
  end
298
297
 
299
298
  test "collection check box checks the correct value to local variables" do
300
- user = User.new
301
- user.tag_ids = [1, 3]
299
+ user = User.build(tag_ids: [1, 3])
302
300
  collection = (1..3).map { |i| [i, "Tag #{i}"] }
301
+
303
302
  with_collection_check_boxes user, :tag_ids, collection, :first, :last
304
303
 
305
304
  assert_select 'form input[type=checkbox][value=1][checked=checked]'
@@ -105,6 +105,14 @@ class AssociationTest < ActionView::TestCase
105
105
  assert_select 'form input.radio_buttons#user_company_id_3'
106
106
  end
107
107
 
108
+ test 'builder allows collection to have a proc as a condition' do
109
+ with_association_for @user, :extra_special_company
110
+ assert_select 'form select.select#user_extra_special_company_id'
111
+ assert_select 'form select option[value=1]'
112
+ assert_no_select 'form select option[value=2]'
113
+ assert_no_select 'form select option[value=3]'
114
+ end
115
+
108
116
  test 'builder marks the record which already belongs to the user' do
109
117
  @user.company_id = 2
110
118
  with_association_for @user, :company, as: :radio_buttons
@@ -87,6 +87,19 @@ class FormBuilderTest < ActionView::TestCase
87
87
  end
88
88
  end
89
89
 
90
+ test 'builder allow to use numbers in the model name' do
91
+ user = UserNumber1And2.build(tags: [Tag.new(nil, 'Tag1')])
92
+
93
+ with_concat_form_for(user, url: '/') do |f|
94
+ f.simple_fields_for(:tags) do |tags|
95
+ tags.input :name
96
+ end
97
+ end
98
+
99
+ assert_select 'form .user_number1_and2_tags_name'
100
+ assert_no_select 'form .user_number1_and2_tags_1_name'
101
+ end
102
+
90
103
  # INPUT TYPES
91
104
  test 'builder should generate text fields for string columns' do
92
105
  with_form_for @user, :name
@@ -21,6 +21,23 @@ class InputFieldTest < ActionView::TestCase
21
21
  assert_select 'textarea#user_name.text'
22
22
  end
23
23
 
24
+ test 'builder input_field should generate input type based on column type' do
25
+ with_concat_form_for(@user) do |f|
26
+ f.input_field :age
27
+ end
28
+
29
+ assert_select 'input[type=number].integer#user_age'
30
+ end
31
+
32
+ test 'builder input_field should be able to disable any component' do
33
+ with_concat_form_for(@user) do |f|
34
+ f.input_field :age, html5: false
35
+ end
36
+
37
+ assert_no_select 'input[html5=false]#user_age'
38
+ assert_select 'input[type=text].integer#user_age'
39
+ end
40
+
24
41
  test 'builder input_field should allow passing options to input tag' do
25
42
  with_concat_form_for(@user) do |f|
26
43
  f.input_field :name, id: 'name_input', class: 'name'
@@ -19,7 +19,7 @@ class LabelTest < ActionView::TestCase
19
19
  assert_no_select 'label[as=boolean]'
20
20
  end
21
21
 
22
- test 'builder should generate a label componet tag with a clean HTML' do
22
+ test 'builder should generate a label component tag with a clean HTML' do
23
23
  with_label_for @user, :name
24
24
  assert_no_select 'label.string[label_html]'
25
25
  end
@@ -137,4 +137,16 @@ class BooleanInputTest < ActionView::TestCase
137
137
  end
138
138
  end
139
139
  end
140
+
141
+ test 'input boolean without additional classes should add "checkbox" class to label' do
142
+ swap_wrapper :default, self.custom_wrapper_without_top_level do
143
+ swap SimpleForm, boolean_style: :nested, generate_additional_classes_for: [:input] do
144
+ with_input_for @user, :active, :boolean
145
+
146
+ assert_select 'label'
147
+ assert_select 'label.checkbox'
148
+ assert_no_select 'label.boolean'
149
+ end
150
+ end
151
+ end
140
152
  end
@@ -60,6 +60,11 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
60
60
  assert_no_select 'form ul'
61
61
  end
62
62
 
63
+ test 'input check boxes accepts html options as the last element of collection' do
64
+ with_input_for @user, :name, :check_boxes, collection: [['Jose', 'jose', class: 'foo']]
65
+ assert_select 'input.foo[type=checkbox][value=jose]'
66
+ end
67
+
63
68
  test 'input check boxes wraps the collection in the configured collection wrapper tag' do
64
69
  swap SimpleForm, collection_wrapper_tag: :ul do
65
70
  with_input_for @user, :active, :check_boxes
@@ -82,6 +82,11 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
82
82
  assert_select 'input[type=radio][value=Carlos][checked=checked]'
83
83
  end
84
84
 
85
+ test 'input should accept html options as the last element of collection' do
86
+ with_input_for @user, :name, :radio_buttons, collection: [['Jose', 'jose', class: 'foo']]
87
+ assert_select 'input.foo[type=radio][value=jose]'
88
+ end
89
+
85
90
  test 'input should allow using a collection with text/value arrays' do
86
91
  with_input_for @user, :name, :radio_buttons, collection: [['Jose', 'jose'], ['Carlos', 'carlos']]
87
92
  assert_select 'input[type=radio][value=jose]'
@@ -56,6 +56,12 @@ class CollectionSelectInputTest < ActionView::TestCase
56
56
  assert_select 'select option[selected=selected]', 'Carlos'
57
57
  end
58
58
 
59
+ test 'input should accept html options as the last element of collection' do
60
+ with_input_for @user, :name, :select, collection: [['Jose', class: 'foo']]
61
+ assert_select 'select.select#user_name'
62
+ assert_select 'select option.foo', 'Jose'
63
+ end
64
+
59
65
  test 'input should mark the selected value also when using integers' do
60
66
  @user.age = 18
61
67
  with_input_for @user, :age, :select, collection: 18..60
@@ -112,7 +118,7 @@ class CollectionSelectInputTest < ActionView::TestCase
112
118
  end
113
119
 
114
120
  test 'input should detect label and value on collections' do
115
- users = [ setup_new_user(id: 1, name: "Jose"), setup_new_user(id: 2, name: "Carlos") ]
121
+ users = [User.build(id: 1, name: "Jose"), User.build(id: 2, name: "Carlos")]
116
122
  with_input_for @user, :description, :select, collection: users
117
123
  assert_select 'select option[value=1]', 'Jose'
118
124
  assert_select 'select option[value=2]', 'Carlos'
@@ -63,26 +63,26 @@ class DateTimeInputTest < ActionView::TestCase
63
63
  end
64
64
 
65
65
  test 'label should use i18n to get target for date input type' do
66
- store_translations(:en, date: { order: [:month, :day, :year] }) do
66
+ store_translations(:en, date: { order: ['month', 'day', 'year'] }) do
67
67
  with_input_for :project, :created_at, :date
68
68
  assert_select 'label[for=project_created_at_2i]'
69
69
  end
70
70
  end
71
71
 
72
72
  test 'label should use i18n to get target for datetime input type' do
73
- store_translations(:en, date: { order: [:month, :day, :year] }) do
73
+ store_translations(:en, date: { order: ['month', 'day', 'year'] }) do
74
74
  with_input_for :project, :created_at, :datetime
75
75
  assert_select 'label[for=project_created_at_2i]'
76
76
  end
77
77
  end
78
78
 
79
79
  test 'label should use order to get target when date input type' do
80
- with_input_for :project, :created_at, :date, order: [:month, :year, :day]
80
+ with_input_for :project, :created_at, :date, order: ['month', 'year', 'day']
81
81
  assert_select 'label[for=project_created_at_2i]'
82
82
  end
83
83
 
84
84
  test 'label should use order to get target when datetime input type' do
85
- with_input_for :project, :created_at, :datetime, order: [:month, :year, :day]
85
+ with_input_for :project, :created_at, :datetime, order: ['month', 'year', 'day']
86
86
  assert_select 'label[for=project_created_at_2i]'
87
87
  end
88
88
 
@@ -20,6 +20,22 @@ class InputTest < ActionView::TestCase
20
20
  assert_select 'input.string[autofocus]'
21
21
  end
22
22
 
23
+ test 'input accepts input_class configuration' do
24
+ swap SimpleForm, input_class: :xlarge do
25
+ with_input_for @user, :name, :string
26
+ assert_select 'input.xlarge'
27
+ assert_no_select 'div.xlarge'
28
+ end
29
+ end
30
+
31
+ test 'input does not add input_class when configured to not generate additional classes for input' do
32
+ swap SimpleForm, input_class: 'xlarge', generate_additional_classes_for: [:wrapper] do
33
+ with_input_for @user, :name, :string
34
+ assert_select 'input'
35
+ assert_no_select '.xlarge'
36
+ end
37
+ end
38
+
23
39
  test 'text input should generate autofocus attribute when autofocus option is true' do
24
40
  with_input_for @user, :description, :text, autofocus: true
25
41
  assert_select 'textarea.text[autofocus]'
@@ -130,4 +130,17 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
130
130
  end
131
131
  end
132
132
  end
133
+
134
+ test 'grouped collection should accept html options as the last element of collection' do
135
+ with_input_for @user, :tag_ids, :grouped_select,
136
+ collection: [['Authors', [['Jose', 'jose', class: 'foo'], ['Carlos', 'carlos', class: 'bar']]]],
137
+ group_method: :last
138
+
139
+ assert_select 'select.grouped_select#user_tag_ids' do
140
+ assert_select 'optgroup[label=Authors]' do
141
+ assert_select 'option.foo', 'Jose'
142
+ assert_select 'option.bar', 'Carlos'
143
+ end
144
+ end
145
+ end
133
146
  end
@@ -52,7 +52,19 @@ class User
52
52
  :description, :created_at, :updated_at, :credit_limit, :password, :url,
53
53
  :delivery_time, :born_at, :special_company_id, :country, :tags, :tag_ids,
54
54
  :avatar, :home_picture, :email, :status, :residence_country, :phone_number,
55
- :post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender
55
+ :post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender,
56
+ :extra_special_company_id
57
+
58
+ def self.build(extra_attributes = {})
59
+ attributes = {
60
+ id: 1,
61
+ name: 'New in SimpleForm!',
62
+ description: 'Hello!',
63
+ created_at: Time.now
64
+ }.merge! extra_attributes
65
+
66
+ new attributes
67
+ end
56
68
 
57
69
  def initialize(options={})
58
70
  @new_record = false
@@ -119,6 +131,8 @@ class User
119
131
  Association.new(Company, association, :has_one, {})
120
132
  when :special_company
121
133
  Association.new(Company, association, :belongs_to, { conditions: { id: 1 } })
134
+ when :extra_special_company
135
+ Association.new(Company, association, :belongs_to, { conditions: proc { { id: 1 } } })
122
136
  end
123
137
  end
124
138
 
@@ -215,3 +229,6 @@ class HashBackedAuthor < Hash
215
229
  'hash backed author'
216
230
  end
217
231
  end
232
+
233
+ class UserNumber1And2 < User
234
+ end
data/test/test_helper.rb CHANGED
@@ -35,40 +35,27 @@ class ActionView::TestCase
35
35
  include SimpleForm::ActionViewExtensions::FormHelper
36
36
 
37
37
  setup :set_controller
38
- setup :setup_new_user
38
+ setup :setup_users
39
39
 
40
40
  def set_controller
41
41
  @controller = MockController.new
42
42
  end
43
43
 
44
- def setup_new_user(options={})
45
- @user = User.new({
46
- id: 1,
47
- name: 'New in SimpleForm!',
48
- description: 'Hello!',
49
- created_at: Time.now
50
- }.merge(options))
51
-
52
- @validating_user = ValidatingUser.new({
53
- id: 1,
54
- name: 'New in SimpleForm!',
55
- description: 'Hello!',
44
+ def setup_users(extra_attributes = {})
45
+ @user = User.build(extra_attributes)
46
+
47
+ @validating_user = ValidatingUser.build({
56
48
  home_picture: 'Home picture',
57
- created_at: Time.now,
58
49
  age: 19,
59
50
  amount: 15,
60
51
  attempts: 1,
61
52
  company: [1]
62
- }.merge(options))
53
+ }.merge!(extra_attributes))
63
54
 
64
- @other_validating_user = OtherValidatingUser.new({
65
- id: 1,
66
- name: 'New in SimpleForm!',
67
- description: 'Hello!',
68
- created_at: Time.now,
55
+ @other_validating_user = OtherValidatingUser.build({
69
56
  age: 19,
70
57
  company: 1
71
- }.merge(options))
58
+ }.merge!(extra_attributes))
72
59
  end
73
60
 
74
61
  def protect_against_forgery?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.rc
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-05-10 00:00:00.000000000 Z
13
+ date: 2013-09-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 4.0.0.rc1
21
+ version: 4.0.0
22
22
  - - <
23
23
  - !ruby/object:Gem::Version
24
24
  version: '4.1'
@@ -28,7 +28,7 @@ dependencies:
28
28
  requirements:
29
29
  - - '>='
30
30
  - !ruby/object:Gem::Version
31
- version: 4.0.0.rc1
31
+ version: 4.0.0
32
32
  - - <
33
33
  - !ruby/object:Gem::Version
34
34
  version: '4.1'
@@ -38,7 +38,7 @@ dependencies:
38
38
  requirements:
39
39
  - - '>='
40
40
  - !ruby/object:Gem::Version
41
- version: 4.0.0.rc1
41
+ version: 4.0.0
42
42
  - - <
43
43
  - !ruby/object:Gem::Version
44
44
  version: '4.1'
@@ -48,7 +48,7 @@ dependencies:
48
48
  requirements:
49
49
  - - '>='
50
50
  - !ruby/object:Gem::Version
51
- version: 4.0.0.rc1
51
+ version: 4.0.0
52
52
  - - <
53
53
  - !ruby/object:Gem::Version
54
54
  version: '4.1'
@@ -72,6 +72,7 @@ files:
72
72
  - lib/generators/simple_form/templates/README
73
73
  - lib/generators/simple_form/USAGE
74
74
  - lib/simple_form/action_view_extensions/builder.rb
75
+ - lib/simple_form/action_view_extensions/builder.rb.orig
75
76
  - lib/simple_form/action_view_extensions/form_helper.rb
76
77
  - lib/simple_form/components/errors.rb
77
78
  - lib/simple_form/components/hints.rb
@@ -86,6 +87,7 @@ files:
86
87
  - lib/simple_form/components.rb
87
88
  - lib/simple_form/error_notification.rb
88
89
  - lib/simple_form/form_builder.rb
90
+ - lib/simple_form/form_builder.rb.orig
89
91
  - lib/simple_form/helpers/autofocus.rb
90
92
  - lib/simple_form/helpers/disabled.rb
91
93
  - lib/simple_form/helpers/readonly.rb
@@ -115,6 +117,7 @@ files:
115
117
  - lib/simple_form/railtie.rb
116
118
  - lib/simple_form/tags.rb
117
119
  - lib/simple_form/version.rb
120
+ - lib/simple_form/version.rb.orig
118
121
  - lib/simple_form/wrappers/builder.rb
119
122
  - lib/simple_form/wrappers/many.rb
120
123
  - lib/simple_form/wrappers/root.rb
@@ -172,12 +175,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
175
  version: '0'
173
176
  required_rubygems_version: !ruby/object:Gem::Requirement
174
177
  requirements:
175
- - - '>'
178
+ - - '>='
176
179
  - !ruby/object:Gem::Version
177
- version: 1.3.1
180
+ version: '0'
178
181
  requirements: []
179
182
  rubyforge_project: simple_form
180
- rubygems_version: 2.0.3
183
+ rubygems_version: 2.0.6
181
184
  signing_key:
182
185
  specification_version: 4
183
186
  summary: Forms made easy!