any_view 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +47 -0
  4. data/README.rdoc +369 -0
  5. data/Rakefile +57 -0
  6. data/lib/any_view/asset_tag_helpers.rb +103 -0
  7. data/lib/any_view/core_ext/array.rb +7 -0
  8. data/lib/any_view/core_ext/hash.rb +41 -0
  9. data/lib/any_view/core_ext/string.rb +17 -0
  10. data/lib/any_view/form_builder/abstract_form_builder.rb +128 -0
  11. data/lib/any_view/form_builder/standard_form_builder.rb +37 -0
  12. data/lib/any_view/form_helpers.rb +217 -0
  13. data/lib/any_view/format_helpers.rb +49 -0
  14. data/lib/any_view/tag_helpers.rb +47 -0
  15. data/lib/any_view/tilt_base.rb +94 -0
  16. data/lib/any_view.rb +30 -0
  17. data/test/fixtures/basic_form_for.erb +3 -0
  18. data/test/fixtures/builder_type_form_for.erb +3 -0
  19. data/test/fixtures/capture_concat.erb +14 -0
  20. data/test/fixtures/capture_concat.haml +13 -0
  21. data/test/fixtures/content_for.erb +11 -0
  22. data/test/fixtures/content_for.haml +9 -0
  23. data/test/fixtures/content_tag.erb +11 -0
  24. data/test/fixtures/content_tag.haml +9 -0
  25. data/test/fixtures/delete_form_for.erb +3 -0
  26. data/test/fixtures/field_set_tag.erb +3 -0
  27. data/test/fixtures/fields_for.erb +8 -0
  28. data/test/fixtures/fields_for.haml +6 -0
  29. data/test/fixtures/fields_for_basic.erb +3 -0
  30. data/test/fixtures/fields_for_nil.erb +3 -0
  31. data/test/fixtures/form_for.erb +56 -0
  32. data/test/fixtures/form_for.haml +47 -0
  33. data/test/fixtures/form_for_nil.erb +3 -0
  34. data/test/fixtures/form_tag.erb +57 -0
  35. data/test/fixtures/form_tag.haml +45 -0
  36. data/test/fixtures/form_tag_methods.erb +19 -0
  37. data/test/fixtures/form_tag_methods.haml +15 -0
  38. data/test/fixtures/link_to.erb +5 -0
  39. data/test/fixtures/link_to.haml +4 -0
  40. data/test/fixtures/mail_to.erb +3 -0
  41. data/test/fixtures/mail_to.haml +3 -0
  42. data/test/fixtures/multipart.erb +12 -0
  43. data/test/fixtures/multipart_form_for.erb +3 -0
  44. data/test/fixtures/put_form_for.erb +3 -0
  45. data/test/fixtures/standard_form_builder.erb +3 -0
  46. data/test/helper.rb +121 -0
  47. data/test/test_asset_tag_helpers.rb +176 -0
  48. data/test/test_form_builder.rb +607 -0
  49. data/test/test_form_helpers.rb +453 -0
  50. data/test/test_format_helpers.rb +59 -0
  51. data/test/test_tag_helpers.rb +65 -0
  52. metadata +160 -0
@@ -0,0 +1,9 @@
1
+ = content_tag :p, "Test 1", :class => 'test', :id => "test1"
2
+
3
+ = content_tag :p, "Test 2"
4
+
5
+ - content_tag(:p, :class => 'test', :id => 'test3') do
6
+ %span Test 3
7
+
8
+ - content_tag(:p) do
9
+ %span Test 4
@@ -0,0 +1,3 @@
1
+ <% form_for MarkupUser.new, "/destroy", :method => :delete do |f| %>
2
+ <p>Demo</p>
3
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <% field_set_tag "Basic", :class => "basic" do %>
2
+ <p>Demo</p>
3
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <% @user = MarkupUser.new %>
2
+ <% form_for @user , '/demo1', :id => 'demo-fields-for' do |f| %>
3
+ <%= f.text_field :gender %>
4
+ <% fields_for @user.permission do |permission| %>
5
+ <%= permission.check_box :can_edit %>
6
+ <%= permission.check_box :can_delete %>
7
+ <% end %>
8
+ <% end %>
@@ -0,0 +1,6 @@
1
+ - @user = MarkupUser.new
2
+ - form_for @user , '/demo1', :id => 'demo-fields-for' do |f|
3
+ = f.text_field :gender
4
+ - fields_for @user.permission do |permission|
5
+ = permission.check_box :can_edit
6
+ = permission.check_box :can_delete
@@ -0,0 +1,3 @@
1
+ <% fields_for MarkupUser.new do |f| %>
2
+ <%= f.text_field(:first_name) %>
3
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <% fields_for nil do |f| %>
2
+ <p>Demo</p>
3
+ <% end %>
@@ -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,3 @@
1
+ <% form_for nil, "/register", :id => "register", :method => :post do |f| %>
2
+ <div>Demo</div>
3
+ <% end %>
@@ -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 => :put 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 => 'username', :id => 'the_username' %>
26
+ </p>
27
+ <p>
28
+ <%= label_tag :password, :class => 'first' %>
29
+ <%= password_field_tag :password, :value => '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 => 'username', :id => 'the_username'
24
+ %p
25
+ = label_tag :password, :class => 'first'
26
+ = password_field_tag :password, :value => '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,19 @@
1
+ <% form_tag "/default", :class => "method-default" do %>
2
+ <p>default</p>
3
+ <% end %>
4
+
5
+ <% form_tag "/put", :class => "method-put", :method => :put do %>
6
+ <p>put</p>
7
+ <% end %>
8
+
9
+ <% form_tag "/delete", :class => "method-delete", :method => :delete do %>
10
+ <p>Delete</p>
11
+ <% end %>
12
+
13
+ <% form_tag "/post", :class => "method-post", :method => :post do %>
14
+ <p>post</p>
15
+ <% end %>
16
+
17
+ <% form_tag "/get", :class => "method-get", :method => :get do %>
18
+ <p>get</p>
19
+ <% end %>
@@ -0,0 +1,15 @@
1
+ - form_tag "/default", :class => "method-default" do
2
+ %p default
3
+
4
+ - form_tag "/put", :class => "method-put", :method => :put do
5
+ %p put
6
+
7
+ - form_tag "/delete", :class => "method-delete", :method => :delete do
8
+ %p Delete
9
+
10
+ - form_tag "/post", :class => "method-post", :method => :post do
11
+ %p post
12
+
13
+ - form_tag "/get", :class => "method-get", :method => :get do
14
+ %p get
15
+
@@ -0,0 +1,5 @@
1
+ <%= link_to "Test 1 No Block", '/test1', :class => 'test', :id => 'test1' %>
2
+
3
+ <% link_to("/test2", :class => 'test', :id => 'test2') do %>
4
+ <span>Test 2 With Block</span>
5
+ <% end %>
@@ -0,0 +1,4 @@
1
+ = link_to "Test 1 No Block", '/test1', :class => 'test', :id => 'test1'
2
+
3
+ - link_to("/test2", :class => 'test', :id => 'test2') do
4
+ %span Test 2 With Block
@@ -0,0 +1,3 @@
1
+ <p class='simple'><%= mail_to 'test@demo.com' %></p>
2
+
3
+ <p class='captioned'><%= mail_to 'test@demo.com', "Click my Email" %></p>
@@ -0,0 +1,3 @@
1
+ %p.simple= mail_to 'test@demo.com'
2
+
3
+ %p.captioned= mail_to 'test@demo.com', "Click my Email"
@@ -0,0 +1,12 @@
1
+ <% form_tag "/explicit", :multipart => true, :class => "explicit" do %>
2
+ <p>Here</p>
3
+ <% end %>
4
+
5
+ <% form_tag "/implicit", :class => "implicit" do %>
6
+ <%= file_field_tag :foo %>
7
+ <% end %>
8
+
9
+ <% form_tag "/no_file", :class => "no_file" do %>
10
+ <p>No file to see here</p>
11
+ <% end %>
12
+
@@ -0,0 +1,3 @@
1
+ <% form_for MarkupUser.new, "/register" do |f| %>
2
+ <%= f.file_field_block :image %>
3
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <% form_for MarkupUser.new, "/update", :method => :put do |f| %>
2
+ <p>Demo</p>
3
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <% form_for MarkupUser.new, "/register" do |f| %>
2
+ <%= f.text_field_block(:name) %>
3
+ <% end %>
data/test/helper.rb ADDED
@@ -0,0 +1,121 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'webrat'
5
+ require 'mocha'
6
+
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
9
+ require File.dirname(__FILE__) + '/../lib/any_view'
10
+
11
+ class Renderer
12
+ class ViewContext
13
+ include AnyView::TiltBase
14
+ include AnyView
15
+ end
16
+
17
+ def self.path
18
+ @path ||= File.expand_path(~'./fixtures')
19
+ end
20
+
21
+ def self.template(name)
22
+ Tilt.new(File.join(path, name))
23
+ end
24
+
25
+ def template(name)
26
+ self.class.template(name)
27
+ end
28
+
29
+ def render(name, locals = {})
30
+ template(name).render(ViewContext.new, locals)
31
+ end
32
+ end
33
+
34
+ class Test::Unit::TestCase
35
+
36
+ def view_context
37
+ Renderer::ViewContext.new
38
+ end
39
+
40
+ def render(*args)
41
+ Renderer.new.render(*args)
42
+ end
43
+
44
+ def stop_time_for_test
45
+ time = Time.now
46
+ Time.stubs(:now).returns(time)
47
+ return time
48
+ end
49
+
50
+ # assert_has_tag(:h1, :content => "yellow") { "<h1>yellow</h1>" }
51
+ # In this case, block is the html to evaluate
52
+ def assert_has_tag(name, attributes = {}, &block)
53
+ html = block && block.call
54
+ matcher = Webrat::Matchers::HaveSelector.new(name, attributes)
55
+ raise "Please specify a block!" if html.blank?
56
+ assert matcher.matches?(html), matcher.failure_message
57
+ end
58
+
59
+ # assert_has_no_tag, tag(:h1, :content => "yellow") { "<h1>green</h1>" }
60
+ # In this case, block is the html to evaluate
61
+ def assert_has_no_tag(name, attributes = {}, &block)
62
+ html = block && block.call
63
+ attributes.merge!(:count => 0)
64
+ matcher = Webrat::Matchers::HaveSelector.new(name, attributes)
65
+ raise "Please specify a block!" if html.blank?
66
+ assert matcher.matches?(html), matcher.failure_message
67
+ end
68
+
69
+ def assert_has_selector(name, attributes = {}, &block)
70
+ html = block && block.call
71
+ matcher = Webrat::Matchers::HaveSelector.new(name, attributes)
72
+ raise "Please specify a block!" if html.blank?
73
+ assert matcher.matches?(html), matcher.failure_message
74
+ end
75
+
76
+ def assert_has_no_selector(name, attributes = {}, &block)
77
+ html = block && block.call
78
+ matcher = Webrat::Matchers::HaveSelector.new(name, attributes)
79
+ raise "Please specify a block!" if html.blank?
80
+ assert !matcher.matches?(html), matcher.negative_failure_message
81
+ end
82
+
83
+ # Silences the output by redirecting to stringIO
84
+ # silence_logger { ...commands... } => "...output..."
85
+ def silence_logger(&block)
86
+ orig_stdout = $stdout
87
+ $stdout = log_buffer = StringIO.new
88
+ block.call
89
+ $stdout = orig_stdout
90
+ log_buffer.rewind && log_buffer.read
91
+ end
92
+
93
+ # Asserts that a file matches the pattern
94
+ def assert_match_in_file(pattern, file)
95
+ assert File.exist?(file), "File '#{file}' does not exist!"
96
+ assert_match pattern, File.read(file)
97
+ end
98
+ end
99
+
100
+ class MarkupUser
101
+ def errors; Errors.new; end
102
+ def session_id; 45; end
103
+ def gender; 'male'; end
104
+ def remember_me; '1'; end
105
+ def image; end
106
+ def permission; Permission.new; end
107
+ end
108
+
109
+ class Permission
110
+ def can_edit; true; end
111
+ def can_delete; false; end
112
+ end
113
+
114
+ class Errors < Array
115
+ def initialize; self << [:fake, :second, :third]; end
116
+ def full_messages
117
+ ["This is a fake error", "This is a second fake error", "This is a third fake error"]
118
+ end
119
+ end
120
+
121
+
@@ -0,0 +1,176 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestAssetTagHelpers < Test::Unit::TestCase
4
+
5
+ context 'for #link_to method' do
6
+ should "display link element with no given attributes" do
7
+ assert_has_tag('a', :content => "Sign up", :href => '/register') { view_context.link_to('Sign up', '/register') }
8
+ end
9
+
10
+ should "display link element with given attributes" do
11
+ actual_html = view_context.link_to('Sign up', '/register', :class => 'first', :id => 'linky')
12
+ assert_has_tag('a#linky.first', :content => "Sign up", :href => '/register') { actual_html }
13
+ end
14
+
15
+ should "#link_tag display link content from a block in erb" do
16
+ actual_html = render("link_to.erb")
17
+ assert_has_tag('a#test2.test', :content => "Test 2 With Block", :href => '/test2') { actual_html }
18
+ end
19
+
20
+ should "#link_tag display link content from a string with no block in erb" do
21
+ actual_html = render("link_to.erb")
22
+ assert_has_tag('a#test1.test', :content => "Test 1 No Block", :href => "/test1"){actual_html}
23
+ end
24
+
25
+ should "#link_to should display the block in haml" do
26
+ actual_html = render("link_to.haml")
27
+ assert_has_tag('a#test2.test', :content => "Test 2 With Block", :href => "/test2"){ actual_html }
28
+ end
29
+
30
+ should "#link_tag display link content from a string with no block in haml" do
31
+ actual_html = render("link_to.haml")
32
+ assert_has_tag('a#test1.test', :content => "Test 1 No Block", :href => "/test1"){actual_html}
33
+ end
34
+ end
35
+
36
+ context 'for #mail_to method' do
37
+ should "display link element for mail to no caption" do
38
+ actual_html = view_context.mail_to('test@demo.com')
39
+ assert_has_tag(:a, :href => "mailto:test@demo.com", :content => 'test@demo.com') { actual_html }
40
+ end
41
+
42
+ should "display link element for mail to with caption" do
43
+ actual_html = view_context.mail_to('test@demo.com', "My Email", :class => 'demo')
44
+ assert_has_tag(:a, :href => "mailto:test@demo.com", :content => 'My Email', :class => 'demo') { actual_html }
45
+ end
46
+
47
+ should "display link element for mail to with caption and mail options" do
48
+ actual_html = view_context.mail_to('test@demo.com', "My Email", :subject => 'demo test', :class => 'demo', :cc => 'foo@test.com')
49
+ assert_has_tag(:a, :class => 'demo') { actual_html }
50
+ assert_match /mailto\:test\@demo.com\?/, actual_html
51
+ assert_match /cc=foo\@test\.com/, actual_html
52
+ assert_match /subject\=demo\%20test/, actual_html
53
+ end
54
+
55
+ should "display mail link element in haml" do
56
+ result = render("mail_to.haml")
57
+ assert_has_selector('p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'){result}
58
+ assert_has_selector('p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'){result}
59
+ end
60
+
61
+ should "display mail link element in erb" do
62
+ result = render("mail_to.erb")
63
+ assert_has_selector('p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'){result}
64
+ assert_has_selector('p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'){result}
65
+ end
66
+ end
67
+
68
+ context 'for #image_tag method' do
69
+ should "display image tag absolute link with no options" do
70
+ assert_has_tag('img', :src => "/absolute/pic.gif") { view_context.image_tag('/absolute/pic.gif') }
71
+ end
72
+
73
+ should "display image tag absolute link with specified uri root" do
74
+ vc = view_context
75
+ vc.stubs(:uri_root).returns("/blog")
76
+ assert_has_tag('img', :src => "/blog/images/relative/pic.gif") { vc.image_tag('relative/pic.gif') }
77
+ end
78
+
79
+ should "display image tag relative link with options" do
80
+ assert_has_tag('img.photo', :src => "/images/relative/pic.gif") { view_context.image_tag('relative/pic.gif', :class => 'photo') }
81
+ end
82
+
83
+ should "display image tag uri link with options" do
84
+ assert_has_tag('img.photo', :src => "http://demo.org/pic.gif") { view_context.image_tag('http://demo.org/pic.gif', :class => 'photo') }
85
+ end
86
+
87
+ should "display image tag relative link with incorrect spacing" do
88
+ assert_has_tag('img.photo', :src => "/images/relative/pic.gif") { view_context.image_tag(' relative/ pic.gif ', :class => 'photo') }
89
+ end
90
+ end
91
+
92
+ context 'for #stylesheet_link_tag method' do
93
+ should "display stylesheet link item" do
94
+ time = stop_time_for_test
95
+ expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
96
+ assert_has_tag('link', expected_options.merge(:href => "/stylesheets/style.css?#{time.to_i}")) { view_context.stylesheet_link_tag('style') }
97
+ end
98
+ should "display stylesheet link item for long relative path" do
99
+ time = stop_time_for_test
100
+ expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
101
+ actual_html = view_context.stylesheet_link_tag('example/demo/style')
102
+ assert_has_tag('link', expected_options.merge(:href => "/stylesheets/example/demo/style.css?#{time.to_i}")) { actual_html }
103
+ end
104
+ should "display stylesheet link item with absolute path" do
105
+ time = stop_time_for_test
106
+ expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
107
+ actual_html = view_context.stylesheet_link_tag('/css/style')
108
+ assert_has_tag('link', expected_options.merge(:href => "/css/style.css?#{time.to_i}")) { actual_html }
109
+ end
110
+ should "display stylesheet link item with uri root" do
111
+ vc = view_context
112
+ vc.stubs(:uri_root).returns("/blog")
113
+ time = stop_time_for_test
114
+ expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
115
+ actual_html = vc.stylesheet_link_tag('style')
116
+ assert_has_tag('link', expected_options.merge(:href => "/blog/stylesheets/style.css?#{time.to_i}")) { actual_html }
117
+ end
118
+ should "display stylesheet link items" do
119
+ time = stop_time_for_test
120
+ actual_html = view_context.stylesheet_link_tag('style', 'layout.css', 'http://google.com/style.css')
121
+ assert_has_tag('link', :media => "screen", :rel => "stylesheet", :type => "text/css", :count => 3) { actual_html }
122
+ assert_has_tag('link', :href => "/stylesheets/style.css?#{time.to_i}") { actual_html }
123
+ assert_has_tag('link', :href => "/stylesheets/layout.css?#{time.to_i}") { actual_html }
124
+ assert_has_tag('link', :href => "http://google.com/style.css") { actual_html }
125
+ end
126
+ end
127
+
128
+ context 'for #javascript_include_tag method' do
129
+ should "display javascript item" do
130
+ time = stop_time_for_test
131
+ actual_html = view_context.javascript_include_tag('application')
132
+ assert_has_tag('script', :src => "/javascripts/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
133
+ end
134
+
135
+ should "display javascript item for long relative path" do
136
+ time = stop_time_for_test
137
+ actual_html = view_context.javascript_include_tag('example/demo/application')
138
+ assert_has_tag('script', :src => "/javascripts/example/demo/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
139
+ end
140
+
141
+ should "display javascript item for path containing js" do
142
+ time = stop_time_for_test
143
+ actual_html = view_context.javascript_include_tag 'test/jquery.json'
144
+ assert_has_tag('script', :src => "/javascripts/test/jquery.json?#{time.to_i}", :type => "text/javascript") { actual_html }
145
+ end
146
+
147
+ should "display javascript item for path containing period" do
148
+ time = stop_time_for_test
149
+ actual_html = view_context.javascript_include_tag 'test/jquery.min'
150
+ assert_has_tag('script', :src => "/javascripts/test/jquery.min.js?#{time.to_i}", :type => "text/javascript") { actual_html }
151
+ end
152
+
153
+ should "display javascript item with absolute path" do
154
+ time = stop_time_for_test
155
+ actual_html = view_context.javascript_include_tag('/js/application')
156
+ assert_has_tag('script', :src => "/js/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
157
+ end
158
+
159
+ should "display javascript item with uri root" do
160
+ vc = view_context
161
+ vc.stubs(:uri_root).returns("/blog")
162
+ time = stop_time_for_test
163
+ actual_html = vc.javascript_include_tag('application')
164
+ assert_has_tag('script', :src => "/blog/javascripts/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
165
+ end
166
+
167
+ should "display javascript items" do
168
+ time = stop_time_for_test
169
+ actual_html = view_context.javascript_include_tag('application', 'base.js', 'http://google.com/lib.js')
170
+ assert_has_tag('script', :type => "text/javascript", :count => 3) { actual_html }
171
+ assert_has_tag('script', :src => "/javascripts/application.js?#{time.to_i}") { actual_html }
172
+ assert_has_tag('script', :src => "/javascripts/base.js?#{time.to_i}") { actual_html }
173
+ assert_has_tag('script', :src => "http://google.com/lib.js") { actual_html }
174
+ end
175
+ end
176
+ end