Skip to content

Commit 6d0f76d

Browse files
authored
Fix Rails Edge tests (#613)
* Fix rubocop offenses * Run tests on all branches * Fetch rails edge from main branch Otherwise bundle gets confused and tries to get master * Include sassc-rails to add Rails.application.config.assets config * Fix tests for Rails 7 - include autocomplete="off" for hidden fields - update rich_text_area test for direct upload * Fix unwanted skipping of test if Rails < 7 - also restructures the test to make it a bit more readable
1 parent dce8d9f commit 6d0f76d

9 files changed

Lines changed: 140 additions & 66 deletions

.github/workflows/ruby.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ name: Ruby
22

33
on:
44
push:
5-
branches: [ main ]
65
pull_request:
7-
branches: [ main ]
86

97
jobs:
108
Lint:

Dangerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ end
4444
# ------------------------------------------------------------------------------
4545
# Did you remove the CHANGELOG's "Your contribution here!" line?
4646
# ------------------------------------------------------------------------------
47-
if has_changelog_changes && IO.read("CHANGELOG.md").scan(/^\s*[-*] Your contribution here/i).count < 3
47+
if has_changelog_changes && File.read("CHANGELOG.md").scan(/^\s*[-*] Your contribution here/i).count < 3
4848
raise(
4949
"Please put the `- Your contribution here!` line back into CHANGELOG.md.",
5050
sticky: false

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ gemspec path: __dir__
66
# gem "rails", "~> 5.2.0"
77
# gem "rails", "~> 6.0.0"
88
# gem "rails", "~> 6.1.0"
9-
# gem "rails", git: "https://github.com/rails/rails.git"
9+
# gem "rails", git: "https://github.com/rails/rails.git", branch: "main"
1010

1111
group :development do
1212
gem "chandler", ">= 0.7.0"
@@ -21,5 +21,6 @@ group :test do
2121
gem "diffy"
2222
gem "equivalent-xml"
2323
gem "mocha"
24+
gem "sassc-rails"
2425
gem "sqlite3"
2526
end

bootstrap_form.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
1616
s.description = "bootstrap_form is a rails form builder that makes it super "\
1717
"easy to create beautiful-looking forms using Bootstrap 5"
1818
s.license = "MIT"
19+
s.metadata = { "rubygems_mfa_required" => "true" }
1920

2021
s.files = `git ls-files -z`.split("\x0").reject do |f|
2122
f.match(%r{^(test)/})

test/bootstrap_checkbox_test.rb

Lines changed: 64 additions & 32 deletions
Large diffs are not rendered by default.

test/bootstrap_fields_test.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ class BootstrapFieldsTest < ActionView::TestCase
103103
end
104104

105105
test "hidden fields are supported" do
106-
expected = '<input id="user_misc" name="user[misc]" type="hidden" />'
106+
expected = <<~HTML
107+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
108+
id="user_misc" name="user[misc]" type="hidden" />
109+
HTML
107110
assert_equivalent_xml expected, @builder.hidden_field(:misc)
108111
end
109112

@@ -259,7 +262,8 @@ class BootstrapFieldsTest < ActionView::TestCase
259262
test "check_box fields are wrapped correctly" do
260263
expected = <<~HTML
261264
<div class="form-check">
262-
<input name="user[misc]" type="hidden" value="0"/>
265+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
266+
name="user[misc]" type="hidden" value="0"/>
263267
<input class="form-check-input" id="user_misc" name="user[misc]" type="checkbox" value="1"/>
264268
<label class="form-check-label" for="user_misc">Misc</label>
265269
</div>
@@ -270,7 +274,8 @@ class BootstrapFieldsTest < ActionView::TestCase
270274
test "switch-style check_box fields are wrapped correctly" do
271275
expected = <<~HTML
272276
<div class="form-check form-switch">
273-
<input name="user[misc]" type="hidden" value="0"/>
277+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
278+
name="user[misc]" type="hidden" value="0"/>
274279
<input class="form-check-input" id="user_misc" name="user[misc]" type="checkbox" value="1"/>
275280
<label class="form-check-label" for="user_misc">Misc</label>
276281
</div>

test/bootstrap_form_test.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class BootstrapFormTest < ActionView::TestCase
2525
</div>
2626
</div>
2727
<div class="form-check">
28-
<input name="user[terms]" type="hidden" value="0" />
28+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
29+
name="user[terms]" type="hidden" value="0" />
2930
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
3031
<label class="form-check-label" for="user_terms">I agree to the terms</label>
3132
</div>
@@ -75,7 +76,8 @@ class BootstrapFormTest < ActionView::TestCase
7576
<input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" />
7677
</div>
7778
<div class="form-check form-check-inline">
78-
<input name="user[terms]" type="hidden" value="0" />
79+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
80+
name="user[terms]" type="hidden" value="0" />
7981
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
8082
<label class="form-check-label" for="user_terms">I agree to the terms</label>
8183
</div>
@@ -137,7 +139,8 @@ class BootstrapFormTest < ActionView::TestCase
137139
<input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" />
138140
</div>
139141
<div class="form-check form-check-inline">
140-
<input name="user[terms]" type="hidden" value="0" />
142+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
143+
name="user[terms]" type="hidden" value="0" />
141144
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
142145
<label class="form-check-label" for="user_terms">I agree to the terms</label>
143146
</div>
@@ -184,7 +187,8 @@ class BootstrapFormTest < ActionView::TestCase
184187
</div>
185188
</div>
186189
<div class="form-check">
187-
<input name="user[terms]" type="hidden" value="0" />
190+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
191+
name="user[terms]" type="hidden" value="0" />
188192
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
189193
<label class="form-check-label" for="user_terms">I agree to the terms</label>
190194
</div>
@@ -233,7 +237,8 @@ class BootstrapFormTest < ActionView::TestCase
233237
<input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" />
234238
</div>
235239
<div class="form-check">
236-
<input name="user[terms]" type="hidden" value="0" />
240+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
241+
name="user[terms]" type="hidden" value="0" />
237242
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
238243
<label class="form-check-label" for="user_terms">I agree to the terms</label>
239244
</div>
@@ -279,7 +284,8 @@ class BootstrapFormTest < ActionView::TestCase
279284
<input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" />
280285
</div>
281286
<div class="form-check form-check-inline">
282-
<input name="user[terms]" type="hidden" value="0" />
287+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
288+
name="user[terms]" type="hidden" value="0" />
283289
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
284290
<label class="form-check-label" for="user_terms">I agree to the terms</label>
285291
</div>
@@ -414,7 +420,8 @@ class BootstrapFormTest < ActionView::TestCase
414420
#{'<input name="utf8" type="hidden" value="&#x2713;"/>' unless ::Rails::VERSION::STRING >= '6'}
415421
<div class="form-check">
416422
<input class="form-check-input" id="#{id}" name="#{name}" type="checkbox" value="1" />
417-
<input name="#{name}" type="hidden" value="0" />
423+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
424+
name="#{name}" type="hidden" value="0" />
418425
<label class="form-check-label" for="#{id}"> Misc</label>
419426
</div>
420427
</form>
Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require_relative "./test_helper"
2+
require "minitest/mock"
23

34
if ::Rails::VERSION::STRING > "6"
45
class BootstrapRichTextAreaTest < ActionView::TestCase
@@ -8,18 +9,35 @@ class BootstrapRichTextAreaTest < ActionView::TestCase
89
setup :setup_test_fixture
910

1011
test "rich text areas are wrapped correctly" do
11-
expected = <<~HTML
12-
<div class="mb-3">
13-
<label class="form-label" for="user_life_story">Life story</label>
14-
<input type="hidden" name="user[life_story]" id="user_life_story_trix_input_user"/>
15-
<trix-editor id="user_life_story" data-blob-url-template="#{data_blob_url_template}" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" input="user_life_story_trix_input_user" class="trix-content form-control" />
16-
</div>
17-
HTML
18-
assert_equivalent_xml expected, form_with_builder.rich_text_area(:life_story)
12+
if ::Rails::VERSION::STRING >= "7"
13+
with_stub_token do
14+
expected = <<~HTML
15+
<div class="mb-3">
16+
<label class="form-label" for="user_life_story">Life story</label>
17+
<input autocomplete="off" type="hidden" name="user[life_story]" id="user_life_story_trix_input_user"/>
18+
<trix-editor class="trix-content form-control" data-blob-url-template="http://test.host/rails/active_storage/blobs/redirect/:signed_id/:filename" data-direct-upload-attachment-name="ActionText::RichText#embeds" data-direct-upload-token="token" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" id="user_life_story" input="user_life_story_trix_input_user"/>
19+
</div>
20+
HTML
21+
assert_equivalent_xml expected, form_with_builder.rich_text_area(:life_story)
22+
end
23+
else
24+
expected = <<~HTML
25+
<div class="mb-3">
26+
<label class="form-label" for="user_life_story">Life story</label>
27+
<input type="hidden" name="user[life_story]" id="user_life_story_trix_input_user"/>
28+
<trix-editor id="user_life_story" data-blob-url-template="#{data_blob_url_template}" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" input="user_life_story_trix_input_user" class="trix-content form-control" />
29+
</div>
30+
HTML
31+
assert_equivalent_xml expected, form_with_builder.rich_text_area(:life_story)
32+
end
1933
end
2034

2135
def data_blob_url_template
2236
"http://test.host/rails/active_storage/blobs/#{'redirect/' if ::Rails::VERSION::STRING >= '6.1'}:signed_id/:filename"
2337
end
38+
39+
def with_stub_token(&block)
40+
ActiveStorage::DirectUploadToken.stub(:generate_direct_upload_token, "token", &block)
41+
end
2442
end
2543
end

test/bootstrap_selects_test.rb

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,12 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
448448
<div class="mb-3">
449449
<label class="form-label" for="user_misc">Misc</label>
450450
<div class="rails-bootstrap-forms-time-select">
451-
<input id="user_misc_1i" name="user[misc(1i)]" type="hidden" value="2012" />
452-
<input id="user_misc_2i" name="user[misc(2i)]" type="hidden" value="2" />
453-
<input id="user_misc_3i" name="user[misc(3i)]" type="hidden" value="3" />
451+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
452+
id="user_misc_1i" name="user[misc(1i)]" type="hidden" value="2012" />
453+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
454+
id="user_misc_2i" name="user[misc(2i)]" type="hidden" value="2" />
455+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
456+
id="user_misc_3i" name="user[misc(3i)]" type="hidden" value="3" />
454457
<select class="form-select" id="user_misc_4i" name="user[misc(4i)]">
455458
#{options_range(start: '00', stop: '23', selected: '12')}
456459
</select>
@@ -474,9 +477,12 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
474477
<div class="mb-3">
475478
<label class="form-label" for="user_misc">Misc</label>
476479
<div class="rails-bootstrap-forms-time-select">
477-
<input id="user_misc_1i" name="user[misc(1i)]" type="hidden" value="2012" />
478-
<input id="user_misc_2i" name="user[misc(2i)]" type="hidden" value="2" />
479-
<input id="user_misc_3i" name="user[misc(3i)]" type="hidden" value="3" />
480+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
481+
id="user_misc_1i" name="user[misc(1i)]" type="hidden" value="2012" />
482+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
483+
id="user_misc_2i" name="user[misc(2i)]" type="hidden" value="2" />
484+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
485+
id="user_misc_3i" name="user[misc(3i)]" type="hidden" value="3" />
480486
<select class="form-select is-invalid" id="user_misc_4i" name="user[misc(4i)]">
481487
#{options_range(start: '00', stop: '23', selected: '12')}
482488
</select>
@@ -499,9 +505,12 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
499505
<div class="mb-3">
500506
<label class="form-label" for="user_misc">Misc</label>
501507
<div class="rails-bootstrap-forms-time-select">
502-
<input id="user_misc_1i" name="user[misc(1i)]" type="hidden" value="1" />
503-
<input id="user_misc_2i" name="user[misc(2i)]" type="hidden" value="1" />
504-
<input id="user_misc_3i" name="user[misc(3i)]" type="hidden" value="1" />
508+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
509+
id="user_misc_1i" name="user[misc(1i)]" type="hidden" value="1" />
510+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
511+
id="user_misc_2i" name="user[misc(2i)]" type="hidden" value="1" />
512+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
513+
id="user_misc_3i" name="user[misc(3i)]" type="hidden" value="1" />
505514
<select class="form-select" id="user_misc_4i" name="user[misc(4i)]">
506515
#{blank_option}
507516
#{options_range(start: '00', stop: '23')}
@@ -524,9 +533,12 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
524533
<div class="mb-3">
525534
<label class="form-label" for="user_misc">Misc</label>
526535
<div class="rails-bootstrap-forms-time-select">
527-
<input id="user_misc_1i" name="user[misc(1i)]" type="hidden" value="1" />
528-
<input id="user_misc_2i" name="user[misc(2i)]" type="hidden" value="1" />
529-
<input id="user_misc_3i" name="user[misc(3i)]" type="hidden" value="1" />
536+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
537+
id="user_misc_1i" name="user[misc(1i)]" type="hidden" value="1" />
538+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
539+
id="user_misc_2i" name="user[misc(2i)]" type="hidden" value="1" />
540+
<input #{'autocomplete="off"' if ::Rails::VERSION::STRING >= '7'}
541+
id="user_misc_3i" name="user[misc(3i)]" type="hidden" value="1" />
530542
<select class="form-select my-time-select" id="user_misc_4i" name="user[misc(4i)]">
531543
#{blank_option}
532544
#{options_range(start: '00', stop: '23')}

0 commit comments

Comments
 (0)