sinatra_more 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -185,7 +185,7 @@ A form_for using these basic fields might look like:
185
185
  - form_for @user, '/register', :id => 'register' do |f|
186
186
  = f.error_messages
187
187
  %p
188
- = f.label :username
188
+ = f.label :username, :caption => "Nickname"
189
189
  = f.text_field :username
190
190
  %p
191
191
  = f.label :email
@@ -194,7 +194,7 @@ A form_for using these basic fields might look like:
194
194
  = f.label :password
195
195
  = f.password_field :password
196
196
  %p
197
- = f.submit "Create"
197
+ = f.submit "Create", :class => 'button'
198
198
 
199
199
  There is also a StandardFormBuilder which builds on the abstract fields that can be used within a form_for:
200
200
 
@@ -213,17 +213,17 @@ A form_for using these standard fields might look like:
213
213
 
214
214
  - form_for @user, '/register', :id => 'register' do |f|
215
215
  = f.error_messages
216
- = f.text_field_block :username
216
+ = f.text_field_block :name, :caption => "Full name"
217
217
  = f.text_field_block :email
218
218
  = f.password_field_block :password
219
- = f.submit_block "Create"
219
+ = f.submit_block "Create", :class => 'button'
220
220
 
221
221
  and would generate this html:
222
222
 
223
223
  <form id="register" action="/register" method="post">
224
- <p><label for="user_name">Name: </label><input type="text" id="user_name" name="user[name]"></p>
224
+ <p><label for="user_name">Full name: </label><input type="text" id="user_name" name="user[name]"></p>
225
225
  ...omitted...
226
- <p><input type="submit" value="Create"></p>
226
+ <p><input type="submit" value="Create" class="button"></p>
227
227
  </form>
228
228
 
229
229
  ==== Format Helpers
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
@@ -44,7 +44,7 @@ class AbstractFormBuilder
44
44
  end
45
45
 
46
46
  # f.submit "Update", :class => 'large'
47
- def submit(caption, options={})
47
+ def submit(caption="Submit", options={})
48
48
  @template.submit_tag caption, options
49
49
  end
50
50
 
@@ -8,18 +8,16 @@ class StandardFormBuilder < AbstractFormBuilder
8
8
  class_eval <<-EOF
9
9
  def #{field_type}_block(field, options={}, label_options={})
10
10
  label_options.reverse_merge!(:caption => options.delete(:caption)) if options[:caption]
11
- @template.content_block_tag(:p) do
12
- html = label(field, label_options)
13
- html << #{field_type}(field, options)
14
- end
11
+ field_html = label(field, label_options)
12
+ field_html << #{field_type}(field, options)
13
+ @template.content_tag(:p, field_html)
15
14
  end
16
15
  EOF
17
16
  end
18
17
 
19
18
  # submit_block("Update")
20
19
  def submit_block(caption, options={})
21
- @template.content_block_tag(:p) do
22
- @template.submit_tag(caption, options)
23
- end
20
+ submit_html = @template.submit_tag(caption, options)
21
+ @template.content_tag(:p, submit_html)
24
22
  end
25
23
  end
@@ -38,8 +38,8 @@ module SinatraMore
38
38
  error_messages = record.errors.full_messages
39
39
  error_items = error_messages.collect { |er| content_tag(:li, er) }.join("\n")
40
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')
41
+ error_html << content_tag(:ul, error_items, :class => 'errors-list')
42
+ content_tag(:div, error_html, :class => 'field-errors')
43
43
  end
44
44
 
45
45
  # Constructs a label tag from the given options
@@ -5,9 +5,11 @@ module SinatraMore
5
5
  def capture_html(*args, &block)
6
6
  if self.respond_to?(:is_haml?) && is_haml?
7
7
  block_is_haml?(block) ? capture_haml(*args, &block) : block.call
8
- else
8
+ elsif has_erb_buffer?
9
9
  result_text = capture_erb(*args, &block)
10
- result_text.present? ? result_text : block.call
10
+ result_text.present? ? result_text : (block_given? && block.call(*args))
11
+ else # theres no template to capture, invoke the block directly
12
+ block.call(*args)
11
13
  end
12
14
  end
13
15
 
@@ -16,9 +18,9 @@ module SinatraMore
16
18
  def concat_content(text="")
17
19
  if self.respond_to?(:is_haml?) && is_haml?
18
20
  haml_concat(text)
19
- elsif @_out_buf
21
+ elsif has_erb_buffer?
20
22
  erb_concat(text)
21
- else # theres no place to concat
23
+ else # theres no template to concat, return the text directly
22
24
  text
23
25
  end
24
26
  end
@@ -32,17 +34,22 @@ module SinatraMore
32
34
 
33
35
  protected
34
36
 
35
-
36
37
  # Used to capture the html from a block of erb code
37
38
  # capture_erb(&block) => '...html...'
38
39
  def capture_erb(*args, &block)
39
- erb_with_output_buffer { block.call(*args) }
40
+ erb_with_output_buffer { block_given? && block.call(*args) }
40
41
  end
41
42
 
42
43
  # Concats directly to an erb template
43
44
  # erb_concat("Direct to buffer")
44
45
  def erb_concat(text)
45
- @_out_buf << text unless @_out_buf.nil?
46
+ @_out_buf << text if has_erb_buffer?
47
+ end
48
+
49
+ # Returns true if an erb buffer is detected
50
+ # has_erb_buffer? => true
51
+ def has_erb_buffer?
52
+ !@_out_buf.nil?
46
53
  end
47
54
 
48
55
  # Used to determine if a block is called from ERB.
@@ -18,7 +18,6 @@ module SinatraMore
18
18
  tag_result = tag(name, options.merge(:content => tag_html))
19
19
  block_is_template?(block) ? concat_content(tag_result) : tag_result
20
20
  end
21
- alias content_block_tag content_tag
22
21
 
23
22
  # Creates an html tag with the given name and options
24
23
  # tag(:br, :style => 'clear:both')
@@ -5,6 +5,7 @@ Dir[File.dirname(__FILE__) + '/markup_plugin/*.rb'].each {|file| load file }
5
5
  module SinatraMore
6
6
  module MarkupPlugin
7
7
  def self.registered(app)
8
+ app.set :default_builder, 'StandardFormBuilder'
8
9
  app.helpers OutputHelpers
9
10
  app.helpers TagHelpers
10
11
  app.helpers AssetTagHelpers
data/sinatra_more.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sinatra_more}
8
- s.version = "0.1.6"
8
+ s.version = "0.1.7"
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"]
@@ -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_for.erb",
47
+ "test/fixtures/markup_app/views/form_for.haml",
46
48
  "test/fixtures/markup_app/views/form_tag.erb",
47
49
  "test/fixtures/markup_app/views/form_tag.haml",
48
50
  "test/fixtures/markup_app/views/link_to.erb",
@@ -10,11 +10,6 @@ class MarkupDemo < Sinatra::Base
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
-
18
13
  get '/:engine/:file' do
19
14
  show(params[:engine], params[:file].to_sym)
20
15
  end
@@ -49,20 +44,15 @@ class MarkupDemo < Sinatra::Base
49
44
  end
50
45
  end
51
46
  end
47
+ end
52
48
 
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
49
+ class MarkupUser
50
+ def errors; Errors.new; end
51
+ end
63
52
 
64
- def full_messages
65
- ["This is a fake error", "This is a second fake error", "This is a third fake error"]
66
- end
53
+ class Errors < Array
54
+ def initialize; self << [:fake, :second, :third]; end
55
+ def full_messages
56
+ ["This is a fake error", "This is a second fake error", "This is a third fake error"]
67
57
  end
68
- end
58
+ end
@@ -0,0 +1,33 @@
1
+ <% form_for MarkupUser.new, '/demo', :id => 'demo' do |f| %>
2
+ <%= f.error_messages(:header_message => "custom MarkupUser cannot be saved!") %>
3
+ <p>
4
+ <%= f.label :username, :caption => "Login", :class => 'user-label' %>
5
+ <%= f.text_field :username, :class => 'user-text', :value => "John" %>
6
+ </p>
7
+ <p>
8
+ <%= f.label :email, :caption => "Email", :class => 'user-email' %>
9
+ <%= f.text_field :email %>
10
+ </p>
11
+ <p>
12
+ <%= f.label :password %>
13
+ <%= f.password_field :password, :class => 'user-password', :value => "secret" %>
14
+ </p>
15
+ <p>
16
+ <%= f.label :photo %>
17
+ <%= f.file_field :photo, :class => 'user-photo' %>
18
+ </p>
19
+ <p>
20
+ <%= f.label :about, :caption => "About Me" %>
21
+ <%= f.text_area :about, :class => 'user-about' %>
22
+ </p>
23
+ <p><%= f.submit "Create", :class => 'success', :id => 'demo-button' %></p>
24
+ <% end %>
25
+
26
+ <% form_for MarkupUser.new, '/another_demo', :id => 'demo2', :method => 'get' do |f| %>
27
+ <%= f.error_messages :header_message => "custom MarkupUser cannot be saved!" %>
28
+ <%= f.text_field_block :username, { :class => 'input' }, { :caption => 'Nickname', :class => 'label' } %>
29
+ <%= f.password_field_block :code, { :class => 'input' } %>
30
+ <%= f.text_area_block :about, { :class => 'textarea' } %>
31
+ <%= f.file_field_block :photo, { :class => 'upload' } %>
32
+ <%= f.submit_block "Create", { :class => 'button', :class => 'button' } %>
33
+ <% end %>
@@ -0,0 +1,27 @@
1
+ - form_for MarkupUser.new, '/demo', :id => 'demo' do |f|
2
+ = f.error_messages(:header_message => "custom MarkupUser cannot be saved!")
3
+ %p
4
+ = f.label :username, :caption => "Login", :class => 'user-label'
5
+ = f.text_field :username, :class => 'user-text', :value => "John"
6
+ %p
7
+ = f.label :email, :caption => "Email", :class => 'user-email'
8
+ = f.text_field :email
9
+ %p
10
+ = f.label :password
11
+ = f.password_field :password, :class => 'user-password', :value => "secret"
12
+ %p
13
+ = f.label :photo
14
+ = f.file_field :photo, :class => 'user-photo'
15
+ %p
16
+ = f.label :about, :caption => "About Me"
17
+ = f.text_area :about, :class => 'user-about'
18
+ %p
19
+ = f.submit "Create", :class => 'success', :id => 'demo-button'
20
+
21
+ - form_for MarkupUser.new, '/another_demo', :id => 'demo2', :method => 'get' do |f|
22
+ = f.error_messages :header_message => "custom MarkupUser cannot be saved!"
23
+ = f.text_field_block :username, { :class => 'input' }, { :caption => 'Nickname', :class => 'label' }
24
+ = f.password_field_block :code, { :class => 'input' }
25
+ = f.text_area_block :about, { :class => 'textarea' }
26
+ = f.file_field_block :photo, { :class => 'upload' }
27
+ = f.submit_block "Create", { :class => 'button' }
@@ -10,7 +10,7 @@
10
10
  <% end %>
11
11
 
12
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!" %>
13
+ <%= error_messages_for MarkupUser.new, :header_message => "There are problems with saving user!" %>
14
14
  <% field_set_tag "Advanced", :class => 'advanced-field-set' do %>
15
15
  <p>
16
16
  <%= label_tag :username, :class => 'first', :caption => "Nickname" %>
@@ -8,7 +8,7 @@
8
8
  = submit_tag
9
9
 
10
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!"
11
+ = error_messages_for MarkupUser.new, :header_message => "There are problems with saving user!"
12
12
  - field_set_tag "Advanced", :class => 'advanced-field-set' do
13
13
  %p
14
14
  = label_tag :username, :class => 'first', :caption => "Nickname"
@@ -8,12 +8,47 @@ class TestFormBuilder < Test::Unit::TestCase
8
8
  MarkupDemo.tap { |app| app.set :environment, :test }
9
9
  end
10
10
 
11
+ def setup
12
+ @user = stub(:errors => stub(:full_messages => ["1", "2"], :none? => false), :class => 'User', :first_name => "Joe")
13
+ @user_none = stub(:errors => stub(:none? => true), :class => 'User')
14
+ end
15
+
16
+ def standard_builder(object=@user)
17
+ StandardFormBuilder.new(self, object)
18
+ end
19
+
11
20
  context 'for #form_for method' do
12
21
  should "display correct form html" do
13
- user = stub()
14
- actual_html = form_for(user, '/register', :id => 'register') { "Demo" }
22
+ actual_html = form_for(@user, '/register', :id => 'register') { "Demo" }
15
23
  assert_has_tag('form', :action => '/register', :id => 'register', :content => "Demo") { actual_html }
16
24
  end
25
+
26
+ should "display correct form html with multipart" do
27
+ actual_html = form_for(@user, '/register', :multipart => true) { "Demo" }
28
+ assert_has_tag('form', :action => '/register', :enctype => "multipart/form-data") { actual_html }
29
+ end
30
+
31
+ should "support changing form builder type" do
32
+ form_html = lambda { form_for(@user, '/register', :builder => "AbstractFormBuilder") { |f| f.text_field_block(:name) } }
33
+ assert_raise(NoMethodError) { form_html.call }
34
+ end
35
+
36
+ should "support using default standard builder" do
37
+ actual_html = form_for(@user, '/register') { |f| f.text_field_block(:name) }
38
+ assert_has_tag('form p input[type=text]') { actual_html }
39
+ end
40
+
41
+ should "display correct form in haml" do
42
+ visit '/haml/form_for'
43
+ assert_have_selector :form, :action => '/demo', :id => 'demo'
44
+ assert_have_selector :form, :action => '/another_demo', :id => 'demo2', :method => 'get'
45
+ end
46
+
47
+ should "display correct form in erb" do
48
+ visit '/erb/form_for'
49
+ assert_have_selector :form, :action => '/demo', :id => 'demo'
50
+ assert_have_selector :form, :action => '/another_demo', :id => 'demo2', :method => 'get'
51
+ end
17
52
  end
18
53
 
19
54
  # ===========================
@@ -21,27 +56,154 @@ class TestFormBuilder < Test::Unit::TestCase
21
56
  # ===========================
22
57
 
23
58
  context 'for #error_messages method' do
59
+ should "display correct form html with no record" do
60
+ actual_html = standard_builder(@user_none).error_messages(:header_message => "Demo form cannot be saved")
61
+ assert actual_html.blank?
62
+ end
63
+
64
+ should "display correct form html with valid record" do
65
+ actual_html = standard_builder.error_messages(:header_message => "Demo form cannot be saved")
66
+ assert_has_tag('div.field-errors p', :content => "Demo form cannot be saved") { actual_html }
67
+ assert_has_tag('div.field-errors ul.errors-list li', :content => "1") { actual_html }
68
+ assert_has_tag('div.field-errors ul.errors-list li', :content => "2") { actual_html }
69
+ end
24
70
 
71
+ should "display correct form in haml" do
72
+ visit '/haml/form_for'
73
+ assert_have_selector '#demo div.field-errors p', :content => "custom MarkupUser cannot be saved!"
74
+ assert_have_selector '#demo div.field-errors ul.errors-list li', :content => "This is a fake error"
75
+ assert_have_selector '#demo2 div.field-errors p', :content => "custom MarkupUser cannot be saved!"
76
+ assert_have_selector '#demo2 div.field-errors ul.errors-list li', :content => "This is a fake error"
77
+ end
78
+
79
+ should "display correct form in erb" do
80
+ visit '/erb/form_for'
81
+ assert_have_selector '#demo div.field-errors p', :content => "custom MarkupUser cannot be saved!"
82
+ assert_have_selector '#demo div.field-errors ul.errors-list li', :content => "This is a fake error"
83
+ assert_have_selector '#demo2 div.field-errors p', :content => "custom MarkupUser cannot be saved!"
84
+ assert_have_selector '#demo2 div.field-errors ul.errors-list li', :content => "This is a fake error"
85
+ end
86
+ end
87
+
88
+ context 'for #label method' do
89
+ should "display correct label html" do
90
+ actual_html = standard_builder.label(:first_name, :class => 'large', :caption => "F. Name")
91
+ assert_has_tag('label', :class => 'large', :for => 'user_first_name', :content => "F. Name: ") { actual_html }
92
+ end
93
+
94
+ should "display correct label in haml" do
95
+ visit '/haml/form_for'
96
+ assert_have_selector '#demo label', :content => "Login: ", :class => 'user-label'
97
+ assert_have_selector '#demo label', :content => "About Me: "
98
+ assert_have_selector '#demo2 label', :content => "Nickname: ", :class => 'label'
99
+ end
100
+
101
+ should "display correct label in erb" do
102
+ visit '/erb/form_for'
103
+ assert_have_selector '#demo label', :content => "Login: ", :class => 'user-label'
104
+ assert_have_selector '#demo label', :content => "About Me: "
105
+ assert_have_selector '#demo2 label', :content => "Nickname: ", :class => 'label'
106
+ end
25
107
  end
26
108
 
27
109
  context 'for #text_field method' do
110
+ should "display correct text field html" do
111
+ actual_html = standard_builder.text_field(:first_name, :class => 'large')
112
+ assert_has_tag('input.large[type=text]', :value => "Joe", :id => 'user_first_name', :name => 'user[first_name]') { actual_html }
113
+ end
114
+
115
+ should "display correct text field in haml" do
116
+ visit '/haml/form_for'
117
+ assert_have_selector '#demo input.user-text[type=text]', :id => 'markup_user_username', :value => "John"
118
+ assert_have_selector '#demo2 input', :class => 'input', :name => 'markup_user[username]'
119
+ end
28
120
 
121
+ should "display correct text field in erb" do
122
+ visit '/erb/form_for'
123
+ assert_have_selector '#demo input.user-text[type=text]', :id => 'markup_user_username', :value => "John"
124
+ assert_have_selector '#demo2 input', :class => 'input', :name => 'markup_user[username]'
125
+ end
29
126
  end
30
127
 
31
128
  context 'for #text_area method' do
129
+ should "display correct text_area html" do
130
+ actual_html = standard_builder.text_area(:about, :class => 'large')
131
+ assert_has_tag('textarea.large', :id => 'user_about', :name => 'user[about]') { actual_html }
132
+ end
133
+
134
+ should "display correct text_area in haml" do
135
+ visit '/haml/form_for'
136
+ assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
137
+ assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
138
+ end
32
139
 
140
+ should "display correct text_area in erb" do
141
+ visit '/erb/form_for'
142
+ assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
143
+ assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
144
+ end
33
145
  end
34
146
 
35
147
  context 'for #password_field method' do
148
+ should "display correct password_field html" do
149
+ actual_html = standard_builder.password_field(:code, :class => 'large')
150
+ assert_has_tag('input.large[type=password]', :id => 'user_code', :name => 'user[code]') { actual_html }
151
+ end
152
+
153
+ should "display correct password_field in haml" do
154
+ visit '/haml/form_for'
155
+ assert_have_selector '#demo input', :type => 'password', :class => 'user-password', :value => 'secret'
156
+ assert_have_selector '#demo2 input', :type => 'password', :class => 'input', :name => 'markup_user[code]'
157
+ end
36
158
 
159
+ should "display correct password_field in erb" do
160
+ visit '/erb/form_for'
161
+ assert_have_selector '#demo input', :type => 'password', :class => 'user-password', :value => 'secret'
162
+ assert_have_selector '#demo2 input', :type => 'password', :class => 'input', :name => 'markup_user[code]'
163
+ end
37
164
  end
38
165
 
39
166
  context 'for #file_field method' do
167
+ should "display correct file_field html" do
168
+ actual_html = standard_builder.file_field(:photo, :class => 'large')
169
+ assert_has_tag('input.large[type=file]', :id => 'user_photo', :name => 'user[photo]') { actual_html }
170
+ end
40
171
 
172
+ should "display correct file_field in haml" do
173
+ visit '/haml/form_for'
174
+ assert_have_selector '#demo input.user-photo', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
175
+ assert_have_selector '#demo2 input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
176
+ end
177
+
178
+ should "display correct file_field in erb" do
179
+ visit '/erb/form_for'
180
+ assert_have_selector '#demo input.user-photo', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
181
+ assert_have_selector '#demo2 input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
182
+ end
41
183
  end
42
184
 
43
185
  context 'for #submit method' do
186
+ should "display correct submit button html with no options" do
187
+ actual_html = standard_builder.submit
188
+ assert_has_tag('input[type=submit]', :value => "Submit") { actual_html }
189
+ end
44
190
 
191
+ should "display correct submit button html" do
192
+ actual_html = standard_builder.submit("Commit", :class => 'large')
193
+ assert_has_tag('input.large[type=submit]', :value => "Commit") { actual_html }
194
+ end
195
+
196
+ should "display correct submit button in haml" do
197
+ visit '/haml/form_for'
198
+ assert_have_selector '#demo input', :type => 'submit', :id => 'demo-button', :class => 'success'
199
+ assert_have_selector '#demo2 input', :type => 'submit', :class => 'button', :value => "Create"
200
+ end
201
+
202
+ should "display correct submit button in erb" do
203
+ visit '/erb/form_for'
204
+ assert_have_selector '#demo input', :type => 'submit', :id => 'demo-button', :class => 'success'
205
+ assert_have_selector '#demo2 input', :type => 'submit', :class => 'button', :value => "Create"
206
+ end
45
207
  end
46
208
 
47
209
  # ===========================
@@ -49,22 +211,99 @@ class TestFormBuilder < Test::Unit::TestCase
49
211
  # ===========================
50
212
 
51
213
  context 'for #text_field_block method' do
214
+ should "display correct text field block html" do
215
+ actual_html = standard_builder.text_field_block(:first_name, :class => 'large', :caption => "FName")
216
+ assert_has_tag('p label', :for => 'user_first_name', :content => "FName: ") { actual_html }
217
+ assert_has_tag('p input.large[type=text]', :value => "Joe", :id => 'user_first_name', :name => 'user[first_name]') { actual_html }
218
+ end
219
+
220
+ should "display correct text field block in haml" do
221
+ visit '/haml/form_for'
222
+ assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname: ", :class => 'label'
223
+ assert_have_selector '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
224
+ end
52
225
 
226
+ should "display correct text field block in erb" do
227
+ visit '/erb/form_for'
228
+ assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname: ", :class => 'label'
229
+ assert_have_selector '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
230
+ end
53
231
  end
54
232
 
55
233
  context 'for #text_area_block method' do
234
+ should "display correct text area block html" do
235
+ actual_html = standard_builder.text_area_block(:about, :class => 'large', :caption => "About Me")
236
+ assert_has_tag('p label', :for => 'user_about', :content => "About Me: ") { actual_html }
237
+ assert_has_tag('p textarea', :id => 'user_about', :name => 'user[about]') { actual_html }
238
+ end
56
239
 
240
+ should "display correct text area block in haml" do
241
+ visit '/haml/form_for'
242
+ assert_have_selector '#demo2 p label', :for => 'markup_user_about', :content => "About: "
243
+ assert_have_selector '#demo2 p textarea', :name => 'markup_user[about]', :id => 'markup_user_about'
244
+ end
245
+
246
+ should "display correct text area block in erb" do
247
+ visit '/erb/form_for'
248
+ assert_have_selector '#demo2 p label', :for => 'markup_user_about', :content => "About: "
249
+ assert_have_selector '#demo2 p textarea', :name => 'markup_user[about]', :id => 'markup_user_about'
250
+ end
57
251
  end
58
252
 
59
253
  context 'for #password_field_block method' do
254
+ should "display correct password field block html" do
255
+ actual_html = standard_builder.password_field_block(:keycode, :class => 'large', :caption => "Code")
256
+ assert_has_tag('p label', :for => 'user_keycode', :content => "Code: ") { actual_html }
257
+ assert_has_tag('p input.large[type=password]', :id => 'user_keycode', :name => 'user[keycode]') { actual_html }
258
+ end
259
+
260
+ should "display correct password field block in haml" do
261
+ visit '/haml/form_for'
262
+ assert_have_selector '#demo2 p label', :for => 'markup_user_code', :content => "Code: "
263
+ assert_have_selector '#demo2 p input', :type => 'password', :name => 'markup_user[code]', :id => 'markup_user_code'
264
+ end
60
265
 
266
+ should "display correct password field block in erb" do
267
+ visit '/erb/form_for'
268
+ assert_have_selector '#demo2 p label', :for => 'markup_user_code', :content => "Code: "
269
+ assert_have_selector '#demo2 p input', :type => 'password', :name => 'markup_user[code]', :id => 'markup_user_code'
270
+ end
61
271
  end
62
272
 
63
273
  context 'for #file_field_block method' do
274
+ should "display correct file field block html" do
275
+ actual_html = standard_builder.file_field_block(:photo, :class => 'large', :caption => "Photo")
276
+ assert_has_tag('p label', :for => 'user_photo', :content => "Photo: ") { actual_html }
277
+ assert_has_tag('p input.large[type=file]', :id => 'user_photo', :name => 'user[photo]') { actual_html }
278
+ end
279
+
280
+ should "display correct file field block in haml" do
281
+ visit '/haml/form_for'
282
+ assert_have_selector '#demo2 p label', :for => 'markup_user_photo', :content => "Photo: "
283
+ assert_have_selector '#demo2 p input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
284
+ end
64
285
 
286
+ should "display correct file field block in erb" do
287
+ visit '/erb/form_for'
288
+ assert_have_selector '#demo2 p label', :for => 'markup_user_photo', :content => "Photo: "
289
+ assert_have_selector '#demo2 p input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
290
+ end
65
291
  end
66
292
 
67
293
  context 'for #submit_block method' do
294
+ should "display correct submit block html" do
295
+ actual_html = standard_builder.submit_block("Update", :class => 'large')
296
+ assert_has_tag('p input.large[type=submit]', :value => 'Update') { actual_html }
297
+ end
298
+
299
+ should "display correct submit block in haml" do
300
+ visit '/haml/form_for'
301
+ assert_have_selector '#demo2 p input', :type => 'submit', :class => 'button'
302
+ end
68
303
 
304
+ should "display correct submit block in erb" do
305
+ visit '/erb/form_for'
306
+ assert_have_selector '#demo2 p input', :type => 'submit', :class => 'button'
307
+ end
69
308
  end
70
309
  end
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.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Esquenazi
@@ -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_for.erb
132
+ - test/fixtures/markup_app/views/form_for.haml
131
133
  - test/fixtures/markup_app/views/form_tag.erb
132
134
  - test/fixtures/markup_app/views/form_tag.haml
133
135
  - test/fixtures/markup_app/views/link_to.erb