padrino-helpers 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/padrino-helpers.rb +4 -1
  3. data/lib/padrino-helpers/asset_tag_helpers.rb +17 -14
  4. data/lib/padrino-helpers/breadcrumb_helpers.rb +6 -6
  5. data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +119 -163
  6. data/lib/padrino-helpers/form_builder/deprecated_builder_methods.rb +92 -0
  7. data/lib/padrino-helpers/form_helpers.rb +66 -347
  8. data/lib/padrino-helpers/form_helpers/errors.rb +138 -0
  9. data/lib/padrino-helpers/form_helpers/options.rb +97 -0
  10. data/lib/padrino-helpers/form_helpers/security.rb +70 -0
  11. data/lib/padrino-helpers/output_helpers.rb +1 -1
  12. data/lib/padrino-helpers/output_helpers/abstract_handler.rb +1 -1
  13. data/lib/padrino-helpers/render_helpers.rb +10 -9
  14. data/lib/padrino-helpers/tag_helpers.rb +2 -1
  15. data/lib/padrino/rendering.rb +378 -0
  16. data/lib/padrino/rendering/extensions/erubis.rb +74 -0
  17. data/lib/padrino/rendering/extensions/haml.rb +29 -0
  18. data/lib/padrino/rendering/extensions/slim.rb +21 -0
  19. data/padrino-helpers.gemspec +2 -1
  20. data/test/fixtures/apps/.components +6 -0
  21. data/test/fixtures/apps/.gitignore +7 -0
  22. data/test/fixtures/apps/render.rb +25 -0
  23. data/test/fixtures/apps/views/article/comment/show.slim +1 -0
  24. data/test/fixtures/apps/views/blog/post.erb +1 -0
  25. data/test/fixtures/apps/views/layouts/specific.erb +1 -0
  26. data/test/fixtures/apps/views/test/post.erb +1 -0
  27. data/test/fixtures/layouts/layout.erb +1 -0
  28. data/test/fixtures/markup_app/app.rb +0 -1
  29. data/test/fixtures/render_app/app.rb +25 -1
  30. data/test/fixtures/render_app/views/_unsafe.html.builder +2 -0
  31. data/test/fixtures/render_app/views/_unsafe_object.html.builder +2 -0
  32. data/test/fixtures/render_app/views/ruby_block_capture_erb.erb +1 -0
  33. data/test/fixtures/render_app/views/ruby_block_capture_haml.haml +1 -0
  34. data/test/fixtures/render_app/views/ruby_block_capture_slim.slim +1 -0
  35. data/test/helper.rb +65 -1
  36. data/test/test_asset_tag_helpers.rb +83 -79
  37. data/test/test_breadcrumb_helpers.rb +20 -20
  38. data/test/test_form_builder.rb +196 -196
  39. data/test/test_form_helpers.rb +163 -163
  40. data/test/test_format_helpers.rb +65 -65
  41. data/test/test_locale.rb +1 -1
  42. data/test/test_number_helpers.rb +10 -11
  43. data/test/test_output_helpers.rb +28 -28
  44. data/test/test_render_helpers.rb +89 -35
  45. data/test/test_rendering.rb +683 -0
  46. data/test/test_rendering_extensions.rb +14 -0
  47. data/test/test_tag_helpers.rb +23 -23
  48. metadata +57 -5
@@ -0,0 +1,74 @@
1
+ begin
2
+ require 'erubis'
3
+
4
+ module Padrino
5
+ module Erubis
6
+ ##
7
+ # SafeBufferEnhancer is an Erubis Enhancer that compiles templates that
8
+ # are fit for using ActiveSupport::SafeBuffer as a Buffer.
9
+ #
10
+ # @api private
11
+ module SafeBufferEnhancer
12
+ def add_expr_literal(src, code)
13
+ src << " #{@bufvar}.concat((" << code << ').to_s);'
14
+ end
15
+
16
+ def add_stmt(src, code)
17
+ code = code.sub('end', 'nil;end') if code =~ /\A\s*end\s*\Z/
18
+ src << code
19
+ src << ';' unless code[-1] == ?\n
20
+ end
21
+
22
+ def add_expr_escaped(src, code)
23
+ src << " #{@bufvar}.safe_concat " << code << ';'
24
+ end
25
+
26
+ def add_text(src, text)
27
+ src << " #{@bufvar}.safe_concat '" << escape_text(text) << "';" unless text.empty?
28
+ end
29
+ end
30
+
31
+ ##
32
+ # SafeBufferTemplate is the classic Erubis template, augmented with
33
+ # SafeBufferEnhancer.
34
+ #
35
+ # @api private
36
+ class SafeBufferTemplate < ::Erubis::Eruby
37
+ include SafeBufferEnhancer
38
+ end
39
+
40
+ ##
41
+ # Modded ErubisTemplate that doesn't insist in an String as output
42
+ # buffer.
43
+ #
44
+ # @api private
45
+ class Template < Tilt::ErubisTemplate
46
+ def render(*args)
47
+ app = args.first
48
+ app_class = app.class
49
+ @is_padrino_app = (defined?(Padrino::Application) && app.kind_of?(Padrino::Application)) ||
50
+ (app_class.respond_to?(:erb) && app_class.erb[:engine_class] == Padrino::Erubis::SafeBufferTemplate)
51
+ super
52
+ end
53
+
54
+ ##
55
+ # In preamble we need a flag `__in_erb_template` and SafeBuffer for padrino apps.
56
+ #
57
+ def precompiled_preamble(locals)
58
+ original = super
59
+ return original unless @is_padrino_app
60
+ "__in_erb_template = true\n" << original.rpartition("\n").first << "#{@outvar} = _buf = ActiveSupport::SafeBuffer.new\n"
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ Tilt.prefer(Padrino::Erubis::Template, :erb)
67
+
68
+ if defined? Padrino::Rendering
69
+ Padrino::Rendering.engine_configurations[:erb] = {
70
+ :engine_class => Padrino::Erubis::SafeBufferTemplate,
71
+ }
72
+ end
73
+ rescue LoadError
74
+ end
@@ -0,0 +1,29 @@
1
+ begin
2
+ require 'haml'
3
+ require 'haml/helpers/xss_mods'
4
+ require 'haml/helpers/action_view_extensions'
5
+
6
+ module Haml
7
+ module Helpers
8
+ include XssMods
9
+ include ActionViewExtensions
10
+ end
11
+
12
+ module Util
13
+ def self.rails_xss_safe?
14
+ true
15
+ end
16
+ end
17
+ end
18
+
19
+ if defined? Padrino::Rendering
20
+ Padrino::Rendering.engine_configurations[:haml] = {
21
+ :escape_html => true,
22
+ }
23
+
24
+ class Tilt::HamlTemplate
25
+ include Padrino::Rendering::SafeTemplate
26
+ end
27
+ end
28
+ rescue LoadError
29
+ end
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'slim'
3
+
4
+ if defined? Padrino::Rendering
5
+ Padrino::Rendering.engine_configurations[:slim] = {
6
+ :generator => Temple::Generators::RailsOutputBuffer,
7
+ :buffer => "@_out_buf",
8
+ :use_html_safe => true,
9
+ :disable_capture => true,
10
+ }
11
+
12
+ class Slim::Template
13
+ include Padrino::Rendering::SafeTemplate
14
+
15
+ def precompiled_preamble(locals)
16
+ "__in_slim_template = true\n" << super
17
+ end
18
+ end
19
+ end
20
+ rescue LoadError
21
+ end
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.require_paths = ["lib"]
24
24
  s.rdoc_options = ["--charset=UTF-8"]
25
25
 
26
- s.add_dependency("padrino-core", Padrino.version)
26
+ s.add_dependency("padrino-support", Padrino.version)
27
+ s.add_dependency("tilt", "~> 1.4.1")
27
28
  s.add_dependency("i18n", "~> 0.6", ">= 0.6.7")
28
29
  end
@@ -0,0 +1,6 @@
1
+ ---
2
+ :test: bacon
3
+ :mock: mocha
4
+ :orm: datamapper
5
+ :renderer: erb
6
+ :script: jquery
@@ -0,0 +1,7 @@
1
+ .DS_Store
2
+ log/**/*
3
+ tmp/**/*
4
+ vendor/gems/gems
5
+ vendor/gems/specifications
6
+ vendor/gems/doc
7
+ vendor/gems/environment.rb
@@ -0,0 +1,25 @@
1
+ PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
2
+
3
+ class RenderDemo2 < Padrino::Application
4
+ register Padrino::Rendering
5
+
6
+ set :reload, true
7
+ end
8
+
9
+ RenderDemo2.controllers :blog do
10
+ get '/' do
11
+ render 'post'
12
+ end
13
+
14
+ get '/override' do
15
+ render 'post', :layout => RenderDemo2.layout_path('specific')
16
+ end
17
+ end
18
+
19
+ RenderDemo2.controllers :article, :comment do
20
+ get '/' do
21
+ render 'show'
22
+ end
23
+ end
24
+
25
+ Padrino.load!
@@ -0,0 +1 @@
1
+ | okay comment
@@ -0,0 +1 @@
1
+ okay
@@ -0,0 +1 @@
1
+ test
@@ -0,0 +1 @@
1
+ <%= yield %> absolute layout
@@ -2,7 +2,6 @@ require 'padrino-core'
2
2
 
3
3
  class MarkupDemo < Sinatra::Base
4
4
  register Padrino::Helpers
5
- register Padrino::Rendering
6
5
 
7
6
  configure do
8
7
  set :logging, false
@@ -9,7 +9,6 @@ class RenderUser
9
9
  end
10
10
 
11
11
  class RenderDemo < Padrino::Application
12
- register Padrino::Rendering
13
12
  register Padrino::Helpers
14
13
 
15
14
  configure do
@@ -36,6 +35,10 @@ class RenderDemo < Padrino::Application
36
35
  render "wrong_capture_#{params[:ext]}"
37
36
  end
38
37
 
38
+ get '/ruby_block_capture_:ext' do
39
+ render "ruby_block_capture_#{params[:ext]}"
40
+ end
41
+
39
42
  # partial with object
40
43
  get '/partial/object' do
41
44
  partial 'template/user', :object => RenderUser.new('John'), :locals => { :extra => "bar" }
@@ -46,6 +49,11 @@ class RenderDemo < Padrino::Application
46
49
  partial 'template/user', :collection => [RenderUser.new('John'), RenderUser.new('Billy')], :locals => { :extra => "bar" }
47
50
  end
48
51
 
52
+ # partial with collection and ext
53
+ get '/partial/collection.ext' do
54
+ partial 'template/user.haml', :collection => [RenderUser.new('John'), RenderUser.new('Billy')], :locals => { :extra => "bar" }
55
+ end
56
+
49
57
  # partial with locals
50
58
  get '/partial/locals' do
51
59
  partial 'template/user', :locals => { :user => RenderUser.new('John'), :extra => "bar" }
@@ -56,6 +64,22 @@ class RenderDemo < Padrino::Application
56
64
  partial '/template/user', :object => RenderUser.new('John'), :locals => { :extra => "bar" }
57
65
  end
58
66
 
67
+ # partial with unsafe engine
68
+ get '/partial/unsafe' do
69
+ block = params[:block] ? proc{ params[:block] } : nil
70
+ partial 'unsafe.html.builder', &block
71
+ end
72
+
73
+ get '/partial/unsafe_one' do
74
+ block = params[:block] ? proc{ params[:block] } : nil
75
+ partial 'unsafe_object', :object => 'Mary', &block
76
+ end
77
+
78
+ get '/partial/unsafe_many' do
79
+ block = params[:block] ? proc{ params[:block] } : nil
80
+ partial 'unsafe_object', :collection => ['John', 'Mary'], &block
81
+ end
82
+
59
83
  get '/render_block_:ext' do
60
84
  render "render_block_#{params[:ext]}" do
61
85
  content_tag :div, 'go block!'
@@ -0,0 +1,2 @@
1
+ xml.h1 'User name is John'
2
+ xml.div{ |x| x << yield } if block_given?
@@ -0,0 +1,2 @@
1
+ xml.h1 "User name is #{unsafe_object}"
2
+ xml.div{ |x| x << yield } if block_given?
@@ -0,0 +1 @@
1
+ <%= content_tag(:a) { content_tag :b, 'c' } %>
@@ -0,0 +1 @@
1
+ = content_tag(:a) { content_tag :b, 'c' }
@@ -0,0 +1 @@
1
+ = content_tag(:a) { content_tag :b, 'c' }
data/test/helper.rb CHANGED
@@ -1,9 +1,14 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+
1
3
  require File.expand_path('../../../load_paths', __FILE__)
2
- require File.join(File.dirname(__FILE__), '..', '..', 'padrino-core', 'test', 'mini_shoulda')
4
+ require 'minitest/autorun'
5
+ require 'minitest/pride'
6
+ require 'mocha/setup'
3
7
  require 'rack/test'
4
8
  require 'webrat'
5
9
  require 'padrino-helpers'
6
10
  require 'active_support/time'
11
+ require 'builder'
7
12
 
8
13
  class MiniTest::Spec
9
14
  include Padrino::Helpers::OutputHelpers
@@ -56,6 +61,65 @@ class MiniTest::Spec
56
61
  record.stubs(:to_ary => [record])
57
62
  record
58
63
  end
64
+
65
+ def create_template(name, content, options={})
66
+ FileUtils.mkdir_p(File.dirname(__FILE__) + "/views")
67
+ FileUtils.mkdir_p(File.dirname(__FILE__) + "/views/layouts")
68
+ path = "/views/#{name}"
69
+ path += ".#{options.delete(:locale)}" if options[:locale].present?
70
+ path += ".#{options[:format]}" if options[:format].present?
71
+ path += ".erb" unless options[:format].to_s =~ /erb|slim|haml|rss|atom/
72
+ path += ".builder" if options[:format].to_s =~ /rss|atom/
73
+ file = File.dirname(__FILE__) + path
74
+ File.open(file, 'w') { |io| io.write content }
75
+ file
76
+ end
77
+ alias :create_view :create_template
78
+ alias :create_layout :create_template
79
+
80
+ def remove_views
81
+ FileUtils.rm_rf(File.dirname(__FILE__) + "/views")
82
+ end
83
+
84
+ def with_template(name, content, options={})
85
+ # Build a temp layout
86
+ template = create_template(name, content, options)
87
+ yield
88
+ ensure
89
+ # Remove temp layout
90
+ File.unlink(template) rescue nil
91
+ remove_views
92
+ end
93
+ alias :with_view :with_template
94
+ alias :with_layout :with_template
95
+
96
+ def mock_app(base=Padrino::Application.dup, &block)
97
+ base.register Padrino::Rendering
98
+ @app = Sinatra.new(base, &block)
99
+ end
100
+
101
+ def app
102
+ Rack::Lint.new(@app)
103
+ end
104
+
105
+ # Asserts that a file matches the pattern
106
+ def assert_match_in_file(pattern, file)
107
+ assert File.exist?(file), "File '#{file}' does not exist!"
108
+ assert_match pattern, File.read(file)
109
+ end
110
+
111
+ # Delegate other missing methods to response.
112
+ def method_missing(name, *args, &block)
113
+ if response && response.respond_to?(name)
114
+ response.send(name, *args, &block)
115
+ else
116
+ super(name, *args, &block)
117
+ end
118
+ rescue Rack::Test::Error # no response yet
119
+ super(name, *args, &block)
120
+ end
121
+
122
+ alias :response :last_response
59
123
  end
60
124
 
61
125
  module Webrat
@@ -12,15 +12,15 @@ describe "AssetTagHelpers" do
12
12
  @_flash ||= { :notice => "Demo notice" }
13
13
  end
14
14
 
15
- context 'for #flash_tag method' do
16
- should "display flash with no given attributes" do
15
+ describe 'for #flash_tag method' do
16
+ it 'should display flash with no given attributes' do
17
17
  assert_has_tag('div.notice', :content => "Demo notice") { flash_tag(:notice) }
18
18
  end
19
- should "display flash with given attributes" do
19
+ it 'should display flash with given attributes' do
20
20
  actual_html = flash_tag(:notice, :class => 'notice', :id => 'notice-area')
21
21
  assert_has_tag('div.notice#notice-area', :content => "Demo notice") { actual_html }
22
22
  end
23
- should "display multiple flash tags with given attributes" do
23
+ it 'should display multiple flash tags with given attributes' do
24
24
  flash[:error] = 'wrong'
25
25
  flash[:success] = 'okey'
26
26
  actual_html = flash_tag(:success, :warning, :error, :id => 'area')
@@ -30,98 +30,98 @@ describe "AssetTagHelpers" do
30
30
  end
31
31
  end
32
32
 
33
- context 'for #link_to method' do
34
- should "display link element with no given attributes" do
33
+ describe 'for #link_to method' do
34
+ it 'should display link element with no given attributes' do
35
35
  assert_has_tag('a', :content => "Sign up", :href => '/register') { link_to('Sign up', '/register') }
36
36
  end
37
37
 
38
- should "display link element with given attributes" do
38
+ it 'should display link element with given attributes' do
39
39
  actual_html = link_to('Sign up', '/register', :class => 'first', :id => 'linky')
40
40
  assert_has_tag('a#linky.first', :content => "Sign up", :href => '/register') { actual_html }
41
41
  end
42
42
 
43
- should "display link element with anchor attribute" do
43
+ it 'should display link element with anchor attribute' do
44
44
  actual_html = link_to("Anchor", "/anchor", :anchor => :foo)
45
45
  assert_has_tag('a', :content => "Anchor", :href => '/anchor#foo') { actual_html }
46
46
  end
47
47
 
48
- should "display link element with void url and options" do
48
+ it 'should display link element with void url and options' do
49
49
  actual_link = link_to('Sign up', :class => "test")
50
50
  assert_has_tag('a', :content => "Sign up", :href => '#', :class => 'test') { actual_link }
51
51
  end
52
52
 
53
- should "display link element with remote option" do
53
+ it 'should display link element with remote option' do
54
54
  actual_link = link_to('Sign up', '/register', :remote => true)
55
55
  assert_has_tag('a', :content => "Sign up", :href => '/register', 'data-remote' => 'true') { actual_link }
56
56
  end
57
57
 
58
- should "display link element with method option" do
58
+ it 'should display link element with method option' do
59
59
  actual_link = link_to('Sign up', '/register', :method => :delete)
60
60
  assert_has_tag('a', :content => "Sign up", :href => '/register', 'data-method' => 'delete', :rel => 'nofollow') { actual_link }
61
61
  end
62
62
 
63
- should "display link element with confirm option" do
63
+ it 'should display link element with confirm option' do
64
64
  actual_link = link_to('Sign up', '/register', :confirm => "Are you sure?")
65
65
  assert_has_tag('a', :content => "Sign up", :href => '/register', 'data-confirm' => 'Are you sure?') { actual_link }
66
66
  end
67
67
 
68
- should "display link element with ruby block" do
68
+ it 'should display link element with ruby block' do
69
69
  actual_link = link_to('/register', :class => 'first', :id => 'binky') { "Sign up" }
70
70
  assert_has_tag('a#binky.first', :content => "Sign up", :href => '/register') { actual_link }
71
71
  end
72
72
 
73
- should "escape the link text" do
73
+ it 'should escape the link text' do
74
74
  actual_link = link_to('/register', :class => 'first', :id => 'binky') { "<&>" }
75
75
  assert_has_tag('a#binky.first', :href => '/register') { actual_link }
76
76
  assert_match "&lt;&amp;&gt;", actual_link
77
77
  end
78
78
 
79
- should "not escape image_tag" do
79
+ it 'should not escape image_tag' do
80
80
  actual_link = link_to(image_tag("/my/fancy/image.png"), :class => 'first', :id => 'binky')
81
81
  assert_has_tag('img', :src => "/my/fancy/image.png") { actual_link }
82
82
  end
83
83
 
84
- should "display link block element in haml" do
84
+ it 'should display link block element in haml' do
85
85
  visit '/haml/link_to'
86
86
  assert_have_selector :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1'
87
87
  assert_have_selector :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2'
88
88
  end
89
89
 
90
- should "display link block element in erb" do
90
+ it 'should display link block element in erb' do
91
91
  visit '/erb/link_to'
92
92
  assert_have_selector :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1'
93
93
  assert_have_selector :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2'
94
94
  end
95
95
 
96
- should "display link block element in slim" do
96
+ it 'should display link block element in slim' do
97
97
  visit '/slim/link_to'
98
98
  assert_have_selector :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1'
99
99
  assert_have_selector :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2'
100
100
  end
101
101
 
102
- should "not double-escape" do
102
+ it 'should not double-escape' do
103
103
  actual_link = link_to('test escape', '?a=1&b=2')
104
104
  assert_has_tag('a', :href => '?a=1&b=2') { actual_link }
105
105
  end
106
106
 
107
- should "escape scary things" do
107
+ it 'should escape scary things' do
108
108
  actual_link = link_to('test escape<adfs>', '?a=1&b=<script>alert(1)</script>')
109
- assert_no_match('<script', actual_link)
109
+ refute_match('<script', actual_link)
110
110
  end
111
111
  end
112
112
 
113
- context 'for #mail_to method' do
114
- should "display link element for mail to no caption" do
113
+ describe 'for #mail_to method' do
114
+ it 'should display link element for mail to no caption' do
115
115
  actual_html = mail_to('test@demo.com')
116
116
  assert_has_tag(:a, :href => "mailto:test@demo.com", :content => 'test@demo.com') { actual_html }
117
117
  end
118
118
 
119
- should "display link element for mail to with caption" do
119
+ it 'should display link element for mail to with caption' do
120
120
  actual_html = mail_to('test@demo.com', "My Email", :class => 'demo')
121
121
  assert_has_tag(:a, :href => "mailto:test@demo.com", :content => 'My Email', :class => 'demo') { actual_html }
122
122
  end
123
123
 
124
- should "display link element for mail to with caption and mail options" do
124
+ it 'should display link element for mail to with caption and mail options' do
125
125
  actual_html = mail_to('test@demo.com', "My Email", :subject => 'demo test', :class => 'demo', :cc => 'foo@test.com')
126
126
  assert_has_tag(:a, :class => 'demo') { actual_html }
127
127
  assert_match %r{mailto\:test\@demo.com\?}, actual_html
@@ -129,157 +129,161 @@ describe "AssetTagHelpers" do
129
129
  assert_match %r{subject\=demo\%20test}, actual_html
130
130
  end
131
131
 
132
- should "escape & with encoded string and &amp; in HTML" do
132
+ it 'should escape & with encoded string and &amp; in HTML' do
133
133
  actual_html = mail_to('test@demo.com', "My&Email", :subject => "this&that")
134
134
  assert_match 'this%26that', actual_html
135
135
  assert_match 'My&amp;Email', actual_html
136
136
  end
137
137
 
138
- should "display mail link element in haml" do
138
+ it 'should display mail link element in haml' do
139
139
  visit '/haml/mail_to'
140
140
  assert_have_selector 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
141
141
  assert_have_selector 'p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'
142
142
  end
143
143
 
144
- should "display mail link element in erb" do
144
+ it 'should display mail link element in erb' do
145
145
  visit '/erb/mail_to'
146
146
  assert_have_selector 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
147
147
  assert_have_selector 'p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'
148
148
  end
149
149
 
150
- should "display mail link element in slim" do
150
+ it 'should display mail link element in slim' do
151
151
  visit '/slim/mail_to'
152
152
  assert_have_selector 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
153
153
  assert_have_selector 'p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'
154
154
  end
155
155
  end
156
156
 
157
- context 'for #meta_tag method' do
158
- should "display meta tag with given content and name" do
157
+ describe 'for #meta_tag method' do
158
+ it 'should display meta tag with given content and name' do
159
159
  actual_html = meta_tag("weblog,news", :name => "keywords")
160
160
  assert_has_tag("meta", :name => "keywords", "content" => "weblog,news") { actual_html }
161
161
  end
162
162
 
163
- should "display meta tag with given content and http-equiv" do
163
+ it 'should display meta tag with given content and http-equiv' do
164
164
  actual_html = meta_tag("text/html; charset=UTF-8", :"http-equiv" => "Content-Type")
165
165
  assert_has_tag("meta", :"http-equiv" => "Content-Type", "content" => "text/html; charset=UTF-8") { actual_html }
166
166
  end
167
167
 
168
- should "display meta tag element in haml" do
168
+ it 'should display meta tag element in haml' do
169
169
  visit '/haml/meta_tag'
170
170
  assert_have_selector 'meta', "content" => "weblog,news", :name => "keywords"
171
171
  assert_have_selector 'meta', "content" => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
172
172
  end
173
173
 
174
- should "display meta tag element in erb" do
174
+ it 'should display meta tag element in erb' do
175
175
  visit '/erb/meta_tag'
176
176
  assert_have_selector 'meta', "content" => "weblog,news", :name => "keywords"
177
177
  assert_have_selector 'meta', "content" => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
178
178
  end
179
179
 
180
- should "display meta tag element in slim" do
180
+ it 'should display meta tag element in slim' do
181
181
  visit '/slim/meta_tag'
182
182
  assert_have_selector 'meta', "content" => "weblog,news", :name => "keywords"
183
183
  assert_have_selector 'meta', "content" => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
184
184
  end
185
185
  end
186
186
 
187
- context 'for #image_tag method' do
188
- should "display image tag absolute link with no options" do
187
+ describe 'for #image_tag method' do
188
+ it 'should display image tag absolute link with no options' do
189
189
  time = stop_time_for_test
190
190
  assert_has_tag('img', :src => "/absolute/pic.gif") { image_tag('/absolute/pic.gif') }
191
191
  end
192
192
 
193
- should "display image tag relative link with specified uri root" do
193
+ it 'should display image tag relative link with specified uri root' do
194
194
  time = stop_time_for_test
195
195
  self.class.stubs(:uri_root).returns("/blog")
196
196
  assert_has_tag('img', :src => "/blog/images/relative/pic.gif?#{time.to_i}") { image_tag('relative/pic.gif') }
197
197
  end
198
198
 
199
- should "display image tag relative link with options" do
199
+ it 'should display image tag relative link with options' do
200
200
  time = stop_time_for_test
201
201
  assert_has_tag('img.photo', :src => "/images/relative/pic.gif?#{time.to_i}") {
202
202
  image_tag('relative/pic.gif', :class => 'photo') }
203
203
  end
204
204
 
205
- should "display image tag uri link with options" do
205
+ it 'should display image tag uri link with options' do
206
206
  time = stop_time_for_test
207
207
  assert_has_tag('img.photo', :src => "http://demo.org/pic.gif") { image_tag('http://demo.org/pic.gif', :class => 'photo') }
208
208
  end
209
209
 
210
- should "display image tag relative link with incorrect spacing" do
210
+ it 'should display image tag relative link with incorrect spacing' do
211
211
  time = stop_time_for_test
212
212
  assert_has_tag('img.photo', :src => "/images/%20relative/%20pic.gif%20%20?#{time.to_i}") {
213
213
  image_tag(' relative/ pic.gif ', :class => 'photo')
214
214
  }
215
215
  end
216
216
 
217
- should "not use a timestamp if stamp setting is false" do
217
+ it 'should not use a timestamp if stamp setting is false' do
218
218
  assert_has_tag('img', :src => "/absolute/pic.gif") { image_tag('/absolute/pic.gif') }
219
219
  end
220
220
 
221
- should "have xhtml convention tag" do
221
+ it 'should have xhtml convention tag' do
222
222
  assert_equal image_tag('/absolute/pic.gif'), '<img src="/absolute/pic.gif" />'
223
223
  end
224
224
  end
225
225
 
226
- context 'for #stylesheet_link_tag method' do
227
- should "display stylesheet link item" do
226
+ describe 'for #stylesheet_link_tag method' do
227
+ it 'should display stylesheet link item' do
228
228
  time = stop_time_for_test
229
229
  actual_html = stylesheet_link_tag('style')
230
- expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
230
+ expected_options = { :rel => "stylesheet", :type => "text/css" }
231
231
  assert_has_tag('link', expected_options.merge(:href => "/stylesheets/style.css?#{time.to_i}")) { actual_html }
232
232
  assert actual_html.html_safe?
233
233
  end
234
234
 
235
- should "display stylesheet link item for long relative path" do
235
+ it 'should display stylesheet link item for long relative path' do
236
236
  time = stop_time_for_test
237
- expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
237
+ expected_options = { :rel => "stylesheet", :type => "text/css" }
238
238
  actual_html = stylesheet_link_tag('example/demo/style')
239
239
  assert_has_tag('link', expected_options.merge(:href => "/stylesheets/example/demo/style.css?#{time.to_i}")) { actual_html }
240
240
  end
241
241
 
242
- should "display stylesheet link item with absolute path" do
242
+ it 'should display stylesheet link item with absolute path' do
243
243
  time = stop_time_for_test
244
- expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
244
+ expected_options = { :rel => "stylesheet", :type => "text/css" }
245
245
  actual_html = stylesheet_link_tag('/css/style')
246
246
  assert_has_tag('link', expected_options.merge(:href => "/css/style.css")) { actual_html }
247
247
  end
248
248
 
249
- should "display stylesheet link item with uri root" do
249
+ it 'should display stylesheet link item with uri root' do
250
250
  self.class.stubs(:uri_root).returns("/blog")
251
251
  time = stop_time_for_test
252
- expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
252
+ expected_options = { :rel => "stylesheet", :type => "text/css" }
253
253
  actual_html = stylesheet_link_tag('style')
254
254
  assert_has_tag('link', expected_options.merge(:href => "/blog/stylesheets/style.css?#{time.to_i}")) { actual_html }
255
255
  end
256
256
 
257
- should "display stylesheet link items" do
257
+ it 'should display stylesheet link items' do
258
258
  time = stop_time_for_test
259
259
  actual_html = stylesheet_link_tag('style', 'layout.css', 'http://google.com/style.css')
260
- assert_has_tag('link', :media => "screen", :rel => "stylesheet", :type => "text/css", :count => 3) { actual_html }
260
+ assert_has_tag('link', :rel => "stylesheet", :type => "text/css", :count => 3) { actual_html }
261
261
  assert_has_tag('link', :href => "/stylesheets/style.css?#{time.to_i}") { actual_html }
262
262
  assert_has_tag('link', :href => "/stylesheets/layout.css?#{time.to_i}") { actual_html }
263
263
  assert_has_tag('link', :href => "http://google.com/style.css") { actual_html }
264
264
  assert_equal actual_html, stylesheet_link_tag(['style', 'layout.css', 'http://google.com/style.css'])
265
265
  end
266
266
 
267
- should "not use a timestamp if stamp setting is false" do
267
+ it 'should not use a timestamp if stamp setting is false' do
268
268
  self.class.expects(:asset_stamp).returns(false)
269
- expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
269
+ expected_options = { :rel => "stylesheet", :type => "text/css" }
270
270
  assert_has_tag('link', expected_options.merge(:href => "/stylesheets/style.css")) { stylesheet_link_tag('style') }
271
271
  end
272
+
273
+ it 'should display stylesheet link used custom options' do
274
+ assert_has_tag('link', :rel => 'stylesheet', :media => 'screen') { stylesheet_link_tag('style', :media => 'screen') }
275
+ end
272
276
  end
273
277
 
274
- context 'for #javascript_include_tag method' do
275
- should "display javascript item" do
278
+ describe 'for #javascript_include_tag method' do
279
+ it 'should display javascript item' do
276
280
  time = stop_time_for_test
277
281
  actual_html = javascript_include_tag('application')
278
282
  assert_has_tag('script', :src => "/javascripts/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
279
283
  assert actual_html.html_safe?
280
284
  end
281
285
 
282
- should "respond to js_asset_folder setting" do
286
+ it 'should respond to js_asset_folder setting' do
283
287
  time = stop_time_for_test
284
288
  self.class.stubs(:js_asset_folder).returns('js')
285
289
  assert_equal 'js', asset_folder_name(:js)
@@ -287,44 +291,44 @@ describe "AssetTagHelpers" do
287
291
  assert_has_tag('script', :src => "/js/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
288
292
  end
289
293
 
290
- should "display javascript item for long relative path" do
294
+ it 'should display javascript item for long relative path' do
291
295
  time = stop_time_for_test
292
296
  actual_html = javascript_include_tag('example/demo/application')
293
297
  assert_has_tag('script', :src => "/javascripts/example/demo/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
294
298
  end
295
299
 
296
- should "display javascript item for path containing js" do
300
+ it 'should display javascript item for path containing js' do
297
301
  time = stop_time_for_test
298
302
  actual_html = javascript_include_tag 'test/jquery.json'
299
303
  assert_has_tag('script', :src => "/javascripts/test/jquery.json?#{time.to_i}", :type => "text/javascript") { actual_html }
300
304
  end
301
305
 
302
- should "display javascript item for path containing period" do
306
+ it 'should display javascript item for path containing period' do
303
307
  time = stop_time_for_test
304
308
  actual_html = javascript_include_tag 'test/jquery.min'
305
309
  assert_has_tag('script', :src => "/javascripts/test/jquery.min.js?#{time.to_i}", :type => "text/javascript") { actual_html }
306
310
  end
307
311
 
308
- should "display javascript item with absolute path" do
312
+ it 'should display javascript item with absolute path' do
309
313
  time = stop_time_for_test
310
314
  actual_html = javascript_include_tag('/js/application')
311
315
  assert_has_tag('script', :src => "/js/application.js", :type => "text/javascript") { actual_html }
312
316
  end
313
317
 
314
- should "display javascript item with uri root" do
318
+ it 'should display javascript item with uri root' do
315
319
  self.class.stubs(:uri_root).returns("/blog")
316
320
  time = stop_time_for_test
317
321
  actual_html = javascript_include_tag('application')
318
322
  assert_has_tag('script', :src => "/blog/javascripts/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
319
323
  end
320
324
 
321
- should "not append extension to absolute paths" do
325
+ it 'should not append extension to absolute paths' do
322
326
  time = stop_time_for_test
323
327
  actual_html = javascript_include_tag('https://maps.googleapis.com/maps/api/js?key=value&sensor=false')
324
328
  assert_has_tag('script', :src => "https://maps.googleapis.com/maps/api/js?key=value&sensor=false") { actual_html }
325
329
  end
326
330
 
327
- should "display javascript items" do
331
+ it 'should display javascript items' do
328
332
  time = stop_time_for_test
329
333
  actual_html = javascript_include_tag('application', 'base.js', 'http://google.com/lib.js')
330
334
  assert_has_tag('script', :type => "text/javascript", :count => 3) { actual_html }
@@ -334,59 +338,59 @@ describe "AssetTagHelpers" do
334
338
  assert_equal actual_html, javascript_include_tag(['application', 'base.js', 'http://google.com/lib.js'])
335
339
  end
336
340
 
337
- should "not use a timestamp if stamp setting is false" do
341
+ it 'should not use a timestamp if stamp setting is false' do
338
342
  self.class.expects(:asset_stamp).returns(false)
339
343
  actual_html = javascript_include_tag('application')
340
344
  assert_has_tag('script', :src => "/javascripts/application.js", :type => "text/javascript") { actual_html }
341
345
  end
342
346
  end
343
347
 
344
- context "for #favicon_tag method" do
345
- should "display favicon" do
348
+ describe "for #favicon_tag method" do
349
+ it 'should display favicon' do
346
350
  time = stop_time_for_test
347
351
  actual_html = favicon_tag('icons/favicon.png')
348
352
  assert_has_tag('link', :rel => 'icon', :type => 'image/png', :href => "/images/icons/favicon.png?#{time.to_i}") { actual_html }
349
353
  end
350
354
 
351
- should "match type with file ext" do
355
+ it 'should match type with file ext' do
352
356
  time = stop_time_for_test
353
357
  actual_html = favicon_tag('favicon.ico')
354
358
  assert_has_tag('link', :rel => 'icon', :type => 'image/ico', :href => "/images/favicon.ico?#{time.to_i}") { actual_html }
355
359
  end
356
360
 
357
- should "allow option overrides" do
361
+ it 'should allow option overrides' do
358
362
  time = stop_time_for_test
359
363
  actual_html = favicon_tag('favicon.png', :type => 'image/ico')
360
364
  assert_has_tag('link', :rel => 'icon', :type => 'image/ico', :href => "/images/favicon.png?#{time.to_i}") { actual_html }
361
365
  end
362
366
  end
363
367
 
364
- context 'for #feed_tag method' do
365
- should "generate correctly link tag for rss" do
368
+ describe 'for #feed_tag method' do
369
+ it 'should generate correctly link tag for rss' do
366
370
  assert_has_tag('link', :type => 'application/rss+xml', :rel => 'alternate', :href => "/blog/post.rss", :title => 'rss') { feed_tag :rss, "/blog/post.rss" }
367
371
  end
368
372
 
369
- should "generate correctly link tag for atom" do
373
+ it 'should generate correctly link tag for atom' do
370
374
  assert_has_tag('link', :type => 'application/atom+xml', :rel => 'alternate', :href => "/blog/post.atom", :title => 'atom') { feed_tag :atom, "/blog/post.atom" }
371
375
  end
372
376
 
373
- should "override options" do
377
+ it 'should override options' do
374
378
  assert_has_tag('link', :type => 'my-type', :rel => 'my-rel', :href => "/blog/post.rss", :title => 'my-title') { feed_tag :rss, "/blog/post.rss", :type => "my-type", :rel => "my-rel", :title => "my-title" }
375
379
  end
376
380
  end
377
381
 
378
- context 'for #asset_path method' do
379
- should 'generate proper paths for js and css' do
382
+ describe 'for #asset_path method' do
383
+ it 'should generate proper paths for js and css' do
380
384
  assert_match /\/javascripts\/app.js\?\d+/, asset_path(:js, 'app')
381
385
  assert_match /\/stylesheets\/app.css\?\d+/, asset_path(:css, 'app')
382
386
  end
383
387
 
384
- should 'generate proper paths for images and other files' do
388
+ it 'should generate proper paths for images and other files' do
385
389
  assert_match /\/images\/app.png\?\d+/, asset_path(:images, 'app.png')
386
390
  assert_match /\/documents\/app.pdf\?\d+/, asset_path(:documents, 'app.pdf')
387
391
  end
388
392
 
389
- should 'generate proper paths for public folder' do
393
+ it 'should generate proper paths for public folder' do
390
394
  assert_match /\/files\/file.ext\?\d+/, asset_path('files/file.ext')
391
395
  end
392
396
  end