sinatra_more 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -4
- data/TODO +4 -0
- data/VERSION +1 -1
- data/lib/sinatra_more/markup_plugin/form_helpers.rb +7 -8
- data/lib/sinatra_more/markup_plugin/output_helpers.rb +11 -2
- data/lib/sinatra_more/markup_plugin/tag_helpers.rb +0 -1
- data/sinatra_more.gemspec +4 -2
- data/test/fixtures/markup_app/app.rb +26 -5
- data/test/fixtures/markup_app/views/form_tag.erb +35 -0
- data/test/fixtures/markup_app/views/form_tag.haml +26 -0
- data/test/helper.rb +10 -1
- data/test/markup_plugin/test_asset_tag_helpers.rb +26 -27
- data/test/markup_plugin/test_form_builder.rb +61 -1
- data/test/markup_plugin/test_form_helpers.rb +208 -1
- data/test/markup_plugin/test_tag_helpers.rb +13 -8
- metadata +4 -2
data/README.rdoc
CHANGED
@@ -152,7 +152,7 @@ A form_tag might look like:
|
|
152
152
|
= text_field_tag :username, :value => params[:username]
|
153
153
|
%p
|
154
154
|
= label_tag :password, :class => 'first'
|
155
|
-
=
|
155
|
+
= password_field_tag :password, :value => params[:password]
|
156
156
|
- field_set_tag(:class => 'buttons') do
|
157
157
|
= submit_tag "Login"
|
158
158
|
|
@@ -280,10 +280,10 @@ provided to make interacting with warden dead simple.
|
|
280
280
|
|
281
281
|
== Acknowledgements
|
282
282
|
|
283
|
-
|
284
|
-
|
283
|
+
* Thanks to keldredd for the sinatra_helpers code that helped me to create erb capture and concat methods.
|
284
|
+
* Thanks to sbfaulkner for the sinatra-helpers code that I looked while starting this library.
|
285
285
|
|
286
|
-
==
|
286
|
+
== Contributors
|
287
287
|
|
288
288
|
* Nathan Esquenazi - Project creator and code maintainer
|
289
289
|
* Arthur Chiu - Forming the idea and various code contributions
|
data/TODO
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
= UNFINISHED
|
2
2
|
|
3
3
|
* Become total warden solution (basically just require warden gem installed, do everything else)
|
4
|
+
* Look into removing overlapping methods and simply leverage sinatra_warden
|
5
|
+
* Take advantage of shared strategies: http://github.com/hassox/warden_strategies/tree/master/lib/
|
4
6
|
* Make warden password strategy support a callback which explains what to do with username, password
|
5
7
|
* WardenPlugin.authenticate_callback { |username, password| User.authenticate(username, password) }
|
6
8
|
* Remove dependency on activesupport! and enumerate dependencies in rakefile
|
9
|
+
* Add support for missing formhelpers/fields (check_box, radio_button, ...)
|
10
|
+
* Add support for forms with method => put, delete using hidden field
|
7
11
|
* Look into creating sinatra generators using rubigen (http://github.com/drnic/rubigen)
|
8
12
|
* http://github.com/quirkey/sinatra-gen
|
9
13
|
* Look into adding any missing helpers from:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
@@ -3,7 +3,8 @@ module SinatraMore
|
|
3
3
|
# Constructs a form for object using given or default form_builder
|
4
4
|
# form_for @user, '/register', :id => 'register' do |f| ... end
|
5
5
|
def form_for(object, url, settings={}, &block)
|
6
|
-
|
6
|
+
default_builder = self.respond_to?(:options) && self.options.default_builder
|
7
|
+
configured_builder = settings[:builder] || default_builder || 'StandardFormBuilder'
|
7
8
|
configured_builder = configured_builder.constantize if configured_builder.is_a?(String)
|
8
9
|
settings.reverse_merge!(:method => 'post', :action => url)
|
9
10
|
settings[:enctype] = "multipart/form-data" if settings.delete(:multipart)
|
@@ -35,12 +36,10 @@ module SinatraMore
|
|
35
36
|
return "" if record.blank? or record.errors.none?
|
36
37
|
options.reverse_merge!(:header_message => "The #{record.class.to_s.downcase} could not be saved!")
|
37
38
|
error_messages = record.errors.full_messages
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
39
|
+
error_items = error_messages.collect { |er| content_tag(:li, er) }.join("\n")
|
40
|
+
error_html = content_tag(:p, options.delete(:header_message))
|
41
|
+
error_html << content_block_tag(:ul, error_items, :class => 'errors-list')
|
42
|
+
content_block_tag(:div, error_html, :class => 'field-errors')
|
44
43
|
end
|
45
44
|
|
46
45
|
# Constructs a label tag from the given options
|
@@ -87,7 +86,7 @@ module SinatraMore
|
|
87
86
|
|
88
87
|
# Constructs a submit button from the given options
|
89
88
|
# submit_tag "Create", :class => 'success'
|
90
|
-
def submit_tag(caption, options={})
|
89
|
+
def submit_tag(caption="Submit", options={})
|
91
90
|
options.reverse_merge!(:value => caption)
|
92
91
|
input_tag(:submit, options)
|
93
92
|
end
|
@@ -16,8 +16,10 @@ module SinatraMore
|
|
16
16
|
def concat_content(text="")
|
17
17
|
if self.respond_to?(:is_haml?) && is_haml?
|
18
18
|
haml_concat(text)
|
19
|
-
|
20
|
-
|
19
|
+
elsif @_out_buf
|
20
|
+
erb_concat(text)
|
21
|
+
else # theres no place to concat
|
22
|
+
text
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
@@ -29,6 +31,7 @@ module SinatraMore
|
|
29
31
|
end
|
30
32
|
|
31
33
|
protected
|
34
|
+
|
32
35
|
|
33
36
|
# Used to capture the html from a block of erb code
|
34
37
|
# capture_erb(&block) => '...html...'
|
@@ -36,6 +39,12 @@ module SinatraMore
|
|
36
39
|
erb_with_output_buffer { block.call(*args) }
|
37
40
|
end
|
38
41
|
|
42
|
+
# Concats directly to an erb template
|
43
|
+
# erb_concat("Direct to buffer")
|
44
|
+
def erb_concat(text)
|
45
|
+
@_out_buf << text unless @_out_buf.nil?
|
46
|
+
end
|
47
|
+
|
39
48
|
# Used to determine if a block is called from ERB.
|
40
49
|
# NOTE: This doesn't actually work yet because the variable __in_erb_template
|
41
50
|
# hasn't been defined in ERB. We need to find a way to fix this.
|
@@ -25,7 +25,6 @@ module SinatraMore
|
|
25
25
|
# tag(:p, :content => "hello", :class => 'large')
|
26
26
|
def tag(name, options={})
|
27
27
|
content = options.delete(:content)
|
28
|
-
options = options.sort { |a, b| a.to_s <=> b.to_s }
|
29
28
|
html_attrs = options.collect { |a, v| v.blank? ? nil : "#{a}=\"#{v}\"" }.compact.join(" ")
|
30
29
|
base_tag = (html_attrs.present? ? "<#{name} #{html_attrs}" : "<#{name}")
|
31
30
|
base_tag << (content ? ">#{content}</#{name}>" : " />")
|
data/sinatra_more.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sinatra_more}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nathan Esquenazi"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-27}
|
13
13
|
s.description = %q{Expands sinatra with standard helpers and tools to allow for complex applications}
|
14
14
|
s.email = %q{nesquena@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -43,6 +43,8 @@ Gem::Specification.new do |s|
|
|
43
43
|
"test/fixtures/markup_app/views/capture_concat.haml",
|
44
44
|
"test/fixtures/markup_app/views/content_tag.erb",
|
45
45
|
"test/fixtures/markup_app/views/content_tag.haml",
|
46
|
+
"test/fixtures/markup_app/views/form_tag.erb",
|
47
|
+
"test/fixtures/markup_app/views/form_tag.haml",
|
46
48
|
"test/fixtures/markup_app/views/link_to.erb",
|
47
49
|
"test/fixtures/markup_app/views/link_to.haml",
|
48
50
|
"test/fixtures/render_app/app.rb",
|
@@ -9,7 +9,12 @@ class MarkupDemo < Sinatra::Base
|
|
9
9
|
configure do
|
10
10
|
set :root, File.dirname(__FILE__)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
|
+
get '/:engine/form_tag' do
|
14
|
+
@user = User.new
|
15
|
+
show(params[:engine], 'form_tag')
|
16
|
+
end
|
17
|
+
|
13
18
|
get '/:engine/:file' do
|
14
19
|
show(params[:engine], params[:file].to_sym)
|
15
20
|
end
|
@@ -20,22 +25,22 @@ class MarkupDemo < Sinatra::Base
|
|
20
25
|
def show(kind, template)
|
21
26
|
eval("#{kind.to_s} #{template.to_sym.inspect}")
|
22
27
|
end
|
23
|
-
|
28
|
+
|
24
29
|
def captured_content(&block)
|
25
30
|
content_html = capture_html(&block)
|
26
31
|
"<p>#{content_html}</p>"
|
27
32
|
end
|
28
|
-
|
33
|
+
|
29
34
|
def concat_in_p(content_html)
|
30
35
|
concat_content "<p>#{content_html}</p>"
|
31
36
|
end
|
32
|
-
|
37
|
+
|
33
38
|
def ruby_not_template_block
|
34
39
|
determine_block_is_template('ruby') do
|
35
40
|
content_tag(:span, "This not a template block")
|
36
41
|
end
|
37
42
|
end
|
38
|
-
|
43
|
+
|
39
44
|
def determine_block_is_template(name, &block)
|
40
45
|
if block_given?
|
41
46
|
concat_content "<p class='is_template'>The #{name} block passed in is a template</p>" if block_is_template?(block)
|
@@ -44,4 +49,20 @@ class MarkupDemo < Sinatra::Base
|
|
44
49
|
end
|
45
50
|
end
|
46
51
|
end
|
52
|
+
|
53
|
+
class User
|
54
|
+
def errors
|
55
|
+
Errors.new
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class Errors < Array
|
60
|
+
def initialize
|
61
|
+
self << [:fake, :second, :third]
|
62
|
+
end
|
63
|
+
|
64
|
+
def full_messages
|
65
|
+
["This is a fake error", "This is a second fake error", "This is a third fake error"]
|
66
|
+
end
|
67
|
+
end
|
47
68
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<% form_tag '/simple', :class => 'simple-form' do %>
|
2
|
+
<%= error_messages_for(nil) %>
|
3
|
+
<% field_set_tag do %>
|
4
|
+
<%= label_tag :username %>
|
5
|
+
<%= text_field_tag :username %>
|
6
|
+
<%= label_tag :password %>
|
7
|
+
<%= password_field_tag :password %>
|
8
|
+
<%= submit_tag %>
|
9
|
+
<% end %>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<% form_tag '/advanced', :id => 'advanced', :class => 'advanced-form', :method => 'get' do %>
|
13
|
+
<%= error_messages_for @user, :header_message => "There are problems with saving user!" %>
|
14
|
+
<% field_set_tag "Advanced", :class => 'advanced-field-set' do %>
|
15
|
+
<p>
|
16
|
+
<%= label_tag :username, :class => 'first', :caption => "Nickname" %>
|
17
|
+
<%= text_field_tag :username, :value => params[:username], :id => 'the_username' %>
|
18
|
+
</p>
|
19
|
+
<p>
|
20
|
+
<%= label_tag :password, :class => 'first' %>
|
21
|
+
<%= password_field_tag :password, :value => params[:password] %>
|
22
|
+
</p>
|
23
|
+
<p>
|
24
|
+
<%= label_tag :about, :class => 'about', :caption => "About Me" %>
|
25
|
+
<%= text_area_tag :about, :class => 'large' %>
|
26
|
+
</p>
|
27
|
+
<p>
|
28
|
+
<%= label_tag :photo, :class => 'photo' %>
|
29
|
+
<%= file_field_tag :photo, :class => 'upload' %>
|
30
|
+
</p>
|
31
|
+
<% end %>
|
32
|
+
<% field_set_tag(:class => 'buttons') do %>
|
33
|
+
<%= submit_tag "Login" %>
|
34
|
+
<% end %>
|
35
|
+
<% end %>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
- form_tag '/simple', :class => 'simple-form' do
|
2
|
+
= error_messages_for nil
|
3
|
+
- field_set_tag do
|
4
|
+
= label_tag :username
|
5
|
+
= text_field_tag :username
|
6
|
+
= label_tag :password
|
7
|
+
= password_field_tag :password
|
8
|
+
= submit_tag
|
9
|
+
|
10
|
+
- form_tag '/advanced', :id => 'advanced', :class => 'advanced-form', :method => 'get' do
|
11
|
+
= error_messages_for @user, :header_message => "There are problems with saving user!"
|
12
|
+
- field_set_tag "Advanced", :class => 'advanced-field-set' do
|
13
|
+
%p
|
14
|
+
= label_tag :username, :class => 'first', :caption => "Nickname"
|
15
|
+
= text_field_tag :username, :value => params[:username], :id => 'the_username'
|
16
|
+
%p
|
17
|
+
= label_tag :password, :class => 'first'
|
18
|
+
= password_field_tag :password, :value => params[:password]
|
19
|
+
%p
|
20
|
+
= label_tag :about, :class => 'about', :caption => "About Me"
|
21
|
+
= text_area_tag :about, :class => 'large'
|
22
|
+
%p
|
23
|
+
= label_tag :photo, :class => 'photo'
|
24
|
+
= file_field_tag :photo, :class => 'upload'
|
25
|
+
- field_set_tag(:class => 'buttons') do
|
26
|
+
= submit_tag "Login"
|
data/test/helper.rb
CHANGED
@@ -19,12 +19,21 @@ class Test::Unit::TestCase
|
|
19
19
|
Webrat.configure do |config|
|
20
20
|
config.mode = :rack
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def stop_time_for_test
|
24
24
|
time = Time.now
|
25
25
|
Time.stubs(:now).returns(time)
|
26
26
|
return time
|
27
27
|
end
|
28
|
+
|
29
|
+
# assert_has_tag(:h1, :content => "yellow") { "<h1>yellow</h1>" }
|
30
|
+
# In this case, block is the html to evaluate
|
31
|
+
def assert_has_tag(name, attributes = {}, &block)
|
32
|
+
html = block && block.call
|
33
|
+
matcher = HaveSelector.new(name, attributes)
|
34
|
+
raise "Please specify a block!" if html.blank?
|
35
|
+
assert matcher.matches?(html), matcher.failure_message
|
36
|
+
end
|
28
37
|
end
|
29
38
|
|
30
39
|
module Webrat
|
@@ -14,28 +14,25 @@ class TestAssetTagHelpers < Test::Unit::TestCase
|
|
14
14
|
|
15
15
|
context 'for #flash_tag method' do
|
16
16
|
should "display flash with no given attributes" do
|
17
|
-
|
17
|
+
assert_has_tag('div.flash', :content => "Demo notice") { flash_tag(:notice) }
|
18
18
|
end
|
19
19
|
should "display flash with given attributes" do
|
20
|
-
|
21
|
-
|
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
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
context 'for #link_to method' do
|
26
26
|
should "display link element with no given attributes" do
|
27
|
-
|
27
|
+
assert_has_tag('a', :content => "Sign up", :href => '/register') { link_to('Sign up', '/register') }
|
28
28
|
end
|
29
29
|
should "display link element with given attributes" do
|
30
|
-
|
31
|
-
|
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
32
|
end
|
33
33
|
should "display link element with ruby block" do
|
34
|
-
|
35
|
-
|
36
|
-
"Sign up"
|
37
|
-
end
|
38
|
-
assert_equal link_expected, actual_link
|
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 }
|
39
36
|
end
|
40
37
|
should "display link block element in haml" do
|
41
38
|
visit '/haml/link_to'
|
@@ -52,43 +49,45 @@ class TestAssetTagHelpers < Test::Unit::TestCase
|
|
52
49
|
|
53
50
|
context 'for #image_tag method' do
|
54
51
|
should "display image tag absolute link with no options" do
|
55
|
-
|
52
|
+
assert_has_tag('img', :src => "/absolute/pic.gif") { image_tag('/absolute/pic.gif') }
|
56
53
|
end
|
57
54
|
should "display image tag relative link with options" do
|
58
|
-
|
55
|
+
assert_has_tag('img.photo', :src => "/images/relative/pic.gif") { image_tag('relative/pic.gif', :class => 'photo') }
|
59
56
|
end
|
60
|
-
should "display image tag relative link with incorrect
|
61
|
-
|
57
|
+
should "display image tag relative link with incorrect spacing" do
|
58
|
+
assert_has_tag('img.photo', :src => "/images/relative/pic.gif") { image_tag(' relative/ pic.gif ', :class => 'photo') }
|
62
59
|
end
|
63
60
|
end
|
64
61
|
|
65
62
|
context 'for #stylesheet_link_tag method' do
|
66
63
|
should "display stylesheet link item" do
|
67
64
|
time = stop_time_for_test
|
68
|
-
|
69
|
-
|
65
|
+
expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
|
66
|
+
assert_has_tag('link', expected_options.merge(:href => "/stylesheets/style.css?#{time.to_i}")) { stylesheet_link_tag('style') }
|
70
67
|
end
|
71
68
|
should "display stylesheet link items" do
|
72
69
|
time = stop_time_for_test
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
actual_html = stylesheet_link_tag('style', 'layout.css', 'http://google.com/style.css')
|
71
|
+
assert_has_tag('link', :media => "screen", :rel => "stylesheet", :type => "text/css", :count => 3) { actual_html }
|
72
|
+
assert_has_tag('link', :href => "/stylesheets/style.css?#{time.to_i}") { actual_html }
|
73
|
+
assert_has_tag('link', :href => "/stylesheets/layout.css?#{time.to_i}") { actual_html }
|
74
|
+
assert_has_tag('link', :href => "http://google.com/style.css") { actual_html }
|
77
75
|
end
|
78
76
|
end
|
79
77
|
|
80
78
|
context 'for #javascript_include_tag method' do
|
81
79
|
should "display javascript item" do
|
82
80
|
time = stop_time_for_test
|
83
|
-
|
84
|
-
|
81
|
+
actual_html = javascript_include_tag('application')
|
82
|
+
assert_has_tag('script', :src => "/javascripts/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
|
85
83
|
end
|
86
84
|
should "display javascript items" do
|
87
85
|
time = stop_time_for_test
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
86
|
+
actual_html = javascript_include_tag('application', 'base.js', 'http://google.com/lib.js')
|
87
|
+
assert_has_tag('script', :type => "text/javascript", :count => 3) { actual_html }
|
88
|
+
assert_has_tag('script', :src => "/javascripts/application.js?#{time.to_i}") { actual_html }
|
89
|
+
assert_has_tag('script', :src => "/javascripts/base.js?#{time.to_i}") { actual_html }
|
90
|
+
assert_has_tag('script', :src => "http://google.com/lib.js") { actual_html }
|
92
91
|
end
|
93
92
|
end
|
94
93
|
end
|
@@ -2,9 +2,69 @@ require 'helper'
|
|
2
2
|
require 'fixtures/markup_app/app'
|
3
3
|
|
4
4
|
class TestFormBuilder < Test::Unit::TestCase
|
5
|
+
include SinatraMore::FormHelpers
|
6
|
+
|
5
7
|
def app
|
6
8
|
MarkupDemo.tap { |app| app.set :environment, :test }
|
7
9
|
end
|
8
10
|
|
9
|
-
|
11
|
+
context 'for #form_for method' do
|
12
|
+
should "display correct form html" do
|
13
|
+
user = stub()
|
14
|
+
actual_html = form_for(user, '/register', :id => 'register') { "Demo" }
|
15
|
+
assert_has_tag('form', :action => '/register', :id => 'register', :content => "Demo") { actual_html }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# ===========================
|
20
|
+
# AbstractFormBuilder
|
21
|
+
# ===========================
|
22
|
+
|
23
|
+
context 'for #error_messages method' do
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'for #text_field method' do
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'for #text_area method' do
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'for #password_field method' do
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'for #file_field method' do
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'for #submit method' do
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
# ===========================
|
48
|
+
# StandardFormBuilder
|
49
|
+
# ===========================
|
50
|
+
|
51
|
+
context 'for #text_field_block method' do
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'for #text_area_block method' do
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'for #password_field_block method' do
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'for #file_field_block method' do
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'for #submit_block method' do
|
68
|
+
|
69
|
+
end
|
10
70
|
end
|
@@ -2,9 +2,216 @@ require 'helper'
|
|
2
2
|
require 'fixtures/markup_app/app'
|
3
3
|
|
4
4
|
class TestFormHelpers < Test::Unit::TestCase
|
5
|
+
include SinatraMore::FormHelpers
|
6
|
+
|
5
7
|
def app
|
6
8
|
MarkupDemo.tap { |app| app.set :environment, :test }
|
7
9
|
end
|
8
10
|
|
9
|
-
|
11
|
+
context 'for #form_tag method' do
|
12
|
+
should "display correct forms in ruby" do
|
13
|
+
actual_html = form_tag('/register', :class => 'test', :action => "hello") { "Demo" }
|
14
|
+
assert_has_tag(:form, :class => "test") { actual_html }
|
15
|
+
end
|
16
|
+
|
17
|
+
should "display correct inputs in ruby for form_tag" do
|
18
|
+
actual_html = form_tag('/register', :class => 'test', :action => "hello") { text_field_tag(:username) }
|
19
|
+
assert_has_tag('form input', :type => 'text', :name => "username") { actual_html }
|
20
|
+
end
|
21
|
+
|
22
|
+
should "display correct forms in erb" do
|
23
|
+
visit '/erb/form_tag'
|
24
|
+
assert_have_selector 'form.simple-form', :action => '/simple'
|
25
|
+
assert_have_selector 'form.advanced-form', :action => '/advanced', :id => 'advanced', :method => 'get'
|
26
|
+
end
|
27
|
+
|
28
|
+
should "display correct forms in haml" do
|
29
|
+
visit '/haml/form_tag'
|
30
|
+
assert_have_selector 'form.simple-form', :action => '/simple'
|
31
|
+
assert_have_selector 'form.advanced-form', :action => '/advanced', :id => 'advanced', :method => 'get'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'for #field_set_tag method' do
|
36
|
+
should "display correct field_sets in ruby" do
|
37
|
+
actual_html = field_set_tag("Basic", :class => 'basic') { "Demo" }
|
38
|
+
assert_has_tag(:fieldset, :class => 'basic') { actual_html }
|
39
|
+
assert_has_tag('fieldset legend', :content => "Basic") { actual_html }
|
40
|
+
end
|
41
|
+
|
42
|
+
should "display correct field_sets in erb" do
|
43
|
+
visit '/erb/form_tag'
|
44
|
+
assert_have_selector 'form.simple-form fieldset', :count => 1
|
45
|
+
assert_have_no_selector 'form.simple-form fieldset legend'
|
46
|
+
assert_have_selector 'form.advanced-form fieldset', :count => 1, :class => 'advanced-field-set'
|
47
|
+
assert_have_selector 'form.advanced-form fieldset legend', :content => "Advanced"
|
48
|
+
end
|
49
|
+
|
50
|
+
should "display correct field_sets in haml" do
|
51
|
+
visit '/haml/form_tag'
|
52
|
+
assert_have_selector 'form.simple-form fieldset', :count => 1
|
53
|
+
assert_have_no_selector 'form.simple-form fieldset legend'
|
54
|
+
assert_have_selector 'form.advanced-form fieldset', :count => 1, :class => 'advanced-field-set'
|
55
|
+
assert_have_selector 'form.advanced-form fieldset legend', :content => "Advanced"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'for #error_messages_for method' do
|
60
|
+
should "display correct error messages list in ruby" do
|
61
|
+
user = stub(:class => "User", :errors => stub(:full_messages => ["1", "2"], :none? => false), :blank? => false)
|
62
|
+
actual_html = error_messages_for(user)
|
63
|
+
assert_has_tag('div.field-errors') { actual_html }
|
64
|
+
assert_has_tag('div.field-errors p', :content => "The user could not be saved") { actual_html }
|
65
|
+
assert_has_tag('div.field-errors ul.errors-list') { actual_html }
|
66
|
+
assert_has_tag('div.field-errors ul.errors-list li', :count => 2) { actual_html }
|
67
|
+
end
|
68
|
+
|
69
|
+
should "display correct error messages list in erb" do
|
70
|
+
visit '/erb/form_tag'
|
71
|
+
assert_have_no_selector 'form.simple-form .field-errors'
|
72
|
+
assert_have_selector 'form.advanced-form .field-errors'
|
73
|
+
assert_have_selector 'form.advanced-form .field-errors p', :content => "There are problems with saving user!"
|
74
|
+
assert_have_selector 'form.advanced-form .field-errors ul.errors-list'
|
75
|
+
assert_have_selector 'form.advanced-form .field-errors ul.errors-list li', :count => 3
|
76
|
+
assert_have_selector 'form.advanced-form .field-errors ul.errors-list li', :content => "This is a second fake error"
|
77
|
+
end
|
78
|
+
|
79
|
+
should "display correct error messages list in haml" do
|
80
|
+
visit '/haml/form_tag'
|
81
|
+
assert_have_no_selector 'form.simple-form .field-errors'
|
82
|
+
assert_have_selector 'form.advanced-form .field-errors'
|
83
|
+
assert_have_selector 'form.advanced-form .field-errors p', :content => "There are problems with saving user!"
|
84
|
+
assert_have_selector 'form.advanced-form .field-errors ul.errors-list'
|
85
|
+
assert_have_selector 'form.advanced-form .field-errors ul.errors-list li', :count => 3
|
86
|
+
assert_have_selector 'form.advanced-form .field-errors ul.errors-list li', :content => "This is a second fake error"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'for #label_tag method' do
|
91
|
+
should "display label tag in ruby" do
|
92
|
+
actual_html = label_tag(:username, :class => 'long-label', :caption => "Nickname")
|
93
|
+
assert_has_tag(:label, :for => 'username', :class => 'long-label', :content => "Nickname: ") { actual_html }
|
94
|
+
end
|
95
|
+
|
96
|
+
should "display label tag in erb for simple form" do
|
97
|
+
visit '/erb/form_tag'
|
98
|
+
assert_have_selector 'form.simple-form label', :count => 2
|
99
|
+
assert_have_selector 'form.simple-form label', :content => "Username", :for => 'username'
|
100
|
+
assert_have_selector 'form.simple-form label', :content => "Password", :for => 'password'
|
101
|
+
end
|
102
|
+
should "display label tag in erb for advanced form" do
|
103
|
+
visit '/erb/form_tag'
|
104
|
+
assert_have_selector 'form.advanced-form label', :count => 4
|
105
|
+
assert_have_selector 'form.advanced-form label.first', :content => "Nickname", :for => 'username'
|
106
|
+
assert_have_selector 'form.advanced-form label.first', :content => "Password", :for => 'password'
|
107
|
+
assert_have_selector 'form.advanced-form label.about', :content => "About Me", :for => 'about'
|
108
|
+
assert_have_selector 'form.advanced-form label.photo', :content => "Photo" , :for => 'photo'
|
109
|
+
end
|
110
|
+
|
111
|
+
should "display label tag in haml for simple form" do
|
112
|
+
visit '/haml/form_tag'
|
113
|
+
assert_have_selector 'form.simple-form label', :count => 2
|
114
|
+
assert_have_selector 'form.simple-form label', :content => "Username", :for => 'username'
|
115
|
+
assert_have_selector 'form.simple-form label', :content => "Password", :for => 'password'
|
116
|
+
end
|
117
|
+
should "display label tag in haml for advanced form" do
|
118
|
+
visit '/haml/form_tag'
|
119
|
+
assert_have_selector 'form.advanced-form label', :count => 4
|
120
|
+
assert_have_selector 'form.advanced-form label.first', :content => "Nickname", :for => 'username'
|
121
|
+
assert_have_selector 'form.advanced-form label.first', :content => "Password", :for => 'password'
|
122
|
+
assert_have_selector 'form.advanced-form label.about', :content => "About Me", :for => 'about'
|
123
|
+
assert_have_selector 'form.advanced-form label.photo', :content => "Photo" , :for => 'photo'
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'for #text_field_tag method' do
|
128
|
+
should "display text field in ruby" do
|
129
|
+
actual_html = text_field_tag(:username, :class => 'long')
|
130
|
+
assert_has_tag(:input, :type => 'text', :class => "long", :name => 'username') { actual_html }
|
131
|
+
end
|
132
|
+
|
133
|
+
should "display text field in erb" do
|
134
|
+
visit '/erb/form_tag'
|
135
|
+
assert_have_selector 'form.simple-form input[type=text]', :count => 1, :name => 'username'
|
136
|
+
assert_have_selector 'form.advanced-form fieldset input[type=text]', :count => 1, :name => 'username', :id => 'the_username'
|
137
|
+
end
|
138
|
+
|
139
|
+
should "display text field in haml" do
|
140
|
+
visit '/haml/form_tag'
|
141
|
+
assert_have_selector 'form.simple-form input[type=text]', :count => 1, :name => 'username'
|
142
|
+
assert_have_selector 'form.advanced-form fieldset input[type=text]', :count => 1, :name => 'username', :id => 'the_username'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'for #text_area_tag method' do
|
147
|
+
should "display text area in ruby" do
|
148
|
+
actual_html = text_area_tag(:about, :class => 'long')
|
149
|
+
assert_has_tag(:textarea, :class => "long", :name => 'about') { actual_html }
|
150
|
+
end
|
151
|
+
|
152
|
+
should "display text area in erb" do
|
153
|
+
visit '/erb/form_tag'
|
154
|
+
assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
|
155
|
+
end
|
156
|
+
|
157
|
+
should "display text area in haml" do
|
158
|
+
visit '/haml/form_tag'
|
159
|
+
assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'for #password_field_tag method' do
|
164
|
+
should "display password field in ruby" do
|
165
|
+
actual_html = password_field_tag(:password, :class => 'long')
|
166
|
+
assert_has_tag(:input, :type => 'password', :class => "long", :name => 'password') { actual_html }
|
167
|
+
end
|
168
|
+
|
169
|
+
should "display password field in erb" do
|
170
|
+
visit '/erb/form_tag'
|
171
|
+
assert_have_selector 'form.simple-form input[type=password]', :count => 1, :name => 'password'
|
172
|
+
assert_have_selector 'form.advanced-form input[type=password]', :count => 1, :name => 'password'
|
173
|
+
end
|
174
|
+
|
175
|
+
should "display password field in haml" do
|
176
|
+
visit '/haml/form_tag'
|
177
|
+
assert_have_selector 'form.simple-form input[type=password]', :count => 1, :name => 'password'
|
178
|
+
assert_have_selector 'form.advanced-form input[type=password]', :count => 1, :name => 'password'
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'for #file_field_tag method' do
|
183
|
+
should "display file field in ruby" do
|
184
|
+
actual_html = file_field_tag(:photo, :class => 'photo')
|
185
|
+
assert_has_tag(:input, :type => 'file', :class => "photo", :name => 'photo') { actual_html }
|
186
|
+
end
|
187
|
+
|
188
|
+
should "display file field in erb" do
|
189
|
+
visit '/erb/form_tag'
|
190
|
+
assert_have_selector 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
|
191
|
+
end
|
192
|
+
|
193
|
+
should "display file field in haml" do
|
194
|
+
visit '/haml/form_tag'
|
195
|
+
assert_have_selector 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context 'for #submit_tag method' do
|
200
|
+
should "display submit tag in ruby" do
|
201
|
+
actual_html = submit_tag("Update", :class => 'success')
|
202
|
+
assert_has_tag(:input, :type => 'submit', :class => "success", :value => 'Update') { actual_html }
|
203
|
+
end
|
204
|
+
|
205
|
+
should "display submit tag in erb" do
|
206
|
+
visit '/erb/form_tag'
|
207
|
+
assert_have_selector 'form.simple-form input[type=submit]', :count => 1, :value => "Submit"
|
208
|
+
assert_have_selector 'form.advanced-form input[type=submit]', :count => 1, :value => "Login"
|
209
|
+
end
|
210
|
+
|
211
|
+
should "display submit tag in haml" do
|
212
|
+
visit '/haml/form_tag'
|
213
|
+
assert_have_selector 'form.simple-form input[type=submit]', :count => 1, :value => "Submit"
|
214
|
+
assert_have_selector 'form.advanced-form input[type=submit]', :count => 1, :value => "Login"
|
215
|
+
end
|
216
|
+
end
|
10
217
|
end
|
@@ -8,25 +8,29 @@ class TestTagHelpers < Test::Unit::TestCase
|
|
8
8
|
|
9
9
|
context 'for #tag method' do
|
10
10
|
should("support tags with no content no attributes") do
|
11
|
-
|
11
|
+
assert_has_tag(:br) { tag(:br) }
|
12
12
|
end
|
13
13
|
should("support tags with no content with attributes") do
|
14
|
-
|
14
|
+
actual_html = tag(:br, :style => 'clear:both', :class => 'yellow')
|
15
|
+
assert_has_tag(:br, :class => 'yellow', :style=>'clear:both') { actual_html }
|
15
16
|
end
|
16
17
|
should "support tags with content no attributes" do
|
17
|
-
|
18
|
+
assert_has_tag(:p, :content => "Demo String") { tag(:p, :content => "Demo String") }
|
18
19
|
end
|
19
20
|
should "support tags with content and attributes" do
|
20
|
-
|
21
|
+
actual_html = tag(:p, :content => "Demo", :class => 'large', :id => 'intro')
|
22
|
+
assert_has_tag('p#intro.large', :content => "Demo") { actual_html }
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
26
|
context 'for #content_tag method' do
|
25
27
|
should "support tags with content as parameter" do
|
26
|
-
|
28
|
+
actual_html = content_tag(:p, "Demo", :class => 'large', :id => 'thing')
|
29
|
+
assert_has_tag('p.large#thing', :content => "Demo") { actual_html }
|
27
30
|
end
|
28
31
|
should "support tags with content as block" do
|
29
|
-
|
32
|
+
actual_html = content_tag(:p, :class => 'large', :id => 'star') { "Demo" }
|
33
|
+
assert_has_tag('p.large#star', :content => "Demo") { actual_html }
|
30
34
|
end
|
31
35
|
should "support tags with erb" do
|
32
36
|
visit '/erb/content_tag'
|
@@ -47,10 +51,11 @@ class TestTagHelpers < Test::Unit::TestCase
|
|
47
51
|
|
48
52
|
context 'for #input_tag method' do
|
49
53
|
should "support field with type" do
|
50
|
-
|
54
|
+
assert_has_tag('input[type=text]') { input_tag(:text) }
|
51
55
|
end
|
52
56
|
should "support field with type and options" do
|
53
|
-
|
57
|
+
actual_html = input_tag(:text, :class => "first", :id => 'texter')
|
58
|
+
assert_has_tag('input.first#texter[type=text]') { actual_html }
|
54
59
|
end
|
55
60
|
end
|
56
61
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra_more
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Esquenazi
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-27 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -128,6 +128,8 @@ files:
|
|
128
128
|
- test/fixtures/markup_app/views/capture_concat.haml
|
129
129
|
- test/fixtures/markup_app/views/content_tag.erb
|
130
130
|
- test/fixtures/markup_app/views/content_tag.haml
|
131
|
+
- test/fixtures/markup_app/views/form_tag.erb
|
132
|
+
- test/fixtures/markup_app/views/form_tag.haml
|
131
133
|
- test/fixtures/markup_app/views/link_to.erb
|
132
134
|
- test/fixtures/markup_app/views/link_to.haml
|
133
135
|
- test/fixtures/render_app/app.rb
|