gretel 3.0.0.beta1 → 3.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b08f97b7c16a830427f2ccf1968732cfec834b6
4
- data.tar.gz: 2cbf78c43a72b8cb525a2485287c09c123672913
3
+ metadata.gz: db6f1e42bb6b92c94ae0ea17349b87d352fda758
4
+ data.tar.gz: 0b5532349fe0a6829bfd2e7d4c52aad04f7232a1
5
5
  SHA512:
6
- metadata.gz: cbd0cf33abb351a39e3fa7dcb723cce2ee75e8f3c219406ceb28bcecdd693f0adeb77ab4f92553d261545a38cde87c6bd801a059eb9702cd16bdf85a99c4bafc
7
- data.tar.gz: 5c2af9e0cd84b039965fb1389f234dd778cd994e7c056f385cd274c6384e4203c275d3572220dd6b221e9fd0a9350a4bdb4e81fcb395222b386193afdb911599
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 2.2
10
+ New in version 3.0
11
11
  ------------------
12
12
 
13
- Gretel now supports 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,
14
- 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.
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
- See below for more info or the [changelog](https://github.com/lassebunk/gretel/blob/master/CHANGELOG.md) for more changes.
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 | Description | Default
92
- ---------------- | -------------------------------------------------------------------------------------------------------------------------- | -------
93
- :style | How to render the breadcrumbs. Can be `:default`, `:ol`, `:ul`, or `:bootstrap`. See below for more info. | `:default`
94
- :pretext | Text to be rendered before breadcrumb, e.g. `"You are here: "`. | None
95
- :posttext | Text to be appended after breadcrumb, e.g. `"Text after breacrumb"`, | None
96
- :separator | Separator between links, e.g. `" &rsaquo; "`. | `" &rsaquo; "`
97
- :autoroot | Whether it should automatically link to the `:root` crumb if no parent is given. | True
98
- :show_root_alone | Whether it should show `:root` if that is the only link. | False
99
- :link_current | Whether the current crumb should be linked to. | False
100
- :semantic | Whether it should generate [semantic breadcrumbs](http://support.google.com/webmasters/bin/answer.py?hl=en&answer=185417). | False
101
- :id | ID for the breadcrumbs container. | None
102
- :class | CSS class for the breadcrumbs container. | `"breadcrumbs"`
103
- :current_class | CSS class for the current link or span. | `"current"`
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. `" &rsaquo; "`. | `" &rsaquo; "`
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` as the seperator.
120
+ `:default` | Renders each link by itself with `&rsaquo;` 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 review section, you want to link back to the reviews instead.
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
@@ -32,6 +32,7 @@ module Gretel
32
32
  # Shows a deprecation warning.
33
33
  def show_deprecation_warning(message)
34
34
  return if suppress_deprecation_warnings?
35
+ message = "[Gretel] #{message}"
35
36
  puts message
36
37
  Rails.logger.warn message
37
38
  end
@@ -6,7 +6,7 @@ module Gretel
6
6
  posttext: "",
7
7
  separator: "",
8
8
  autoroot: true,
9
- show_root_alone: false,
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
- # Reload breadcrumbs configuration if needed
97
- Gretel::Crumbs.reload_if_needed
102
+ if @breadcrumb_key.present?
103
+ # Reload breadcrumbs configuration if needed
104
+ Gretel::Crumbs.reload_if_needed
98
105
 
99
- # Get breadcrumb set by the `breadcrumb` method
100
- crumb = Gretel::Crumb.new(self, breadcrumb_key, *breadcrumb_args)
106
+ # Get breadcrumb set by the `breadcrumb` method
107
+ crumb = Gretel::Crumb.new(context, breadcrumb_key, *breadcrumb_args)
101
108
 
102
- # Links of first crumb
103
- links = crumb.links.dup
104
-
105
- links.last.tap do |last|
106
- last.url = request.try(:fullpath) || last.url
107
- end
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
- # Get trail
110
- links.unshift *trail_for(crumb)
117
+ # Get trail
118
+ links.unshift *trail_for(crumb)
111
119
 
112
- links
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.count == 1 && out.first.key == :root && !options[:show_root_alone]
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
- if url.present?
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
- if url.present?
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.crypt(secret)
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.crypt(secret)
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
- # Ensures that a secret has been set, and raises an exception if this is not the case.
67
- def ensure_secret!
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
@@ -1,3 +1,3 @@
1
1
  module Gretel
2
- VERSION = "3.0.0.beta1"
2
+ VERSION = "3.0.0.beta2"
3
3
  end
@@ -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
@@ -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
@@ -65,10 +65,16 @@ class HelperMethodsTest < ActionView::TestCase
65
65
  assert_equal "", breadcrumbs
66
66
  end
67
67
 
68
- test "shows root alone" do
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(show_root_alone: true)
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 %{<div class="breadcrumbs"><span class="current">About</span></div>},
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 "12MoG3DY5eLzU_W1siYmFzaWMiLCJBYm91dCIsIi9hYm91dCJdXQ==", breadcrumb_trail
260
+ assert_equal "667ea523f92bdb3a086494575b18f587170e482b_W1siYmFzaWMiLCJBYm91dCIsMCwiL2Fib3V0Il1d", breadcrumb_trail
228
261
  end
229
262
 
230
263
  test "loading trail" do
231
- params[:trail] = "12MoG3DY5eLzU_W1siYmFzaWMiLCJBYm91dCIsIi9hYm91dCJdXQ=="
264
+ params[:trail] = "667ea523f92bdb3a086494575b18f587170e482b_W1siYmFzaWMiLCJBYm91dCIsMCwiL2Fib3V0Il1d"
232
265
  breadcrumb :multiple_links
233
266
 
234
267
  assert_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>},
@@ -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] = "12MoG3DY5eLzU_W1siYmFzaWMiLCJBYm91dCIsIi9hYm91dCJdXQ=="
273
+ params[:mytest] = "667ea523f92bdb3a086494575b18f587170e482b_W1siYmFzaWMiLCJBYm91dCIsMCwiL2Fib3V0Il1d"
241
274
  breadcrumb :multiple_links
242
275
 
243
276
  assert_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>},
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
- ["root", "Home", "/"],
8
- ["store", "Store", "/store"],
9
- ["search", "Search", "/store/search?q=test"]
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 "122.5Th13fvkg_W1sicm9vdCIsIkhvbWUiLCIvIl0sWyJzdG9yZSIsIlN0b3JlIiwiL3N0b3JlIl0sWyJzZWFyY2giLCJTZWFyY2giLCIvc3RvcmUvc2VhcmNoP3E9dGVzdCJdXQ==",
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
- assert_equal @links,
24
- Gretel::Trail.decode("122.5Th13fvkg_W1sicm9vdCIsIkhvbWUiLCIvIl0sWyJzdG9yZSIsIlN0b3JlIiwiL3N0b3JlIl0sWyJzZWFyY2giLCJTZWFyY2giLCIvc3RvcmUvc2VhcmNoP3E9dGVzdCJdXQ==").map { |link| [link.key, link.text, link.url] }
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("122.5Th13fvkg_X1sicm9vdCIsIkhvbWUiLCIvIl0sWyJzdG9yZSIsIlN0b3JlIiwiL3N0b3JlIl0sWyJzZWFyY2giLCJTZWFyY2giLCIvc3RvcmUvc2VhcmNoP3E9dGVzdCJdXQ==")
29
+ assert_equal [], Gretel::Trail.decode("28f104524f5eaf6b3bd035710432fd2b9cbfd62c_X1sicm9vdCIsIkhvbWUiLDAsIi8iXSxbInN0b3JlIiwiU3RvcmUiLDAsIi9zdG9yZSJdLFsic2VhcmNoIiwiU2VhcmNoIiwwLCIvc3RvcmUvc2VhcmNoP3E9dGVzdCJdXQ==")
29
30
  end
30
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gretel
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta1
4
+ version: 3.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lasse Bunk