padrino-helpers 0.12.2 → 0.12.3

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: febadf7b3fad75194b40771bb1d5c414303b6786
4
- data.tar.gz: 3e5d9099e89fa2d58a149b09c54f993ff7a14c53
3
+ metadata.gz: efe48decfbfb7a521da3666e93d1c6b94834de2a
4
+ data.tar.gz: ba1024635b475297a8367408c506e1e7e3850a94
5
5
  SHA512:
6
- metadata.gz: 56a145692e0257c6c8d938da7218807ee0ea528c8ff2b3b29ededf270faabed6a30bbd8e690d1326ce9f9745203634948ae756fbff06ce11c1c9a5304051cea4
7
- data.tar.gz: 7650154ec4c435655aa9e2414b71c00f9aaec7516c8d875855689b51e9f55c274b6d3080ad4f8174c4ecf85731dbe2143239209d488e09f0e68aec79db39f792
6
+ metadata.gz: 9db32bf5d81c31e7c8305e5039308adff035ab8514d05a13934c4122107e643e017b400bcc958bc27d90fe434296fc42e15634dc247324a5ac7e1767a5215654
7
+ data.tar.gz: d728280dfec2211d4b78affa33d4a456477902126545fbb0c33065a624c1054f1d55a4f7e0200378d3cd12ab78b0133657e00f11b8a35500eda6e032f4a463c2
@@ -31,7 +31,6 @@ module Padrino
31
31
  # Padrino::Helpers::FormatHelpers
32
32
  # Padrino::Helpers::RenderHelpers
33
33
  # Padrino::Helpers::NumberHelpers
34
- # Padrino::Helpers::Breadcrumbs
35
34
  #
36
35
  # @param [Sinatra::Application] app
37
36
  # The specified Padrino application.
@@ -57,7 +56,6 @@ module Padrino
57
56
  base.send :include, Padrino::Helpers::RenderHelpers
58
57
  base.send :include, Padrino::Helpers::NumberHelpers
59
58
  base.send :include, Padrino::Helpers::TranslationHelpers
60
- base.send :include, Padrino::Helpers::Breadcrumbs
61
59
  end
62
60
  end
63
61
  end
@@ -135,7 +135,7 @@ module Padrino
135
135
  nested_options = { :parent => self, :association => child_association }
136
136
  Array(collection).each_with_index.inject(ActiveSupport::SafeBuffer.new) do |all,(child_instance,index)|
137
137
  nested_options[:index] = options[:index] || (include_index ? index : nil)
138
- all << @template.fields_for(child_instance, { :nested => nested_options }, &block) << "\n"
138
+ all << @template.fields_for(child_instance, { :nested => nested_options, :builder => self.class }, &block) << "\n"
139
139
  end
140
140
  end
141
141
 
@@ -397,7 +397,7 @@ module Padrino
397
397
  # text_area_tag :username, :class => 'long', :value => "Demo?"
398
398
  #
399
399
  def text_area_tag(name, options={})
400
- inner_html = options.delete(:value).to_s
400
+ inner_html = "\n#{options.delete(:value)}"
401
401
  options = { :name => name, :rows => "", :cols => "" }.update(options)
402
402
  content_tag(:textarea, inner_html, options)
403
403
  end
@@ -582,7 +582,8 @@ module Padrino
582
582
  options = args.extract_options!.dup
583
583
  name, url = *args
584
584
  options['data-remote'] = 'true' if options.delete(:remote)
585
- block ||= proc { submit_tag(name, options.delete(:submit_options) || {}) }
585
+ submit_options = options.delete(:submit_options) || {}
586
+ block ||= proc { submit_tag(name, submit_options) }
586
587
  form_tag(url || name, options, &block)
587
588
  end
588
589
 
@@ -98,6 +98,6 @@ zh_tw:
98
98
  errors:
99
99
  template:
100
100
  header:
101
- one: " 1 個錯誤發生使得「%{model}」無法被儲存。"
102
- other: " %{count} 個錯誤發生使得「%{model}」無法被儲存。"
101
+ one: "發生了 1 個錯誤使得「%{model}」無法被儲存。"
102
+ other: "發生了 %{count} 個錯誤使得「%{model}」無法被儲存。"
103
103
  body: "以下欄位發生問題:"
@@ -158,7 +158,7 @@ module Padrino
158
158
  # content_for? :header => true
159
159
  #
160
160
  def content_for?(key)
161
- content_blocks[key.to_sym].present?
161
+ !content_blocks[key.to_sym].empty?
162
162
  end
163
163
 
164
164
  ##
@@ -12,13 +12,13 @@ module Padrino
12
12
  "<" => "&lt;",
13
13
  ">" => "&gt;",
14
14
  '"' => "&quot;"
15
- }
15
+ }.freeze
16
16
 
17
17
  ##
18
18
  # Cached Regexp for escaping values to avoid rebuilding one
19
19
  # on every escape operation.
20
20
  #
21
- ESCAPE_REGEXP = Regexp.union(*ESCAPE_VALUES.keys)
21
+ ESCAPE_REGEXP = Regexp.union(*ESCAPE_VALUES.keys).freeze
22
22
 
23
23
  BOOLEAN_ATTRIBUTES = [
24
24
  :autoplay,
@@ -39,7 +39,7 @@ module Padrino
39
39
  :itemscope,
40
40
  :noresize,
41
41
  :novalidate
42
- ]
42
+ ].freeze
43
43
 
44
44
  ##
45
45
  # Custom data attributes,
@@ -53,7 +53,7 @@ module Padrino
53
53
  :method,
54
54
  :remote,
55
55
  :confirm
56
- ]
56
+ ].freeze
57
57
 
58
58
  ##
59
59
  # A html_safe newline string to avoid allocating a new on each
@@ -200,7 +200,7 @@ module Padrino
200
200
  # # => <input type="number" autocomplete="off" />
201
201
  #
202
202
  def input_tag(type, options = {})
203
- tag(:input, options.reverse_merge!(:type => type))
203
+ tag(:input, { :type => type }.update(options))
204
204
  end
205
205
 
206
206
  ##
@@ -230,7 +230,7 @@ module Padrino
230
230
  # # => <img src="sinatra.jpg" data-nsfw="false" data-geo="34.087 -118.407" />
231
231
  #
232
232
  def tag(name, options = nil, open = false)
233
- options = parse_data_options(name, options)
233
+ options = parse_data_options(name, options)
234
234
  attributes = tag_attributes(options)
235
235
  "<#{name}#{attributes}#{open ? '>' : ' />'}".html_safe
236
236
  end
@@ -241,50 +241,51 @@ module Padrino
241
241
  # Returns a compiled list of HTML attributes.
242
242
  #
243
243
  def tag_attributes(options)
244
- return '' if options.nil?
245
- attributes = options.map do |k, v|
246
- next if v.nil? || v == false
247
- if v.is_a?(Hash)
248
- nested_values(k, v)
249
- elsif BOOLEAN_ATTRIBUTES.include?(k)
250
- %(#{k}="#{k}")
244
+ return '' unless options
245
+ options.inject('') do |all,(key,value)|
246
+ next all unless value
247
+ all << ' ' if all.empty?
248
+ all << if value.is_a?(Hash)
249
+ nested_values(key, value)
250
+ elsif BOOLEAN_ATTRIBUTES.include?(key)
251
+ %(#{key}="#{key}" )
251
252
  else
252
- %(#{k}="#{escape_value(v)}")
253
+ %(#{key}="#{escape_value(value)}" )
253
254
  end
254
- end.compact
255
- attributes.empty? ? '' : " #{attributes * ' '}"
255
+ end.chomp!(' ')
256
256
  end
257
257
 
258
258
  ##
259
259
  # Escape tag values to their HTML/XML entities.
260
260
  #
261
261
  def escape_value(string)
262
- string.to_s.gsub(ESCAPE_REGEXP) { |c| ESCAPE_VALUES[c] }
262
+ string.to_s.gsub(ESCAPE_REGEXP) { |char| ESCAPE_VALUES[char] }
263
263
  end
264
264
 
265
265
  ##
266
266
  # Iterate through nested values.
267
267
  #
268
268
  def nested_values(attribute, hash)
269
- hash.map do |k, v|
270
- if v.is_a?(Hash)
271
- nested_values("#{attribute}-#{k.to_s.dasherize}", v)
269
+ hash.inject('') do |all,(key,value)|
270
+ attribute_with_name = "#{attribute}-#{key.to_s.dasherize}"
271
+ all << if value.is_a?(Hash)
272
+ nested_values(attribute_with_name, value)
272
273
  else
273
- %(#{attribute}-#{k.to_s.dasherize}="#{escape_value(v)}")
274
+ %(#{attribute_with_name}="#{escape_value(value)}" )
274
275
  end
275
- end * ' '
276
+ end
276
277
  end
277
278
 
278
279
  ##
279
280
  # Parses custom data attributes.
280
281
  #
281
282
  def parse_data_options(tag, options)
282
- return if options.nil?
283
+ return unless options
283
284
  parsed_options = options.dup
284
- options.each do |k, v|
285
- next if !DATA_ATTRIBUTES.include?(k) || (tag.to_s == 'form' && k == :method)
286
- parsed_options["data-#{k}"] = parsed_options.delete(k)
287
- parsed_options[:rel] = 'nofollow' if k == :method
285
+ options.each do |key, value|
286
+ next if !DATA_ATTRIBUTES.include?(key) || (tag.to_s == 'form' && key == :method)
287
+ parsed_options["data-#{key}"] = parsed_options.delete(key)
288
+ parsed_options[:rel] = 'nofollow' if key == :method
288
289
  end
289
290
  parsed_options
290
291
  end
@@ -221,6 +221,8 @@ module Padrino
221
221
  # This means that no engine was explicitly defined
222
222
  data, engine = resolve_template(engine, options) if data.nil?
223
223
 
224
+ options[:layout] ||= false unless Rendering.engine_configurations.has_key?(engine)
225
+
224
226
  # Cleanup the template.
225
227
  @current_engine, engine_was = engine, @current_engine
226
228
  @_out_buf, buf_was = ActiveSupport::SafeBuffer.new, @_out_buf
@@ -68,7 +68,7 @@ class MiniTest::Spec
68
68
  path = "/views/#{name}"
69
69
  path += ".#{options.delete(:locale)}" if options[:locale].present?
70
70
  path += ".#{options[:format]}" if options[:format].present?
71
- path += ".erb" unless options[:format].to_s =~ /erb|slim|haml|rss|atom/
71
+ path += ".erb" unless options[:format].to_s =~ /erb|slim|haml|rss|atom|builder/
72
72
  path += ".builder" if options[:format].to_s =~ /rss|atom/
73
73
  file = File.dirname(__FILE__) + path
74
74
  File.open(file, 'w') { |io| io.write content }
@@ -167,6 +167,16 @@ describe "FormBuilder" do
167
167
  assert_raises(RuntimeError) { fields_for(@not_real) { |f| "Demo" } }
168
168
  end
169
169
 
170
+ it 'should respect the builder of parent' do
171
+ assert_raises(NoMethodError) do
172
+ form_for(@user, '/register', builder: "AbstractFormBuilder") do |f|
173
+ f.fields_for(:role_types, @user.role_types) do |field|
174
+ field.submit_block "Submit"
175
+ end
176
+ end
177
+ end
178
+ end
179
+
170
180
  it 'should display correct simple fields in haml' do
171
181
  visit '/haml/fields_for'
172
182
  assert_have_selector :form, :action => '/demo1', :id => 'demo-fields-for'
@@ -498,6 +498,12 @@ describe "FormHelpers" do
498
498
  assert_has_tag(:textarea, :content => "a test", :name => 'about', :rows => "5", :cols => "6") { actual_html }
499
499
  end
500
500
 
501
+ it 'should insert newline to before of content' do
502
+ actual_html = text_area_tag(:about, :value => "\na test")
503
+ assert_has_tag(:textarea, :content => "\na test", :name => 'about') { actual_html }
504
+ assert_match(%r{<textarea[^>]*>\n\na test</textarea>}, actual_html)
505
+ end
506
+
501
507
  it 'should display text area in erb' do
502
508
  visit '/erb/form_tag'
503
509
  assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
@@ -990,6 +996,7 @@ describe "FormHelpers" do
990
996
  it 'should pass options on submit button when submit_options are given' do
991
997
  actual_html = button_to("Fancy button", '/users/1', :submit_options => { :class => :fancy })
992
998
  assert_has_tag('form input', :type => 'submit', :value => 'Fancy button', :class => 'fancy') { actual_html }
999
+ assert_has_no_tag('form', :"submit_options-class" => 'fancy'){ actual_html }
993
1000
  end
994
1001
 
995
1002
  it 'should display correct button_to in erb' do
@@ -246,6 +246,17 @@ describe "Rendering" do
246
246
  assert_equal "application layout for erb", body.chomp
247
247
  end
248
248
 
249
+ it 'should not apply default layout to unsupported layout engines' do
250
+ create_layout :application, "erb template <%= yield %>", :format => :erb
251
+ create_view 'foo', "xml.instruct!", :format => :builder
252
+ mock_app do
253
+ get('/layout_test.xml' ){ render :foo }
254
+ end
255
+ get "/layout_test.xml"
256
+ refute_match /erb template/, body
257
+ assert_match '<?xml', body
258
+ end
259
+
249
260
  describe 'for application render functionality' do
250
261
 
251
262
  it 'should work properly with logging and missing layout' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-05-12 00:00:00.000000000 Z
14
+ date: 2014-08-13 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: padrino-support
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.12.2
22
+ version: 0.12.3
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.12.2
29
+ version: 0.12.3
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: tilt
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -77,7 +77,6 @@ files:
77
77
  - Rakefile
78
78
  - lib/padrino-helpers.rb
79
79
  - lib/padrino-helpers/asset_tag_helpers.rb
80
- - lib/padrino-helpers/breadcrumb_helpers.rb
81
80
  - lib/padrino-helpers/form_builder/abstract_form_builder.rb
82
81
  - lib/padrino-helpers/form_builder/deprecated_builder_methods.rb
83
82
  - lib/padrino-helpers/form_builder/standard_form_builder.rb
@@ -202,7 +201,6 @@ files:
202
201
  - test/fixtures/render_app/views/wrong_capture_slim.slim
203
202
  - test/helper.rb
204
203
  - test/test_asset_tag_helpers.rb
205
- - test/test_breadcrumb_helpers.rb
206
204
  - test/test_form_builder.rb
207
205
  - test/test_form_helpers.rb
208
206
  - test/test_format_helpers.rb
@@ -321,7 +319,6 @@ test_files:
321
319
  - test/fixtures/render_app/views/wrong_capture_slim.slim
322
320
  - test/helper.rb
323
321
  - test/test_asset_tag_helpers.rb
324
- - test/test_breadcrumb_helpers.rb
325
322
  - test/test_form_builder.rb
326
323
  - test/test_form_helpers.rb
327
324
  - test/test_format_helpers.rb
@@ -1,183 +0,0 @@
1
- module Padrino
2
- module Helpers
3
- class Breadcrumb
4
- attr_accessor :home, :items
5
-
6
- DEFAULT_URL = "/"
7
- DEFAULT_CAPTION ="Home Page"
8
-
9
- ##
10
- # Initialize breadcrumbs with default value.
11
- #
12
- # @example
13
- # before do
14
- # @breadcrumbs = breadcrumbs.new
15
- # end
16
- #
17
- def initialize
18
- reset!
19
- end
20
-
21
- ##
22
- # Set the custom home (Parent) link.
23
- #
24
- # @param [String] url
25
- # The url href.
26
- #
27
- # @param [String] caption
28
- # The text caption.
29
- #
30
- # @param [Hash] options
31
- # The HTML options to include in li.
32
- #
33
- # @example
34
- # breadcrumbs.set_home "/HomeFoo", "Foo Home", :id => "home-breadcrumb"
35
- #
36
- def set_home(url, caption, options = {})
37
- self.home = {
38
- :url => url.to_s,
39
- :caption => caption.to_s.humanize.html_safe,
40
- :name => :home,
41
- :options => options
42
- }
43
- reset
44
- end
45
-
46
- ##
47
- # Reset breadcrumbs to default or personal home.
48
- #
49
- # @example
50
- # breadcrumbs.reset
51
- #
52
- def reset
53
- self.items = []
54
- self.items << home
55
- end
56
-
57
- ##
58
- # Reset breadcrumbs to default home.
59
- #
60
- # @example
61
- # breadcrumbs.reset!
62
- #
63
- def reset!
64
- self.home = {
65
- :name => :home,
66
- :url => DEFAULT_URL,
67
- :caption => DEFAULT_CAPTION,
68
- :options => {}
69
- }
70
- reset
71
- end
72
-
73
- ##
74
- # Add a new breadcrumbs.
75
- #
76
- # @param [String] name
77
- # The name of resource.
78
- # @param [Symbol] name
79
- # The name of resource.
80
- #
81
- # @param [String] url
82
- # The url href.
83
- #
84
- # @param [String] caption
85
- # The text caption.
86
- #
87
- # @param [Hash] options
88
- # The HTML options to include in li.
89
- #
90
- # @example
91
- # breadcrumbs.add "foo", "/foo", "Foo Link", :id => "foo-id"
92
- # breadcrumbs.add :foo, "/foo", "Foo Link", :class => "foo-class"
93
- #
94
- def add(name, url, caption, options = {})
95
- items << {
96
- :name => name.to_sym,
97
- :url => url.to_s,
98
- :caption => caption.to_s.humanize.html_safe,
99
- :options => options
100
- }
101
- end
102
- alias :<< :add
103
-
104
- ##
105
- # Remove a breadcrumb.
106
- #
107
- # @param [String] name
108
- # The name of resource to delete from breadcrumbs list.
109
- #
110
- # @example
111
- # breadcrumbs.del "foo"
112
- # breadcrumbs.del :foo
113
- #
114
- def del(name)
115
- items.delete_if { |item| item[:name] == name.to_sym }
116
- end
117
- end
118
-
119
- module Breadcrumbs
120
- ##
121
- # Render breadcrumbs to view.
122
- #
123
- # @param [Breadcrumbs] breadcrumbs
124
- # The breadcrumbs to render into view.
125
- #
126
- # @param [Boolean] bootstrap
127
- # If true, render separation (useful with Twitter Bootstrap).
128
- #
129
- # @param [String] active
130
- # CSS class style set to active breadcrumb.
131
- #
132
- # @param [Hash] options
133
- # The HTML options to include in ul.
134
- #
135
- # @return [String] Unordered list with breadcrumbs
136
- #
137
- # @example
138
- # = breadcrumbs @breacrumbs
139
- # # Generates:
140
- # # <ul>
141
- # # <li><a href="/foo">Foo Link</a></li>
142
- # # <li class="active"><a href="/bar">Bar Link</a></li>
143
- # # </ul>
144
- #
145
- def breadcrumbs(breadcrumbs, bootstrap = false, active = "active", options = {})
146
- content = ActiveSupport::SafeBuffer.new
147
- breadcrumbs.items[0..-2].each do |item|
148
- content << render_item(item, bootstrap)
149
- end
150
- last = breadcrumbs.items.last
151
- last_options = last[:options]
152
- last = link_to(last[:caption], last[:url])
153
-
154
- classes = [options[:class], last_options[:class]].map { |class_name| class_name.to_s.split(/\s/) }
155
- classes[0] << "breadcrumb"
156
- classes[1] << active if active
157
- options[:class], last_options[:class] = classes.map { |class_name| class_name * " " }
158
-
159
- content << content_tag(:li, last, last_options)
160
- content_tag(:ul, content, options)
161
- end
162
-
163
- private
164
- ##
165
- # Private method to return list item.
166
- #
167
- # @param [Hash] item
168
- # The breadcrumb item.
169
- #
170
- # @param [Boolean] bootstrap
171
- # If true, render separation (useful with Twitter Bootstrap).
172
- #
173
- # @return [String] List item with breadcrumb
174
- #
175
- def render_item(item, bootstrap)
176
- content = ActiveSupport::SafeBuffer.new
177
- content << link_to(item[:caption], item[:url])
178
- content << content_tag(:span, "/", :class => "divider") if bootstrap
179
- content_tag(:li, content, item[:options])
180
- end
181
- end
182
- end
183
- end
@@ -1,134 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/helper')
2
-
3
- describe "BreadcrumbHelpers" do
4
- include Padrino::Helpers::Breadcrumbs
5
-
6
- def breadcrumb
7
- @breadcrumb ||= Padrino::Helpers::Breadcrumb.new
8
- end
9
-
10
- before(:each) { breadcrumb.reset! }
11
-
12
- describe "for Breadcrumbs#breadcrumbs method" do
13
- it 'should support breadcrumbs which is Padrino::Helpers::Breadcrumbs instance.' do
14
- breadcrumb.add "foo", "/foo", "foo link"
15
- assert_has_tag(:a, :content => "Foo link", :href => "/foo") { breadcrumbs(breadcrumb) }
16
- end
17
-
18
- it 'should support bootstrap' do
19
- breadcrumb.add "foo", "/foo", "foo link"
20
- assert_has_tag(:span, :content => "/", :class => "divider") { breadcrumbs(breadcrumb, true) }
21
- end
22
-
23
- it 'should support active' do
24
- breadcrumb.add "foo", "/foo", "foo link"
25
- assert_has_tag(:li, :class => "custom-active") { breadcrumbs(breadcrumb, nil, "custom-active") }
26
- end
27
-
28
- it 'should support options' do
29
- assert_has_tag(:ul, :class => "breadcrumbs-class breadcrumb", :id => "breadcrumbs-id") do
30
- breadcrumbs(breadcrumb, nil, nil, :id => "breadcrumbs-id", :class => "breadcrumbs-class")
31
- end
32
- end
33
- end
34
-
35
- describe "for #add method" do
36
- it 'should support name of string and symbol type' do
37
- breadcrumb.add "foo", "/foo", "Foo Link"
38
- breadcrumb.add :bar, "/bar", "Bar Link"
39
-
40
- actual_html = breadcrumbs(breadcrumb)
41
- assert_has_tag(:a, :content => "Foo link", :href => "/foo") { actual_html }
42
- assert_has_tag(:a, :content => "Bar link", :href => "/bar") { actual_html }
43
- end
44
-
45
- it 'should support url' do
46
- breadcrumb.add :foo, "/foo", "Foo Link"
47
- assert_has_tag(:a, :href => "/foo") { breadcrumbs(breadcrumb) }
48
- end
49
-
50
- it 'should support caption' do
51
- breadcrumb.add :foo, "/foo", "Foo Link"
52
- assert_has_tag(:a, :content => "Foo link") { breadcrumbs(breadcrumb) }
53
- end
54
-
55
- it 'should support options' do
56
- breadcrumb.add :foo, "/foo", "Foo Link", :id => "foo-id", :class => "foo-class"
57
- breadcrumb.add :bar, "/bar", "Bar Link", :id => "bar-id", :class => "bar-class"
58
-
59
- actual_html = breadcrumbs(breadcrumb)
60
- assert_has_tag(:li, :class => "foo-class", :id => "foo-id") { actual_html }
61
- assert_has_tag(:li, :class => "bar-class active", :id => "bar-id") { actual_html }
62
- end
63
- end
64
-
65
- describe "for #del method" do
66
- it 'should support name of string type' do
67
- breadcrumb.add "foo", "/foo", "Foo Link"
68
- breadcrumb.add :bar, "/bar", "Bar Link"
69
-
70
- breadcrumb.del "foo"
71
- breadcrumb.del "bar"
72
-
73
- actual_html = breadcrumbs(breadcrumb)
74
- assert_has_no_tag(:a, :content => "Foo link", :href => "/foo") { actual_html }
75
- assert_has_no_tag(:a, :content => "Bar link", :href => "/bar") { actual_html }
76
- end
77
-
78
- it 'should support name of symbol type' do
79
- breadcrumb.add "foo", "/foo", "Foo Link"
80
- breadcrumb.add :bar, "/bar", "Bar Link"
81
-
82
- breadcrumb.del :foo
83
- breadcrumb.del :bar
84
-
85
- actual_html = breadcrumbs(breadcrumb)
86
- assert_has_no_tag(:a, :content => "Foo link", :href => "/foo") { actual_html }
87
- assert_has_no_tag(:a, :content => "Bar link", :href => "/bar") { actual_html }
88
- end
89
- end
90
-
91
- describe "for #set_home method" do
92
- it 'should modified home item elements.' do
93
- breadcrumb.set_home("/custom", "Custom Home Page")
94
- assert_has_tag(:a, :content => "Custom home page", :href => "/custom") { breadcrumbs(breadcrumb) }
95
- end
96
-
97
- it 'should support options' do
98
- breadcrumb.set_home("/custom", "Custom Home Page", :id => "home-id")
99
-
100
- actual_html = breadcrumbs(breadcrumb)
101
- assert_has_tag(:li, :id => "home-id") { actual_html }
102
- assert_has_tag(:a, :content => "Custom home page", :href => "/custom") { actual_html }
103
- end
104
- end
105
-
106
- describe "for #reset method" do
107
- it 'should be #items which contains only home item.' do
108
- breadcrumb.set_home("/custom", "Custom Home Page")
109
- breadcrumb.add "foo", "/foo", "Foo Link"
110
- breadcrumb.add :bar, "/bar", "Bar Link"
111
-
112
- breadcrumb.reset
113
-
114
- actual_html = breadcrumbs(breadcrumb)
115
- assert_has_tag(:a, :content => "Custom home page", :href => "/custom") { actual_html }
116
- assert_has_no_tag(:a, :content => "Foo link", :href => "/foo") { actual_html }
117
- assert_has_no_tag(:a, :content => "Bar link", :href => "/bar") { actual_html }
118
- end
119
- end
120
-
121
- describe "for #reset! method" do
122
- it 'should be #items which contains only default home item.' do
123
- breadcrumb.add "foo", "/foo", "foo link"
124
- breadcrumb.add :bar, "/bar", "Bar Link"
125
-
126
- breadcrumb.reset!
127
-
128
- actual_html = breadcrumbs(breadcrumb)
129
- assert_has_tag(:a, :content => "Home Page", :href => "/") { actual_html }
130
- assert_has_no_tag(:a, :content => "Foo link", :href => "/foo") { actual_html }
131
- assert_has_no_tag(:a, :content => "Bar link", :href => "/bar") { actual_html }
132
- end
133
- end
134
- end