formtastic 2.1.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +1 -0
  3. data/.github/workflows/test.yml +61 -0
  4. data/.gitignore +4 -2
  5. data/CHANGELOG.md +52 -0
  6. data/Gemfile +1 -1
  7. data/Gemfile.lock +105 -0
  8. data/MIT-LICENSE +1 -1
  9. data/{README.textile → README.md} +204 -219
  10. data/RELEASE_PROCESS +3 -1
  11. data/Rakefile +27 -29
  12. data/app/assets/stylesheets/formtastic.css +3 -2
  13. data/bin/appraisal +8 -0
  14. data/formtastic.gemspec +11 -14
  15. data/gemfiles/rails_5.2/Gemfile +5 -0
  16. data/gemfiles/rails_6.0/Gemfile +5 -0
  17. data/gemfiles/rails_6.1/Gemfile +5 -0
  18. data/gemfiles/rails_edge/Gemfile +13 -0
  19. data/lib/formtastic/action_class_finder.rb +18 -0
  20. data/lib/formtastic/actions/button_action.rb +55 -60
  21. data/lib/formtastic/actions/input_action.rb +59 -57
  22. data/lib/formtastic/actions/link_action.rb +68 -67
  23. data/lib/formtastic/actions.rb +6 -3
  24. data/lib/formtastic/deprecation.rb +5 -0
  25. data/lib/formtastic/engine.rb +3 -1
  26. data/lib/formtastic/form_builder.rb +35 -16
  27. data/lib/formtastic/helpers/action_helper.rb +34 -28
  28. data/lib/formtastic/helpers/enum.rb +13 -0
  29. data/lib/formtastic/helpers/errors_helper.rb +2 -2
  30. data/lib/formtastic/helpers/fieldset_wrapper.rb +16 -12
  31. data/lib/formtastic/helpers/form_helper.rb +19 -16
  32. data/lib/formtastic/helpers/input_helper.rb +69 -97
  33. data/lib/formtastic/helpers/inputs_helper.rb +35 -25
  34. data/lib/formtastic/helpers/reflection.rb +4 -4
  35. data/lib/formtastic/helpers.rb +1 -2
  36. data/lib/formtastic/html_attributes.rb +12 -1
  37. data/lib/formtastic/i18n.rb +1 -1
  38. data/lib/formtastic/input_class_finder.rb +18 -0
  39. data/lib/formtastic/inputs/base/choices.rb +2 -2
  40. data/lib/formtastic/inputs/base/collections.rb +46 -14
  41. data/lib/formtastic/inputs/base/database.rb +7 -2
  42. data/lib/formtastic/inputs/base/datetime_pickerish.rb +85 -0
  43. data/lib/formtastic/inputs/base/errors.rb +7 -7
  44. data/lib/formtastic/inputs/base/hints.rb +2 -2
  45. data/lib/formtastic/inputs/base/html.rb +10 -9
  46. data/lib/formtastic/inputs/base/labelling.rb +5 -8
  47. data/lib/formtastic/inputs/base/naming.rb +4 -4
  48. data/lib/formtastic/inputs/base/numeric.rb +1 -1
  49. data/lib/formtastic/inputs/base/options.rb +3 -4
  50. data/lib/formtastic/inputs/base/stringish.rb +10 -2
  51. data/lib/formtastic/inputs/base/timeish.rb +34 -22
  52. data/lib/formtastic/inputs/base/validations.rb +41 -13
  53. data/lib/formtastic/inputs/base/wrapping.rb +29 -26
  54. data/lib/formtastic/inputs/base.rb +22 -15
  55. data/lib/formtastic/inputs/boolean_input.rb +26 -12
  56. data/lib/formtastic/inputs/check_boxes_input.rb +39 -31
  57. data/lib/formtastic/inputs/color_input.rb +41 -0
  58. data/lib/formtastic/inputs/country_input.rb +24 -5
  59. data/lib/formtastic/inputs/datalist_input.rb +41 -0
  60. data/lib/formtastic/inputs/date_picker_input.rb +93 -0
  61. data/lib/formtastic/inputs/{date_input.rb → date_select_input.rb} +1 -1
  62. data/lib/formtastic/inputs/datetime_picker_input.rb +103 -0
  63. data/lib/formtastic/inputs/{datetime_input.rb → datetime_select_input.rb} +1 -1
  64. data/lib/formtastic/inputs/file_input.rb +2 -2
  65. data/lib/formtastic/inputs/hidden_input.rb +2 -6
  66. data/lib/formtastic/inputs/radio_input.rb +28 -22
  67. data/lib/formtastic/inputs/select_input.rb +36 -39
  68. data/lib/formtastic/inputs/time_picker_input.rb +99 -0
  69. data/lib/formtastic/inputs/{time_input.rb → time_select_input.rb} +6 -2
  70. data/lib/formtastic/inputs/time_zone_input.rb +16 -6
  71. data/lib/formtastic/inputs.rb +32 -21
  72. data/lib/formtastic/localized_string.rb +1 -1
  73. data/lib/formtastic/localizer.rb +24 -24
  74. data/lib/formtastic/namespaced_class_finder.rb +99 -0
  75. data/lib/formtastic/version.rb +1 -1
  76. data/lib/formtastic.rb +20 -10
  77. data/lib/generators/formtastic/form/form_generator.rb +10 -4
  78. data/lib/generators/formtastic/input/input_generator.rb +46 -0
  79. data/lib/generators/formtastic/install/install_generator.rb +5 -19
  80. data/lib/generators/templates/_form.html.slim +2 -2
  81. data/lib/generators/templates/formtastic.rb +46 -25
  82. data/lib/generators/templates/input.rb +19 -0
  83. data/sample/basic_inputs.html +23 -3
  84. data/script/integration-template.rb +74 -0
  85. data/script/integration.sh +19 -0
  86. data/spec/action_class_finder_spec.rb +12 -0
  87. data/spec/actions/button_action_spec.rb +8 -8
  88. data/spec/actions/generic_action_spec.rb +92 -56
  89. data/spec/actions/input_action_spec.rb +7 -7
  90. data/spec/actions/link_action_spec.rb +10 -10
  91. data/spec/builder/custom_builder_spec.rb +36 -20
  92. data/spec/builder/error_proc_spec.rb +4 -4
  93. data/spec/builder/semantic_fields_for_spec.rb +28 -29
  94. data/spec/fast_spec_helper.rb +12 -0
  95. data/spec/generators/formtastic/form/form_generator_spec.rb +45 -32
  96. data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
  97. data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
  98. data/spec/helpers/action_helper_spec.rb +75 -103
  99. data/spec/helpers/actions_helper_spec.rb +17 -17
  100. data/spec/helpers/form_helper_spec.rb +84 -33
  101. data/spec/helpers/input_helper_spec.rb +333 -285
  102. data/spec/helpers/inputs_helper_spec.rb +167 -121
  103. data/spec/helpers/reflection_helper_spec.rb +3 -3
  104. data/spec/helpers/semantic_errors_helper_spec.rb +23 -23
  105. data/spec/i18n_spec.rb +26 -26
  106. data/spec/input_class_finder_spec.rb +10 -0
  107. data/spec/inputs/base/collections_spec.rb +76 -0
  108. data/spec/inputs/base/validations_spec.rb +480 -0
  109. data/spec/inputs/boolean_input_spec.rb +100 -65
  110. data/spec/inputs/check_boxes_input_spec.rb +200 -101
  111. data/spec/inputs/color_input_spec.rb +85 -0
  112. data/spec/inputs/country_input_spec.rb +20 -20
  113. data/spec/inputs/custom_input_spec.rb +3 -4
  114. data/spec/inputs/datalist_input_spec.rb +61 -0
  115. data/spec/inputs/date_picker_input_spec.rb +449 -0
  116. data/spec/inputs/date_select_input_spec.rb +249 -0
  117. data/spec/inputs/datetime_picker_input_spec.rb +490 -0
  118. data/spec/inputs/datetime_select_input_spec.rb +209 -0
  119. data/spec/inputs/email_input_spec.rb +5 -5
  120. data/spec/inputs/file_input_spec.rb +6 -6
  121. data/spec/inputs/hidden_input_spec.rb +22 -35
  122. data/spec/inputs/include_blank_spec.rb +11 -11
  123. data/spec/inputs/label_spec.rb +62 -25
  124. data/spec/inputs/number_input_spec.rb +112 -112
  125. data/spec/inputs/password_input_spec.rb +5 -5
  126. data/spec/inputs/phone_input_spec.rb +5 -5
  127. data/spec/inputs/placeholder_spec.rb +6 -6
  128. data/spec/inputs/radio_input_spec.rb +99 -55
  129. data/spec/inputs/range_input_spec.rb +66 -66
  130. data/spec/inputs/readonly_spec.rb +50 -0
  131. data/spec/inputs/search_input_spec.rb +5 -5
  132. data/spec/inputs/select_input_spec.rb +170 -170
  133. data/spec/inputs/string_input_spec.rb +68 -16
  134. data/spec/inputs/text_input_spec.rb +16 -16
  135. data/spec/inputs/time_picker_input_spec.rb +455 -0
  136. data/spec/inputs/time_select_input_spec.rb +261 -0
  137. data/spec/inputs/time_zone_input_spec.rb +54 -28
  138. data/spec/inputs/url_input_spec.rb +5 -5
  139. data/spec/inputs/with_options_spec.rb +7 -7
  140. data/spec/localizer_spec.rb +39 -17
  141. data/spec/namespaced_class_finder_spec.rb +79 -0
  142. data/spec/schema.rb +21 -0
  143. data/spec/spec_helper.rb +254 -221
  144. data/spec/support/custom_macros.rb +128 -95
  145. data/spec/support/shared_examples.rb +12 -0
  146. data/spec/support/specialized_class_finder_shared_example.rb +27 -0
  147. data/spec/support/test_environment.rb +26 -10
  148. metadata +177 -238
  149. data/.travis.yml +0 -8
  150. data/Appraisals +0 -11
  151. data/CHANGELOG +0 -371
  152. data/gemfiles/rails-3.0.gemfile +0 -7
  153. data/gemfiles/rails-3.1.gemfile +0 -7
  154. data/gemfiles/rails-3.2.gemfile +0 -7
  155. data/lib/formtastic/helpers/buttons_helper.rb +0 -310
  156. data/lib/formtastic/inputs/base/grouped_collections.rb +0 -77
  157. data/lib/formtastic/util.rb +0 -25
  158. data/lib/tasks/verify_rcov.rb +0 -44
  159. data/spec/helpers/buttons_helper_spec.rb +0 -166
  160. data/spec/helpers/commit_button_helper_spec.rb +0 -530
  161. data/spec/inputs/date_input_spec.rb +0 -227
  162. data/spec/inputs/datetime_input_spec.rb +0 -185
  163. data/spec/inputs/time_input_spec.rb +0 -267
  164. data/spec/support/deferred_garbage_collection.rb +0 -21
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'password input' do
4
+ RSpec.describe 'password input' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
@@ -71,15 +71,15 @@ describe 'password input' do
71
71
  end
72
72
 
73
73
  it 'should index the id of the wrapper' do
74
- output_buffer.should have_tag("li#post_author_attributes_3_name_input")
74
+ expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
75
75
  end
76
76
 
77
77
  it 'should index the id of the select tag' do
78
- output_buffer.should have_tag("input#post_author_attributes_3_name")
78
+ expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
79
79
  end
80
80
 
81
81
  it 'should index the name of the select tag' do
82
- output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
82
+ expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][name]']")
83
83
  end
84
84
 
85
85
  end
@@ -91,7 +91,7 @@ describe 'password input' do
91
91
  concat(semantic_form_for(@new_post) do |builder|
92
92
  concat(builder.input(:title, :as => :password, :required => true))
93
93
  end)
94
- output_buffer.should have_tag("input[@required]")
94
+ expect(output_buffer).to have_tag("input[@required]")
95
95
  end
96
96
  end
97
97
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'phone input' do
4
+ RSpec.describe 'phone input' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
@@ -56,15 +56,15 @@ describe 'phone input' do
56
56
  end
57
57
 
58
58
  it 'should index the id of the wrapper' do
59
- output_buffer.should have_tag("li#post_author_attributes_3_name_input")
59
+ expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
60
60
  end
61
61
 
62
62
  it 'should index the id of the select tag' do
63
- output_buffer.should have_tag("input#post_author_attributes_3_name")
63
+ expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
64
64
  end
65
65
 
66
66
  it 'should index the name of the select tag' do
67
- output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
67
+ expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][name]']")
68
68
  end
69
69
 
70
70
  end
@@ -76,7 +76,7 @@ describe 'phone input' do
76
76
  concat(semantic_form_for(@new_post) do |builder|
77
77
  concat(builder.input(:title, :as => :phone, :required => true))
78
78
  end)
79
- output_buffer.should have_tag("input[@required]")
79
+ expect(output_buffer).to have_tag("input[@required]")
80
80
  end
81
81
  end
82
82
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'string input' do
4
+ RSpec.describe 'string input' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
@@ -16,7 +16,7 @@ describe 'string input' do
16
16
 
17
17
  describe "placeholder text" do
18
18
 
19
- [:email, :number, :password, :phone, :search, :string, :url, :text].each do |type|
19
+ [:email, :number, :password, :phone, :search, :string, :url, :text, :date_picker, :time_picker, :datetime_picker].each do |type|
20
20
 
21
21
  describe "for #{type} inputs" do
22
22
 
@@ -27,7 +27,7 @@ describe 'string input' do
27
27
  concat(semantic_form_for(@new_post) do |builder|
28
28
  concat(builder.input(:title, :as => type))
29
29
  end)
30
- output_buffer.should have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder="War and Peace"]')
30
+ expect(output_buffer).to have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder="War and Peace"]')
31
31
  end
32
32
  end
33
33
  end
@@ -37,7 +37,7 @@ describe 'string input' do
37
37
  concat(semantic_form_for(@new_post) do |builder|
38
38
  concat(builder.input(:title, :as => type))
39
39
  end)
40
- output_buffer.should_not have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder]')
40
+ expect(output_buffer).not_to have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder]')
41
41
  end
42
42
  end
43
43
 
@@ -48,7 +48,7 @@ describe 'string input' do
48
48
  concat(semantic_form_for(@new_post) do |builder|
49
49
  concat(builder.input(:title, :as => type, :input_html => { :placeholder => "Foo" }))
50
50
  end)
51
- output_buffer.should have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder="Foo"]')
51
+ expect(output_buffer).to have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder="Foo"]')
52
52
  end
53
53
  end
54
54
  end
@@ -58,7 +58,7 @@ describe 'string input' do
58
58
  concat(semantic_form_for(@new_post) do |builder|
59
59
  concat(builder.input(:title, :as => type, :input_html => { :placeholder => "Untitled" }))
60
60
  end)
61
- output_buffer.should have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder="Untitled"]')
61
+ expect(output_buffer).to have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder="Untitled"]')
62
62
  end
63
63
  end
64
64
 
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'radio input' do
4
+ RSpec.describe 'radio input' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
@@ -27,66 +27,66 @@ describe 'radio input' do
27
27
  it_should_use_the_collection_when_provided(:radio, 'input')
28
28
 
29
29
  it 'should generate a legend containing a label with text for the input' do
30
- output_buffer.should have_tag('form li fieldset legend.label label')
31
- output_buffer.should have_tag('form li fieldset legend.label label', /Author/)
30
+ expect(output_buffer).to have_tag('form li fieldset legend.label label')
31
+ expect(output_buffer).to have_tag('form li fieldset legend.label label', :text => /Author/)
32
32
  end
33
33
 
34
34
  it 'should not link the label within the legend to any input' do
35
- output_buffer.should_not have_tag('form li fieldset legend label[@for]')
35
+ expect(output_buffer).not_to have_tag('form li fieldset legend label[@for]')
36
36
  end
37
37
 
38
38
  it 'should generate an ordered list with a list item for each choice' do
39
- output_buffer.should have_tag('form li fieldset ol')
40
- output_buffer.should have_tag('form li fieldset ol li.choice', :count => ::Author.all.size)
39
+ expect(output_buffer).to have_tag('form li fieldset ol')
40
+ expect(output_buffer).to have_tag('form li fieldset ol li.choice', :count => ::Author.all.size)
41
41
  end
42
42
 
43
43
  it 'should have one option with a "checked" attribute' do
44
- output_buffer.should have_tag('form li input[@checked]', :count => 1)
44
+ expect(output_buffer).to have_tag('form li input[@checked]', :count => 1)
45
45
  end
46
46
 
47
47
  describe "each choice" do
48
48
 
49
49
  it 'should not give the choice label the .label class' do
50
- output_buffer.should_not have_tag('li.choice label.label')
50
+ expect(output_buffer).not_to have_tag('li.choice label.label')
51
51
  end
52
52
 
53
53
  it 'should not add the required attribute to each input' do
54
- output_buffer.should_not have_tag('li.choice input[@required]')
54
+ expect(output_buffer).not_to have_tag('li.choice input[@required]')
55
55
  end
56
56
 
57
57
 
58
58
  it 'should contain a label for the radio input with a nested input and label text' do
59
59
  ::Author.all.each do |author|
60
- output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
61
- output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_id_#{author.id}']")
60
+ expect(output_buffer).to have_tag('form li fieldset ol li label', /#{author.to_label}/)
61
+ expect(output_buffer).to have_tag("form li fieldset ol li label[@for='post_author_id_#{author.id}']")
62
62
  end
63
63
  end
64
64
 
65
65
  it 'should use values as li.class when value_as_class is true' do
66
66
  ::Author.all.each do |author|
67
- output_buffer.should have_tag("form li fieldset ol li.author_#{author.id} label")
67
+ expect(output_buffer).to have_tag("form li fieldset ol li.author_#{author.id} label")
68
68
  end
69
69
  end
70
70
 
71
71
  it "should have a radio input" do
72
72
  ::Author.all.each do |author|
73
- output_buffer.should have_tag("form li fieldset ol li label input#post_author_id_#{author.id}")
74
- output_buffer.should have_tag("form li fieldset ol li label input[@type='radio']")
75
- output_buffer.should have_tag("form li fieldset ol li label input[@value='#{author.id}']")
76
- output_buffer.should have_tag("form li fieldset ol li label input[@name='post[author_id]']")
73
+ expect(output_buffer).to have_tag("form li fieldset ol li label input#post_author_id_#{author.id}")
74
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@type='radio']")
75
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='#{author.id}']")
76
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@name='post[author_id]']")
77
77
  end
78
78
  end
79
79
 
80
80
  it "should mark input as checked if it's the the existing choice" do
81
- @new_post.author_id.should == @bob.id
82
- @new_post.author.id.should == @bob.id
83
- @new_post.author.should == @bob
81
+ expect(@new_post.author_id).to eq(@bob.id)
82
+ expect(@new_post.author.id).to eq(@bob.id)
83
+ expect(@new_post.author).to eq(@bob)
84
84
 
85
85
  concat(semantic_form_for(@new_post) do |builder|
86
86
  concat(builder.input(:author, :as => :radio))
87
87
  end)
88
88
 
89
- output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked']")
89
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@checked='checked']")
90
90
  end
91
91
 
92
92
  it "should mark the input as disabled if options attached for disabling" do
@@ -94,8 +94,8 @@ describe 'radio input' do
94
94
  concat(builder.input(:author, :as => :radio, :collection => [["Test", 'test'], ["Try", "try", {:disabled => true}]]))
95
95
  end)
96
96
 
97
- output_buffer.should_not have_tag("form li fieldset ol li label input[@value='test'][@disabled='disabled']")
98
- output_buffer.should have_tag("form li fieldset ol li label input[@value='try'][@disabled='disabled']")
97
+ expect(output_buffer).not_to have_tag("form li fieldset ol li label input[@value='test'][@disabled='disabled']")
98
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='try'][@disabled='disabled']")
99
99
  end
100
100
 
101
101
  it "should not contain invalid HTML attributes" do
@@ -104,13 +104,13 @@ describe 'radio input' do
104
104
  concat(builder.input(:author, :as => :radio))
105
105
  end)
106
106
 
107
- output_buffer.should_not have_tag("form li fieldset ol li input[@find_options]")
107
+ expect(output_buffer).not_to have_tag("form li fieldset ol li input[@find_options]")
108
108
  end
109
109
 
110
110
  end
111
111
 
112
112
  describe 'and no object is given' do
113
- before(:each) do
113
+ before(:example) do
114
114
  output_buffer.replace ''
115
115
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
116
116
  concat(builder.input(:author_id, :as => :radio, :collection => ::Author.all))
@@ -118,17 +118,17 @@ describe 'radio input' do
118
118
  end
119
119
 
120
120
  it 'should generate a fieldset with legend' do
121
- output_buffer.should have_tag('form li fieldset legend', /Author/)
121
+ expect(output_buffer).to have_tag('form li fieldset legend', :text => /Author/)
122
122
  end
123
123
 
124
124
  it 'should generate an li tag for each item in the collection' do
125
- output_buffer.should have_tag('form li fieldset ol li', :count => ::Author.all.size)
125
+ expect(output_buffer).to have_tag('form li fieldset ol li', :count => ::Author.all.size)
126
126
  end
127
127
 
128
128
  it 'should generate labels for each item' do
129
129
  ::Author.all.each do |author|
130
- output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
131
- output_buffer.should have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
130
+ expect(output_buffer).to have_tag('form li fieldset ol li label', :text => /#{author.to_label}/)
131
+ expect(output_buffer).to have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
132
132
  end
133
133
  end
134
134
 
@@ -136,29 +136,55 @@ describe 'radio input' do
136
136
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
137
137
  concat(builder.input(:author_id, :as => :radio, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
138
138
  end)
139
- output_buffer.should have_tag('form li fieldset ol li label') do |label|
140
- label.body.should match /&lt;b&gt;Item [12]&lt;\/b&gt;$/
141
- end
139
+ expect(output_buffer).to have_tag('form li fieldset ol li label', text: %r{<b>Item [12]</b>}, count: 2)
142
140
  end
143
141
 
144
142
  it 'should generate inputs for each item' do
145
143
  ::Author.all.each do |author|
146
- output_buffer.should have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
147
- output_buffer.should have_tag("form li fieldset ol li label input[@type='radio']")
148
- output_buffer.should have_tag("form li fieldset ol li label input[@value='#{author.id}']")
149
- output_buffer.should have_tag("form li fieldset ol li label input[@name='project[author_id]']")
144
+ expect(output_buffer).to have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
145
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@type='radio']")
146
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='#{author.id}']")
147
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@name='project[author_id]']")
150
148
  end
151
149
  end
152
150
  end
153
151
  end
154
152
 
153
+ describe 'for a enum column' do
154
+ before do
155
+ allow(@new_post).to receive(:status) { 'inactive' }
156
+ statuses = ActiveSupport::HashWithIndifferentAccess.new("active"=>0, "inactive"=>1)
157
+ allow(@new_post.class).to receive(:statuses) { statuses }
158
+ allow(@new_post).to receive(:defined_enums) { { "status" => statuses } }
159
+ end
160
+
161
+ before do
162
+ concat(semantic_form_for(@new_post) do |builder|
163
+ concat(builder.input(:status, :as => :radio))
164
+ end)
165
+ end
166
+
167
+ it 'should have a radio input for each defined enum status' do
168
+ expect(output_buffer).to have_tag("form li input[@name='post[status]'][@type='radio']", :count => @new_post.class.statuses.count)
169
+ @new_post.class.statuses.each do |label, value|
170
+ expect(output_buffer).to have_tag("form li input[@value='#{label}']")
171
+ expect(output_buffer).to have_tag("form li label", :text => /#{label.humanize}/)
172
+ end
173
+ end
174
+
175
+ it 'should have one radio input with a "checked" attribute' do
176
+ expect(output_buffer).to have_tag("form li input[@name='post[status]'][@checked]", :count => 1)
177
+ end
178
+ end
179
+
180
+
155
181
  describe "with i18n of the legend label" do
156
182
 
157
183
  before do
158
184
  ::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
159
185
 
160
186
  with_config :i18n_lookups_by_default, true do
161
- @new_post.stub!(:author_ids).and_return(nil)
187
+ allow(@new_post).to receive(:author_ids).and_return(nil)
162
188
  concat(semantic_form_for(@new_post) do |builder|
163
189
  concat(builder.input(:authors, :as => :radio))
164
190
  end)
@@ -170,66 +196,66 @@ describe 'radio input' do
170
196
  end
171
197
 
172
198
  it "should do foo" do
173
- output_buffer.should have_tag("legend.label label", /Translated/)
199
+ expect(output_buffer).to have_tag("legend.label label", :text => /Translated/)
174
200
  end
175
201
 
176
202
  end
177
203
 
178
204
  describe "when :label option is set" do
179
205
  before do
180
- @new_post.stub!(:author_ids).and_return(nil)
206
+ allow(@new_post).to receive(:author_ids).and_return(nil)
181
207
  concat(semantic_form_for(@new_post) do |builder|
182
208
  concat(builder.input(:authors, :as => :radio, :label => 'The authors'))
183
209
  end)
184
210
  end
185
211
 
186
212
  it "should output the correct label title" do
187
- output_buffer.should have_tag("legend.label label", /The authors/)
213
+ expect(output_buffer).to have_tag("legend.label label", :text => /The authors/)
188
214
  end
189
215
  end
190
216
 
191
217
  describe "when :label option is false" do
192
218
  before do
193
219
  @output_buffer = ''
194
- @new_post.stub!(:author_ids).and_return(nil)
220
+ allow(@new_post).to receive(:author_ids).and_return(nil)
195
221
  concat(semantic_form_for(@new_post) do |builder|
196
222
  concat(builder.input(:authors, :as => :radio, :label => false))
197
223
  end)
198
224
  end
199
225
 
200
226
  it "should not output the legend" do
201
- output_buffer.should_not have_tag("legend.label")
202
- output_buffer.should_not include("&gt;")
227
+ expect(output_buffer).not_to have_tag("legend.label")
228
+ expect(output_buffer).not_to include("&gt;")
203
229
  end
204
230
 
205
231
  it "should not cause escaped HTML" do
206
- output_buffer.should_not include("&gt;")
232
+ expect(output_buffer).not_to include("&gt;")
207
233
  end
208
234
  end
209
235
 
210
236
  describe "when :required option is true" do
211
237
  before do
212
- @new_post.stub!(:author_ids).and_return(nil)
238
+ allow(@new_post).to receive(:author_ids).and_return(nil)
213
239
  concat(semantic_form_for(@new_post) do |builder|
214
240
  concat(builder.input(:authors, :as => :radio, :required => true))
215
241
  end)
216
242
  end
217
243
 
218
244
  it "should output the correct label title" do
219
- output_buffer.should have_tag("legend.label label abbr")
245
+ expect(output_buffer).to have_tag("legend.label label abbr")
220
246
  end
221
247
  end
222
248
 
223
249
  describe "when :namespace is given on form" do
224
250
  before do
225
251
  @output_buffer = ''
226
- @new_post.stub!(:author_ids).and_return(nil)
252
+ allow(@new_post).to receive(:author_ids).and_return(nil)
227
253
  concat(semantic_form_for(@new_post, :namespace => "custom_prefix") do |builder|
228
254
  concat(builder.input(:authors, :as => :radio, :label => ''))
229
255
  end)
230
256
 
231
- output_buffer.should match(/for="custom_prefix_post_author_ids_(\d+)"/)
232
- output_buffer.should match(/id="custom_prefix_post_author_ids_(\d+)"/)
257
+ expect(output_buffer).to match(/for="custom_prefix_post_author_ids_(\d+)"/)
258
+ expect(output_buffer).to match(/id="custom_prefix_post_author_ids_(\d+)"/)
233
259
  end
234
260
  it_should_have_input_wrapper_with_id("custom_prefix_post_authors_input")
235
261
  end
@@ -248,16 +274,16 @@ describe 'radio input' do
248
274
  end
249
275
 
250
276
  it 'should index the id of the wrapper' do
251
- output_buffer.should have_tag("li#post_author_attributes_3_name_input")
277
+ expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
252
278
  end
253
279
 
254
280
  it 'should index the id of the select tag' do
255
- output_buffer.should have_tag("input#post_author_attributes_3_name_true")
256
- output_buffer.should have_tag("input#post_author_attributes_3_name_false")
281
+ expect(output_buffer).to have_tag("input#post_author_attributes_3_name_true")
282
+ expect(output_buffer).to have_tag("input#post_author_attributes_3_name_false")
257
283
  end
258
284
 
259
285
  it 'should index the name of the select tag' do
260
- output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
286
+ expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][name]']")
261
287
  end
262
288
 
263
289
  end
@@ -273,10 +299,28 @@ describe 'radio input' do
273
299
  end
274
300
 
275
301
  it 'should output the correct labels' do
276
- output_buffer.should have_tag("li.choice label", /1/)
277
- output_buffer.should have_tag("li.choice label", /2/)
278
- output_buffer.should have_tag("li.choice label", /3/)
302
+ expect(output_buffer).to have_tag("li.choice label", :text => /1/)
303
+ expect(output_buffer).to have_tag("li.choice label", :text => /2/)
304
+ expect(output_buffer).to have_tag("li.choice label", :text => /3/)
305
+ end
306
+ end
307
+
308
+ describe "when collection contains symbols" do
309
+ before do
310
+ @output_buffer = ''
311
+ mock_everything
312
+
313
+ concat(semantic_form_for(:project) do |builder|
314
+ concat(builder.input(:author_id, :as => :radio, :collection => Set.new([["A", :a], ["B", :b], ["C", :c]])))
315
+ end)
316
+ end
317
+
318
+ it 'should output the correct labels' do
319
+ expect(output_buffer).to have_tag("li.choice label", :text => /A/)
320
+ expect(output_buffer).to have_tag("li.choice label", :text => /B/)
321
+ expect(output_buffer).to have_tag("li.choice label", :text => /C/)
279
322
  end
280
323
  end
281
324
 
325
+
282
326
  end