formtastic 2.1.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +1 -0
- data/.github/workflows/test.yml +61 -0
- data/.gitignore +4 -2
- data/CHANGELOG.md +52 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +105 -0
- data/MIT-LICENSE +1 -1
- data/{README.textile → README.md} +204 -219
- data/RELEASE_PROCESS +3 -1
- data/Rakefile +27 -29
- data/app/assets/stylesheets/formtastic.css +3 -2
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +11 -14
- data/gemfiles/rails_5.2/Gemfile +5 -0
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_6.1/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic/action_class_finder.rb +18 -0
- data/lib/formtastic/actions/button_action.rb +55 -60
- data/lib/formtastic/actions/input_action.rb +59 -57
- data/lib/formtastic/actions/link_action.rb +68 -67
- data/lib/formtastic/actions.rb +6 -3
- data/lib/formtastic/deprecation.rb +5 -0
- data/lib/formtastic/engine.rb +3 -1
- data/lib/formtastic/form_builder.rb +35 -16
- data/lib/formtastic/helpers/action_helper.rb +34 -28
- data/lib/formtastic/helpers/enum.rb +13 -0
- data/lib/formtastic/helpers/errors_helper.rb +2 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +16 -12
- data/lib/formtastic/helpers/form_helper.rb +19 -16
- data/lib/formtastic/helpers/input_helper.rb +69 -97
- data/lib/formtastic/helpers/inputs_helper.rb +35 -25
- data/lib/formtastic/helpers/reflection.rb +4 -4
- data/lib/formtastic/helpers.rb +1 -2
- data/lib/formtastic/html_attributes.rb +12 -1
- data/lib/formtastic/i18n.rb +1 -1
- data/lib/formtastic/input_class_finder.rb +18 -0
- data/lib/formtastic/inputs/base/choices.rb +2 -2
- data/lib/formtastic/inputs/base/collections.rb +46 -14
- data/lib/formtastic/inputs/base/database.rb +7 -2
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +85 -0
- data/lib/formtastic/inputs/base/errors.rb +7 -7
- data/lib/formtastic/inputs/base/hints.rb +2 -2
- data/lib/formtastic/inputs/base/html.rb +10 -9
- data/lib/formtastic/inputs/base/labelling.rb +5 -8
- data/lib/formtastic/inputs/base/naming.rb +4 -4
- data/lib/formtastic/inputs/base/numeric.rb +1 -1
- data/lib/formtastic/inputs/base/options.rb +3 -4
- data/lib/formtastic/inputs/base/stringish.rb +10 -2
- data/lib/formtastic/inputs/base/timeish.rb +34 -22
- data/lib/formtastic/inputs/base/validations.rb +41 -13
- data/lib/formtastic/inputs/base/wrapping.rb +29 -26
- data/lib/formtastic/inputs/base.rb +22 -15
- data/lib/formtastic/inputs/boolean_input.rb +26 -12
- data/lib/formtastic/inputs/check_boxes_input.rb +39 -31
- data/lib/formtastic/inputs/color_input.rb +41 -0
- data/lib/formtastic/inputs/country_input.rb +24 -5
- data/lib/formtastic/inputs/datalist_input.rb +41 -0
- data/lib/formtastic/inputs/date_picker_input.rb +93 -0
- data/lib/formtastic/inputs/{date_input.rb → date_select_input.rb} +1 -1
- data/lib/formtastic/inputs/datetime_picker_input.rb +103 -0
- data/lib/formtastic/inputs/{datetime_input.rb → datetime_select_input.rb} +1 -1
- data/lib/formtastic/inputs/file_input.rb +2 -2
- data/lib/formtastic/inputs/hidden_input.rb +2 -6
- data/lib/formtastic/inputs/radio_input.rb +28 -22
- data/lib/formtastic/inputs/select_input.rb +36 -39
- data/lib/formtastic/inputs/time_picker_input.rb +99 -0
- data/lib/formtastic/inputs/{time_input.rb → time_select_input.rb} +6 -2
- data/lib/formtastic/inputs/time_zone_input.rb +16 -6
- data/lib/formtastic/inputs.rb +32 -21
- data/lib/formtastic/localized_string.rb +1 -1
- data/lib/formtastic/localizer.rb +24 -24
- data/lib/formtastic/namespaced_class_finder.rb +99 -0
- data/lib/formtastic/version.rb +1 -1
- data/lib/formtastic.rb +20 -10
- data/lib/generators/formtastic/form/form_generator.rb +10 -4
- data/lib/generators/formtastic/input/input_generator.rb +46 -0
- data/lib/generators/formtastic/install/install_generator.rb +5 -19
- data/lib/generators/templates/_form.html.slim +2 -2
- data/lib/generators/templates/formtastic.rb +46 -25
- data/lib/generators/templates/input.rb +19 -0
- data/sample/basic_inputs.html +23 -3
- data/script/integration-template.rb +74 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +12 -0
- data/spec/actions/button_action_spec.rb +8 -8
- data/spec/actions/generic_action_spec.rb +92 -56
- data/spec/actions/input_action_spec.rb +7 -7
- data/spec/actions/link_action_spec.rb +10 -10
- data/spec/builder/custom_builder_spec.rb +36 -20
- data/spec/builder/error_proc_spec.rb +4 -4
- data/spec/builder/semantic_fields_for_spec.rb +28 -29
- data/spec/fast_spec_helper.rb +12 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +45 -32
- data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
- data/spec/helpers/action_helper_spec.rb +75 -103
- data/spec/helpers/actions_helper_spec.rb +17 -17
- data/spec/helpers/form_helper_spec.rb +84 -33
- data/spec/helpers/input_helper_spec.rb +333 -285
- data/spec/helpers/inputs_helper_spec.rb +167 -121
- data/spec/helpers/reflection_helper_spec.rb +3 -3
- data/spec/helpers/semantic_errors_helper_spec.rb +23 -23
- data/spec/i18n_spec.rb +26 -26
- data/spec/input_class_finder_spec.rb +10 -0
- data/spec/inputs/base/collections_spec.rb +76 -0
- data/spec/inputs/base/validations_spec.rb +480 -0
- data/spec/inputs/boolean_input_spec.rb +100 -65
- data/spec/inputs/check_boxes_input_spec.rb +200 -101
- data/spec/inputs/color_input_spec.rb +85 -0
- data/spec/inputs/country_input_spec.rb +20 -20
- data/spec/inputs/custom_input_spec.rb +3 -4
- data/spec/inputs/datalist_input_spec.rb +61 -0
- data/spec/inputs/date_picker_input_spec.rb +449 -0
- data/spec/inputs/date_select_input_spec.rb +249 -0
- data/spec/inputs/datetime_picker_input_spec.rb +490 -0
- data/spec/inputs/datetime_select_input_spec.rb +209 -0
- data/spec/inputs/email_input_spec.rb +5 -5
- data/spec/inputs/file_input_spec.rb +6 -6
- data/spec/inputs/hidden_input_spec.rb +22 -35
- data/spec/inputs/include_blank_spec.rb +11 -11
- data/spec/inputs/label_spec.rb +62 -25
- data/spec/inputs/number_input_spec.rb +112 -112
- data/spec/inputs/password_input_spec.rb +5 -5
- data/spec/inputs/phone_input_spec.rb +5 -5
- data/spec/inputs/placeholder_spec.rb +6 -6
- data/spec/inputs/radio_input_spec.rb +99 -55
- data/spec/inputs/range_input_spec.rb +66 -66
- data/spec/inputs/readonly_spec.rb +50 -0
- data/spec/inputs/search_input_spec.rb +5 -5
- data/spec/inputs/select_input_spec.rb +170 -170
- data/spec/inputs/string_input_spec.rb +68 -16
- data/spec/inputs/text_input_spec.rb +16 -16
- data/spec/inputs/time_picker_input_spec.rb +455 -0
- data/spec/inputs/time_select_input_spec.rb +261 -0
- data/spec/inputs/time_zone_input_spec.rb +54 -28
- data/spec/inputs/url_input_spec.rb +5 -5
- data/spec/inputs/with_options_spec.rb +7 -7
- data/spec/localizer_spec.rb +39 -17
- data/spec/namespaced_class_finder_spec.rb +79 -0
- data/spec/schema.rb +21 -0
- data/spec/spec_helper.rb +254 -221
- data/spec/support/custom_macros.rb +128 -95
- data/spec/support/shared_examples.rb +12 -0
- data/spec/support/specialized_class_finder_shared_example.rb +27 -0
- data/spec/support/test_environment.rb +26 -10
- metadata +177 -238
- data/.travis.yml +0 -8
- data/Appraisals +0 -11
- data/CHANGELOG +0 -371
- data/gemfiles/rails-3.0.gemfile +0 -7
- data/gemfiles/rails-3.1.gemfile +0 -7
- data/gemfiles/rails-3.2.gemfile +0 -7
- data/lib/formtastic/helpers/buttons_helper.rb +0 -310
- data/lib/formtastic/inputs/base/grouped_collections.rb +0 -77
- data/lib/formtastic/util.rb +0 -25
- data/lib/tasks/verify_rcov.rb +0 -44
- data/spec/helpers/buttons_helper_spec.rb +0 -166
- data/spec/helpers/commit_button_helper_spec.rb +0 -530
- data/spec/inputs/date_input_spec.rb +0 -227
- data/spec/inputs/datetime_input_spec.rb +0 -185
- data/spec/inputs/time_input_spec.rb +0 -267
- 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 'country input' do
|
4
|
+
RSpec.describe 'country input' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -13,11 +13,11 @@ describe 'country input' do
|
|
13
13
|
describe "when country_select is not available as a helper from a plugin" do
|
14
14
|
|
15
15
|
it "should raise an error, sugesting the author installs a plugin" do
|
16
|
-
|
16
|
+
expect {
|
17
17
|
semantic_form_for(@new_post) do |builder|
|
18
18
|
concat(builder.input(:country, :as => :country))
|
19
19
|
end
|
20
|
-
}.
|
20
|
+
}.to raise_error(Formtastic::Inputs::CountryInput::CountrySelectPluginMissing)
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
@@ -26,7 +26,7 @@ describe 'country input' do
|
|
26
26
|
|
27
27
|
before do
|
28
28
|
concat(semantic_form_for(@new_post) do |builder|
|
29
|
-
builder.
|
29
|
+
allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
|
30
30
|
concat(builder.input(:country, :as => :country))
|
31
31
|
end)
|
32
32
|
end
|
@@ -39,13 +39,13 @@ describe 'country input' do
|
|
39
39
|
#it_should_apply_error_logic_for_input_type(:country)
|
40
40
|
|
41
41
|
it 'should generate a label for the input' do
|
42
|
-
output_buffer.
|
43
|
-
output_buffer.
|
44
|
-
output_buffer.
|
42
|
+
expect(output_buffer).to have_tag('form li label')
|
43
|
+
expect(output_buffer).to have_tag('form li label[@for="post_country"]')
|
44
|
+
expect(output_buffer).to have_tag('form li label', :text => /Country/)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should generate a select" do
|
48
|
-
output_buffer.
|
48
|
+
expect(output_buffer).to have_tag("form li select")
|
49
49
|
end
|
50
50
|
|
51
51
|
end
|
@@ -55,8 +55,8 @@ describe 'country input' do
|
|
55
55
|
it "should be passed down to the country_select helper when provided" do
|
56
56
|
priority_countries = ["Foo", "Bah"]
|
57
57
|
semantic_form_for(@new_post) do |builder|
|
58
|
-
builder.
|
59
|
-
builder.
|
58
|
+
allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
|
59
|
+
expect(builder).to receive(:country_select).with(:country, priority_countries, {}, {:id => "post_country", :required => false, :autofocus => false, :readonly => false}).and_return("<select><option>...</option></select>".html_safe)
|
60
60
|
|
61
61
|
concat(builder.input(:country, :as => :country, :priority_countries => priority_countries))
|
62
62
|
end
|
@@ -64,12 +64,12 @@ describe 'country input' do
|
|
64
64
|
|
65
65
|
it "should default to the @@priority_countries config when absent" do
|
66
66
|
priority_countries = Formtastic::FormBuilder.priority_countries
|
67
|
-
priority_countries.
|
68
|
-
priority_countries.
|
67
|
+
expect(priority_countries).not_to be_empty
|
68
|
+
expect(priority_countries).not_to be_nil
|
69
69
|
|
70
70
|
semantic_form_for(@new_post) do |builder|
|
71
|
-
builder.
|
72
|
-
builder.
|
71
|
+
allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
|
72
|
+
expect(builder).to receive(:country_select).with(:country, priority_countries, {}, {:id => "post_country", :required => false, :autofocus => false, :readonly => false}).and_return("<select><option>...</option></select>".html_safe)
|
73
73
|
|
74
74
|
concat(builder.input(:country, :as => :country))
|
75
75
|
end
|
@@ -84,8 +84,8 @@ describe 'country input' do
|
|
84
84
|
mock_everything
|
85
85
|
|
86
86
|
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
87
|
-
builder.
|
88
|
-
builder.
|
87
|
+
allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
|
88
|
+
expect(builder).to receive(:country_select).with(:country, [], {}, {:id => "context2_post_country", :required => false, :autofocus => false, :readonly => false}).and_return("<select><option>...</option></select>".html_safe)
|
89
89
|
concat(builder.input(:country, :priority_countries => []))
|
90
90
|
end)
|
91
91
|
end
|
@@ -101,13 +101,13 @@ describe 'country input' do
|
|
101
101
|
|
102
102
|
before do
|
103
103
|
concat(semantic_form_for(@new_post) do |builder|
|
104
|
-
builder.
|
104
|
+
allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
|
105
105
|
concat(builder.input(:country))
|
106
106
|
end)
|
107
107
|
end
|
108
108
|
|
109
109
|
it "should render a country input" do
|
110
|
-
output_buffer.
|
110
|
+
expect(output_buffer).to have_tag "form li.country"
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
@@ -121,8 +121,8 @@ describe 'country input' do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
it "should render a country input" do
|
124
|
-
output_buffer.
|
125
|
-
output_buffer.
|
124
|
+
expect(output_buffer).not_to have_tag "form li.country"
|
125
|
+
expect(output_buffer).to have_tag "form li.string", :count => 2
|
126
126
|
end
|
127
127
|
|
128
128
|
end
|
@@ -11,8 +11,7 @@ module TestInputs
|
|
11
11
|
@method = :title
|
12
12
|
@options = {}
|
13
13
|
@proc = Proc.new {}
|
14
|
-
@builder = Formtastic::FormBuilder.new(@object_name, @object, @template, @options
|
15
|
-
|
14
|
+
@builder = Formtastic::FormBuilder.new(@object_name, @object, @template, @options)
|
16
15
|
[@builder, @template, @object, @object_name, @method, @options]
|
17
16
|
end
|
18
17
|
|
@@ -28,7 +27,7 @@ module TestInputs
|
|
28
27
|
|
29
28
|
end
|
30
29
|
|
31
|
-
describe 'AnyCustomInput' do
|
30
|
+
RSpec.describe 'AnyCustomInput' do
|
32
31
|
|
33
32
|
include TestInputs
|
34
33
|
|
@@ -42,7 +41,7 @@ describe 'AnyCustomInput' do
|
|
42
41
|
|
43
42
|
describe 'with an implementation' do
|
44
43
|
it "should raise a NotImplementedError exception" do
|
45
|
-
expect { ::ImplementedInput.new(*input_args).to_html }.to_not raise_error
|
44
|
+
expect { ::ImplementedInput.new(*input_args).to_html }.to_not raise_error
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe "datalist inputs" do
|
5
|
+
include FormtasticSpecHelper
|
6
|
+
|
7
|
+
before do
|
8
|
+
@output_buffer = ''
|
9
|
+
mock_everything
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "renders correctly" do
|
13
|
+
lists_without_values =[
|
14
|
+
%w(a b c),
|
15
|
+
["a", "b", "c"],
|
16
|
+
("a".."c")
|
17
|
+
]
|
18
|
+
lists_with_values = [
|
19
|
+
{a: 1, b: 2, c:3},
|
20
|
+
{"a" => 1, "b" => 2, "c" =>3},
|
21
|
+
[["a",1], ["b",2], ["c", 3]]
|
22
|
+
]
|
23
|
+
|
24
|
+
def self.common_tests(list)
|
25
|
+
it_should_have_label_with_text(/Document/)
|
26
|
+
it_should_have_label_for("post_document")
|
27
|
+
it_should_have_input_wrapper_with_class(:datalist)
|
28
|
+
it_should_have_input_with(id: "post_document", type: :text, list:"post_document_datalist")
|
29
|
+
it_should_have_tag_with(:datalist, id: "post_document_datalist" )
|
30
|
+
it_should_have_many_tags(:option, list.count)
|
31
|
+
end
|
32
|
+
|
33
|
+
context "Rendering list of simple items" do
|
34
|
+
lists_without_values.each do |list|
|
35
|
+
describe "renders #{list.to_s} correctly" do
|
36
|
+
before do
|
37
|
+
concat(semantic_form_for(@new_post) do |builder|
|
38
|
+
concat(builder.input(:document, as: :datalist, collection: list))
|
39
|
+
end)
|
40
|
+
end
|
41
|
+
common_tests list
|
42
|
+
it_should_have_tag_with :option, value: list.first
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "Rendering list of complex items, key-value pairs and such" do
|
48
|
+
lists_with_values.each do |list|
|
49
|
+
describe "renders #{list.to_s} correctly" do
|
50
|
+
before do
|
51
|
+
concat(semantic_form_for(@new_post) do |builder|
|
52
|
+
concat(builder.input(:document, as: :datalist, collection: list))
|
53
|
+
end)
|
54
|
+
end
|
55
|
+
common_tests list
|
56
|
+
it_should_have_tag_with :option, value: list.first.last
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,449 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe 'date_picker input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
end
|
12
|
+
|
13
|
+
context "with an object" do
|
14
|
+
before do
|
15
|
+
concat(semantic_form_for(@new_post) do |builder|
|
16
|
+
concat(builder.input(:publish_at, :as => :date_picker))
|
17
|
+
end)
|
18
|
+
end
|
19
|
+
|
20
|
+
it_should_have_input_wrapper_with_class(:date_picker)
|
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_publish_at_input")
|
24
|
+
it_should_have_label_with_text(/Publish at/)
|
25
|
+
it_should_have_label_for("post_publish_at")
|
26
|
+
it_should_have_input_with_id("post_publish_at")
|
27
|
+
it_should_have_input_with_type(:date)
|
28
|
+
it_should_have_input_with_name("post[publish_at]")
|
29
|
+
it_should_apply_custom_input_attributes_when_input_html_provided(:date_picker)
|
30
|
+
it_should_apply_custom_for_to_label_when_input_html_id_provided(:date_picker)
|
31
|
+
# TODO why does this blow-up it_should_apply_error_logic_for_input_type(:date_picker)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "size attribute" do
|
36
|
+
|
37
|
+
it "defaults to 10 chars (YYYY-YY-YY)" do
|
38
|
+
concat(
|
39
|
+
semantic_form_for(@new_post) do |f|
|
40
|
+
concat(f.input(:publish_at, :as => :date_picker))
|
41
|
+
end
|
42
|
+
)
|
43
|
+
expect(output_buffer).to have_tag "input[size='10']"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "can be set from :input_html options" do
|
47
|
+
concat(
|
48
|
+
semantic_form_for(@new_post) do |f|
|
49
|
+
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :size => "11" }))
|
50
|
+
end
|
51
|
+
)
|
52
|
+
expect(output_buffer).to have_tag "input[size='11']"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "can be set from options (ignoring input_html)" do
|
56
|
+
concat(
|
57
|
+
semantic_form_for(@new_post) do |f|
|
58
|
+
concat(f.input(:publish_at, :as => :date_picker, :size => '12', :input_html => { :size => "11" }))
|
59
|
+
end
|
60
|
+
)
|
61
|
+
expect(output_buffer).to have_tag "input[size='12']"
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "maxlength attribute" do
|
67
|
+
|
68
|
+
it "defaults to 10 chars (YYYY-YY-YY)" do
|
69
|
+
concat(
|
70
|
+
semantic_form_for(@new_post) do |f|
|
71
|
+
concat(f.input(:publish_at, :as => :date_picker))
|
72
|
+
end
|
73
|
+
)
|
74
|
+
expect(output_buffer).to have_tag "input[maxlength='10']"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "can be set from :input_html options" do
|
78
|
+
concat(
|
79
|
+
semantic_form_for(@new_post) do |f|
|
80
|
+
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :maxlength => "11" }))
|
81
|
+
end
|
82
|
+
)
|
83
|
+
expect(output_buffer).to have_tag "input[maxlength='11']"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "can be set from options (ignoring input_html)" do
|
87
|
+
concat(
|
88
|
+
semantic_form_for(@new_post) do |f|
|
89
|
+
concat(f.input(:publish_at, :as => :date_picker, :maxlength => 12, :input_html => { :maxlength => "11" }))
|
90
|
+
end
|
91
|
+
)
|
92
|
+
expect(output_buffer).to have_tag "input[maxlength='12']"
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "value attribute" do
|
98
|
+
|
99
|
+
context "when method returns nil" do
|
100
|
+
|
101
|
+
it "has no value" do
|
102
|
+
concat(
|
103
|
+
semantic_form_for(@new_post) do |f|
|
104
|
+
concat(f.input(:publish_at, :as => :date_picker ))
|
105
|
+
end
|
106
|
+
)
|
107
|
+
expect(output_buffer).not_to have_tag "li input[value]"
|
108
|
+
end
|
109
|
+
|
110
|
+
it "can be set from :input_html options" do
|
111
|
+
concat(
|
112
|
+
semantic_form_for(@new_post) do |f|
|
113
|
+
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :value => "1111-11-11" }))
|
114
|
+
end
|
115
|
+
)
|
116
|
+
expect(output_buffer).to have_tag "input[value='1111-11-11']"
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
context "when method returns a Date" do
|
122
|
+
|
123
|
+
before do
|
124
|
+
@date = Date.new(2000, 11, 11)
|
125
|
+
allow(@new_post).to receive(:publish_at).and_return(@date)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "renders the date as YYYY-MM-DD" do
|
129
|
+
concat(
|
130
|
+
semantic_form_for(@new_post) do |f|
|
131
|
+
concat(f.input(:publish_at, :as => :date_picker ))
|
132
|
+
end
|
133
|
+
)
|
134
|
+
expect(output_buffer).to have_tag "input[value='#{@date.to_s}']"
|
135
|
+
end
|
136
|
+
|
137
|
+
it "can be set from :input_html options" do
|
138
|
+
concat(
|
139
|
+
semantic_form_for(@new_post) do |f|
|
140
|
+
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :value => "1111-11-11" }))
|
141
|
+
end
|
142
|
+
)
|
143
|
+
expect(output_buffer).to have_tag "input[value='1111-11-11']"
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
context "when method returns a Time" do
|
149
|
+
|
150
|
+
before do
|
151
|
+
@time = Time.utc(2000,11,11,11,11,11)
|
152
|
+
allow(@new_post).to receive(:publish_at).and_return(@time)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "renders the time as a YYYY-MM-DD" do
|
156
|
+
concat(
|
157
|
+
semantic_form_for(@new_post) do |f|
|
158
|
+
concat(f.input(:publish_at, :as => :date_picker ))
|
159
|
+
end
|
160
|
+
)
|
161
|
+
expect(output_buffer).to have_tag "input[value='2000-11-11']"
|
162
|
+
end
|
163
|
+
|
164
|
+
it "can be set from :input_html options" do
|
165
|
+
concat(
|
166
|
+
semantic_form_for(@new_post) do |f|
|
167
|
+
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :value => "1111-11-11" }))
|
168
|
+
end
|
169
|
+
)
|
170
|
+
expect(output_buffer).to have_tag "input[value='1111-11-11']"
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
context "when method returns an empty String" do
|
176
|
+
|
177
|
+
before do
|
178
|
+
allow(@new_post).to receive(:publish_at).and_return("")
|
179
|
+
end
|
180
|
+
|
181
|
+
it "will be empty" do
|
182
|
+
concat(
|
183
|
+
semantic_form_for(@new_post) do |f|
|
184
|
+
concat(f.input(:publish_at, :as => :date_picker ))
|
185
|
+
end
|
186
|
+
)
|
187
|
+
expect(output_buffer).to have_tag "input[value='']"
|
188
|
+
end
|
189
|
+
|
190
|
+
it "can be set from :input_html options" do
|
191
|
+
concat(
|
192
|
+
semantic_form_for(@new_post) do |f|
|
193
|
+
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :value => "1111-11-11" }))
|
194
|
+
end
|
195
|
+
)
|
196
|
+
expect(output_buffer).to have_tag "input[value='1111-11-11']"
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
context "when method returns a String" do
|
202
|
+
|
203
|
+
before do
|
204
|
+
allow(@new_post).to receive(:publish_at).and_return("yeah")
|
205
|
+
end
|
206
|
+
|
207
|
+
it "will be the string" do
|
208
|
+
concat(
|
209
|
+
semantic_form_for(@new_post) do |f|
|
210
|
+
concat(f.input(:publish_at, :as => :date_picker ))
|
211
|
+
end
|
212
|
+
)
|
213
|
+
expect(output_buffer).to have_tag "input[value='yeah']"
|
214
|
+
end
|
215
|
+
|
216
|
+
it "can be set from :input_html options" do
|
217
|
+
concat(
|
218
|
+
semantic_form_for(@new_post) do |f|
|
219
|
+
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :value => "1111-11-11" }))
|
220
|
+
end
|
221
|
+
)
|
222
|
+
expect(output_buffer).to have_tag "input[value='1111-11-11']"
|
223
|
+
end
|
224
|
+
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
228
|
+
|
229
|
+
describe "min attribute" do
|
230
|
+
|
231
|
+
it "will be omitted by default" do
|
232
|
+
concat(
|
233
|
+
semantic_form_for(@new_post) do |f|
|
234
|
+
concat(f.input(:publish_at, :as => :date_picker))
|
235
|
+
end
|
236
|
+
)
|
237
|
+
expect(output_buffer).not_to have_tag "input[min]"
|
238
|
+
end
|
239
|
+
|
240
|
+
it "can be set from :input_html options" do
|
241
|
+
concat(
|
242
|
+
semantic_form_for(@new_post) do |f|
|
243
|
+
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :min => "1970-01-01" }))
|
244
|
+
end
|
245
|
+
)
|
246
|
+
expect(output_buffer).to have_tag "input[min='1970-01-01']"
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
describe "max attribute" do
|
252
|
+
|
253
|
+
it "will be omitted by default" do
|
254
|
+
concat(
|
255
|
+
semantic_form_for(@new_post) do |f|
|
256
|
+
concat(f.input(:publish_at, :as => :date_picker))
|
257
|
+
end
|
258
|
+
)
|
259
|
+
expect(output_buffer).not_to have_tag "input[max]"
|
260
|
+
end
|
261
|
+
|
262
|
+
it "can be set from :input_html options" do
|
263
|
+
concat(
|
264
|
+
semantic_form_for(@new_post) do |f|
|
265
|
+
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :max => "1970-01-01" }))
|
266
|
+
end
|
267
|
+
)
|
268
|
+
expect(output_buffer).to have_tag "input[max='1970-01-01']"
|
269
|
+
end
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
describe "step attribute" do
|
274
|
+
|
275
|
+
it "defaults to 1" do
|
276
|
+
concat(
|
277
|
+
semantic_form_for(@new_post) do |f|
|
278
|
+
concat(f.input(:publish_at, :as => :date_picker))
|
279
|
+
end
|
280
|
+
)
|
281
|
+
expect(output_buffer).to have_tag "input[step='1']"
|
282
|
+
end
|
283
|
+
|
284
|
+
it "can be set from :input_html options" do
|
285
|
+
concat(
|
286
|
+
semantic_form_for(@new_post) do |f|
|
287
|
+
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :step => "5" }))
|
288
|
+
end
|
289
|
+
)
|
290
|
+
expect(output_buffer).to have_tag "input[step='5']"
|
291
|
+
end
|
292
|
+
|
293
|
+
describe "macros" do
|
294
|
+
|
295
|
+
before do
|
296
|
+
concat(
|
297
|
+
semantic_form_for(@new_post) do |f|
|
298
|
+
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :step => step }))
|
299
|
+
end
|
300
|
+
)
|
301
|
+
end
|
302
|
+
|
303
|
+
context ":day" do
|
304
|
+
let(:step) { :day }
|
305
|
+
it "uses 1" do
|
306
|
+
expect(output_buffer).to have_tag "input[step='1']"
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
context ":seven_days" do
|
311
|
+
let(:step) { :seven_days }
|
312
|
+
it "uses 7" do
|
313
|
+
expect(output_buffer).to have_tag "input[step='7']"
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
context ":week" do
|
318
|
+
let(:step) { :week }
|
319
|
+
it "uses 7" do
|
320
|
+
expect(output_buffer).to have_tag "input[step='7']"
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
context ":fortnight" do
|
325
|
+
let(:step) { :fortnight }
|
326
|
+
it "uses 14" do
|
327
|
+
expect(output_buffer).to have_tag "input[step='14']"
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
context ":two_weeks" do
|
332
|
+
let(:step) { :two_weeks }
|
333
|
+
it "uses 14" do
|
334
|
+
expect(output_buffer).to have_tag "input[step='14']"
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
context ":four_weeks" do
|
339
|
+
let(:step) { :four_weeks }
|
340
|
+
it "uses 28" do
|
341
|
+
expect(output_buffer).to have_tag "input[step='28']"
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
context ":thirty_days" do
|
346
|
+
let(:step) { :thirty_days }
|
347
|
+
it "uses 30" do
|
348
|
+
expect(output_buffer).to have_tag "input[step='30']"
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
end
|
353
|
+
|
354
|
+
end
|
355
|
+
|
356
|
+
describe "placeholder attribute" do
|
357
|
+
|
358
|
+
it "will be omitted" do
|
359
|
+
concat(
|
360
|
+
semantic_form_for(@new_post) do |f|
|
361
|
+
concat(f.input(:publish_at, :as => :date_picker))
|
362
|
+
end
|
363
|
+
)
|
364
|
+
expect(output_buffer).not_to have_tag "input[placeholder]"
|
365
|
+
end
|
366
|
+
|
367
|
+
it "can be set from :input_html options" do
|
368
|
+
concat(
|
369
|
+
semantic_form_for(@new_post) do |f|
|
370
|
+
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :placeholder => "1970-01-01" }))
|
371
|
+
end
|
372
|
+
)
|
373
|
+
expect(output_buffer).to have_tag "input[placeholder='1970-01-01']"
|
374
|
+
end
|
375
|
+
|
376
|
+
context "with i18n set" do
|
377
|
+
before do
|
378
|
+
::I18n.backend.store_translations :en, :formtastic => { :placeholders => { :publish_at => 'YYYY-MM-DD' }}
|
379
|
+
end
|
380
|
+
|
381
|
+
it "can be set with i18n" do
|
382
|
+
with_config :i18n_lookups_by_default, true do
|
383
|
+
concat(semantic_form_for(@new_post) do |builder|
|
384
|
+
concat(builder.input(:publish_at, :as => :date_picker))
|
385
|
+
end)
|
386
|
+
expect(output_buffer).to have_tag('input[@placeholder="YYYY-MM-DD"]')
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
it "can be set with input_html, trumping i18n" do
|
391
|
+
with_config :i18n_lookups_by_default, true do
|
392
|
+
concat(semantic_form_for(@new_post) do |builder|
|
393
|
+
concat(builder.input(:publish_at, :as => :date_picker, :input_html => { :placeholder => "Something" }))
|
394
|
+
end)
|
395
|
+
expect(output_buffer).to have_tag('input[@placeholder="Something"]')
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
end
|
401
|
+
|
402
|
+
describe "when namespace is provided" do
|
403
|
+
before do
|
404
|
+
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
405
|
+
concat(builder.input(:publish_at, :as => :date_picker))
|
406
|
+
end)
|
407
|
+
end
|
408
|
+
|
409
|
+
it_should_have_input_wrapper_with_id("context2_post_publish_at_input")
|
410
|
+
it_should_have_label_and_input_with_id("context2_post_publish_at")
|
411
|
+
end
|
412
|
+
|
413
|
+
describe "when index is provided" do
|
414
|
+
before do
|
415
|
+
@output_buffer = ''
|
416
|
+
mock_everything
|
417
|
+
|
418
|
+
concat(semantic_form_for(@new_post) do |builder|
|
419
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
420
|
+
concat(author.input(:created_at, :as => :date_picker))
|
421
|
+
end)
|
422
|
+
end)
|
423
|
+
end
|
424
|
+
|
425
|
+
it 'should index the id of the wrapper' do
|
426
|
+
expect(output_buffer).to have_tag("li#post_author_attributes_3_created_at_input")
|
427
|
+
end
|
428
|
+
|
429
|
+
it 'should index the id of the select tag' do
|
430
|
+
expect(output_buffer).to have_tag("input#post_author_attributes_3_created_at")
|
431
|
+
end
|
432
|
+
|
433
|
+
it 'should index the name of the select tag' do
|
434
|
+
expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][created_at]']")
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
describe "when required" do
|
439
|
+
it "should add the required attribute to the input's html options" do
|
440
|
+
with_config :use_required_attribute, true do
|
441
|
+
concat(semantic_form_for(@new_post) do |builder|
|
442
|
+
concat(builder.input(:publish_at, :as => :date_picker, :required => true))
|
443
|
+
end)
|
444
|
+
expect(output_buffer).to have_tag("input[@required]")
|
445
|
+
end
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
end
|