gov_uk_date_fields 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gov_uk_date_fields/form_fields.rb +12 -3
- data/lib/gov_uk_date_fields/version.rb +1 -1
- data/test/dummy/log/test.log +108 -0
- data/test/form_fields_test.rb +28 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 019c47dec540df18ad926d8f63d2cd303500a529
|
4
|
+
data.tar.gz: 1fe179381218745ceb752a68b78cebbc07ec2abf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ed038d2457e55ddabf3989e99ec490ed818dfe67f11e8de564a17afeca394541d45311c7e42bfe914d7992245adb7f1a3d718e57cc5e5f5c3946c4d01576220
|
7
|
+
data.tar.gz: 2c646bb53b4b2c762da3040cd83051878140655e58f7bd36e26d8ce48de7a2230d9c7f5caa4f49b3a0b99d2570ea75f50facdba41ef0fda06683f2444020d6b2
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module GovUkDateFields
|
2
2
|
|
3
3
|
class FormFields
|
4
|
-
VALID_OPTIONS = [:legend_text, :legend_class, :form_hint_text, :placeholders]
|
4
|
+
VALID_OPTIONS = [:legend_text, :legend_class, :form_hint_text, :id, :placeholders]
|
5
5
|
|
6
6
|
DATE_SEGMENTS = {
|
7
7
|
day: '_dd',
|
@@ -26,6 +26,7 @@ module GovUkDateFields
|
|
26
26
|
@year_value = @object.send("#{@attribute}_yyyy")
|
27
27
|
@form_hint_text = @options[:form_hint_text] || "For example, 31 3 1980"
|
28
28
|
@fieldset_required = false
|
29
|
+
@fieldset_id = @options[:id]
|
29
30
|
parse_options
|
30
31
|
end
|
31
32
|
|
@@ -57,13 +58,21 @@ module GovUkDateFields
|
|
57
58
|
|
58
59
|
def generate_start_fieldset
|
59
60
|
%Q|
|
60
|
-
|
61
|
+
#{generate_fieldset_tag}
|
61
62
|
#{generate_legend_tag}#{@options[:legend_text]}</legend>
|
62
63
|
<div class="form-date">
|
63
64
|
<p class="form-hint" id="#{@attribute}-hint">#{@form_hint_text}</p>
|
64
65
|
|
|
65
66
|
end
|
66
67
|
|
68
|
+
def generate_fieldset_tag
|
69
|
+
if @fieldset_id.nil?
|
70
|
+
"<fieldset>"
|
71
|
+
else
|
72
|
+
%Q|<fieldset id="#{@fieldset_id}">|
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
67
76
|
def generate_end_fieldset
|
68
77
|
"</div></fieldset>"
|
69
78
|
end
|
@@ -124,7 +133,7 @@ module GovUkDateFields
|
|
124
133
|
|
125
134
|
def parse_options
|
126
135
|
validate_option_keys
|
127
|
-
if @options.key?(:legend_text)
|
136
|
+
if @options.key?(:legend_text) || @options.key?(:id)
|
128
137
|
@fieldset_required = true
|
129
138
|
else
|
130
139
|
if @options.key?(:legend_class) || @options.key?(:form_hint_text)
|
data/test/dummy/log/test.log
CHANGED
@@ -4933,3 +4933,111 @@ GovUkDateFieldsTest: test_placeholder_output_without_fieldset
|
|
4933
4933
|
GovUkDateFieldsTest: test_basic_output_without_fieldset
|
4934
4934
|
-------------------------------------------------------
|
4935
4935
|
[1m[35m (0.1ms)[0m ROLLBACK
|
4936
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.4ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
4937
|
+
[1m[35m (0.1ms)[0m BEGIN
|
4938
|
+
-------------------------------------------------------
|
4939
|
+
GovUkDateFieldsTest: test_basic_output_without_fieldset
|
4940
|
+
-------------------------------------------------------
|
4941
|
+
[1m[36m (0.2ms)[0m [1mROLLBACK[0m
|
4942
|
+
[1m[35m (0.1ms)[0m BEGIN
|
4943
|
+
-------------------------------------------------------------
|
4944
|
+
GovUkDateFieldsTest: test_placeholder_output_without_fieldset
|
4945
|
+
-------------------------------------------------------------
|
4946
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
4947
|
+
[1m[35m (0.1ms)[0m BEGIN
|
4948
|
+
--------------------------------------------------------
|
4949
|
+
GovUkDateFieldsTest: test_fieldset_output_with_form_hint
|
4950
|
+
--------------------------------------------------------
|
4951
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
4952
|
+
[1m[35m (0.3ms)[0m BEGIN
|
4953
|
+
-------------------------------------
|
4954
|
+
GovUkDateFieldsTest: test_squash_html
|
4955
|
+
-------------------------------------
|
4956
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
4957
|
+
[1m[35m (0.1ms)[0m BEGIN
|
4958
|
+
------------------------------------------
|
4959
|
+
GovUkDateFieldsTest: test_fieldset_with_id
|
4960
|
+
------------------------------------------
|
4961
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
4962
|
+
[1m[35m (0.1ms)[0m BEGIN
|
4963
|
+
-----------------------------------------------------------
|
4964
|
+
GovUkDateFieldsTest: test_fieldset_output_with_legend_class
|
4965
|
+
-----------------------------------------------------------
|
4966
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
4967
|
+
[1m[35m (0.1ms)[0m BEGIN
|
4968
|
+
---------------------------------------------------------------
|
4969
|
+
GovUkDateFieldsTest: test_error_raised_if_invalid_options_given
|
4970
|
+
---------------------------------------------------------------
|
4971
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
4972
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
4973
|
+
[1m[35m (0.2ms)[0m BEGIN
|
4974
|
+
-----------------------------------------------------------
|
4975
|
+
GovUkDateFieldsTest: test_fieldset_output_with_legend_class
|
4976
|
+
-----------------------------------------------------------
|
4977
|
+
[1m[36m (0.2ms)[0m [1mROLLBACK[0m
|
4978
|
+
[1m[35m (0.1ms)[0m BEGIN
|
4979
|
+
------------------------------------------
|
4980
|
+
GovUkDateFieldsTest: test_fieldset_with_id
|
4981
|
+
------------------------------------------
|
4982
|
+
[1m[36m (0.2ms)[0m [1mROLLBACK[0m
|
4983
|
+
[1m[35m (0.1ms)[0m BEGIN
|
4984
|
+
-------------------------------------
|
4985
|
+
GovUkDateFieldsTest: test_squash_html
|
4986
|
+
-------------------------------------
|
4987
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
4988
|
+
[1m[35m (0.1ms)[0m BEGIN
|
4989
|
+
-------------------------------------------------------------
|
4990
|
+
GovUkDateFieldsTest: test_placeholder_output_without_fieldset
|
4991
|
+
-------------------------------------------------------------
|
4992
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
4993
|
+
[1m[35m (0.1ms)[0m BEGIN
|
4994
|
+
---------------------------------------------------------------
|
4995
|
+
GovUkDateFieldsTest: test_error_raised_if_invalid_options_given
|
4996
|
+
---------------------------------------------------------------
|
4997
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
4998
|
+
[1m[35m (0.1ms)[0m BEGIN
|
4999
|
+
-------------------------------------------------------
|
5000
|
+
GovUkDateFieldsTest: test_basic_output_without_fieldset
|
5001
|
+
-------------------------------------------------------
|
5002
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
5003
|
+
[1m[35m (0.1ms)[0m BEGIN
|
5004
|
+
--------------------------------------------------------
|
5005
|
+
GovUkDateFieldsTest: test_fieldset_output_with_form_hint
|
5006
|
+
--------------------------------------------------------
|
5007
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
5008
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
5009
|
+
[1m[35m (0.2ms)[0m BEGIN
|
5010
|
+
-------------------------------------------------------------
|
5011
|
+
GovUkDateFieldsTest: test_placeholder_output_without_fieldset
|
5012
|
+
-------------------------------------------------------------
|
5013
|
+
[1m[36m (0.2ms)[0m [1mROLLBACK[0m
|
5014
|
+
[1m[35m (0.1ms)[0m BEGIN
|
5015
|
+
---------------------------------------------------------------
|
5016
|
+
GovUkDateFieldsTest: test_error_raised_if_invalid_options_given
|
5017
|
+
---------------------------------------------------------------
|
5018
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
5019
|
+
[1m[35m (0.0ms)[0m BEGIN
|
5020
|
+
------------------------------------------
|
5021
|
+
GovUkDateFieldsTest: test_fieldset_with_id
|
5022
|
+
------------------------------------------
|
5023
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
5024
|
+
[1m[35m (0.1ms)[0m BEGIN
|
5025
|
+
--------------------------------------------------------
|
5026
|
+
GovUkDateFieldsTest: test_fieldset_output_with_form_hint
|
5027
|
+
--------------------------------------------------------
|
5028
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
5029
|
+
[1m[35m (0.1ms)[0m BEGIN
|
5030
|
+
-------------------------------------
|
5031
|
+
GovUkDateFieldsTest: test_squash_html
|
5032
|
+
-------------------------------------
|
5033
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
5034
|
+
[1m[35m (0.1ms)[0m BEGIN
|
5035
|
+
-----------------------------------------------------------
|
5036
|
+
GovUkDateFieldsTest: test_fieldset_output_with_legend_class
|
5037
|
+
-----------------------------------------------------------
|
5038
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
5039
|
+
[1m[35m (0.1ms)[0m BEGIN
|
5040
|
+
-------------------------------------------------------
|
5041
|
+
GovUkDateFieldsTest: test_basic_output_without_fieldset
|
5042
|
+
-------------------------------------------------------
|
5043
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
data/test/form_fields_test.rb
CHANGED
@@ -40,13 +40,17 @@ class GovUkDateFieldsTest < ActiveSupport::TestCase
|
|
40
40
|
date_fields = GovUkDateFields::FormFields.new(@form_builder, :employee, :dob, {legend_text: 'Date of birth', legend_class: 'govuk_legend_class', form_hint_text: 'In the form: dd mm yyyy'})
|
41
41
|
assert_html_equal(date_fields.raw_output, expected_fieldset_output_with_form_hint)
|
42
42
|
end
|
43
|
-
|
44
43
|
|
45
44
|
test 'fieldset output with legend class' do
|
46
45
|
date_fields = GovUkDateFields::FormFields.new(@form_builder, :employee, :joined, {legend_text: 'Joining date', legend_class: 'date-legend-class', form_hint_text: 'For example, 31 3 1980'})
|
47
46
|
assert_html_equal(date_fields.raw_output, expected_fieldset_output_with_legend_class)
|
48
47
|
end
|
49
48
|
|
49
|
+
test 'fieldset with id' do
|
50
|
+
date_fields = GovUkDateFields::FormFields.new(@form_builder, :employee, :joined, {legend_text: 'Joining date', id: 'employee_date_joined'})
|
51
|
+
assert_html_equal(date_fields.raw_output, expected_fieldset_output_with_id)
|
52
|
+
end
|
53
|
+
|
50
54
|
test "squash_html" do
|
51
55
|
html = " <html> This is some text \n <tr> \n <td> <%= dfkhdfh %> </td> </tr>\n</html> "
|
52
56
|
expected_result = "<html>This is some text<tr><td><%= dfkhdfh %></td></tr></html>"
|
@@ -71,6 +75,29 @@ class GovUkDateFieldsTest < ActiveSupport::TestCase
|
|
71
75
|
}
|
72
76
|
end
|
73
77
|
|
78
|
+
def expected_fieldset_output_with_id
|
79
|
+
%Q{
|
80
|
+
<fieldset id="employee_date_joined">
|
81
|
+
<legend>Joining date</legend>
|
82
|
+
<div class="form-date">
|
83
|
+
<p class="form-hint" id="joined-hint">For example, 31 3 1980</p>
|
84
|
+
<div class="form-group form-group-day">
|
85
|
+
<label for="joined-day">Day</label>
|
86
|
+
<input class="form-control" id="joined-day" name="joined-day" type="number" pattern="[0-9]*" min="0" max="31" aria-describedby="joined-hint" value="1">
|
87
|
+
</div>
|
88
|
+
<div class="form-group form-group-month">
|
89
|
+
<label for="joined-month">Month</label>
|
90
|
+
<input class="form-control" id="joined-month" name="joined-month" type="number" pattern="[0-9]*" min="0" max="12" value="4">
|
91
|
+
</div>
|
92
|
+
<div class="form-group form-group-year">
|
93
|
+
<label for="joined-year">Year</label>
|
94
|
+
<input class="form-control" id="joined-year" name="joined-year" type="number" pattern="[0-9]*" min="0" max="2016" value="2015">
|
95
|
+
</div>
|
96
|
+
</div>
|
97
|
+
</fieldset>
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
74
101
|
def expected_fieldset_output_with_form_hint
|
75
102
|
%Q{
|
76
103
|
<fieldset>
|