bootstrap_form 2.5.2 → 2.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,7 @@ class SpecialFormClassModelsTest < ActionView::TestCase
15
15
  I18n.backend.store_translations(:en, {activerecord: {help: {user: {password: "A good password should be at least six characters long"}}}})
16
16
 
17
17
  expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="date" /></div>}
18
- assert_equal expected, @builder.date_field(:misc)
18
+ assert_equivalent_xml expected, @builder.date_field(:misc)
19
19
  end
20
20
 
21
21
  test "Nil models are supported for form builder" do
@@ -25,7 +25,7 @@ class SpecialFormClassModelsTest < ActionView::TestCase
25
25
  I18n.backend.store_translations(:en, {activerecord: {help: {user: {password: "A good password should be at least six characters long"}}}})
26
26
 
27
27
  expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="date" /></div>}
28
- assert_equal expected, @builder.date_field(:misc)
28
+ assert_equivalent_xml expected, @builder.date_field(:misc)
29
29
  end
30
30
 
31
31
  test "Objects without model names are supported for form builder" do
@@ -37,7 +37,7 @@ class SpecialFormClassModelsTest < ActionView::TestCase
37
37
  I18n.backend.store_translations(:en, {activerecord: {help: {faux_user: {password: "A good password should be at least six characters long"}}}})
38
38
 
39
39
  expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="date" /></div>}
40
- assert_equal expected, @builder.date_field(:misc)
40
+ assert_equivalent_xml expected, @builder.date_field(:misc)
41
41
  end
42
42
 
43
43
  end
@@ -1,4 +1,7 @@
1
1
  require 'timecop'
2
+ require 'diffy'
3
+ require 'nokogiri'
4
+ require 'equivalent-xml'
2
5
  require 'mocha/mini_test'
3
6
 
4
7
  # Configure Rails Environment
@@ -16,5 +19,68 @@ def setup_test_fixture
16
19
  @user = User.new(email: 'steve@example.com', password: 'secret', comments: 'my comment')
17
20
  @builder = BootstrapForm::FormBuilder.new(:user, @user, self, {})
18
21
  @horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, { layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10" })
19
- I18n.backend.store_translations(:en, {activerecord: {help: {user: {password: "A good password should be at least six characters long"}}}})
22
+ I18n.backend.store_translations(:en, {
23
+ activerecord: {
24
+ attributes: {
25
+ user: {
26
+ email: "Email"
27
+ }
28
+ },
29
+ help: {
30
+ user: {
31
+ password: "A good password should be at least six characters long"
32
+ }
33
+ }
34
+ }
35
+ })
36
+ end
37
+
38
+ def sort_attributes doc
39
+ doc.dup.traverse do |node|
40
+ if node.is_a?(Nokogiri::XML::Element)
41
+ attributes = node.attribute_nodes.sort_by(&:name)
42
+ attributes.each do |attribute|
43
+ node.delete(attribute.name)
44
+ node[attribute.name] = attribute.value
45
+ end
46
+ end
47
+ node
48
+ end
49
+ end
50
+
51
+ class ActionView::TestCase
52
+ def assert_equivalent_xml(expected, actual)
53
+ expected_xml = Nokogiri::XML(expected)
54
+ actual_xml = Nokogiri::XML(actual)
55
+ ignored_attributes = %w(style data-disable-with)
56
+ equivalent = EquivalentXml.equivalent?(expected_xml, actual_xml, {
57
+ ignore_attr_values: ignored_attributes
58
+ }) do |a, b, result|
59
+ if result === false && b.is_a?(Nokogiri::XML::Element)
60
+ if b.attr('name') == 'utf8'
61
+ # Handle wrapped utf8 hidden field for Rails 4.2+
62
+ result = EquivalentXml.equivalent?(a.child, b)
63
+ end
64
+ if b.delete('data-disable-with')
65
+ # Remove data-disable-with for Rails 5+
66
+ # Workaround because ignoring in EquivalentXml doesn't work
67
+ result = EquivalentXml.equivalent?(a, b)
68
+ end
69
+ if a.attr('type') == 'datetime' && b.attr('type') == 'datetime-local'
70
+ a.delete('type')
71
+ b.delete('type')
72
+ # Handle new datetime type for Rails 5+
73
+ result = EquivalentXml.equivalent?(a, b)
74
+ end
75
+ end
76
+ result
77
+ end
78
+ assert equivalent, lambda {
79
+ # using a lambda because diffing is expensive
80
+ Diffy::Diff.new(
81
+ sort_attributes(expected_xml.root),
82
+ sort_attributes(actual_xml.root)
83
+ ).to_s(:color)
84
+ }
85
+ end
20
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.2
4
+ version: 2.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Potenza
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-08 00:00:00.000000000 Z
12
+ date: 2016-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mime-types
@@ -29,14 +29,14 @@ dependencies:
29
29
  name: rails
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '4.0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '4.0'
42
42
  - !ruby/object:Gem::Dependency
@@ -81,6 +81,62 @@ dependencies:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: appraisal
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: equivalent-xml
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: nokogiri
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: diffy
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
84
140
  description: bootstrap_form is a rails form builder that makes it super easy to create
85
141
  beautiful-looking forms using Twitter Bootstrap 3+
86
142
  email:
@@ -181,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
237
  version: '0'
182
238
  requirements: []
183
239
  rubyforge_project:
184
- rubygems_version: 2.6.7
240
+ rubygems_version: 2.6.8
185
241
  signing_key:
186
242
  specification_version: 4
187
243
  summary: Rails form builder that makes it easy to style forms using Twitter Bootstrap