gretel 4.0.1 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -6
  3. data/.travis.yml +1 -1
  4. data/CHANGELOG.md +4 -0
  5. data/README.md +9 -49
  6. data/Rakefile +3 -7
  7. data/gretel.gemspec +7 -10
  8. data/lib/gretel/renderer.rb +6 -2
  9. data/lib/gretel/version.rb +1 -1
  10. metadata +12 -114
  11. data/test/dummy/Rakefile +0 -7
  12. data/test/dummy/app/assets/config/manifest.js +0 -0
  13. data/test/dummy/app/assets/javascripts/application.js +0 -15
  14. data/test/dummy/app/assets/stylesheets/application.css +0 -13
  15. data/test/dummy/app/controllers/application_controller.rb +0 -3
  16. data/test/dummy/app/helpers/application_helper.rb +0 -5
  17. data/test/dummy/app/mailers/.gitkeep +0 -0
  18. data/test/dummy/app/models/.gitkeep +0 -0
  19. data/test/dummy/app/models/issue.rb +0 -3
  20. data/test/dummy/app/models/project.rb +0 -3
  21. data/test/dummy/app/views/breadcrumbs/site.rb +0 -3
  22. data/test/dummy/config.ru +0 -4
  23. data/test/dummy/config/application.rb +0 -14
  24. data/test/dummy/config/boot.rb +0 -10
  25. data/test/dummy/config/breadcrumbs.rb +0 -3
  26. data/test/dummy/config/breadcrumbs/test_crumbs.rb +0 -85
  27. data/test/dummy/config/database.yml +0 -25
  28. data/test/dummy/config/environment.rb +0 -5
  29. data/test/dummy/config/environments/development.rb +0 -2
  30. data/test/dummy/config/environments/production.rb +0 -2
  31. data/test/dummy/config/environments/test.rb +0 -2
  32. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  33. data/test/dummy/config/initializers/inflections.rb +0 -15
  34. data/test/dummy/config/initializers/mime_types.rb +0 -5
  35. data/test/dummy/config/initializers/secret_token.rb +0 -7
  36. data/test/dummy/config/initializers/session_store.rb +0 -8
  37. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  38. data/test/dummy/config/locales/en.yml +0 -5
  39. data/test/dummy/config/routes.rb +0 -11
  40. data/test/dummy/db/migrate/20130122163007_create_projects.rb +0 -9
  41. data/test/dummy/db/migrate/20130122163051_create_issues.rb +0 -10
  42. data/test/dummy/db/schema.rb +0 -28
  43. data/test/dummy/lib/assets/.gitkeep +0 -0
  44. data/test/dummy/log/.gitkeep +0 -0
  45. data/test/dummy/public/404.html +0 -26
  46. data/test/dummy/public/422.html +0 -26
  47. data/test/dummy/public/500.html +0 -25
  48. data/test/dummy/public/favicon.ico +0 -0
  49. data/test/dummy/script/rails +0 -6
  50. data/test/fixtures/issues.yml +0 -4
  51. data/test/fixtures/projects.yml +0 -3
  52. data/test/gretel_test.rb +0 -23
  53. data/test/helper_methods_test.rb +0 -555
  54. data/test/test_helper.rb +0 -23
@@ -1,555 +0,0 @@
1
- require 'test_helper'
2
-
3
- class HelperMethodsTest < ActionView::TestCase
4
- include Gretel::ViewHelpers
5
-
6
- self.fixture_path = File.expand_path("../../test/fixtures", __FILE__)
7
- fixtures :all
8
-
9
- helper :application
10
-
11
- setup do
12
- Gretel.reset!
13
- end
14
-
15
- # Breadcrumb generation
16
-
17
- test "basic breadcrumb" do
18
- breadcrumb :basic
19
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
20
- breadcrumbs.to_s
21
- end
22
-
23
- test "breadcrumb with root" do
24
- breadcrumb :with_root
25
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
26
- breadcrumbs.to_s
27
- end
28
-
29
- test "breadcrumb with parent" do
30
- breadcrumb :with_parent
31
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">About</a> &rsaquo; <span class="current">Contact</span></div>},
32
- breadcrumbs.to_s
33
- end
34
-
35
- test "breadcrumb with autopath" do
36
- breadcrumb :with_autopath, projects(:one)
37
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test Project</span></div>},
38
- breadcrumbs.to_s
39
- end
40
-
41
- test "breadcrumb with parent object" do
42
- breadcrumb :with_parent_object, issues(:one)
43
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/projects/1">Test Project</a> &rsaquo; <span class="current">Test Issue</span></div>},
44
- breadcrumbs.to_s
45
- end
46
-
47
- test "multiple links" do
48
- breadcrumb :multiple_links
49
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about/contact">Contact</a> &rsaquo; <span class="current">Contact form</span></div>},
50
- breadcrumbs.to_s
51
- end
52
-
53
- test "multiple links with parent" do
54
- breadcrumb :multiple_links_with_parent
55
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">About</a> &rsaquo; <a href="/about/contact">Contact</a> &rsaquo; <span class="current">Contact form</span></div>},
56
- breadcrumbs.to_s
57
- end
58
-
59
- test "semantic breadcrumb" do
60
- breadcrumb :with_root
61
- assert_dom_equal %{<div class="breadcrumbs" itemscope="itemscope" itemtype="https://schema.org/BreadcrumbList"><span itemprop="itemListElement" itemscope="itemscope" itemtype="https://schema.org/ListItem"><a itemprop="item" href="/"><span itemprop="name">Home</span></a><meta itemprop="position" content="1" /></span> &rsaquo; <span class="current" itemprop="itemListElement" itemscope="itemscope" itemtype="https://schema.org/ListItem"><span itemprop="name">About</span><meta itemprop="item" content="http://test.host/about" /><meta itemprop="position" content="2" /></span></div>},
62
- breadcrumbs(semantic: true).to_s
63
- end
64
-
65
- test "doesn't show root alone" do
66
- breadcrumb :root
67
- assert_dom_equal "", breadcrumbs.to_s
68
- end
69
-
70
- test "displays single fragment" do
71
- breadcrumb :root
72
- assert_dom_equal %{<div class="breadcrumbs"><span class="current">Home</span></div>},
73
- breadcrumbs(display_single_fragment: true).to_s
74
- end
75
-
76
- test "displays single non-root fragment" do
77
- breadcrumb :basic
78
- assert_dom_equal %{<div class="breadcrumbs"><span class="current">About</span></div>},
79
- breadcrumbs(autoroot: false, display_single_fragment: true).to_s
80
- end
81
-
82
- test "no breadcrumb" do
83
- assert_dom_equal "", breadcrumbs.to_s
84
- end
85
-
86
- test "links current breadcrumb" do
87
- breadcrumb :with_root
88
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about" class="current">About</a></div>},
89
- breadcrumbs(link_current: true).to_s
90
- end
91
-
92
- test "pretext" do
93
- breadcrumb :basic
94
- assert_dom_equal %{<div class="breadcrumbs"><span class="pretext">You are here:</span> <a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
95
- breadcrumbs(pretext: "You are here:").to_s
96
- end
97
-
98
- test "posttext" do
99
- breadcrumb :basic
100
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span> <span class="posttext">text after breadcrumbs</span></div>},
101
- breadcrumbs(posttext: "text after breadcrumbs").to_s
102
- end
103
-
104
- test "autoroot disabled" do
105
- breadcrumb :basic
106
- assert_dom_equal "", breadcrumbs(autoroot: false).to_s
107
- end
108
-
109
- test "separator" do
110
- breadcrumb :with_root
111
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &raquo; <span class="current">About</span></div>},
112
- breadcrumbs(separator: " &raquo; ").to_s
113
- end
114
-
115
- test "element id" do
116
- breadcrumb :basic
117
- assert_dom_equal %{<div class="breadcrumbs" id="custom_id"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
118
- breadcrumbs(id: "custom_id").to_s
119
- end
120
-
121
- test "custom container class" do
122
- breadcrumb :basic
123
- assert_dom_equal %{<div class="custom_class"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
124
- breadcrumbs(class: "custom_class").to_s
125
- end
126
-
127
- test "custom fragment class" do
128
- breadcrumb :basic
129
- assert_dom_equal %{<div class="breadcrumbs"><a class="custom_fragment_class" href="/">Home</a> &rsaquo; <span class="custom_fragment_class current">About</span></div>},
130
- breadcrumbs(fragment_class: "custom_fragment_class").to_s
131
- end
132
-
133
- test "custom current class" do
134
- breadcrumb :basic
135
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="custom_current_class">About</span></div>},
136
- breadcrumbs(current_class: "custom_current_class").to_s
137
- end
138
-
139
- test "custom pretext class" do
140
- breadcrumb :basic
141
- assert_dom_equal %{<div class="breadcrumbs"><span class="custom_pretext_class">You are here:</span> <a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
142
- breadcrumbs(pretext: "You are here:", pretext_class: "custom_pretext_class").to_s
143
- end
144
-
145
- test "custom posttext class" do
146
- breadcrumb :basic
147
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span> <span class="custom_posttext_class">after breadcrumbs</span></div>},
148
- breadcrumbs(posttext: "after breadcrumbs", posttext_class: "custom_posttext_class").to_s
149
- end
150
-
151
- test "unsafe html" do
152
- breadcrumb :with_unsafe_html
153
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test &lt;strong&gt;bold text&lt;/strong&gt;</span></div>},
154
- breadcrumbs.to_s
155
- end
156
-
157
- test "safe html" do
158
- breadcrumb :with_safe_html
159
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test <strong>bold text</strong></span></div>},
160
- breadcrumbs.to_s
161
- end
162
-
163
- test "parent breadcrumb" do
164
- breadcrumb :multiple_links_with_parent
165
-
166
- parent = parent_breadcrumb
167
- assert_equal [:multiple_links_with_parent, "Contact", "/about/contact"],
168
- [parent.key, parent.text, parent.url]
169
- end
170
-
171
- test "yields parent breadcrumb" do
172
- breadcrumb :multiple_links_with_parent
173
-
174
- out = parent_breadcrumb do |parent|
175
- [parent.key, parent.text, parent.url]
176
- end
177
- assert_equal [:multiple_links_with_parent, "Contact", "/about/contact"],
178
- out
179
- end
180
-
181
- test "parent breadcrumb returns nil if not present" do
182
- breadcrumb :basic
183
-
184
- assert_nil parent_breadcrumb(autoroot: false)
185
- end
186
-
187
- test "parent breadcrumb yields only if present" do
188
- breadcrumb :basic
189
-
190
- out = parent_breadcrumb(autoroot: false) do
191
- # :nocov:
192
- "yielded"
193
- # :nocov:
194
- end
195
-
196
- assert_nil out
197
- end
198
-
199
- test "link keys" do
200
- breadcrumb :basic
201
- assert_equal [:root, :basic], breadcrumbs.keys
202
- end
203
-
204
- test "using breadcrumbs as array" do
205
- breadcrumb :basic
206
-
207
- breadcrumbs.tap do |links|
208
- assert_kind_of Array, links
209
- assert_equal 2, links.count
210
- end
211
- end
212
-
213
- test "sets current on last link in array" do
214
- breadcrumb :multiple_links_with_parent
215
- assert_equal [false, false, false, true], breadcrumbs.map(&:current?)
216
- end
217
-
218
- test "passing options to links" do
219
- breadcrumb :with_link_options
220
-
221
- breadcrumbs(autoroot: false).tap do |links|
222
- links[0].tap do |link|
223
- assert link.title?
224
- assert_equal "My Title", link.title
225
-
226
- assert link.other?
227
- assert_equal "Other Option", link.other
228
-
229
- assert !link.nonexistent?
230
- assert_nil link.nonexistent
231
- end
232
-
233
- links[1].tap do |link|
234
- assert link.some_option?
235
- assert_equal "Test", link.some_option
236
- end
237
- end
238
-
239
- assert_dom_equal %{<div class="breadcrumbs"><a href="/about">Test</a> &rsaquo; <span class="current">Other Link</span></div>},
240
- breadcrumbs(autoroot: false).to_s
241
- end
242
-
243
- test "without link" do
244
- breadcrumb :without_link
245
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; Also without link &rsaquo; <span class="current">Without link</span></div>},
246
- breadcrumbs.to_s
247
- end
248
-
249
- test "view context" do
250
- breadcrumb :using_view_helper
251
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">TestTest</span></div>},
252
- breadcrumbs.to_s
253
- end
254
-
255
- test "multiple arguments" do
256
- breadcrumb :with_multiple_arguments, "One", "Two", "Three"
257
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">First OneOne then TwoTwo then ThreeThree</a> &rsaquo; <span class="current">One and Two and Three</span></div>},
258
- breadcrumbs.to_s
259
- end
260
-
261
- test "from views folder" do
262
- breadcrumb :from_views
263
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Breadcrumb From View</span></div>},
264
- breadcrumbs.to_s
265
- end
266
-
267
- test "with_breadcrumb" do
268
- breadcrumb :basic
269
-
270
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
271
- breadcrumbs.to_s
272
-
273
- with_breadcrumb(:with_parent_object, issues(:one)) do
274
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/projects/1">Test Project</a> &rsaquo; <span class="current">Test Issue</span></div>},
275
- breadcrumbs.to_s
276
- end
277
-
278
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
279
- breadcrumbs.to_s
280
- end
281
-
282
- test "calling breadcrumbs helper twice" do
283
- breadcrumb :with_parent
284
- 2.times do
285
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">About</a> &rsaquo; <span class="current">Contact</span></div>},
286
- breadcrumbs.to_s
287
- end
288
- end
289
-
290
- test "breadcrumb not found" do
291
- assert_raises ArgumentError do
292
- breadcrumb :nonexistent
293
- breadcrumbs
294
- end
295
- end
296
-
297
- test "current link url is set to fullpath" do
298
- self.request = OpenStruct.new(fullpath: "/testpath?a=1&b=2")
299
-
300
- breadcrumb :basic
301
- assert_equal "/testpath?a=1&b=2", breadcrumbs.last.url
302
- end
303
-
304
- test "current link url is not set to fullpath using link_current_to_request_path=false" do
305
- self.request = OpenStruct.new(fullpath: "/testpath?a=1&b=2")
306
-
307
- breadcrumb :basic
308
- assert_equal "/about", breadcrumbs(:link_current_to_request_path => false).last.url
309
- end
310
-
311
- test "calling the breadcrumb method with wrong arguments" do
312
- assert_nothing_raised do
313
- breadcrumb :basic, test: 1
314
- end
315
-
316
- assert_raises ArgumentError do
317
- breadcrumb
318
- end
319
-
320
- assert_raises ArgumentError do
321
- breadcrumb(pretext: "bla")
322
- end
323
- end
324
-
325
- test "inferred breadcrumb" do
326
- breadcrumb Project.first
327
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test Project</span></div>},
328
- breadcrumbs.to_s
329
- end
330
-
331
- test "inferred parent" do
332
- breadcrumb :with_inferred_parent
333
-
334
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/projects/1">Test Project</a> &rsaquo; <span class="current">Test</span></div>},
335
- breadcrumbs.to_s
336
- end
337
-
338
- # Styles
339
-
340
- test "default style" do
341
- breadcrumb :basic
342
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
343
- breadcrumbs.to_s
344
- end
345
-
346
- test "ordered list style" do
347
- breadcrumb :basic
348
- assert_dom_equal %{<ol class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ol>},
349
- breadcrumbs(style: :ol).to_s
350
- end
351
-
352
- test "unordered list style" do
353
- breadcrumb :basic
354
- assert_dom_equal %{<ul class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ul>},
355
- breadcrumbs(style: :ul).to_s
356
- end
357
-
358
- test "bootstrap style" do
359
- breadcrumb :basic
360
- assert_dom_equal %{<ol class="breadcrumb"><li><a href="/">Home</a></li><li class="active">About</li></ol>},
361
- breadcrumbs(style: :bootstrap).to_s
362
- end
363
-
364
- test "bootstrap4 style" do
365
- breadcrumb :basic
366
- assert_dom_equal %{<ol class="breadcrumb"><li class="breadcrumb-item"><a href="/">Home</a></li><li class="breadcrumb-item active">About</li></ol>},
367
- breadcrumbs(style: :bootstrap4).to_s
368
- end
369
-
370
- test "foundation5 style" do
371
- breadcrumb :basic
372
- assert_dom_equal %{<ul class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ul>},
373
- breadcrumbs(style: :foundation5).to_s
374
- end
375
-
376
- test "custom container and fragment tags" do
377
- breadcrumb :basic
378
- assert_dom_equal %{<c class="breadcrumbs"><f><a href="/">Home</a></f> &rsaquo; <f class="current">About</f></c>},
379
- breadcrumbs(container_tag: :c, fragment_tag: :f).to_s
380
- end
381
-
382
- test "custom semantic container and fragment tags" do
383
- breadcrumb :basic
384
- assert_dom_equal %{<c class="breadcrumbs" itemscope="itemscope" itemtype="https://schema.org/BreadcrumbList"><f itemprop="itemListElement" itemscope="itemscope" itemtype="https://schema.org/ListItem"><a itemprop="item" href="/"><span itemprop="name">Home</span></a><meta itemprop="position" content="1" /></f> &rsaquo; <f class="current" itemprop="itemListElement" itemscope="itemscope" itemtype="https://schema.org/ListItem"><span itemprop="name">About</span><meta itemprop="item" content="http://test.host/about" /><meta itemprop="position" content="2" /></f></c>},
385
- breadcrumbs(container_tag: :c, fragment_tag: :f, semantic: true).to_s
386
- end
387
-
388
- test "unknown style" do
389
- breadcrumb :basic
390
- assert_raises ArgumentError do
391
- breadcrumbs(style: :nonexistent)
392
- end
393
- end
394
-
395
- test "register style" do
396
- Gretel.register_style :test_style, { container_tag: :one, fragment_tag: :two }
397
-
398
- breadcrumb :basic
399
-
400
- assert_dom_equal %{<one class="breadcrumbs"><two><a href="/">Home</a></two><two class="current">About</two></one>},
401
- breadcrumbs(style: :test_style).to_s
402
- end
403
-
404
- # Configuration reload
405
-
406
- test "reload configuration when file is changed" do
407
- path = setup_loading_from_tmp_folder
408
- Gretel.reload_environments << "test"
409
-
410
- File.open(path.join("site.rb"), "w") do |f|
411
- f.write <<-EOT
412
- crumb :root do
413
- link "Home (loaded)", root_path
414
- end
415
- crumb :about do
416
- link "About (loaded)", about_path
417
- end
418
- EOT
419
- end
420
-
421
- breadcrumb :about
422
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
423
-
424
- sleep 1 # File change interval is 1 second
425
-
426
- File.open(path.join("site.rb"), "w") do |f|
427
- f.write <<-EOT
428
- crumb :root do
429
- link "Home (reloaded)", "/test"
430
- end
431
- crumb :about do
432
- link "About (reloaded)", "/reloaded"
433
- end
434
- EOT
435
- end
436
-
437
- breadcrumb :about
438
- assert_dom_equal %{<div class="breadcrumbs"><a href="/test">Home (reloaded)</a> &rsaquo; <span class="current">About (reloaded)</span></div>}, breadcrumbs.to_s
439
- end
440
-
441
- test "reload configuration when file is added" do
442
- path = setup_loading_from_tmp_folder
443
- Gretel.reload_environments << "test"
444
-
445
- File.open(path.join("site.rb"), "w") do |f|
446
- f.write <<-EOT
447
- crumb :root do
448
- link "Home (loaded)", root_path
449
- end
450
- EOT
451
- end
452
-
453
- assert_raises ArgumentError do
454
- breadcrumb :about
455
- breadcrumbs
456
- end
457
-
458
- File.open(path.join("pages.rb"), "w") do |f|
459
- f.write <<-EOT
460
- crumb :about do
461
- link "About (loaded)", about_path
462
- end
463
- EOT
464
- end
465
-
466
- breadcrumb :about
467
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
468
- end
469
-
470
- test "reload configuration when file is deleted" do
471
- path = setup_loading_from_tmp_folder
472
- Gretel.reload_environments << "test"
473
-
474
- File.open(path.join("site.rb"), "w") do |f|
475
- f.write <<-EOT
476
- crumb :root do
477
- link "Home (loaded)", root_path
478
- end
479
- crumb :about do
480
- link "About (loaded)", about_path
481
- end
482
- EOT
483
- end
484
-
485
- File.open(path.join("pages.rb"), "w") do |f|
486
- f.write <<-EOT
487
- crumb :contact do
488
- link "Contact (loaded)", "/contact"
489
- parent :about
490
- end
491
- EOT
492
- end
493
-
494
- breadcrumb :contact
495
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <a href="/about">About (loaded)</a> &rsaquo; <span class="current">Contact (loaded)</span></div>}, breadcrumbs.to_s
496
-
497
- File.delete path.join("pages.rb")
498
-
499
- assert_raises ArgumentError do
500
- breadcrumb :contact
501
- breadcrumbs
502
- end
503
-
504
- breadcrumb :about
505
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
506
- end
507
-
508
- test "reloads only in development environment" do
509
- path = setup_loading_from_tmp_folder
510
-
511
- assert_equal ["development"], Gretel.reload_environments
512
-
513
- File.open(path.join("site.rb"), "w") do |f|
514
- f.write <<-EOT
515
- crumb :root do
516
- link "Home (loaded)", root_path
517
- end
518
- crumb :about do
519
- link "About (loaded)", about_path
520
- end
521
- EOT
522
- end
523
-
524
- breadcrumb :about
525
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
526
-
527
- sleep 1
528
-
529
- File.open(path.join("site.rb"), "w") do |f|
530
- f.write <<-EOT
531
- crumb :root do
532
- link "Home (reloaded)", "/test"
533
- end
534
- crumb :about do
535
- link "About (reloaded)", "/reloaded"
536
- end
537
- EOT
538
- end
539
-
540
- breadcrumb :about
541
- assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
542
- end
543
-
544
- private
545
-
546
- def setup_loading_from_tmp_folder
547
- path = Rails.root.join("tmp", "testcrumbs")
548
- FileUtils.rm_rf path
549
- FileUtils.mkdir_p path
550
-
551
- Gretel.breadcrumb_paths = [path.join("*.rb")]
552
-
553
- path
554
- end
555
- end