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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f339e206ab6ddf10b3905aecd2e6bea7e7bbada
4
- data.tar.gz: 9736e32d381faf7360d57eb488673ccb2f289dbf
3
+ metadata.gz: 019c47dec540df18ad926d8f63d2cd303500a529
4
+ data.tar.gz: 1fe179381218745ceb752a68b78cebbc07ec2abf
5
5
  SHA512:
6
- metadata.gz: ebd14090f8f6418ea1fc1505a49fc5bcc416550b6a3da4df120503668fb76b0cd18676594f38a5d2020a969f1da5982f98293d8356a96a3ce79d4958f50bbf3b
7
- data.tar.gz: 15e120b2cfa3269fd93e84b3c6b5e30b9ff2261bef3e7e322e6f8d003ffc7c0e4043fd7a505e94bec47f830538db0126c0a53e30b7849d59a305c8348b3db75d
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
- <fieldset>
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)
@@ -1,3 +1,3 @@
1
1
  module GovUkDateFields
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -4933,3 +4933,111 @@ GovUkDateFieldsTest: test_placeholder_output_without_fieldset
4933
4933
  GovUkDateFieldsTest: test_basic_output_without_fieldset
4934
4934
  -------------------------------------------------------
4935
4935
   (0.1ms) ROLLBACK
4936
+ ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
4937
+  (0.1ms) BEGIN
4938
+ -------------------------------------------------------
4939
+ GovUkDateFieldsTest: test_basic_output_without_fieldset
4940
+ -------------------------------------------------------
4941
+  (0.2ms) ROLLBACK
4942
+  (0.1ms) BEGIN
4943
+ -------------------------------------------------------------
4944
+ GovUkDateFieldsTest: test_placeholder_output_without_fieldset
4945
+ -------------------------------------------------------------
4946
+  (0.1ms) ROLLBACK
4947
+  (0.1ms) BEGIN
4948
+ --------------------------------------------------------
4949
+ GovUkDateFieldsTest: test_fieldset_output_with_form_hint
4950
+ --------------------------------------------------------
4951
+  (0.1ms) ROLLBACK
4952
+  (0.3ms) BEGIN
4953
+ -------------------------------------
4954
+ GovUkDateFieldsTest: test_squash_html
4955
+ -------------------------------------
4956
+  (0.1ms) ROLLBACK
4957
+  (0.1ms) BEGIN
4958
+ ------------------------------------------
4959
+ GovUkDateFieldsTest: test_fieldset_with_id
4960
+ ------------------------------------------
4961
+  (0.1ms) ROLLBACK
4962
+  (0.1ms) BEGIN
4963
+ -----------------------------------------------------------
4964
+ GovUkDateFieldsTest: test_fieldset_output_with_legend_class
4965
+ -----------------------------------------------------------
4966
+  (0.1ms) ROLLBACK
4967
+  (0.1ms) BEGIN
4968
+ ---------------------------------------------------------------
4969
+ GovUkDateFieldsTest: test_error_raised_if_invalid_options_given
4970
+ ---------------------------------------------------------------
4971
+  (0.1ms) ROLLBACK
4972
+ ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
4973
+  (0.2ms) BEGIN
4974
+ -----------------------------------------------------------
4975
+ GovUkDateFieldsTest: test_fieldset_output_with_legend_class
4976
+ -----------------------------------------------------------
4977
+  (0.2ms) ROLLBACK
4978
+  (0.1ms) BEGIN
4979
+ ------------------------------------------
4980
+ GovUkDateFieldsTest: test_fieldset_with_id
4981
+ ------------------------------------------
4982
+  (0.2ms) ROLLBACK
4983
+  (0.1ms) BEGIN
4984
+ -------------------------------------
4985
+ GovUkDateFieldsTest: test_squash_html
4986
+ -------------------------------------
4987
+  (0.1ms) ROLLBACK
4988
+  (0.1ms) BEGIN
4989
+ -------------------------------------------------------------
4990
+ GovUkDateFieldsTest: test_placeholder_output_without_fieldset
4991
+ -------------------------------------------------------------
4992
+  (0.1ms) ROLLBACK
4993
+  (0.1ms) BEGIN
4994
+ ---------------------------------------------------------------
4995
+ GovUkDateFieldsTest: test_error_raised_if_invalid_options_given
4996
+ ---------------------------------------------------------------
4997
+  (0.1ms) ROLLBACK
4998
+  (0.1ms) BEGIN
4999
+ -------------------------------------------------------
5000
+ GovUkDateFieldsTest: test_basic_output_without_fieldset
5001
+ -------------------------------------------------------
5002
+  (0.1ms) ROLLBACK
5003
+  (0.1ms) BEGIN
5004
+ --------------------------------------------------------
5005
+ GovUkDateFieldsTest: test_fieldset_output_with_form_hint
5006
+ --------------------------------------------------------
5007
+  (0.1ms) ROLLBACK
5008
+ ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
5009
+  (0.2ms) BEGIN
5010
+ -------------------------------------------------------------
5011
+ GovUkDateFieldsTest: test_placeholder_output_without_fieldset
5012
+ -------------------------------------------------------------
5013
+  (0.2ms) ROLLBACK
5014
+  (0.1ms) BEGIN
5015
+ ---------------------------------------------------------------
5016
+ GovUkDateFieldsTest: test_error_raised_if_invalid_options_given
5017
+ ---------------------------------------------------------------
5018
+  (0.1ms) ROLLBACK
5019
+  (0.0ms) BEGIN
5020
+ ------------------------------------------
5021
+ GovUkDateFieldsTest: test_fieldset_with_id
5022
+ ------------------------------------------
5023
+  (0.1ms) ROLLBACK
5024
+  (0.1ms) BEGIN
5025
+ --------------------------------------------------------
5026
+ GovUkDateFieldsTest: test_fieldset_output_with_form_hint
5027
+ --------------------------------------------------------
5028
+  (0.1ms) ROLLBACK
5029
+  (0.1ms) BEGIN
5030
+ -------------------------------------
5031
+ GovUkDateFieldsTest: test_squash_html
5032
+ -------------------------------------
5033
+  (0.1ms) ROLLBACK
5034
+  (0.1ms) BEGIN
5035
+ -----------------------------------------------------------
5036
+ GovUkDateFieldsTest: test_fieldset_output_with_legend_class
5037
+ -----------------------------------------------------------
5038
+  (0.1ms) ROLLBACK
5039
+  (0.1ms) BEGIN
5040
+ -------------------------------------------------------
5041
+ GovUkDateFieldsTest: test_basic_output_without_fieldset
5042
+ -------------------------------------------------------
5043
+  (0.1ms) ROLLBACK
@@ -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>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gov_uk_date_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Richards