twitter-bootstrap-rails 5.4.0 → 5.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +68 -0
- data/README.md +104 -1
- data/app/helpers/badge_label_helper.rb +5 -6
- data/app/helpers/bootstrap_flash_helper.rb +10 -5
- data/app/helpers/flash_block_helper.rb +6 -4
- data/app/helpers/form_errors_helper.rb +3 -2
- data/app/helpers/modal_helper.rb +13 -13
- data/app/helpers/navbar_helper.rb +54 -47
- data/app/helpers/twitter_breadcrumbs_helper.rb +2 -2
- data/app/views/twitter-bootstrap/_breadcrumbs.html.erb +11 -11
- data/lib/generators/bootstrap/agent/agent_generator.rb +86 -0
- data/lib/generators/bootstrap/agent/templates/guide.md.erb +73 -0
- data/lib/generators/bootstrap/doctor/doctor_generator.rb +49 -0
- data/lib/generators/bootstrap/partial/templates/_login.html.erb +11 -15
- data/lib/generators/bootstrap/snippets/snippet_base.rb +23 -4
- data/lib/generators/bootstrap/themed/templates/_form.html.haml +7 -9
- data/lib/generators/bootstrap/themed/templates/_form.html.slim +8 -10
- data/lib/generators/bootstrap/themed/templates/edit.html.erb +1 -1
- data/lib/generators/bootstrap/themed/templates/edit.html.haml +1 -1
- data/lib/generators/bootstrap/themed/templates/edit.html.slim +1 -1
- data/lib/generators/bootstrap/themed/templates/index.html.haml +4 -4
- data/lib/generators/bootstrap/themed/templates/index.html.slim +4 -4
- data/lib/generators/bootstrap/themed/templates/new.html.erb +1 -1
- data/lib/generators/bootstrap/themed/templates/new.html.haml +1 -1
- data/lib/generators/bootstrap/themed/templates/new.html.slim +1 -1
- data/lib/generators/bootstrap/themed/templates/show.html.erb +1 -1
- data/lib/generators/bootstrap/themed/templates/show.html.haml +3 -3
- data/lib/generators/bootstrap/themed/templates/show.html.slim +3 -3
- data/lib/generators/bootstrap/themed/templates/simple_form/_form.html.erb +1 -1
- data/lib/generators/bootstrap/themed/templates/simple_form/_form.html.haml +2 -2
- data/lib/generators/bootstrap/themed/templates/simple_form/_form.html.slim +2 -2
- data/lib/twitter/bootstrap/rails/doctor.rb +238 -0
- data/lib/twitter/bootstrap/rails/legacy_markup.rb +119 -0
- data/lib/twitter/bootstrap/rails/v6_migration.rb +156 -0
- data/lib/twitter/bootstrap/rails/version.rb +1 -1
- data/spec/lib/breadcrumbs_spec.rb +8 -2
- data/spec/lib/generators/agent_generator_spec.rb +120 -0
- data/spec/lib/generators/doctor_generator_spec.rb +272 -0
- data/spec/lib/generators/snippet_generators_spec.rb +23 -0
- data/spec/lib/twitter_bootstrap_rails/badge_label_helper_spec.rb +7 -3
- data/spec/lib/twitter_bootstrap_rails/bootstrap_flash_helper_spec.rb +23 -45
- data/spec/lib/twitter_bootstrap_rails/breadcrumbs_view_spec.rb +35 -0
- data/spec/lib/twitter_bootstrap_rails/flash_block_helper_spec.rb +26 -0
- data/spec/lib/twitter_bootstrap_rails/form_errors_helper_spec.rb +2 -2
- data/spec/lib/twitter_bootstrap_rails/legacy_markup_spec.rb +74 -0
- data/spec/lib/twitter_bootstrap_rails/modal_helper_spec.rb +21 -8
- data/spec/lib/twitter_bootstrap_rails/navbar_helper_spec.rb +94 -92
- data/spec/lib/twitter_bootstrap_rails/v6_migration_spec.rb +98 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/support/generator_spec_helper.rb +2 -0
- metadata +24 -3
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Bootstrap::Generators::DoctorGenerator do
|
|
4
|
+
let(:rails_mod) { Twitter::Bootstrap::Rails }
|
|
5
|
+
let(:version) { rails_mod::BOOTSTRAP_VERSION }
|
|
6
|
+
|
|
7
|
+
before { stub_rails_application }
|
|
8
|
+
|
|
9
|
+
def report
|
|
10
|
+
rails_mod::Doctor.new(destination_root).report
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def check(id)
|
|
14
|
+
report[:checks].find { |c| c[:id] == id }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def install_static_on_propshaft
|
|
18
|
+
rails_mod.asset_pipeline = :propshaft
|
|
19
|
+
run_generator(Bootstrap::Generators::InstallGenerator, %w[static])
|
|
20
|
+
run_generator(Bootstrap::Generators::LayoutGenerator)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "where Bootstrap comes from" do
|
|
24
|
+
it "is happy with a Propshaft app set up by the generators" do
|
|
25
|
+
install_static_on_propshaft
|
|
26
|
+
|
|
27
|
+
expect(report).to include(:status => "ok", :asset_mode => "static", :asset_pipeline => "propshaft")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "is happy with a Sprockets app set up by the generators" do
|
|
31
|
+
rails_mod.asset_pipeline = :sprockets
|
|
32
|
+
run_generator(Bootstrap::Generators::InstallGenerator, %w[static])
|
|
33
|
+
run_generator(Bootstrap::Generators::LayoutGenerator)
|
|
34
|
+
|
|
35
|
+
expect(report).to include(:status => "ok", :asset_pipeline => "sprockets")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "is happy with a CDN app set up by the generators" do
|
|
39
|
+
run_generator(Bootstrap::Generators::InstallGenerator, %w[cdn])
|
|
40
|
+
run_generator(Bootstrap::Generators::LayoutGenerator, %w[--cdn])
|
|
41
|
+
|
|
42
|
+
expect(report).to include(:status => "ok", :asset_mode => "cdn")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "reports an error when a Propshaft layout does not link the vendored files" do
|
|
46
|
+
rails_mod.asset_pipeline = :propshaft
|
|
47
|
+
run_generator(Bootstrap::Generators::InstallGenerator, %w[static])
|
|
48
|
+
write_destination("app/views/layouts/application.html.erb", %{<%= stylesheet_link_tag "application" %>})
|
|
49
|
+
|
|
50
|
+
expect(check("bootstrap_css")).to include(:status => "error", :fix => a_string_including("bootstrap:layout"))
|
|
51
|
+
expect(check("bootstrap_js")[:status]).to eq("error")
|
|
52
|
+
expect(report[:status]).to eq("error")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "reports an error when the layout links vendored files that are not there" do
|
|
56
|
+
rails_mod.asset_pipeline = :propshaft
|
|
57
|
+
write_destination("app/views/layouts/application.html.erb",
|
|
58
|
+
%{<%= stylesheet_link_tag "twitter/bootstrap/bootstrap.min" %>})
|
|
59
|
+
|
|
60
|
+
expect(check("bootstrap_css")).to include(:status => "error", :fix => a_string_including("bootstrap:install"))
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "reports an error when a Sprockets manifest requires Bootstrap but no layout links it" do
|
|
64
|
+
rails_mod.asset_pipeline = :sprockets
|
|
65
|
+
run_generator(Bootstrap::Generators::InstallGenerator, %w[static])
|
|
66
|
+
|
|
67
|
+
expect(check("bootstrap_css")[:status]).to eq("error")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "only warns when Bootstrap comes from a JavaScript bundler it can't verify" do
|
|
71
|
+
write_destination("package.json", %{{"dependencies": {"bootstrap": "^5.3.0"}}})
|
|
72
|
+
|
|
73
|
+
expect(check("bootstrap_css")[:status]).to eq("warn")
|
|
74
|
+
expect(check("bootstrap_js")[:status]).to eq("warn")
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "reads the mode from the layout if the initializer is missing" do
|
|
78
|
+
write_destination("app/views/layouts/application.html.erb",
|
|
79
|
+
%{<link href="https://cdn.jsdelivr.net/npm/bootstrap@#{version}/dist/css/bootstrap.min.css">})
|
|
80
|
+
|
|
81
|
+
expect(report[:asset_mode]).to eq("cdn")
|
|
82
|
+
expect(check("bootstrap_css")[:status]).to eq("ok")
|
|
83
|
+
expect(check("bootstrap_js")[:status]).to eq("error")
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
describe "the Bootstrap version" do
|
|
88
|
+
it "warns about an old CDN version" do
|
|
89
|
+
write_destination("app/views/layouts/application.html.erb",
|
|
90
|
+
%{<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css">})
|
|
91
|
+
|
|
92
|
+
expect(check("bootstrap_version")).to include(:status => "warn", :message => a_string_including("5.1.0"))
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "warns about old vendored files" do
|
|
96
|
+
install_static_on_propshaft
|
|
97
|
+
write_destination("app/assets/stylesheets/twitter/bootstrap/bootstrap.min.css", "/*! Bootstrap v5.3.3 */")
|
|
98
|
+
|
|
99
|
+
expect(check("bootstrap_version")).to include(:status => "warn", :message => a_string_including("5.3.3"))
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "accepts what the generators installed" do
|
|
103
|
+
install_static_on_propshaft
|
|
104
|
+
|
|
105
|
+
expect(check("bootstrap_version")[:status]).to eq("ok")
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
describe "the icon sprite" do
|
|
110
|
+
let(:layout) { "app/views/layouts/application.html.erb" }
|
|
111
|
+
|
|
112
|
+
before { run_generator(Bootstrap::Generators::HeaderGenerator) }
|
|
113
|
+
|
|
114
|
+
it "reports an error when it is installed but never rendered" do
|
|
115
|
+
write_destination(layout, "<body></body>")
|
|
116
|
+
|
|
117
|
+
expect(check("icon_sprite")).to include(:status => "error", :fix => a_string_including('render "shared/bootstrap_icons"'))
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "is happy when it is rendered once" do
|
|
121
|
+
write_destination(layout, %{<%= render "shared/bootstrap_icons" %>})
|
|
122
|
+
|
|
123
|
+
expect(check("icon_sprite")[:status]).to eq("ok")
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "warns when it is rendered more than once" do
|
|
127
|
+
write_destination(layout, %{<%= render "shared/bootstrap_icons" %>})
|
|
128
|
+
write_destination("app/views/tasks/index.html.erb", %{<%= render "shared/bootstrap_icons" %>})
|
|
129
|
+
|
|
130
|
+
expect(check("icon_sprite")[:status]).to eq("warn")
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "has nothing to say about the sprite when it is not installed" do
|
|
135
|
+
expect(check("icon_sprite")[:status]).to eq("ok")
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it "warns about placeholder images left in a view, with the location" do
|
|
139
|
+
run_generator(Bootstrap::Generators::HeroGenerator, %w[centered])
|
|
140
|
+
|
|
141
|
+
expect(check("placeholder_images")[:status]).to eq("warn")
|
|
142
|
+
expect(check("placeholder_images")[:files].first).to start_with("app/views/shared/_hero.html.erb:")
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
describe "legacy markup" do
|
|
146
|
+
it "lists each finding with its location" do
|
|
147
|
+
write_destination("app/views/tasks/index.html.erb", %{<p>ok</p>\n<a class="btn btn-default" data-toggle="modal">x</a>})
|
|
148
|
+
|
|
149
|
+
expect(report[:legacy_markup]).to contain_exactly(
|
|
150
|
+
a_hash_including(:file => "app/views/tasks/index.html.erb", :line => 2, :found => "btn-default"),
|
|
151
|
+
a_hash_including(:file => "app/views/tasks/index.html.erb", :line => 2, :found => "data-toggle")
|
|
152
|
+
)
|
|
153
|
+
expect(check("legacy_markup")).to include(:status => "warn", :message => a_string_including("2"))
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it "also scans helpers" do
|
|
157
|
+
write_destination("app/helpers/tasks_helper.rb", %{tag.a("x", class: "pull-right")})
|
|
158
|
+
|
|
159
|
+
expect(report[:legacy_markup].first[:found]).to eq("pull-right")
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "does not scan other directories" do
|
|
163
|
+
write_destination("vendor/theme/index.html.erb", %{<a class="btn-default"></a>})
|
|
164
|
+
|
|
165
|
+
expect(report[:legacy_markup]).to be_empty
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
describe "Bootstrap 6 migration" do
|
|
170
|
+
def v6_report
|
|
171
|
+
rails_mod::Doctor.new(destination_root).report(:v6 => true)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it "is left out unless asked for" do
|
|
175
|
+
write_destination("app/views/tasks/index.html.erb", %{<div class="modal-body"></div>})
|
|
176
|
+
|
|
177
|
+
expect(report).not_to have_key(:v6_migration)
|
|
178
|
+
expect(report[:checks].map { |c| c[:id] }).not_to include("v6_migration")
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it "lists what changes in Bootstrap 6, with the location" do
|
|
182
|
+
write_destination("app/views/tasks/index.html.erb", %{<p>ok</p>\n<button data-bs-toggle="modal" class="btn btn-primary">x</button>})
|
|
183
|
+
|
|
184
|
+
expect(v6_report[:v6_migration]).to contain_exactly(
|
|
185
|
+
a_hash_including(:file => "app/views/tasks/index.html.erb", :line => 2, :found => "btn-primary"),
|
|
186
|
+
a_hash_including(:file => "app/views/tasks/index.html.erb", :line => 2, :found => %{data-bs-toggle="modal"})
|
|
187
|
+
)
|
|
188
|
+
check = v6_report[:checks].find { |c| c[:id] == "v6_migration" }
|
|
189
|
+
expect(check).to include(:status => "warn", :fix => a_string_including("bootstrap-v5-v6-migration"))
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it "scans the app's JavaScript and stylesheets" do
|
|
193
|
+
write_destination("app/javascript/controllers/menu_controller.js", "new bootstrap.Dropdown(this.element)")
|
|
194
|
+
write_destination("app/assets/stylesheets/custom.scss", %{@import "bootstrap/scss/functions";})
|
|
195
|
+
|
|
196
|
+
expect(v6_report[:v6_migration].map { |f| f[:file] })
|
|
197
|
+
.to eq(%w[app/assets/stylesheets/custom.scss app/javascript/controllers/menu_controller.js])
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
it "skips the Bootstrap files the gem vendored" do
|
|
201
|
+
install_static_on_propshaft
|
|
202
|
+
layout_findings = v6_report[:v6_migration].reject { |f| f[:file].start_with?("app/views/") }
|
|
203
|
+
|
|
204
|
+
expect(layout_findings).to be_empty
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
it "finds the Bootstrap 5 markup in a layout the generators wrote" do
|
|
208
|
+
install_static_on_propshaft
|
|
209
|
+
|
|
210
|
+
expect(v6_report[:v6_migration].map { |f| f[:found] }).to include("navbar-expand-lg")
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
it "is happy when nothing needs to change" do
|
|
214
|
+
expect(v6_report[:checks].find { |c| c[:id] == "v6_migration" }[:status]).to eq("ok")
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
describe "facts" do
|
|
219
|
+
it "states the versions and template engine" do
|
|
220
|
+
expect(report).to include(
|
|
221
|
+
:bootstrap_version => version,
|
|
222
|
+
:gem_version => rails_mod::VERSION,
|
|
223
|
+
:rails_version => ::Rails.version,
|
|
224
|
+
:template_engine => "erb"
|
|
225
|
+
)
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
describe "the command" do
|
|
230
|
+
before { install_static_on_propshaft }
|
|
231
|
+
|
|
232
|
+
it "prints the report as JSON with --json" do
|
|
233
|
+
parsed = JSON.parse(run_generator(described_class, %w[--json]))
|
|
234
|
+
|
|
235
|
+
expect(parsed).to include("status" => "ok", "bootstrap_version" => version)
|
|
236
|
+
expect(parsed["checks"].map { |c| c["id"] }).to include("bootstrap_css", "legacy_markup")
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
it "prints readable lines without --json" do
|
|
240
|
+
output = run_generator(described_class)
|
|
241
|
+
|
|
242
|
+
expect(output).to match(/\[ok\]\s+bootstrap_css/)
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
it "writes nothing" do
|
|
246
|
+
before = Dir[destination_path("**/*")].sort
|
|
247
|
+
run_generator(described_class)
|
|
248
|
+
|
|
249
|
+
expect(Dir[destination_path("**/*")].sort).to eq(before)
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
it "exits non-zero when a check fails, so agents and CI can rely on it" do
|
|
253
|
+
FileUtils.rm(destination_path("app/views/layouts/application.html.erb"))
|
|
254
|
+
|
|
255
|
+
expect { run_generator(described_class, %w[--json]) }
|
|
256
|
+
.to raise_error(SystemExit) { |e| expect(e.status).to eq(1) }
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
it "adds the Bootstrap 6 worklist with --v6" do
|
|
260
|
+
parsed = JSON.parse(run_generator(described_class, %w[--v6 --json]))
|
|
261
|
+
|
|
262
|
+
expect(parsed["v6_migration"]).to include(a_hash_including("found" => "navbar-expand-lg", "replacement" => "lg:navbar-expand"))
|
|
263
|
+
expect(run_generator(described_class, %w[--v6])).to match(%r{\[warn\]\s+v6_migration.*\n(.*\n)*\s+app/views/layouts/application\.html\.erb:\d+\s+navbar-expand-lg -> lg:navbar-expand})
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
it "exits normally on warnings" do
|
|
267
|
+
write_destination("app/views/tasks/index.html.erb", %{<a class="btn-default"></a>})
|
|
268
|
+
|
|
269
|
+
expect { run_generator(described_class) }.not_to raise_error
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
end
|
|
@@ -171,6 +171,29 @@ describe "Bootstrap snippet generators" do
|
|
|
171
171
|
end
|
|
172
172
|
end
|
|
173
173
|
|
|
174
|
+
describe "--json" do
|
|
175
|
+
let(:listing) { JSON.parse(run_generator(generator_for("hero"), %w[--json])) }
|
|
176
|
+
|
|
177
|
+
it "describes the generator and its default variant" do
|
|
178
|
+
expect(listing).to include("generator" => "bootstrap:hero", "category" => "heroes", "default" => "centered")
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it "lists every variant with what it needs" do
|
|
182
|
+
expect(listing["variants"].map { |v| v["name"] }).to eq(Catalog.variant_names("heroes"))
|
|
183
|
+
expect(listing["variants"].first).to include("description" => a_kind_of(String), "icons" => false, "images" => true)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it "gives the command that generates each variant" do
|
|
187
|
+
expect(listing["variants"].last["command"]).to eq("rails g bootstrap:hero dark")
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it "writes nothing" do
|
|
191
|
+
listing
|
|
192
|
+
|
|
193
|
+
expect(Dir[destination_path("**/*")]).to be_empty
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
174
197
|
describe "--list" do
|
|
175
198
|
it "prints each variant with its description and writes nothing" do
|
|
176
199
|
output = run_generator(generator_for("sidebar"), %w[--list])
|
|
@@ -19,12 +19,16 @@ describe BadgeLabelHelper, :type => :helper do
|
|
|
19
19
|
.to eql(BADGE_WITH_CLASS.gsub(/\s/, '').downcase)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
it "should render tag_label as a badge, since Bootstrap 5 has no labels" do
|
|
23
|
+
expect(tag_label('Beta', :info)).to eql %{<span class="badge text-bg-info">Beta</span>}
|
|
24
|
+
end
|
|
25
|
+
|
|
22
26
|
it "should take a Number as its first parameter" do
|
|
23
27
|
expect(badge(12).gsub(/\s/, '').downcase)
|
|
24
28
|
.to eql(BADGE_WITH_NUMBER_PARAM.gsub(/\s/, '').downcase)
|
|
25
29
|
end
|
|
26
30
|
end
|
|
27
31
|
|
|
28
|
-
BASIC_BADGE = %{<span class="badge">New!</span>}
|
|
29
|
-
BADGE_WITH_CLASS = %{<span class="badge
|
|
30
|
-
BADGE_WITH_NUMBER_PARAM = %{<span class="badge">12</span>}
|
|
32
|
+
BASIC_BADGE = %{<span class="badge text-bg-secondary">New!</span>}
|
|
33
|
+
BADGE_WITH_CLASS = %{<span class="badge text-bg-warning">2</span>}
|
|
34
|
+
BADGE_WITH_NUMBER_PARAM = %{<span class="badge text-bg-secondary">12</span>}
|
|
@@ -29,16 +29,10 @@ describe BootstrapFlashHelper, type: :helper do
|
|
|
29
29
|
element = bootstrap_flash
|
|
30
30
|
|
|
31
31
|
expect(element).to have_tag(:div,
|
|
32
|
-
text: "
|
|
33
|
-
with: {class: "alert
|
|
32
|
+
text: "Hello",
|
|
33
|
+
with: {class: "alert alert-success alert-dismissible fade show"}) {
|
|
34
34
|
|
|
35
|
-
with_tag(:button,
|
|
36
|
-
text: "×",
|
|
37
|
-
with: {
|
|
38
|
-
class: "close",
|
|
39
|
-
"data-dismiss" => "alert"
|
|
40
|
-
}
|
|
41
|
-
)
|
|
35
|
+
with_tag(:button, with: {class: "btn-close", "data-bs-dismiss" => "alert", type: "button", "aria-label" => "Close"})
|
|
42
36
|
|
|
43
37
|
}
|
|
44
38
|
end
|
|
@@ -49,16 +43,10 @@ describe BootstrapFlashHelper, type: :helper do
|
|
|
49
43
|
element = bootstrap_flash(class: "extra-class")
|
|
50
44
|
|
|
51
45
|
expect(element).to have_tag(:div,
|
|
52
|
-
text: "
|
|
53
|
-
with: {class: "alert
|
|
46
|
+
text: "Hello",
|
|
47
|
+
with: {class: "alert alert-success alert-dismissible fade show extra-class"}) {
|
|
54
48
|
|
|
55
|
-
with_tag(:button,
|
|
56
|
-
text: "×",
|
|
57
|
-
with: {
|
|
58
|
-
class: "close",
|
|
59
|
-
"data-dismiss" => "alert"
|
|
60
|
-
}
|
|
61
|
-
)
|
|
49
|
+
with_tag(:button, with: {class: "btn-close", "data-bs-dismiss" => "alert", type: "button", "aria-label" => "Close"})
|
|
62
50
|
|
|
63
51
|
}
|
|
64
52
|
end
|
|
@@ -69,19 +57,13 @@ describe BootstrapFlashHelper, type: :helper do
|
|
|
69
57
|
element = bootstrap_flash(class: "extra-class", "data-no-transition-cache" => true)
|
|
70
58
|
|
|
71
59
|
expect(element).to have_tag(:div,
|
|
72
|
-
text: "
|
|
60
|
+
text: "Hello",
|
|
73
61
|
with: {
|
|
74
|
-
class: "alert
|
|
62
|
+
class: "alert alert-success alert-dismissible fade show extra-class",
|
|
75
63
|
"data-no-transition-cache" => true
|
|
76
64
|
}) {
|
|
77
65
|
|
|
78
|
-
with_tag(:button,
|
|
79
|
-
text: "×",
|
|
80
|
-
with: {
|
|
81
|
-
class: "close",
|
|
82
|
-
"data-dismiss" => "alert"
|
|
83
|
-
}
|
|
84
|
-
)
|
|
66
|
+
with_tag(:button, with: {class: "btn-close", "data-bs-dismiss" => "alert", type: "button", "aria-label" => "Close"})
|
|
85
67
|
|
|
86
68
|
}
|
|
87
69
|
end
|
|
@@ -92,33 +74,29 @@ describe BootstrapFlashHelper, type: :helper do
|
|
|
92
74
|
element = bootstrap_flash
|
|
93
75
|
|
|
94
76
|
expect(element).to have_tag(:div,
|
|
95
|
-
text: "
|
|
96
|
-
with: {class: "alert
|
|
97
|
-
with_tag(:button,
|
|
98
|
-
text: "×",
|
|
99
|
-
with: {
|
|
100
|
-
class: "close",
|
|
101
|
-
"data-dismiss" => "alert"
|
|
102
|
-
}
|
|
103
|
-
)
|
|
77
|
+
text: "<script>alert(1)</script>",
|
|
78
|
+
with: {class: "alert alert-success alert-dismissible fade show"}) {
|
|
79
|
+
with_tag(:button, with: {class: "btn-close", "data-bs-dismiss" => "alert", type: "button", "aria-label" => "Close"})
|
|
104
80
|
}
|
|
105
81
|
end
|
|
106
82
|
|
|
83
|
+
it "should keep the extra class on every message" do
|
|
84
|
+
allow(self).to receive(:flash) { {notice: ["One", "Two"]} }
|
|
85
|
+
|
|
86
|
+
element = bootstrap_flash(class: "extra-class")
|
|
87
|
+
|
|
88
|
+
expect(element).to have_tag("div.extra-class", count: 2)
|
|
89
|
+
end
|
|
90
|
+
|
|
107
91
|
it "should not escape a link if marked as safe by user" do
|
|
108
92
|
allow(self).to receive(:flash) { {notice: "<a href='example.com'>awesome link!</a>".html_safe} }
|
|
109
93
|
|
|
110
94
|
element = bootstrap_flash
|
|
111
95
|
|
|
112
96
|
expect(element).to have_tag(:div,
|
|
113
|
-
text: "
|
|
114
|
-
with: {class: "alert
|
|
115
|
-
with_tag(:button,
|
|
116
|
-
text: "×",
|
|
117
|
-
with: {
|
|
118
|
-
class: "close",
|
|
119
|
-
"data-dismiss" => "alert"
|
|
120
|
-
}
|
|
121
|
-
),
|
|
97
|
+
text: "awesome link!",
|
|
98
|
+
with: {class: "alert alert-success alert-dismissible fade show"}) { [
|
|
99
|
+
with_tag(:button, with: {class: "btn-close", "data-bs-dismiss" => "alert", type: "button", "aria-label" => "Close"}),
|
|
122
100
|
with_tag(:a,
|
|
123
101
|
text: 'awesome link!')
|
|
124
102
|
]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require_relative '../../../app/helpers/twitter_breadcrumbs_helper'
|
|
3
|
+
|
|
4
|
+
describe "twitter-bootstrap/_breadcrumbs" do
|
|
5
|
+
let(:crumbs) do
|
|
6
|
+
[{ :name => "Home", :url => "/", :options => {} },
|
|
7
|
+
{ :name => "Tasks", :url => "/tasks", :options => {} }]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
let(:view) do
|
|
11
|
+
views = File.expand_path("../../../app/views", __dir__)
|
|
12
|
+
ActionView::Base.with_empty_template_cache
|
|
13
|
+
.with_view_paths([views], { "__bs_breadcrumbs" => crumbs })
|
|
14
|
+
.tap { |v| v.extend(TwitterBreadcrumbsHelper) }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "renders Bootstrap 5 breadcrumb markup" do
|
|
18
|
+
html = view.render_bootstrap_breadcrumbs
|
|
19
|
+
|
|
20
|
+
expect(html).to have_tag("nav", :with => { "aria-label" => "breadcrumb" }) do
|
|
21
|
+
with_tag("ol.breadcrumb li.breadcrumb-item a", :text => "Home", :with => { :href => "/" })
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "marks the last crumb as the current page" do
|
|
26
|
+
expect(view.render_bootstrap_breadcrumbs)
|
|
27
|
+
.to have_tag("li.breadcrumb-item.active", :text => /Tasks/, :with => { "aria-current" => "page" })
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "sets the divider through Bootstrap's CSS variable" do
|
|
31
|
+
nav = Nokogiri::HTML.fragment(view.render_bootstrap_breadcrumbs(">")).at_css("nav")
|
|
32
|
+
|
|
33
|
+
expect(nav["style"]).to eq("--bs-breadcrumb-divider: '>';")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
require_relative '../../../app/helpers/flash_block_helper'
|
|
4
|
+
|
|
5
|
+
include ActionView::Helpers
|
|
6
|
+
include ActionView::Context
|
|
7
|
+
include FlashBlockHelper
|
|
8
|
+
|
|
9
|
+
describe FlashBlockHelper, :type => :helper do
|
|
10
|
+
it "maps Rails flash keys onto Bootstrap's alert colours" do
|
|
11
|
+
allow(self).to receive(:flash) { { :notice => "Saved", :alert => "Nope" } }
|
|
12
|
+
|
|
13
|
+
expect(flash_block).to have_tag("div.alert.alert-success.alert-dismissible.fade.show", :text => "Saved")
|
|
14
|
+
expect(flash_block).to have_tag("div.alert.alert-danger", :text => "Nope")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "renders a Bootstrap 5 close button" do
|
|
18
|
+
expect(flash_container(:info, "Hi")).to have_tag(:button, :with => {
|
|
19
|
+
:class => "btn-close", :type => "button", "data-bs-dismiss" => "alert", "aria-label" => "Close"
|
|
20
|
+
})
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "escapes unsafe messages" do
|
|
24
|
+
expect(flash_container(:info, "<script>alert(1)</script>")).not_to include("<script>")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -27,8 +27,8 @@ describe FormErrorsHelper, :type => :helper do
|
|
|
27
27
|
allow(self).to receive_messages(:protect_against_forgery? => false)
|
|
28
28
|
allow(self).to receive_messages(:polymorphic_path => '')
|
|
29
29
|
|
|
30
|
-
@default_class = '
|
|
31
|
-
@default_error_class = 'has-
|
|
30
|
+
@default_class = 'invalid-feedback'
|
|
31
|
+
@default_error_class = 'has-validation'
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'twitter/bootstrap/rails/legacy_markup'
|
|
3
|
+
|
|
4
|
+
describe Twitter::Bootstrap::Rails::LegacyMarkup do
|
|
5
|
+
def found(text, extension = ".erb")
|
|
6
|
+
described_class.scan(text, extension).map { |f| f[:found] }
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "reports the line and the replacement" do
|
|
10
|
+
finding = described_class.scan(%{<p>ok</p>\n<a class="btn btn-default">x</a>}, ".erb").first
|
|
11
|
+
|
|
12
|
+
expect(finding).to include(:line => 2, :found => "btn-default", :replacement => "btn-secondary")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "finds old data attributes" do
|
|
16
|
+
expect(found(%{<a data-toggle="modal" data-target="#m"></a>})).to eq(%w[data-toggle data-target])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "leaves Bootstrap 5 data attributes alone" do
|
|
20
|
+
expect(found(%{<a data-bs-toggle="modal" data-bs-target="#m"></a>})).to be_empty
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "finds old data attributes in Ruby hashes" do
|
|
24
|
+
expect(found(%{<%= link_to "x", "#", data: { toggle: "modal" } %>})).to eq(%w[data-toggle])
|
|
25
|
+
expect(found(%{<%= link_to "x", "#", :data => { :dismiss => "modal" } %>})).to eq(%w[data-dismiss])
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "finds old classes in each Ruby hash style" do
|
|
29
|
+
expect(found(%{<%= link_to "x", "#", class: "btn btn-default" %>})).to eq(%w[btn-default])
|
|
30
|
+
expect(found(%{<%= link_to "x", "#", :class => 'btn-xs' %>})).to eq(%w[btn-xs])
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "ignores interpolated code inside a class attribute" do
|
|
34
|
+
expect(found('<div class="<%= close %> #{well}"></div>')).to be_empty
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "matches whole class names only" do
|
|
38
|
+
expect(found(%{<div class="my-panel closed wells"></div>})).to be_empty
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "ignores the same words outside class attributes" do
|
|
42
|
+
expect(found(%{<p>Close the panel, it went well.</p>})).to be_empty
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "rewrites numbered classes" do
|
|
46
|
+
finding = described_class.scan(%{<div class="col-xs-6 ml-3 pr-md-2"></div>}, ".erb")
|
|
47
|
+
|
|
48
|
+
expect(finding.map { |f| f[:replacement] }).to eq(%w[col-6 ms-3 pe-md-2])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "finds class shorthand in Haml and Slim" do
|
|
52
|
+
expect(found("%button.btn.btn-default Save", ".haml")).to eq(%w[btn-default])
|
|
53
|
+
expect(found(".form-group\n = f.label :x", ".haml")).to eq(%w[form-group])
|
|
54
|
+
expect(found("button.btn-xs Save", ".slim")).to eq(%w[btn-xs])
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "does not treat plain Haml text as class shorthand" do
|
|
58
|
+
expect(found("Visit example.close today", ".haml")).to be_empty
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# The gem can't tell agents off for markup it ships itself.
|
|
62
|
+
it "finds nothing in the markup this gem ships" do
|
|
63
|
+
root = File.expand_path("../../..", __dir__)
|
|
64
|
+
files = Dir[File.join(root, "lib/generators/**/templates/**/*"), File.join(root, "app/views/**/*"), File.join(root, "app/helpers/**/*")]
|
|
65
|
+
.select { |f| File.file?(f) }
|
|
66
|
+
|
|
67
|
+
offenders = files.flat_map do |file|
|
|
68
|
+
described_class.scan(File.read(file), File.extname(file))
|
|
69
|
+
.map { |f| "#{file.sub("#{root}/", '')}:#{f[:line]} #{f[:found]}" }
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
expect(offenders).to eq([])
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -28,35 +28,48 @@ describe ModalHelper, :type => :helper do
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it 'renders a close button' do
|
|
31
|
-
expect(close_button('modal')).to eql
|
|
31
|
+
expect(close_button('modal')).to eql CLOSE_BUTTON
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
it 'dismisses the modal when no dismiss target is given' do
|
|
35
|
+
expect(close_button(nil)).to eql CLOSE_BUTTON
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'escapes the dismiss target' do
|
|
39
|
+
expect(close_button('"><script>')).not_to include('<script>')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'applies the requested size to the dialog' do
|
|
43
|
+
expect(modal_dialog(options.merge(:size => 'modal-lg'))).to have_tag('div.modal-dialog.modal-lg')
|
|
44
|
+
end
|
|
45
|
+
|
|
34
46
|
it 'renders a modal toggle button' do
|
|
35
47
|
expect(modal_toggle('Save', :href => "#modal").gsub(/\n/, "")).to eql MODAL_TOGGLE.gsub(/\n/, "")
|
|
36
48
|
end
|
|
37
49
|
|
|
38
50
|
it 'renders a cancel button' do
|
|
39
|
-
expect(modal_cancel_button("Cancel", :
|
|
51
|
+
expect(modal_cancel_button("Cancel", :href => "#modal").gsub(/\n/, "")).to eql MODAL_CANCEL_BUTTON.gsub(/\n/, "")
|
|
40
52
|
end
|
|
41
53
|
end
|
|
42
54
|
|
|
55
|
+
CLOSE_BUTTON = %q{<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>}
|
|
56
|
+
|
|
43
57
|
BASIC_MODAL = <<-HTML
|
|
44
|
-
<div class
|
|
58
|
+
<div class="bootstrap-modal modal fade" id="modal" tabindex="-1" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h5 class="modal-title">Modal header</h5><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button></div><div class="modal-body">This is the body</div><div class="modal-footer"><button class="btn">Save</button></div></div></div></div>
|
|
45
59
|
HTML
|
|
46
60
|
|
|
47
61
|
MODAL_HEADER_WITHOUT_CLOSE = <<-HTML
|
|
48
|
-
<div class="modal-header"><
|
|
62
|
+
<div class="modal-header"><h5 class="modal-title">Modal header</h5></div>
|
|
49
63
|
HTML
|
|
50
64
|
|
|
51
65
|
MODAL_HEADER_WITH_CLOSE = <<-HTML
|
|
52
|
-
<div class="modal-header"><button class="close" data-dismiss="modal" aria-
|
|
66
|
+
<div class="modal-header"><h5 class="modal-title">Modal header</h5><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button></div>
|
|
53
67
|
HTML
|
|
54
68
|
|
|
55
69
|
MODAL_TOGGLE = <<-HTML
|
|
56
|
-
<a class="btn btn-
|
|
70
|
+
<a class="btn btn-secondary" data-bs-toggle="modal" href="#modal">Save</a>
|
|
57
71
|
HTML
|
|
58
72
|
|
|
59
73
|
MODAL_CANCEL_BUTTON = <<-HTML
|
|
60
|
-
<a class="btn bootstrap-modal-cancel-button" data-dismiss="modal" href="#modal">Cancel</a>
|
|
74
|
+
<a class="btn btn-secondary bootstrap-modal-cancel-button" data-bs-dismiss="modal" href="#modal">Cancel</a>
|
|
61
75
|
HTML
|
|
62
|
-
|