gretel 3.0.0.beta1 → 3.0.0.beta2
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 +5 -2
- data/README.md +30 -21
- data/lib/gretel.rb +1 -0
- data/lib/gretel/renderer.rb +37 -30
- data/lib/gretel/trail.rb +7 -11
- data/lib/gretel/version.rb +1 -1
- data/lib/gretel/view_helpers.rb +6 -1
- data/test/deprecated_test.rb +7 -0
- data/test/helper_methods_test.rb +40 -7
- data/test/trail_test.rb +8 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db6f1e42bb6b92c94ae0ea17349b87d352fda758
|
4
|
+
data.tar.gz: 0b5532349fe0a6829bfd2e7d4c52aad04f7232a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8975240e40fa018ba3a80ff04782657d3a13045ba293162655e0ddd8f3b33b2d6685e9695d4a8f46e7dd9e25cc169e183ee75412aae95d84282ea625c01a35c
|
7
|
+
data.tar.gz: 105977c62283b95aa4c886ed38f85d2be8bb0ef64793c68673032bb416b9de284964de94d34a7cbe661d04c4a9f48bf7aeb3024c60c9e26f02ed84c2b59b1c4e
|
data/CHANGELOG.md
CHANGED
@@ -3,10 +3,13 @@ Changelog
|
|
3
3
|
|
4
4
|
Version 3.0
|
5
5
|
-----------
|
6
|
-
* Support for `Gretel::Crumbs.layout do ... end` in an initializer has been removed. See the readme for details on how to upgrade.
|
7
|
-
* Support for setting trails via the URL – `params[:trail]`. This makes it possible to link to a different breadcrumb trail than the one specified in your breadcrumb,
|
6
|
+
* Support for defining breadcrumbs using `Gretel::Crumbs.layout do ... end` in an initializer has been removed. See the readme for details on how to upgrade.
|
7
|
+
* Support for setting trails via the URL – `params[:trail]`. This makes it possible to link back to a different breadcrumb trail than the one specified in your breadcrumb,
|
8
8
|
for example if you have a store with products that have a default parent to their category, but when linking from the review section, you want to link back to the reviews instead.
|
9
9
|
See the readme for more info.
|
10
|
+
* Breadcrumbs rendering is now done in a separate class to unclutter the view with helpers. The public API is still the same.
|
11
|
+
* Support for rendering the breadcrumbs in different styles like ul- and ol lists, and for use with [Twitter Bootstrap](http://getbootstrap.com/). See the `:style` option in the readme for more info.
|
12
|
+
* The `:show_root_alone` option is now called `:display_single_fragment` and can be used to display the breadcrumbs only when there are more than one link, also if it is not the root breadcrumb.
|
10
13
|
|
11
14
|
Version 2.1
|
12
15
|
-----------
|
data/README.md
CHANGED
@@ -7,13 +7,20 @@ Gretel also supports [semantic breadcrumbs](http://support.google.com/webmasters
|
|
7
7
|
|
8
8
|
Have fun! And please do write, if you (dis)like it – [lassebunk@gmail.com](mailto:lassebunk@gmail.com).
|
9
9
|
|
10
|
-
New in version
|
10
|
+
New in version 3.0
|
11
11
|
------------------
|
12
12
|
|
13
|
-
|
14
|
-
for example if you have a store with products that have a default parent to their category, but when linking from the
|
13
|
+
* You can now set trails via the URL – `params[:trail]`. This makes it possible to link back to a different breadcrumb trail than the one specified in your breadcrumb,
|
14
|
+
for example if you have a store with products that have a default parent to their category, but when linking from the reviews section, you want to link back to the reviews instead.
|
15
|
+
Read more about trails below.
|
16
|
+
* Breadcrumbs can now be rendered in different styles like ul- and ol lists, and for use with the [Twitter Bootstrap](http://getbootstrap.com/) framework. See the `:style` option below for more info.
|
17
|
+
* Defining breadcrumbs using `Gretel::Crumbs.layout do ... end` in an initializer has been removed. See below for details on how to upgrade.
|
18
|
+
* The `:show_root_alone` option is now called `:display_single_fragment` and can be used to hide the breadcrumbs when there are only one link, also if it is not the root breadcrumb.
|
19
|
+
The old `:show_root_alone` option is still supported until Gretel version 4.0 and will show a deprecation warning when it's used.
|
15
20
|
|
16
|
-
|
21
|
+
I hope you find these changes as useful as I did when I made them – if you have more suggestions, please create an [Issue](https://github.com/lassebunk/gretel/issues) or [Pull Request](https://github.com/lassebunk/gretel/pulls).
|
22
|
+
|
23
|
+
See below for more info or the [changelog](https://github.com/lassebunk/gretel/blob/master/CHANGELOG.md) for less significant changes.
|
17
24
|
|
18
25
|
Installation
|
19
26
|
------------
|
@@ -21,7 +28,7 @@ Installation
|
|
21
28
|
In your *Gemfile*:
|
22
29
|
|
23
30
|
```ruby
|
24
|
-
gem "gretel"
|
31
|
+
gem "gretel", "3.0.0.beta2"
|
25
32
|
```
|
26
33
|
|
27
34
|
And run:
|
@@ -88,19 +95,21 @@ Options
|
|
88
95
|
|
89
96
|
You can pass options to `<%= breadcrumbs %>`, e.g. `<%= breadcrumbs pretext: "You are here: " %>`:
|
90
97
|
|
91
|
-
Option
|
92
|
-
|
93
|
-
:style
|
94
|
-
:pretext
|
95
|
-
:posttext
|
96
|
-
:separator
|
97
|
-
:autoroot
|
98
|
-
:
|
99
|
-
:link_current
|
100
|
-
:semantic
|
101
|
-
:id
|
102
|
-
:class
|
103
|
-
:current_class
|
98
|
+
Option | Description | Default
|
99
|
+
------------------------ | -------------------------------------------------------------------------------------------------------------------------- | -------
|
100
|
+
:style | How to render the breadcrumbs. Can be `:default`, `:ol`, `:ul`, or `:bootstrap`. See below for more info. | `:default`
|
101
|
+
:pretext | Text to be rendered before breadcrumb, e.g. `"You are here: "`. | None
|
102
|
+
:posttext | Text to be appended after breadcrumb, e.g. `"Text after breacrumb"`, | None
|
103
|
+
:separator | Separator between links, e.g. `" › "`. | `" › "`
|
104
|
+
:autoroot | Whether it should automatically link to the `:root` crumb if no parent is given. | True
|
105
|
+
:display_single_fragment | Whether it should display the breadcrumb if it includes only one link. | False
|
106
|
+
:link_current | Whether the current crumb should be linked to. | False
|
107
|
+
:semantic | Whether it should generate [semantic breadcrumbs](http://support.google.com/webmasters/bin/answer.py?hl=en&answer=185417). | False
|
108
|
+
:id | ID for the breadcrumbs container. | None
|
109
|
+
:class | CSS class for the breadcrumbs container. | `"breadcrumbs"`
|
110
|
+
:current_class | CSS class for the current link or span. | `"current"`
|
111
|
+
:container_tag | Tag type that contains the breadcrumbs. | `:div`
|
112
|
+
:fragment_tag | Tag type to contain each breadcrumb fragment/link. | None
|
104
113
|
|
105
114
|
### Styles
|
106
115
|
|
@@ -108,7 +117,7 @@ These are the styles you can use with `breadcrumb style: :xx`.
|
|
108
117
|
|
109
118
|
Style | Description
|
110
119
|
------------ | -----------
|
111
|
-
`:default` | Renders each link by itself with `&rsaquo
|
120
|
+
`:default` | Renders each link by itself with `›` as the seperator.
|
112
121
|
`:ol` | Renders the links in `<li>` elements contained in an outer `<ol>`.
|
113
122
|
`:ul` | Renders the links in `<li>` elements contained in an outer `<ul>`.
|
114
123
|
`:bootstrap` | Renders the links for use in [Twitter Bootstrap](http://getbootstrap.com/).
|
@@ -224,9 +233,9 @@ If you supply a block to the `breadcrumbs` method, it will yield an array with t
|
|
224
233
|
Setting breadcrumb trails
|
225
234
|
--------------------------------
|
226
235
|
|
227
|
-
You can set a breadcrumb trail via `params[:trail]`. This makes it possible to link to a different breadcrumb trail than the one specified in your breadcrumb.
|
236
|
+
You can set a breadcrumb trail via `params[:trail]`. This makes it possible to link back to a different breadcrumb trail than the one specified in your breadcrumb.
|
228
237
|
|
229
|
-
An example is if you have a store with products that have a default parent to their category, but when linking from the
|
238
|
+
An example is if you have a store with products that have a default parent to their category, but when linking from the reviews section, you want to link back to the reviews instead.
|
230
239
|
|
231
240
|
### Initial setup
|
232
241
|
|
data/lib/gretel.rb
CHANGED
data/lib/gretel/renderer.rb
CHANGED
@@ -6,7 +6,7 @@ module Gretel
|
|
6
6
|
posttext: "",
|
7
7
|
separator: "",
|
8
8
|
autoroot: true,
|
9
|
-
|
9
|
+
display_single_fragment: false,
|
10
10
|
link_current: false,
|
11
11
|
semantic: false,
|
12
12
|
class: "breadcrumbs",
|
@@ -73,9 +73,17 @@ module Gretel
|
|
73
73
|
|
74
74
|
attr_reader :context, :breadcrumb_key, :breadcrumb_args
|
75
75
|
|
76
|
+
# Returns merged options for rendering breadcrumbs.
|
76
77
|
def options_for_render(options = {})
|
77
78
|
style = options_for_style(options[:style] || DEFAULT_OPTIONS[:style])
|
78
|
-
DEFAULT_OPTIONS.merge(style).merge(options)
|
79
|
+
options = DEFAULT_OPTIONS.merge(style).merge(options)
|
80
|
+
|
81
|
+
if show_root_alone = options.delete(:show_root_alone)
|
82
|
+
Gretel.show_deprecation_warning "The :show_root_alone option is deprecated. Use `breadcrumbs(display_single_fragment: #{show_root_alone.inspect})` instead."
|
83
|
+
options[:display_single_fragment] = show_root_alone
|
84
|
+
end
|
85
|
+
|
86
|
+
options
|
79
87
|
end
|
80
88
|
|
81
89
|
# Returns options for the given +style_key+ and raises an exception if it's not found.
|
@@ -90,26 +98,29 @@ module Gretel
|
|
90
98
|
# Array of links for the path of the breadcrumb.
|
91
99
|
# Also reloads the breadcrumb configuration if needed.
|
92
100
|
def links
|
93
|
-
return [] if @breadcrumb_key.blank?
|
94
|
-
|
95
101
|
@links ||= begin
|
96
|
-
|
97
|
-
|
102
|
+
if @breadcrumb_key.present?
|
103
|
+
# Reload breadcrumbs configuration if needed
|
104
|
+
Gretel::Crumbs.reload_if_needed
|
98
105
|
|
99
|
-
|
100
|
-
|
106
|
+
# Get breadcrumb set by the `breadcrumb` method
|
107
|
+
crumb = Gretel::Crumb.new(context, breadcrumb_key, *breadcrumb_args)
|
101
108
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
109
|
+
# Links of first crumb
|
110
|
+
links = crumb.links.dup
|
111
|
+
|
112
|
+
# Set current link to actual path
|
113
|
+
if links.any? && request
|
114
|
+
links.last.url = request.fullpath
|
115
|
+
end
|
108
116
|
|
109
|
-
|
110
|
-
|
117
|
+
# Get trail
|
118
|
+
links.unshift *trail_for(crumb)
|
111
119
|
|
112
|
-
|
120
|
+
links
|
121
|
+
else
|
122
|
+
[]
|
123
|
+
end
|
113
124
|
end
|
114
125
|
end
|
115
126
|
|
@@ -138,7 +149,7 @@ module Gretel
|
|
138
149
|
end
|
139
150
|
|
140
151
|
# Handle show root alone
|
141
|
-
if out.
|
152
|
+
if out.size == 1 && !options[:display_single_fragment]
|
142
153
|
out.shift
|
143
154
|
end
|
144
155
|
|
@@ -160,12 +171,10 @@ module Gretel
|
|
160
171
|
text = content_tag(:span, text, itemprop: "title")
|
161
172
|
text = link_to(text, url, itemprop: "url") if url.present?
|
162
173
|
content_tag(fragment_tag, text, class: options[:class], itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
|
174
|
+
elsif url.present?
|
175
|
+
content_tag(:div, link_to(content_tag(:span, text, itemprop: "title"), url, class: options[:class], itemprop: "url"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
|
163
176
|
else
|
164
|
-
|
165
|
-
content_tag(:div, link_to(content_tag(:span, text, itemprop: "title"), url, class: options[:class], itemprop: "url"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
|
166
|
-
else
|
167
|
-
content_tag(:div, content_tag(:span, text, class: options[:class], itemprop: "title"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
|
168
|
-
end
|
177
|
+
content_tag(:div, content_tag(:span, text, class: options[:class], itemprop: "title"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
|
169
178
|
end
|
170
179
|
end
|
171
180
|
|
@@ -174,14 +183,12 @@ module Gretel
|
|
174
183
|
if fragment_tag
|
175
184
|
text = link_to(text, url) if url.present?
|
176
185
|
content_tag(fragment_tag, text, class: options[:class])
|
186
|
+
elsif url.present?
|
187
|
+
link_to(text, url, class: options[:class])
|
188
|
+
elsif options[:class].present?
|
189
|
+
content_tag(:span, text, class: options[:class])
|
177
190
|
else
|
178
|
-
|
179
|
-
link_to(text, url, class: options[:class])
|
180
|
-
elsif options[:class].present?
|
181
|
-
content_tag(:span, text, class: options[:class])
|
182
|
-
else
|
183
|
-
text
|
184
|
-
end
|
191
|
+
text
|
185
192
|
end
|
186
193
|
end
|
187
194
|
|
data/lib/gretel/trail.rb
CHANGED
@@ -8,24 +8,20 @@ module Gretel
|
|
8
8
|
|
9
9
|
# Securely encodes array of links to a trail string to be used in URL.
|
10
10
|
def encode(links)
|
11
|
-
ensure_secret!
|
12
|
-
|
13
11
|
base64 = encode_base64(links)
|
14
|
-
hash = base64
|
12
|
+
hash = generate_hash(base64)
|
15
13
|
|
16
14
|
[hash, base64].join("_")
|
17
15
|
end
|
18
16
|
|
19
17
|
# Securely decodes a URL trail string to array of links.
|
20
18
|
def decode(trail)
|
21
|
-
ensure_secret!
|
22
|
-
|
23
19
|
hash, base64 = trail.split("_", 2)
|
24
20
|
|
25
21
|
if base64.blank?
|
26
22
|
Rails.logger.info "[Gretel] Trail decode failed: No Base64 in trail"
|
27
23
|
[]
|
28
|
-
elsif hash == base64
|
24
|
+
elsif hash == generate_hash(base64)
|
29
25
|
decode_base64(base64)
|
30
26
|
else
|
31
27
|
Rails.logger.info "[Gretel] Trail decode failed: Invalid hash '#{hash}' in trail"
|
@@ -49,7 +45,7 @@ module Gretel
|
|
49
45
|
|
50
46
|
# Encodes links array to Base64, internally using JSON for serialization.
|
51
47
|
def encode_base64(links)
|
52
|
-
arr = links.map { |link| [link.key, link.text, link.url] }
|
48
|
+
arr = links.map { |link| [link.key, link.text, (link.text.html_safe? ? 1 : 0), link.url] }
|
53
49
|
Base64.urlsafe_encode64(arr.to_json)
|
54
50
|
end
|
55
51
|
|
@@ -57,17 +53,17 @@ module Gretel
|
|
57
53
|
def decode_base64(base64)
|
58
54
|
json = Base64.urlsafe_decode64(base64)
|
59
55
|
arr = JSON.parse(json)
|
60
|
-
arr.map { |key, text, url| Link.new(key, text, url) }
|
56
|
+
arr.map { |key, text, html_safe, url| Link.new(key.to_sym, (html_safe == 1 ? text.html_safe : text), url) }
|
61
57
|
rescue
|
62
58
|
Rails.logger.info "[Gretel] Trail decode failed: Invalid Base64 '#{base64}' in trail"
|
63
59
|
[]
|
64
60
|
end
|
65
61
|
|
66
|
-
#
|
67
|
-
def
|
62
|
+
# Generates a salted hash of +base64+.
|
63
|
+
def generate_hash(base64)
|
68
64
|
raise "Gretel::Trail.secret is not set. Please set it to an unguessable string, e.g. from `rake secret`, or use `rails generate gretel:install` to generate and set it automatically." if secret.blank?
|
65
|
+
Digest::SHA1.hexdigest([base64, secret].join)
|
69
66
|
end
|
70
|
-
|
71
67
|
end
|
72
68
|
end
|
73
69
|
end
|
data/lib/gretel/version.rb
CHANGED
data/lib/gretel/view_helpers.rb
CHANGED
@@ -4,7 +4,10 @@ module Gretel
|
|
4
4
|
# <%
|
5
5
|
# breadcrumb :category, @category
|
6
6
|
# %>
|
7
|
-
def breadcrumb(key, *args)
|
7
|
+
def breadcrumb(key = nil, *args)
|
8
|
+
if key.nil? || key.is_a?(Hash)
|
9
|
+
raise ArgumentError, "The `breadcrumb` method was called with #{key.inspect} as the key. This method is used to set the breadcrumb. Maybe you meant to call the `breadcrumbs` method (with an 's' in the end) which is used to render the breadcrumbs?"
|
10
|
+
end
|
8
11
|
@_gretel_renderer = Gretel::Renderer.new(self, key, *args)
|
9
12
|
end
|
10
13
|
|
@@ -28,12 +31,14 @@ module Gretel
|
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
34
|
+
# Encoded breadcrumb trail to be used in URLs.
|
31
35
|
def breadcrumb_trail
|
32
36
|
gretel_renderer.trail
|
33
37
|
end
|
34
38
|
|
35
39
|
private
|
36
40
|
|
41
|
+
# Reference to the Gretel breadcrumbs renderer.
|
37
42
|
def gretel_renderer
|
38
43
|
@_gretel_renderer ||= Gretel::Renderer.new(self, nil)
|
39
44
|
end
|
data/test/deprecated_test.rb
CHANGED
@@ -7,6 +7,13 @@ class DeprecatedTest < ActionView::TestCase
|
|
7
7
|
|
8
8
|
setup do
|
9
9
|
Gretel.reset!
|
10
|
+
Gretel.suppress_deprecation_warnings = true
|
11
|
+
end
|
12
|
+
|
13
|
+
test "show root alone" do
|
14
|
+
breadcrumb :root
|
15
|
+
assert_equal %{<div class="breadcrumbs"><span class="current">Home</span></div>},
|
16
|
+
breadcrumbs(show_root_alone: true)
|
10
17
|
end
|
11
18
|
|
12
19
|
test "deprecated configuration block" do
|
data/test/helper_methods_test.rb
CHANGED
@@ -65,10 +65,16 @@ class HelperMethodsTest < ActionView::TestCase
|
|
65
65
|
assert_equal "", breadcrumbs
|
66
66
|
end
|
67
67
|
|
68
|
-
test "
|
68
|
+
test "displays single fragment" do
|
69
69
|
breadcrumb :root
|
70
70
|
assert_equal %{<div class="breadcrumbs"><span class="current">Home</span></div>},
|
71
|
-
breadcrumbs(
|
71
|
+
breadcrumbs(display_single_fragment: true)
|
72
|
+
end
|
73
|
+
|
74
|
+
test "displays single non-root fragment" do
|
75
|
+
breadcrumb :basic
|
76
|
+
assert_equal %{<div class="breadcrumbs"><span class="current">About</span></div>},
|
77
|
+
breadcrumbs(autoroot: false, display_single_fragment: true)
|
72
78
|
end
|
73
79
|
|
74
80
|
test "shows no breadcrumb" do
|
@@ -95,8 +101,7 @@ class HelperMethodsTest < ActionView::TestCase
|
|
95
101
|
|
96
102
|
test "autoroot disabled" do
|
97
103
|
breadcrumb :basic
|
98
|
-
assert_equal
|
99
|
-
breadcrumbs(autoroot: false)
|
104
|
+
assert_equal "", breadcrumbs(autoroot: false)
|
100
105
|
end
|
101
106
|
|
102
107
|
test "shows separator" do
|
@@ -174,6 +179,34 @@ class HelperMethodsTest < ActionView::TestCase
|
|
174
179
|
end
|
175
180
|
end
|
176
181
|
|
182
|
+
test "breadcrumb not found" do
|
183
|
+
assert_raises ArgumentError do
|
184
|
+
breadcrumb :nonexistent
|
185
|
+
breadcrumbs
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
test "current link url is set to fullpath" do
|
190
|
+
self.request = OpenStruct.new(fullpath: "/testpath?a=1&b=2")
|
191
|
+
|
192
|
+
breadcrumb :basic
|
193
|
+
assert_equal "/testpath?a=1&b=2", breadcrumbs { |links| links.last.url }
|
194
|
+
end
|
195
|
+
|
196
|
+
test "calling the breadcrumb method with wrong arguments" do
|
197
|
+
assert_nothing_raised do
|
198
|
+
breadcrumb :basic, test: 1
|
199
|
+
end
|
200
|
+
|
201
|
+
assert_raises ArgumentError do
|
202
|
+
breadcrumb
|
203
|
+
end
|
204
|
+
|
205
|
+
assert_raises ArgumentError do
|
206
|
+
breadcrumb(pretext: "bla")
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
177
210
|
# Styles
|
178
211
|
|
179
212
|
test "default style" do
|
@@ -224,11 +257,11 @@ class HelperMethodsTest < ActionView::TestCase
|
|
224
257
|
test "trail helper" do
|
225
258
|
breadcrumb :basic
|
226
259
|
|
227
|
-
assert_equal "
|
260
|
+
assert_equal "667ea523f92bdb3a086494575b18f587170e482b_W1siYmFzaWMiLCJBYm91dCIsMCwiL2Fib3V0Il1d", breadcrumb_trail
|
228
261
|
end
|
229
262
|
|
230
263
|
test "loading trail" do
|
231
|
-
params[:trail] = "
|
264
|
+
params[:trail] = "667ea523f92bdb3a086494575b18f587170e482b_W1siYmFzaWMiLCJBYm91dCIsMCwiL2Fib3V0Il1d"
|
232
265
|
breadcrumb :multiple_links
|
233
266
|
|
234
267
|
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <a href="/about">About</a> › <a href="/about/contact">Contact</a> › <span class="current">Contact form</span></div>},
|
@@ -237,7 +270,7 @@ class HelperMethodsTest < ActionView::TestCase
|
|
237
270
|
|
238
271
|
test "different trail param" do
|
239
272
|
Gretel::Trail.trail_param = :mytest
|
240
|
-
params[:mytest] = "
|
273
|
+
params[:mytest] = "667ea523f92bdb3a086494575b18f587170e482b_W1siYmFzaWMiLCJBYm91dCIsMCwiL2Fib3V0Il1d"
|
241
274
|
breadcrumb :multiple_links
|
242
275
|
|
243
276
|
assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <a href="/about">About</a> › <a href="/about/contact">Contact</a> › <span class="current">Contact form</span></div>},
|
data/test/trail_test.rb
CHANGED
@@ -4,9 +4,9 @@ class TrailTest < ActiveSupport::TestCase
|
|
4
4
|
setup do
|
5
5
|
Gretel::Trail.secret = "128107d341e912db791d98bbe874a8250f784b0a0b4dbc5d5032c0fc1ca7bda9c6ece667bd18d23736ee833ea79384176faeb54d2e0d21012898dde78631cdf1"
|
6
6
|
@links = [
|
7
|
-
[
|
8
|
-
[
|
9
|
-
[
|
7
|
+
[:root, "Home", "/"],
|
8
|
+
[:store, "Store <b>Test</b>".html_safe, "/store"],
|
9
|
+
[:search, "Search", "/store/search?q=test"]
|
10
10
|
]
|
11
11
|
end
|
12
12
|
|
@@ -15,16 +15,17 @@ class TrailTest < ActiveSupport::TestCase
|
|
15
15
|
end
|
16
16
|
|
17
17
|
test "encoding" do
|
18
|
-
assert_equal "
|
18
|
+
assert_equal "5543214e6d7bbc3ba5209b2362cd7513d500f61b_W1sicm9vdCIsIkhvbWUiLDAsIi8iXSxbInN0b3JlIiwiU3RvcmUgPGI-VGVzdDwvYj4iLDEsIi9zdG9yZSJdLFsic2VhcmNoIiwiU2VhcmNoIiwwLCIvc3RvcmUvc2VhcmNoP3E9dGVzdCJdXQ==",
|
19
19
|
Gretel::Trail.encode(@links.map { |key, text, url| Gretel::Link.new(key, text, url) })
|
20
20
|
end
|
21
21
|
|
22
22
|
test "decoding" do
|
23
|
-
|
24
|
-
|
23
|
+
decoded = Gretel::Trail.decode("5543214e6d7bbc3ba5209b2362cd7513d500f61b_W1sicm9vdCIsIkhvbWUiLDAsIi8iXSxbInN0b3JlIiwiU3RvcmUgPGI-VGVzdDwvYj4iLDEsIi9zdG9yZSJdLFsic2VhcmNoIiwiU2VhcmNoIiwwLCIvc3RvcmUvc2VhcmNoP3E9dGVzdCJdXQ==")
|
24
|
+
assert_equal @links, decoded.map { |link| [link.key, link.text, link.url] }
|
25
|
+
assert_equal [false, true, false], decoded.map { |link| link.text.html_safe? }
|
25
26
|
end
|
26
27
|
|
27
28
|
test "invalid trail" do
|
28
|
-
assert_equal [], Gretel::Trail.decode("
|
29
|
+
assert_equal [], Gretel::Trail.decode("28f104524f5eaf6b3bd035710432fd2b9cbfd62c_X1sicm9vdCIsIkhvbWUiLDAsIi8iXSxbInN0b3JlIiwiU3RvcmUiLDAsIi9zdG9yZSJdLFsic2VhcmNoIiwiU2VhcmNoIiwwLCIvc3RvcmUvc2VhcmNoP3E9dGVzdCJdXQ==")
|
29
30
|
end
|
30
31
|
end
|