padrino-helpers 0.1.0
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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/lib/padrino-helpers.rb +16 -0
- data/lib/padrino-helpers/asset_tag_helpers.rb +97 -0
- data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +139 -0
- data/lib/padrino-helpers/form_builder/standard_form_builder.rb +37 -0
- data/lib/padrino-helpers/form_helpers.rb +194 -0
- data/lib/padrino-helpers/format_helpers.rb +74 -0
- data/lib/padrino-helpers/output_helpers.rb +98 -0
- data/lib/padrino-helpers/render_helpers.rb +63 -0
- data/lib/padrino-helpers/tag_helpers.rb +42 -0
- data/test/active_support_helpers.rb +7 -0
- data/test/fixtures/markup_app/app.rb +61 -0
- data/test/fixtures/markup_app/views/capture_concat.erb +14 -0
- data/test/fixtures/markup_app/views/capture_concat.haml +13 -0
- data/test/fixtures/markup_app/views/content_for.erb +11 -0
- data/test/fixtures/markup_app/views/content_for.haml +9 -0
- data/test/fixtures/markup_app/views/content_tag.erb +11 -0
- data/test/fixtures/markup_app/views/content_tag.haml +9 -0
- data/test/fixtures/markup_app/views/fields_for.erb +8 -0
- data/test/fixtures/markup_app/views/fields_for.haml +6 -0
- data/test/fixtures/markup_app/views/form_for.erb +56 -0
- data/test/fixtures/markup_app/views/form_for.haml +47 -0
- data/test/fixtures/markup_app/views/form_tag.erb +57 -0
- data/test/fixtures/markup_app/views/form_tag.haml +45 -0
- data/test/fixtures/markup_app/views/link_to.erb +5 -0
- data/test/fixtures/markup_app/views/link_to.haml +4 -0
- data/test/fixtures/markup_app/views/mail_to.erb +3 -0
- data/test/fixtures/markup_app/views/mail_to.haml +3 -0
- data/test/fixtures/render_app/app.rb +53 -0
- data/test/fixtures/render_app/views/erb/test.erb +1 -0
- data/test/fixtures/render_app/views/haml/test.haml +1 -0
- data/test/fixtures/render_app/views/template/_user.haml +7 -0
- data/test/fixtures/render_app/views/template/haml_template.haml +1 -0
- data/test/fixtures/render_app/views/template/some_template.haml +2 -0
- data/test/helper.rb +73 -0
- data/test/test_asset_tag_helpers.rb +127 -0
- data/test/test_form_builder.rb +611 -0
- data/test/test_form_helpers.rb +406 -0
- data/test/test_format_helpers.rb +96 -0
- data/test/test_output_helpers.rb +63 -0
- data/test/test_render_helpers.rb +78 -0
- data/test/test_tag_helpers.rb +73 -0
- metadata +174 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
<% form_for MarkupUser.new, '/demo', :id => 'demo' do |f| %>
|
2
|
+
<%= f.error_messages(:header_message => "custom MarkupUser cannot be saved!") %>
|
3
|
+
<%= f.hidden_field :session_id %>
|
4
|
+
<p>
|
5
|
+
<%= f.label :username, :caption => "Login", :class => 'user-label' %>
|
6
|
+
<%= f.text_field :username, :class => 'user-text', :value => "John" %>
|
7
|
+
</p>
|
8
|
+
<p>
|
9
|
+
<%= f.label :email, :caption => "Email", :class => 'user-email' %>
|
10
|
+
<%= f.text_field :email %>
|
11
|
+
</p>
|
12
|
+
<p>
|
13
|
+
<%= f.label :password %>
|
14
|
+
<%= f.password_field :password, :class => 'user-password', :value => "secret" %>
|
15
|
+
</p>
|
16
|
+
<p>
|
17
|
+
<%= f.label :photo %>
|
18
|
+
<%= f.file_field :photo, :class => 'user-photo' %>
|
19
|
+
</p>
|
20
|
+
<p>
|
21
|
+
<%= f.label :about, :caption => "About Me" %>
|
22
|
+
<%= f.text_area :about, :class => 'user-about' %>
|
23
|
+
</p>
|
24
|
+
<p>
|
25
|
+
<%= f.label :gender, :caption => "Your gender:" %>
|
26
|
+
<%= f.radio_button :gender, :value => 'male' %>
|
27
|
+
<%= f.radio_button :gender, :value => 'female' %>
|
28
|
+
</p>
|
29
|
+
<p>
|
30
|
+
<%= f.label :country, :caption => "Your country" %>
|
31
|
+
<%= f.select :country, :options => ['USA', 'Canada', 'Mexico'], :selected => 'USA', :class => 'selector' %>
|
32
|
+
</p>
|
33
|
+
<p>
|
34
|
+
<%= f.label :remember_me %>
|
35
|
+
<%= f.check_box :remember_me, :value => '1' %>
|
36
|
+
</p>
|
37
|
+
<p><%= f.submit "Create", :class => 'success', :id => 'demo-button' %></p>
|
38
|
+
<p><%= f.image_submit "buttons/post.png", :class => 'success', :id => 'image-button' %></p>
|
39
|
+
<% end %>
|
40
|
+
|
41
|
+
<% form_for MarkupUser.new, '/another_demo', :id => 'demo2', :method => 'get' do |f| %>
|
42
|
+
<%= f.error_messages :header_message => "custom MarkupUser cannot be saved!" %>
|
43
|
+
<%= f.hidden_field :session_id %>
|
44
|
+
<%= f.text_field_block :username, { :class => 'input' }, { :caption => 'Nickname', :class => 'label' } %>
|
45
|
+
<%= f.password_field_block :code, { :class => 'input' } %>
|
46
|
+
<%= f.text_area_block :about, { :class => 'textarea' } %>
|
47
|
+
<%= f.file_field_block :photo, { :class => 'upload' } %>
|
48
|
+
<%= f.check_box_block :remember_me, { :class => 'checker' } %>
|
49
|
+
<%= f.select_block :state, :options => ['California', 'Texas'], :class => 'selector' %>
|
50
|
+
<%= f.submit_block "Create", { :class => 'button' } %>
|
51
|
+
<%= f.image_submit_block "buttons/ok.png", { :class => 'image' } %>
|
52
|
+
<% end %>
|
53
|
+
|
54
|
+
<% form_for :markup_user, '/third_demo', :id => 'demo3', :method => 'get' do |f| %>
|
55
|
+
<%= f.text_field_block :username %>
|
56
|
+
<% end %>
|
@@ -0,0 +1,47 @@
|
|
1
|
+
- form_for MarkupUser.new, '/demo', :id => 'demo' do |f|
|
2
|
+
= f.error_messages(:header_message => "custom MarkupUser cannot be saved!")
|
3
|
+
= f.hidden_field :session_id
|
4
|
+
%p
|
5
|
+
= f.label :username, :caption => "Login", :class => 'user-label'
|
6
|
+
= f.text_field :username, :class => 'user-text', :value => "John"
|
7
|
+
%p
|
8
|
+
= f.label :email, :caption => "Email", :class => 'user-email'
|
9
|
+
= f.text_field :email
|
10
|
+
%p
|
11
|
+
= f.label :password
|
12
|
+
= f.password_field :password, :class => 'user-password', :value => "secret"
|
13
|
+
%p
|
14
|
+
= f.label :photo
|
15
|
+
= f.file_field :photo, :class => 'user-photo'
|
16
|
+
%p
|
17
|
+
= f.label :about, :caption => "About Me"
|
18
|
+
= f.text_area :about, :class => 'user-about'
|
19
|
+
%p
|
20
|
+
= f.label :gender, :caption => "Your gender"
|
21
|
+
= f.radio_button :gender, :value => 'male'
|
22
|
+
= f.radio_button :gender, :value => 'female'
|
23
|
+
%p
|
24
|
+
= f.label :country, :caption => "Your country"
|
25
|
+
= f.select :country, :options => ['USA', 'Canada', 'Mexico'], :selected => 'USA', :class => 'selector'
|
26
|
+
%p
|
27
|
+
= f.label :remember_me
|
28
|
+
= f.check_box :remember_me, :value => "1"
|
29
|
+
%p
|
30
|
+
= f.submit "Create", :class => 'success', :id => 'demo-button'
|
31
|
+
%p
|
32
|
+
= f.image_submit "buttons/post.png", :class => 'success', :id => 'image-button'
|
33
|
+
|
34
|
+
- form_for MarkupUser.new, '/another_demo', :id => 'demo2', :method => 'get' do |f|
|
35
|
+
= f.error_messages :header_message => "custom MarkupUser cannot be saved!"
|
36
|
+
= f.hidden_field :session_id
|
37
|
+
= f.text_field_block :username, { :class => 'input' }, { :caption => 'Nickname', :class => 'label' }
|
38
|
+
= f.password_field_block :code, { :class => 'input' }
|
39
|
+
= f.text_area_block :about, { :class => 'textarea' }
|
40
|
+
= f.file_field_block :photo, { :class => 'upload' }
|
41
|
+
= f.check_box_block :remember_me, { :class => 'checker' }
|
42
|
+
= f.select_block :state, :options => ['California', 'Texas'], :class => 'selector'
|
43
|
+
= f.submit_block "Create", { :class => 'button' }
|
44
|
+
= f.image_submit_block "buttons/ok.png", { :class => 'image' }
|
45
|
+
|
46
|
+
- form_for :markup_user, '/third_demo', :id => 'demo3', :method => 'get' do |f|
|
47
|
+
= f.text_field_block :username
|
@@ -0,0 +1,57 @@
|
|
1
|
+
<% form_tag '/simple', :class => 'simple-form' do %>
|
2
|
+
<%= error_messages_for(nil) %>
|
3
|
+
<%= hidden_field_tag :session_id, :value => "__secret__" %>
|
4
|
+
<% field_set_tag do %>
|
5
|
+
<%= label_tag :username %>
|
6
|
+
<%= text_field_tag :username %>
|
7
|
+
<%= label_tag :password %>
|
8
|
+
<%= password_field_tag :password %>
|
9
|
+
<%= check_box_tag :remember_me %>
|
10
|
+
<%= label_tag :gender %>
|
11
|
+
<%= label_tag :color %>
|
12
|
+
<%= select_tag :color, :options => ['green', 'orange', 'purple'] %>
|
13
|
+
<%= radio_button_tag :gender, :value => 'male' %>
|
14
|
+
<%= radio_button_tag :gender, :value => 'female' %>
|
15
|
+
<%= submit_tag %>
|
16
|
+
<% end %>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<% form_tag '/advanced', :id => 'advanced', :class => 'advanced-form', :method => 'get' do %>
|
20
|
+
<%= error_messages_for MarkupUser.new, :header_message => "There are problems with saving user!" %>
|
21
|
+
<%= hidden_field_tag :session_id, :value => "__secret__" %>
|
22
|
+
<% field_set_tag "Advanced", :class => 'advanced-field-set' do %>
|
23
|
+
<p>
|
24
|
+
<%= label_tag :username, :class => 'first', :caption => "Nickname" %>
|
25
|
+
<%= text_field_tag :username, :value => params[:username], :id => 'the_username' %>
|
26
|
+
</p>
|
27
|
+
<p>
|
28
|
+
<%= label_tag :password, :class => 'first' %>
|
29
|
+
<%= password_field_tag :password, :value => params[:password] %>
|
30
|
+
</p>
|
31
|
+
<p>
|
32
|
+
<%= label_tag :about, :class => 'about', :caption => "About Me" %>
|
33
|
+
<%= text_area_tag :about, :class => 'large' %>
|
34
|
+
</p>
|
35
|
+
<p>
|
36
|
+
<%= label_tag :photo, :class => 'photo' %>
|
37
|
+
<%= file_field_tag :photo, :class => 'upload' %>
|
38
|
+
</p>
|
39
|
+
<p>
|
40
|
+
<%= label_tag :gender, :class => 'gender' %>
|
41
|
+
<%= radio_button_tag :gender, :value => 'male', :checked => true %>
|
42
|
+
<%= radio_button_tag :remember_me, :value => 'female' %>
|
43
|
+
<p>
|
44
|
+
<p>
|
45
|
+
<%= label_tag :fav_color %>
|
46
|
+
<%= select_tag :fav_color, :options => [ ['green', '1'], ['orange', '2'], ['purple', '3'] ], :selected => '2' %>
|
47
|
+
</p>
|
48
|
+
<p>
|
49
|
+
<%= check_box_tag :remember_me, :value => '1', :checked => true %>
|
50
|
+
<p>
|
51
|
+
<% end %>
|
52
|
+
<% field_set_tag(:class => 'buttons') do %>
|
53
|
+
<%= submit_tag "Login" %>
|
54
|
+
<%= button_tag "Cancel" %>
|
55
|
+
<%= image_submit_tag "buttons/submit.png" %>
|
56
|
+
<% end %>
|
57
|
+
<% end %>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
- form_tag '/simple', :class => 'simple-form' do
|
2
|
+
= error_messages_for nil
|
3
|
+
- field_set_tag do
|
4
|
+
= hidden_field_tag :session_id, :value => "__secret__"
|
5
|
+
= label_tag :username
|
6
|
+
= text_field_tag :username
|
7
|
+
= label_tag :password
|
8
|
+
= password_field_tag :password
|
9
|
+
= label_tag :color
|
10
|
+
= select_tag :color, :options => ['green', 'orange', 'purple']
|
11
|
+
= label_tag :gender
|
12
|
+
= radio_button_tag :gender, :value => 'male'
|
13
|
+
= radio_button_tag :gender, :value => 'female'
|
14
|
+
= check_box_tag :remember_me
|
15
|
+
= submit_tag
|
16
|
+
|
17
|
+
- form_tag '/advanced', :id => 'advanced', :class => 'advanced-form', :method => 'get' do
|
18
|
+
= error_messages_for MarkupUser.new, :header_message => "There are problems with saving user!"
|
19
|
+
= hidden_field_tag :session_id, :value => "__secret__"
|
20
|
+
- field_set_tag "Advanced", :class => 'advanced-field-set' do
|
21
|
+
%p
|
22
|
+
= label_tag :username, :class => 'first', :caption => "Nickname"
|
23
|
+
= text_field_tag :username, :value => params[:username], :id => 'the_username'
|
24
|
+
%p
|
25
|
+
= label_tag :password, :class => 'first'
|
26
|
+
= password_field_tag :password, :value => params[:password]
|
27
|
+
%p
|
28
|
+
= label_tag :about, :class => 'about', :caption => "About Me"
|
29
|
+
= text_area_tag :about, :class => 'large'
|
30
|
+
%p
|
31
|
+
= label_tag :gender, :class => 'gender'
|
32
|
+
= radio_button_tag :gender, :value => 'male', :checked => true
|
33
|
+
= radio_button_tag :gender, :value => 'female'
|
34
|
+
%p
|
35
|
+
= label_tag :photo, :class => 'photo'
|
36
|
+
= file_field_tag :photo, :class => 'upload'
|
37
|
+
%p
|
38
|
+
= label_tag :fav_color
|
39
|
+
= select_tag :fav_color, :options => [ ['green', '1'], ['orange', '2'], ['purple', '3'] ], :selected => '2'
|
40
|
+
%p
|
41
|
+
= check_box_tag :remember_me, :value => "1", :checked => true
|
42
|
+
- field_set_tag(:class => 'buttons') do
|
43
|
+
= submit_tag "Login"
|
44
|
+
= button_tag "Cancel"
|
45
|
+
= image_submit_tag "buttons/submit.png"
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'haml'
|
3
|
+
|
4
|
+
class RenderUser
|
5
|
+
attr_accessor :name
|
6
|
+
def initialize(name); @name = name; end
|
7
|
+
end
|
8
|
+
|
9
|
+
class RenderDemo < Sinatra::Base
|
10
|
+
register Padrino::Helpers
|
11
|
+
|
12
|
+
configure do
|
13
|
+
set :root, File.dirname(__FILE__)
|
14
|
+
end
|
15
|
+
|
16
|
+
# haml_template
|
17
|
+
get '/render_haml' do
|
18
|
+
@template = 'haml'
|
19
|
+
haml_template 'haml/test'
|
20
|
+
end
|
21
|
+
|
22
|
+
# erb_template
|
23
|
+
get '/render_erb' do
|
24
|
+
@template = 'erb'
|
25
|
+
erb_template 'erb/test'
|
26
|
+
end
|
27
|
+
|
28
|
+
# render_template with explicit engine
|
29
|
+
get '/render_template/:engine' do
|
30
|
+
@template = params[:engine]
|
31
|
+
render_template "template/#{@template}_template", :template_engine => @template
|
32
|
+
end
|
33
|
+
|
34
|
+
# render_template without explicit engine
|
35
|
+
get '/render_template' do
|
36
|
+
render_template "template/some_template"
|
37
|
+
end
|
38
|
+
|
39
|
+
# partial with object
|
40
|
+
get '/partial/object' do
|
41
|
+
partial 'template/user', :object => RenderUser.new('John'), :locals => { :extra => "bar" }
|
42
|
+
end
|
43
|
+
|
44
|
+
# partial with collection
|
45
|
+
get '/partial/collection' do
|
46
|
+
partial 'template/user', :collection => [RenderUser.new('John'), RenderUser.new('Billy')], :locals => { :extra => "bar" }
|
47
|
+
end
|
48
|
+
|
49
|
+
# partial with locals
|
50
|
+
get '/partial/locals' do
|
51
|
+
partial 'template/user', :locals => { :user => RenderUser.new('John'), :extra => "bar" }
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>This is a <%= @template %> template!</h1>
|
@@ -0,0 +1 @@
|
|
1
|
+
%h1 This is a #{@template} template!
|
@@ -0,0 +1 @@
|
|
1
|
+
%h1 This is a #{@template} template sent from render_template!
|
data/test/helper.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
require 'rack/test'
|
6
|
+
require 'webrat'
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
10
|
+
require 'active_support_helpers'
|
11
|
+
require File.dirname(__FILE__) + '/../lib/padrino-helpers.rb'
|
12
|
+
|
13
|
+
class Test::Unit::TestCase
|
14
|
+
include Padrino::Helpers::OutputHelpers
|
15
|
+
include Padrino::Helpers::TagHelpers
|
16
|
+
include Padrino::Helpers::AssetTagHelpers
|
17
|
+
include Rack::Test::Methods
|
18
|
+
include Webrat::Methods
|
19
|
+
include Webrat::Matchers
|
20
|
+
|
21
|
+
Webrat.configure do |config|
|
22
|
+
config.mode = :rack
|
23
|
+
end
|
24
|
+
|
25
|
+
def stop_time_for_test
|
26
|
+
time = Time.now
|
27
|
+
Time.stubs(:now).returns(time)
|
28
|
+
return time
|
29
|
+
end
|
30
|
+
|
31
|
+
# assert_has_tag(:h1, :content => "yellow") { "<h1>yellow</h1>" }
|
32
|
+
# In this case, block is the html to evaluate
|
33
|
+
def assert_has_tag(name, attributes = {}, &block)
|
34
|
+
html = block && block.call
|
35
|
+
matcher = HaveSelector.new(name, attributes)
|
36
|
+
raise "Please specify a block!" if html.blank?
|
37
|
+
assert matcher.matches?(html), matcher.failure_message
|
38
|
+
end
|
39
|
+
|
40
|
+
# assert_has_no_tag, tag(:h1, :content => "yellow") { "<h1>green</h1>" }
|
41
|
+
# In this case, block is the html to evaluate
|
42
|
+
def assert_has_no_tag(name, attributes = {}, &block)
|
43
|
+
html = block && block.call
|
44
|
+
attributes.merge!(:count => 0)
|
45
|
+
matcher = HaveSelector.new(name, attributes)
|
46
|
+
raise "Please specify a block!" if html.blank?
|
47
|
+
assert matcher.matches?(html), matcher.failure_message
|
48
|
+
end
|
49
|
+
|
50
|
+
# Silences the output by redirecting to stringIO
|
51
|
+
# silence_logger { ...commands... } => "...output..."
|
52
|
+
def silence_logger(&block)
|
53
|
+
orig_stdout = $stdout
|
54
|
+
$stdout = log_buffer = StringIO.new
|
55
|
+
block.call
|
56
|
+
$stdout = orig_stdout
|
57
|
+
log_buffer.rewind && log_buffer.read
|
58
|
+
end
|
59
|
+
|
60
|
+
# Asserts that a file matches the pattern
|
61
|
+
def assert_match_in_file(pattern, file)
|
62
|
+
assert File.exist?(file), "File '#{file}' does not exist!"
|
63
|
+
assert_match pattern, File.read(file)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
module Webrat
|
68
|
+
module Logging
|
69
|
+
def logger # :nodoc:
|
70
|
+
@logger = nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require File.dirname(__FILE__) + '/fixtures/markup_app/app'
|
3
|
+
|
4
|
+
class TestAssetTagHelpers < Test::Unit::TestCase
|
5
|
+
include Padrino::Helpers::AssetTagHelpers
|
6
|
+
|
7
|
+
def app
|
8
|
+
MarkupDemo.tap { |app| app.set :environment, :test }
|
9
|
+
end
|
10
|
+
|
11
|
+
def flash
|
12
|
+
{ :notice => "Demo notice" }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'for #flash_tag method' do
|
16
|
+
should "display flash with no given attributes" do
|
17
|
+
assert_has_tag('div.flash', :content => "Demo notice") { flash_tag(:notice) }
|
18
|
+
end
|
19
|
+
should "display flash with given attributes" do
|
20
|
+
actual_html = flash_tag(:notice, :class => 'notice', :id => 'notice-area')
|
21
|
+
assert_has_tag('div.notice#notice-area', :content => "Demo notice") { actual_html }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'for #link_to method' do
|
26
|
+
should "display link element with no given attributes" do
|
27
|
+
assert_has_tag('a', :content => "Sign up", :href => '/register') { link_to('Sign up', '/register') }
|
28
|
+
end
|
29
|
+
should "display link element with given attributes" do
|
30
|
+
actual_html = link_to('Sign up', '/register', :class => 'first', :id => 'linky')
|
31
|
+
assert_has_tag('a#linky.first', :content => "Sign up", :href => '/register') { actual_html }
|
32
|
+
end
|
33
|
+
should "display link element with ruby block" do
|
34
|
+
actual_link = link_to('/register', :class => 'first', :id => 'binky') { "Sign up" }
|
35
|
+
assert_has_tag('a#binky.first', :content => "Sign up", :href => '/register') { actual_link }
|
36
|
+
end
|
37
|
+
should "display link block element in haml" do
|
38
|
+
visit '/haml/link_to'
|
39
|
+
assert_have_selector :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1'
|
40
|
+
assert_have_selector :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2'
|
41
|
+
end
|
42
|
+
should "display link block element in erb" do
|
43
|
+
visit '/erb/link_to'
|
44
|
+
assert_have_selector :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1'
|
45
|
+
assert_have_selector :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'for #mail_to method' do
|
50
|
+
should "display link element for mail to no caption" do
|
51
|
+
actual_html = mail_to('test@demo.com')
|
52
|
+
assert_has_tag(:a, :href => "mailto:test@demo.com", :content => 'test@demo.com') { actual_html }
|
53
|
+
end
|
54
|
+
|
55
|
+
should "display link element for mail to with caption" do
|
56
|
+
actual_html = mail_to('test@demo.com', "My Email", :class => 'demo')
|
57
|
+
assert_has_tag(:a, :href => "mailto:test@demo.com", :content => 'My Email', :class => 'demo') { actual_html }
|
58
|
+
end
|
59
|
+
|
60
|
+
should "display link element for mail to with caption and mail options" do
|
61
|
+
actual_html = mail_to('test@demo.com', "My Email", :subject => 'demo test', :class => 'demo', :cc => 'foo@test.com')
|
62
|
+
assert_has_tag(:a, :class => 'demo') { actual_html }
|
63
|
+
assert_match /mailto\:test\@demo.com\?/, actual_html
|
64
|
+
assert_match /cc=foo\@test\.com/, actual_html
|
65
|
+
assert_match /subject\=demo\%20test/, actual_html
|
66
|
+
end
|
67
|
+
|
68
|
+
should "display mail link element in haml" do
|
69
|
+
visit '/haml/mail_to'
|
70
|
+
assert_have_selector 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
|
71
|
+
assert_have_selector 'p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'
|
72
|
+
end
|
73
|
+
|
74
|
+
should "display mail link element in erb" do
|
75
|
+
visit '/erb/mail_to'
|
76
|
+
assert_have_selector 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
|
77
|
+
assert_have_selector 'p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'for #image_tag method' do
|
82
|
+
should "display image tag absolute link with no options" do
|
83
|
+
assert_has_tag('img', :src => "/absolute/pic.gif") { image_tag('/absolute/pic.gif') }
|
84
|
+
end
|
85
|
+
should "display image tag relative link with options" do
|
86
|
+
assert_has_tag('img.photo', :src => "/images/relative/pic.gif") { image_tag('relative/pic.gif', :class => 'photo') }
|
87
|
+
end
|
88
|
+
should "display image tag uri link with options" do
|
89
|
+
assert_has_tag('img.photo', :src => "http://demo.org/pic.gif") { image_tag('http://demo.org/pic.gif', :class => 'photo') }
|
90
|
+
end
|
91
|
+
should "display image tag relative link with incorrect spacing" do
|
92
|
+
assert_has_tag('img.photo', :src => "/images/relative/pic.gif") { image_tag(' relative/ pic.gif ', :class => 'photo') }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'for #stylesheet_link_tag method' do
|
97
|
+
should "display stylesheet link item" do
|
98
|
+
time = stop_time_for_test
|
99
|
+
expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
|
100
|
+
assert_has_tag('link', expected_options.merge(:href => "/stylesheets/style.css?#{time.to_i}")) { stylesheet_link_tag('style') }
|
101
|
+
end
|
102
|
+
should "display stylesheet link items" do
|
103
|
+
time = stop_time_for_test
|
104
|
+
actual_html = stylesheet_link_tag('style', 'layout.css', 'http://google.com/style.css')
|
105
|
+
assert_has_tag('link', :media => "screen", :rel => "stylesheet", :type => "text/css", :count => 3) { actual_html }
|
106
|
+
assert_has_tag('link', :href => "/stylesheets/style.css?#{time.to_i}") { actual_html }
|
107
|
+
assert_has_tag('link', :href => "/stylesheets/layout.css?#{time.to_i}") { actual_html }
|
108
|
+
assert_has_tag('link', :href => "http://google.com/style.css") { actual_html }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'for #javascript_include_tag method' do
|
113
|
+
should "display javascript item" do
|
114
|
+
time = stop_time_for_test
|
115
|
+
actual_html = javascript_include_tag('application')
|
116
|
+
assert_has_tag('script', :src => "/javascripts/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
|
117
|
+
end
|
118
|
+
should "display javascript items" do
|
119
|
+
time = stop_time_for_test
|
120
|
+
actual_html = javascript_include_tag('application', 'base.js', 'http://google.com/lib.js')
|
121
|
+
assert_has_tag('script', :type => "text/javascript", :count => 3) { actual_html }
|
122
|
+
assert_has_tag('script', :src => "/javascripts/application.js?#{time.to_i}") { actual_html }
|
123
|
+
assert_has_tag('script', :src => "/javascripts/base.js?#{time.to_i}") { actual_html }
|
124
|
+
assert_has_tag('script', :src => "http://google.com/lib.js") { actual_html }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|