formtastic 1.2.5 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.yardopts +1 -0
- data/CHANGELOG +279 -0
- data/Gemfile +3 -0
- data/README.textile +155 -172
- data/RELEASE_PROCESS +7 -0
- data/Rakefile +52 -0
- data/app/assets/stylesheets/formtastic.css +275 -0
- data/app/assets/stylesheets/formtastic_ie6.css +27 -0
- data/app/assets/stylesheets/formtastic_ie7.css +17 -0
- data/formtastic.gemspec +51 -0
- data/lib/formtastic.rb +21 -1960
- data/lib/formtastic/engine.rb +7 -0
- data/lib/formtastic/form_builder.rb +83 -0
- data/lib/formtastic/helpers.rb +16 -0
- data/lib/formtastic/helpers/buttons_helper.rb +277 -0
- data/lib/formtastic/helpers/errors_helper.rb +113 -0
- data/lib/formtastic/helpers/fieldset_wrapper.rb +75 -0
- data/lib/formtastic/helpers/file_column_detection.rb +16 -0
- data/lib/formtastic/helpers/form_helper.rb +198 -0
- data/lib/formtastic/helpers/input_helper.rb +366 -0
- data/lib/formtastic/helpers/inputs_helper.rb +392 -0
- data/lib/formtastic/helpers/reflection.rb +33 -0
- data/lib/formtastic/helpers/semantic_form_helper.rb +11 -0
- data/lib/formtastic/html_attributes.rb +21 -0
- data/lib/formtastic/i18n.rb +1 -0
- data/lib/formtastic/inputs.rb +31 -0
- data/lib/formtastic/inputs/base.rb +61 -0
- data/lib/formtastic/inputs/base/associations.rb +31 -0
- data/lib/formtastic/inputs/base/choices.rb +103 -0
- data/lib/formtastic/inputs/base/collections.rb +94 -0
- data/lib/formtastic/inputs/base/database.rb +17 -0
- data/lib/formtastic/inputs/base/errors.rb +58 -0
- data/lib/formtastic/inputs/base/fileish.rb +23 -0
- data/lib/formtastic/inputs/base/grouped_collections.rb +77 -0
- data/lib/formtastic/inputs/base/hints.rb +31 -0
- data/lib/formtastic/inputs/base/html.rb +52 -0
- data/lib/formtastic/inputs/base/labelling.rb +55 -0
- data/lib/formtastic/inputs/base/naming.rb +42 -0
- data/lib/formtastic/inputs/base/options.rb +18 -0
- data/lib/formtastic/inputs/base/stringish.rb +35 -0
- data/lib/formtastic/inputs/base/timeish.rb +128 -0
- data/lib/formtastic/inputs/base/validations.rb +166 -0
- data/lib/formtastic/inputs/base/wrapping.rb +40 -0
- data/lib/formtastic/inputs/boolean_input.rb +96 -0
- data/lib/formtastic/inputs/check_boxes_input.rb +179 -0
- data/lib/formtastic/inputs/country_input.rb +66 -0
- data/lib/formtastic/inputs/date_input.rb +14 -0
- data/lib/formtastic/inputs/datetime_input.rb +9 -0
- data/lib/formtastic/inputs/email_input.rb +40 -0
- data/lib/formtastic/inputs/file_input.rb +42 -0
- data/lib/formtastic/inputs/hidden_input.rb +66 -0
- data/lib/formtastic/inputs/number_input.rb +118 -0
- data/lib/formtastic/inputs/numeric_input.rb +21 -0
- data/lib/formtastic/inputs/password_input.rb +40 -0
- data/lib/formtastic/inputs/phone_input.rb +41 -0
- data/lib/formtastic/inputs/radio_input.rb +157 -0
- data/lib/formtastic/inputs/range_input.rb +119 -0
- data/lib/formtastic/inputs/search_input.rb +40 -0
- data/lib/formtastic/inputs/select_input.rb +210 -0
- data/lib/formtastic/inputs/string_input.rb +34 -0
- data/lib/formtastic/inputs/text_input.rb +47 -0
- data/lib/formtastic/inputs/time_input.rb +14 -0
- data/lib/formtastic/inputs/time_zone_input.rb +48 -0
- data/lib/formtastic/inputs/url_input.rb +40 -0
- data/lib/formtastic/localized_string.rb +105 -0
- data/lib/formtastic/railtie.rb +5 -7
- data/lib/formtastic/semantic_form_builder.rb +11 -0
- data/lib/formtastic/util.rb +6 -19
- data/lib/formtastic/version.rb +3 -0
- data/lib/generators/formtastic/install/install_generator.rb +28 -6
- data/lib/generators/templates/_form.html.erb +10 -4
- data/lib/generators/templates/_form.html.haml +8 -4
- data/lib/generators/templates/formtastic.rb +25 -32
- data/lib/locale/en.yml +1 -0
- data/lib/tasks/verify_rcov.rb +44 -0
- data/sample/basic_inputs.html +182 -0
- data/sample/config.ru +69 -0
- data/sample/index.html +14 -0
- data/spec/builder/custom_builder_spec.rb +109 -0
- data/spec/builder/error_proc_spec.rb +27 -0
- data/spec/builder/errors_spec.rb +193 -0
- data/spec/builder/semantic_fields_for_spec.rb +88 -0
- data/spec/helpers/buttons_helper_spec.rb +150 -0
- data/spec/helpers/commit_button_helper_spec.rb +470 -0
- data/spec/helpers/form_helper_spec.rb +135 -0
- data/spec/helpers/input_helper_spec.rb +837 -0
- data/spec/helpers/inputs_helper_spec.rb +562 -0
- data/spec/helpers/semantic_errors_helper_spec.rb +112 -0
- data/spec/i18n_spec.rb +199 -0
- data/spec/inputs/boolean_input_spec.rb +184 -0
- data/spec/inputs/check_boxes_input_spec.rb +375 -0
- data/spec/inputs/country_input_spec.rb +133 -0
- data/spec/inputs/custom_input_spec.rb +52 -0
- data/spec/inputs/date_input_spec.rb +110 -0
- data/spec/inputs/datetime_input_spec.rb +115 -0
- data/spec/inputs/email_input_spec.rb +55 -0
- data/spec/inputs/file_input_spec.rb +59 -0
- data/spec/inputs/hidden_input_spec.rb +120 -0
- data/spec/inputs/include_blank_spec.rb +70 -0
- data/spec/inputs/label_spec.rb +104 -0
- data/spec/inputs/number_input_spec.rb +487 -0
- data/spec/inputs/numeric_input_spec.rb +41 -0
- data/spec/inputs/password_input_spec.rb +69 -0
- data/spec/inputs/phone_input_spec.rb +55 -0
- data/spec/inputs/placeholder_spec.rb +71 -0
- data/spec/inputs/radio_input_spec.rb +234 -0
- data/spec/inputs/range_input_spec.rb +477 -0
- data/spec/inputs/search_input_spec.rb +55 -0
- data/spec/inputs/select_input_spec.rb +545 -0
- data/spec/inputs/string_input_spec.rb +163 -0
- data/spec/inputs/text_input_spec.rb +158 -0
- data/spec/inputs/time_input_spec.rb +155 -0
- data/spec/inputs/time_zone_input_spec.rb +87 -0
- data/spec/inputs/url_input_spec.rb +55 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +361 -0
- data/spec/support/custom_macros.rb +656 -0
- data/spec/support/deferred_garbage_collection.rb +21 -0
- data/spec/support/deprecation.rb +6 -0
- data/spec/support/test_environment.rb +30 -0
- metadata +306 -88
- data/generators/form/USAGE +0 -16
- data/generators/form/form_generator.rb +0 -111
- data/generators/formtastic/formtastic_generator.rb +0 -26
- data/init.rb +0 -5
- data/lib/formtastic/layout_helper.rb +0 -12
- data/lib/generators/formtastic/form/form_generator.rb +0 -84
- data/lib/generators/templates/formtastic.css +0 -145
- data/lib/generators/templates/formtastic_changes.css +0 -14
- data/lib/generators/templates/rails2/_form.html.erb +0 -5
- data/lib/generators/templates/rails2/_form.html.haml +0 -4
- data/rails/init.rb +0 -2
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'numeric input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should call NumberInput.new" do
|
14
|
+
input = mock('input', :to_html => "HTML codez")
|
15
|
+
::Formtastic::Inputs::NumericInput.should_receive(:new).and_return(input)
|
16
|
+
concat(semantic_form_for(@new_post) do |builder|
|
17
|
+
concat(builder.input(:title, :as => :numeric))
|
18
|
+
end)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have an li.numeric" do
|
22
|
+
with_deprecation_silenced do
|
23
|
+
concat(semantic_form_for(@new_post) do |builder|
|
24
|
+
concat(builder.input(:title, :as => :numeric))
|
25
|
+
end)
|
26
|
+
end
|
27
|
+
output_buffer.should have_tag('li.numeric')
|
28
|
+
output_buffer.should have_tag('li.input')
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should warn that :numeric is deprecated in favor of :number" do
|
32
|
+
::ActiveSupport::Deprecation.should_receive(:warn)
|
33
|
+
with_deprecation_silenced do
|
34
|
+
concat(semantic_form_for(@new_post) do |builder|
|
35
|
+
concat(builder.input(:title, :as => :numeric))
|
36
|
+
end)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'password input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
|
12
|
+
concat(semantic_form_for(@new_post) do |builder|
|
13
|
+
concat(builder.input(:title, :as => :password))
|
14
|
+
end)
|
15
|
+
end
|
16
|
+
|
17
|
+
it_should_have_input_wrapper_with_class(:password)
|
18
|
+
it_should_have_input_wrapper_with_class(:input)
|
19
|
+
it_should_have_input_wrapper_with_class(:stringish)
|
20
|
+
it_should_have_input_wrapper_with_id("post_title_input")
|
21
|
+
it_should_have_label_with_text(/Title/)
|
22
|
+
it_should_have_label_for("post_title")
|
23
|
+
it_should_have_input_with_id("post_title")
|
24
|
+
it_should_have_input_with_type(:password)
|
25
|
+
it_should_have_input_with_name("post[title]")
|
26
|
+
it_should_have_maxlength_matching_column_limit
|
27
|
+
it_should_use_default_text_field_size_when_not_nil(:string)
|
28
|
+
it_should_not_use_default_text_field_size_when_nil(:string)
|
29
|
+
it_should_apply_custom_input_attributes_when_input_html_provided(:string)
|
30
|
+
it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
|
31
|
+
it_should_apply_error_logic_for_input_type(:password)
|
32
|
+
|
33
|
+
describe "when no object is provided" do
|
34
|
+
before do
|
35
|
+
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
36
|
+
concat(builder.input(:title, :as => :password))
|
37
|
+
end)
|
38
|
+
end
|
39
|
+
|
40
|
+
it_should_have_label_with_text(/Title/)
|
41
|
+
it_should_have_label_for("project_title")
|
42
|
+
it_should_have_input_with_id("project_title")
|
43
|
+
it_should_have_input_with_type(:password)
|
44
|
+
it_should_have_input_with_name("project[title]")
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "when namespace is provided" do
|
48
|
+
|
49
|
+
before do
|
50
|
+
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
51
|
+
concat(builder.input(:title, :as => :password))
|
52
|
+
end)
|
53
|
+
end
|
54
|
+
|
55
|
+
it_should_have_input_wrapper_with_id("context2_post_title_input")
|
56
|
+
it_should_have_label_and_input_with_id("context2_post_title")
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "when required" do
|
61
|
+
it "should add the required attribute to the input's html options" do
|
62
|
+
concat(semantic_form_for(@new_post) do |builder|
|
63
|
+
concat(builder.input(:title, :as => :password, :required => true))
|
64
|
+
end)
|
65
|
+
output_buffer.should have_tag("input[@required]")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'phone input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "when object is provided" do
|
14
|
+
before do
|
15
|
+
concat(semantic_form_for(@new_post) do |builder|
|
16
|
+
concat(builder.input(:phone))
|
17
|
+
end)
|
18
|
+
end
|
19
|
+
|
20
|
+
it_should_have_input_wrapper_with_class(:phone)
|
21
|
+
it_should_have_input_wrapper_with_class(:input)
|
22
|
+
it_should_have_input_wrapper_with_class(:stringish)
|
23
|
+
it_should_have_input_wrapper_with_id("post_phone_input")
|
24
|
+
it_should_have_label_with_text(/Phone/)
|
25
|
+
it_should_have_label_for("post_phone")
|
26
|
+
it_should_have_input_with_id("post_phone")
|
27
|
+
it_should_have_input_with_type(:tel)
|
28
|
+
it_should_have_input_with_name("post[phone]")
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "when namespace is provided" do
|
33
|
+
|
34
|
+
before do
|
35
|
+
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
36
|
+
concat(builder.input(:phone))
|
37
|
+
end)
|
38
|
+
end
|
39
|
+
|
40
|
+
it_should_have_input_wrapper_with_id("context2_post_phone_input")
|
41
|
+
it_should_have_label_and_input_with_id("context2_post_phone")
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "when required" do
|
46
|
+
it "should add the required attribute to the input's html options" do
|
47
|
+
concat(semantic_form_for(@new_post) do |builder|
|
48
|
+
concat(builder.input(:title, :as => :phone, :required => true))
|
49
|
+
end)
|
50
|
+
output_buffer.should have_tag("input[@required]")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'string input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
::I18n.backend.reload!
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "placeholder text" do
|
18
|
+
|
19
|
+
[:email, :number, :password, :phone, :search, :string, :url].each do |type|
|
20
|
+
|
21
|
+
describe "for #{type} inputs" do
|
22
|
+
|
23
|
+
describe "when found in i18n" do
|
24
|
+
it "should have a placeholder containing i18n text" do
|
25
|
+
with_config :i18n_lookups_by_default, true do
|
26
|
+
::I18n.backend.store_translations :en, :formtastic => { :placeholders => { :title => 'War and Peace' }}
|
27
|
+
concat(semantic_form_for(@new_post) do |builder|
|
28
|
+
concat(builder.input(:title))
|
29
|
+
end)
|
30
|
+
output_buffer.should have_tag('input[@placeholder="War and Peace"]')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "when not found in i18n" do
|
36
|
+
it "should not have placeholder" do
|
37
|
+
concat(semantic_form_for(@new_post) do |builder|
|
38
|
+
concat(builder.input(:title))
|
39
|
+
end)
|
40
|
+
output_buffer.should_not have_tag('input[@placeholder]')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "when found in i18n and :input_html" do
|
45
|
+
it "should favor :input_html" do
|
46
|
+
with_config :i18n_lookups_by_default, true do
|
47
|
+
::I18n.backend.store_translations :en, :formtastic => { :placeholders => { :title => 'War and Peace' }}
|
48
|
+
concat(semantic_form_for(@new_post) do |builder|
|
49
|
+
concat(builder.input(:title, :input_html => { :placeholder => "Foo" }))
|
50
|
+
end)
|
51
|
+
output_buffer.should have_tag('input[@placeholder="Foo"]')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "when found in :input_html" do
|
57
|
+
it "should use the :input_html placeholder" do
|
58
|
+
concat(semantic_form_for(@new_post) do |builder|
|
59
|
+
concat(builder.input(:title, :input_html => { :placeholder => "Untitled" }))
|
60
|
+
end)
|
61
|
+
output_buffer.should have_tag('input[@placeholder="Untitled"]')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'radio input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'for belongs_to association' do
|
14
|
+
before do
|
15
|
+
concat(semantic_form_for(@new_post) do |builder|
|
16
|
+
concat(builder.input(:author, :as => :radio, :value_as_class => true, :required => true))
|
17
|
+
end)
|
18
|
+
end
|
19
|
+
|
20
|
+
it_should_have_input_wrapper_with_class("radio")
|
21
|
+
it_should_have_input_wrapper_with_class(:input)
|
22
|
+
it_should_have_input_wrapper_with_id("post_author_input")
|
23
|
+
it_should_have_a_nested_fieldset
|
24
|
+
it_should_have_a_nested_fieldset_with_class('choices')
|
25
|
+
it_should_have_a_nested_ordered_list_with_class('choices-group')
|
26
|
+
it_should_apply_error_logic_for_input_type(:radio)
|
27
|
+
it_should_use_the_collection_when_provided(:radio, 'input')
|
28
|
+
|
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/)
|
32
|
+
end
|
33
|
+
|
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]')
|
36
|
+
end
|
37
|
+
|
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)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should have one option with a "checked" attribute' do
|
44
|
+
output_buffer.should have_tag('form li input[@checked]', :count => 1)
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "each choice" do
|
48
|
+
|
49
|
+
it 'should contain a label for the radio input with a nested input and label text' do
|
50
|
+
::Author.all.each do |author|
|
51
|
+
output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
|
52
|
+
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_id_#{author.id}']")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should use values as li.class when value_as_class is true' do
|
57
|
+
::Author.all.each do |author|
|
58
|
+
output_buffer.should have_tag("form li fieldset ol li.author_#{author.id} label")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should add the required attribute to the input's html options" do
|
63
|
+
::Author.all.each do |post|
|
64
|
+
output_buffer.should have_tag("form li fieldset ol li.author_#{post.id} input[@required]")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should have a radio input" do
|
69
|
+
::Author.all.each do |author|
|
70
|
+
output_buffer.should have_tag("form li fieldset ol li label input#post_author_id_#{author.id}")
|
71
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@type='radio']")
|
72
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@value='#{author.id}']")
|
73
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@name='post[author_id]']")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should mark input as checked if it's the the existing choice" do
|
78
|
+
@new_post.author_id.should == @bob.id
|
79
|
+
@new_post.author.id.should == @bob.id
|
80
|
+
@new_post.author.should == @bob
|
81
|
+
|
82
|
+
concat(semantic_form_for(@new_post) do |builder|
|
83
|
+
concat(builder.input(:author, :as => :radio))
|
84
|
+
end)
|
85
|
+
|
86
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked']")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should mark the input as disabled if options attached for disabling" do
|
90
|
+
concat(semantic_form_for(@new_post) do |builder|
|
91
|
+
concat(builder.input(:author, :as => :radio, :collection => [["Test", 'test'], ["Try", "try", {:disabled => true}]]))
|
92
|
+
end)
|
93
|
+
|
94
|
+
output_buffer.should_not have_tag("form li fieldset ol li label input[@value='test'][@disabled='disabled']")
|
95
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@value='try'][@disabled='disabled']")
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should not contain invalid HTML attributes" do
|
99
|
+
|
100
|
+
concat(semantic_form_for(@new_post) do |builder|
|
101
|
+
concat(builder.input(:author, :as => :radio))
|
102
|
+
end)
|
103
|
+
|
104
|
+
output_buffer.should_not have_tag("form li fieldset ol li input[@find_options]")
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
describe 'and no object is given' do
|
110
|
+
before(:each) do
|
111
|
+
output_buffer.replace ''
|
112
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
113
|
+
concat(builder.input(:author_id, :as => :radio, :collection => ::Author.all))
|
114
|
+
end)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should generate a fieldset with legend' do
|
118
|
+
output_buffer.should have_tag('form li fieldset legend', /Author/)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should generate an li tag for each item in the collection' do
|
122
|
+
output_buffer.should have_tag('form li fieldset ol li', :count => ::Author.all.size)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should generate labels for each item' do
|
126
|
+
::Author.all.each do |author|
|
127
|
+
output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
|
128
|
+
output_buffer.should have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should html escape the label string' do
|
133
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
134
|
+
concat(builder.input(:author_id, :as => :radio, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
|
135
|
+
end)
|
136
|
+
output_buffer.should have_tag('form li fieldset ol li label') do |label|
|
137
|
+
label.body.should match /<b>Item [12]<\/b>$/
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should generate inputs for each item' do
|
142
|
+
::Author.all.each do |author|
|
143
|
+
output_buffer.should have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
|
144
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@type='radio']")
|
145
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@value='#{author.id}']")
|
146
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@name='project[author_id]']")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "with i18n of the legend label" do
|
153
|
+
|
154
|
+
before do
|
155
|
+
::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
|
156
|
+
|
157
|
+
with_config :i18n_lookups_by_default, true do
|
158
|
+
@new_post.stub!(:author_ids).and_return(nil)
|
159
|
+
concat(semantic_form_for(@new_post) do |builder|
|
160
|
+
concat(builder.input(:authors, :as => :radio))
|
161
|
+
end)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
after do
|
166
|
+
::I18n.backend.reload!
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should do foo" do
|
170
|
+
output_buffer.should have_tag("legend.label label", /Translated/)
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "when :label option is set" do
|
176
|
+
before do
|
177
|
+
@new_post.stub!(:author_ids).and_return(nil)
|
178
|
+
concat(semantic_form_for(@new_post) do |builder|
|
179
|
+
concat(builder.input(:authors, :as => :radio, :label => 'The authors'))
|
180
|
+
end)
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should output the correct label title" do
|
184
|
+
output_buffer.should have_tag("legend.label label", /The authors/)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "when :label option is false" do
|
189
|
+
before do
|
190
|
+
@output_buffer = ''
|
191
|
+
@new_post.stub!(:author_ids).and_return(nil)
|
192
|
+
concat(semantic_form_for(@new_post) do |builder|
|
193
|
+
concat(builder.input(:authors, :as => :radio, :label => false))
|
194
|
+
end)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should not output the legend" do
|
198
|
+
output_buffer.should_not have_tag("legend.label")
|
199
|
+
output_buffer.should_not include(">")
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should not cause escaped HTML" do
|
203
|
+
output_buffer.should_not include(">")
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "when :required option is true" do
|
208
|
+
before do
|
209
|
+
@new_post.stub!(:author_ids).and_return(nil)
|
210
|
+
concat(semantic_form_for(@new_post) do |builder|
|
211
|
+
concat(builder.input(:authors, :as => :radio, :required => true))
|
212
|
+
end)
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should output the correct label title" do
|
216
|
+
output_buffer.should have_tag("legend.label label abbr")
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "when :namespace is given on form" do
|
221
|
+
before do
|
222
|
+
@output_buffer = ''
|
223
|
+
@new_post.stub!(:author_ids).and_return(nil)
|
224
|
+
concat(semantic_form_for(@new_post, :namespace => "custom_prefix") do |builder|
|
225
|
+
concat(builder.input(:authors, :as => :radio, :label => ''))
|
226
|
+
end)
|
227
|
+
|
228
|
+
output_buffer.should match(/for="custom_prefix_post_author_ids_(\d+)"/)
|
229
|
+
output_buffer.should match(/id="custom_prefix_post_author_ids_(\d+)"/)
|
230
|
+
end
|
231
|
+
it_should_have_input_wrapper_with_id("custom_prefix_post_authors_input")
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|