padrino-fields 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +40 -0
- data/Gemfile.lock +133 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +189 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/padrino-fields.rb +30 -0
- data/lib/padrino-fields/form_builder.rb +183 -0
- data/lib/padrino-fields/form_helpers.rb +63 -0
- data/lib/padrino-fields/orms/datamapper.rb +54 -0
- data/lib/padrino-fields/settings.rb +18 -0
- data/load_paths.rb +12 -0
- data/padrino-fields.gemspec +141 -0
- data/test/.DS_Store +0 -0
- data/test/fixtures/datamapper/app.rb +48 -0
- data/test/fixtures/datamapper/views/capture_concat.erb +14 -0
- data/test/fixtures/datamapper/views/capture_concat.haml +12 -0
- data/test/fixtures/datamapper/views/content_for.erb +11 -0
- data/test/fixtures/datamapper/views/content_for.haml +9 -0
- data/test/fixtures/datamapper/views/content_tag.erb +11 -0
- data/test/fixtures/datamapper/views/content_tag.haml +9 -0
- data/test/fixtures/datamapper/views/fields_for.erb +20 -0
- data/test/fixtures/datamapper/views/fields_for.haml +15 -0
- data/test/fixtures/datamapper/views/form_for.erb +56 -0
- data/test/fixtures/datamapper/views/form_for.haml +47 -0
- data/test/fixtures/datamapper/views/form_tag.erb +56 -0
- data/test/fixtures/datamapper/views/form_tag.haml +45 -0
- data/test/fixtures/datamapper/views/link_to.erb +5 -0
- data/test/fixtures/datamapper/views/link_to.haml +4 -0
- data/test/fixtures/datamapper/views/mail_to.erb +3 -0
- data/test/fixtures/datamapper/views/mail_to.haml +3 -0
- data/test/fixtures/datamapper/views/meta_tag.erb +3 -0
- data/test/fixtures/datamapper/views/meta_tag.haml +3 -0
- data/test/helper.rb +128 -0
- data/test/test_datamapper.rb +109 -0
- data/test/test_form_builder.rb +193 -0
- data/test/test_form_helpers.rb +59 -0
- data/test/test_settings.rb +51 -0
- metadata +288 -0
data/test/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'dm-core'
|
3
|
+
require 'dm-validations'
|
4
|
+
require 'dm-do-adapter'
|
5
|
+
require 'dm-sqlite-adapter'
|
6
|
+
require 'haml'
|
7
|
+
|
8
|
+
class DataMapperDemo < Sinatra::Base
|
9
|
+
register Padrino::Helpers
|
10
|
+
configure do
|
11
|
+
set :environment, :test
|
12
|
+
set :root, File.dirname(__FILE__)
|
13
|
+
end
|
14
|
+
DataMapper.setup(:default, "sqlite3::memory:")
|
15
|
+
end
|
16
|
+
|
17
|
+
class Person
|
18
|
+
include DataMapper::Resource
|
19
|
+
property :id, Serial
|
20
|
+
property :name, String
|
21
|
+
property :string, String
|
22
|
+
property :integer, Integer
|
23
|
+
property :boolean, Boolean
|
24
|
+
property :decimal, Decimal
|
25
|
+
property :float, Float
|
26
|
+
property :string, String
|
27
|
+
property :text, Text
|
28
|
+
property :date, Date
|
29
|
+
property :datetime, DateTime
|
30
|
+
property :email, String
|
31
|
+
property :phone, String
|
32
|
+
property :tel, String
|
33
|
+
property :url, String
|
34
|
+
property :search, String
|
35
|
+
property :website, String
|
36
|
+
validates_presence_of :name
|
37
|
+
has n, :nobodies
|
38
|
+
end
|
39
|
+
|
40
|
+
class Nobody
|
41
|
+
include DataMapper::Resource
|
42
|
+
property :id, Serial
|
43
|
+
property :name, String
|
44
|
+
belongs_to :person, :required => false
|
45
|
+
end
|
46
|
+
|
47
|
+
DataMapper.auto_migrate!
|
48
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<% @content = captured_content do %>
|
2
|
+
<span>Captured Line 1</span>
|
3
|
+
<span>Captured Line 2</span>
|
4
|
+
<% end %>
|
5
|
+
<%= @content %>
|
6
|
+
|
7
|
+
<% concat_in_p('Concat Line 3') %>
|
8
|
+
|
9
|
+
<% determine_block_is_template('erb') do %>
|
10
|
+
<span>This is erb</span>
|
11
|
+
<span>This is erb</span>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<% ruby_not_template_block %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<% content_for :demo do %>
|
2
|
+
<h1>This is content yielded from a content_for</h1>
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<div class='demo'><%= yield_content :demo %></div>
|
6
|
+
|
7
|
+
<% content_for :demo2 do |fname, lname| %>
|
8
|
+
<h1>This is content yielded with name <%= fname + " " + lname %></h1>
|
9
|
+
<% end %>
|
10
|
+
|
11
|
+
<div class='demo2'><%= yield_content :demo2, "Johnny", "Smith" %></div>
|
@@ -0,0 +1,11 @@
|
|
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</span>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<% content_tag(:p) do %>
|
10
|
+
<span>Test 4</span>
|
11
|
+
<% end %>
|
@@ -0,0 +1,20 @@
|
|
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
|
+
<% f.fields_for :telephone do |child_form| %>
|
9
|
+
<%= child_form.label :number %>
|
10
|
+
<%= child_form.text_field :number %>
|
11
|
+
<% end %>
|
12
|
+
<% f.fields_for :addresses do |child_form| %>
|
13
|
+
<%= child_form.label :name %>
|
14
|
+
<%= child_form.text_field :name %>
|
15
|
+
<% unless child_form.object.new_record? %>
|
16
|
+
<%= child_form.check_box '_destroy' %>
|
17
|
+
<%= child_form.label '_destroy', :caption => 'Remove' %>
|
18
|
+
<% end %>
|
19
|
+
<% end %>
|
20
|
+
<% end %>
|
@@ -0,0 +1,15 @@
|
|
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
|
+
- f.fields_for :telephone do |child_form|
|
8
|
+
= child_form.label :number
|
9
|
+
= child_form.text_field :number
|
10
|
+
- f.fields_for :addresses do |child_form|
|
11
|
+
= child_form.label :name
|
12
|
+
= child_form.text_field :name
|
13
|
+
- unless child_form.object.new_record?
|
14
|
+
= child_form.check_box '_destroy'
|
15
|
+
= child_form.label '_destroy', :caption => 'Remove'
|
@@ -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,56 @@
|
|
1
|
+
<% form_tag '/simple', :class => 'simple-form' do %>
|
2
|
+
<%= hidden_field_tag :session_id, :value => "__secret__" %>
|
3
|
+
<% field_set_tag do %>
|
4
|
+
<%= label_tag :username %>
|
5
|
+
<%= text_field_tag :username %>
|
6
|
+
<%= label_tag :password %>
|
7
|
+
<%= password_field_tag :password %>
|
8
|
+
<%= check_box_tag :remember_me %>
|
9
|
+
<%= label_tag :gender %>
|
10
|
+
<%= label_tag :color %>
|
11
|
+
<%= select_tag :color, :options => ['green', 'orange', 'purple'] %>
|
12
|
+
<%= radio_button_tag :gender, :value => 'male' %>
|
13
|
+
<%= radio_button_tag :gender, :value => 'female' %>
|
14
|
+
<%= submit_tag %>
|
15
|
+
<% end %>
|
16
|
+
<% end %>
|
17
|
+
|
18
|
+
<% form_tag '/advanced', :id => 'advanced', :class => 'advanced-form', :method => 'get' do %>
|
19
|
+
<%= error_messages_for MarkupUser.new, :header_message => "There are problems with saving user!" %>
|
20
|
+
<%= hidden_field_tag :session_id, :value => "__secret__" %>
|
21
|
+
<% field_set_tag "Advanced", :class => 'advanced-field-set' do %>
|
22
|
+
<p>
|
23
|
+
<%= label_tag :username, :class => 'first', :caption => "Nickname" %>
|
24
|
+
<%= text_field_tag :username, :value => params[:username], :id => 'the_username' %>
|
25
|
+
</p>
|
26
|
+
<p>
|
27
|
+
<%= label_tag :password, :class => 'first' %>
|
28
|
+
<%= password_field_tag :password, :value => params[:password] %>
|
29
|
+
</p>
|
30
|
+
<p>
|
31
|
+
<%= label_tag :about, :class => 'about', :caption => "About Me" %>
|
32
|
+
<%= text_area_tag :about, :class => 'large' %>
|
33
|
+
</p>
|
34
|
+
<p>
|
35
|
+
<%= label_tag :photo, :class => 'photo' %>
|
36
|
+
<%= file_field_tag :photo, :class => 'upload' %>
|
37
|
+
</p>
|
38
|
+
<p>
|
39
|
+
<%= label_tag :gender, :class => 'gender' %>
|
40
|
+
<%= radio_button_tag :gender, :value => 'male', :checked => true %>
|
41
|
+
<%= radio_button_tag :remember_me, :value => 'female' %>
|
42
|
+
<p>
|
43
|
+
<p>
|
44
|
+
<%= label_tag :fav_color %>
|
45
|
+
<%= select_tag :fav_color, :options => [ ['green', '1'], ['orange', '2'], ['purple', '3'] ], :selected => '2' %>
|
46
|
+
</p>
|
47
|
+
<p>
|
48
|
+
<%= check_box_tag :remember_me, :value => '1', :checked => true %>
|
49
|
+
<p>
|
50
|
+
<% end %>
|
51
|
+
<% field_set_tag(:class => 'buttons') do %>
|
52
|
+
<%= submit_tag "Login" %>
|
53
|
+
<%= button_tag "Cancel" %>
|
54
|
+
<%= image_submit_tag "buttons/submit.png" %>
|
55
|
+
<% end %>
|
56
|
+
<% 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"
|
data/test/helper.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rack/test'
|
11
|
+
require 'test/unit'
|
12
|
+
require 'shoulda'
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
15
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
16
|
+
require 'sinatra'
|
17
|
+
require 'padrino'
|
18
|
+
require 'padrino-helpers'
|
19
|
+
require 'webrat'
|
20
|
+
require 'mocha'
|
21
|
+
require 'phocus'
|
22
|
+
require 'dm-core'
|
23
|
+
require 'dm-validations'
|
24
|
+
require 'dm-migrations'
|
25
|
+
require 'dm-sqlite-adapter'
|
26
|
+
|
27
|
+
# We need some extension for do our tests
|
28
|
+
begin
|
29
|
+
# As 2.3.x
|
30
|
+
require 'active_support/core_ext/date'
|
31
|
+
require 'active_support/core_ext/time'
|
32
|
+
require 'active_support/core_ext/numeric'
|
33
|
+
require 'active_support/duration'
|
34
|
+
rescue LoadError
|
35
|
+
# As 3.x
|
36
|
+
require 'active_support/time'
|
37
|
+
end
|
38
|
+
|
39
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/datamapper/app')
|
40
|
+
require File.expand_path("../padrino-fields/lib/padrino-fields")
|
41
|
+
|
42
|
+
class Test::Unit::TestCase
|
43
|
+
include PadrinoFields::Settings
|
44
|
+
include Padrino::Helpers::FormHelpers
|
45
|
+
include Padrino::Helpers::OutputHelpers
|
46
|
+
include Padrino::Helpers::TagHelpers
|
47
|
+
include Padrino::Helpers::AssetTagHelpers
|
48
|
+
include Rack::Test
|
49
|
+
include Rack::Test::Methods
|
50
|
+
include Webrat
|
51
|
+
include Webrat::Methods
|
52
|
+
include Webrat::Matchers
|
53
|
+
|
54
|
+
def app
|
55
|
+
DataMapperDemo.tap { |app| app.set :environment, :test }
|
56
|
+
end
|
57
|
+
|
58
|
+
def field(object=Person.new)
|
59
|
+
Padrino::Helpers::FormBuilder::PadrinoFieldsBuilder.new(self, object)
|
60
|
+
end
|
61
|
+
|
62
|
+
Webrat.configure do |config|
|
63
|
+
config.mode = :rack
|
64
|
+
end
|
65
|
+
|
66
|
+
def stop_time_for_test
|
67
|
+
time = Time.now
|
68
|
+
Time.stubs(:now).returns(time)
|
69
|
+
return time
|
70
|
+
end
|
71
|
+
|
72
|
+
# assert_has_tag(:h1, :content => "yellow") { "<h1>yellow</h1>" }
|
73
|
+
# In this case, block is the html to evaluate
|
74
|
+
def assert_has_tag(name, attributes = {}, &block)
|
75
|
+
html = block && block.call
|
76
|
+
matcher = HaveSelector.new(name, attributes)
|
77
|
+
raise "Please specify a block!" if html.blank?
|
78
|
+
assert matcher.matches?(html), matcher.failure_message
|
79
|
+
end
|
80
|
+
|
81
|
+
# assert_has_no_tag, tag(:h1, :content => "yellow") { "<h1>green</h1>" }
|
82
|
+
# In this case, block is the html to evaluate
|
83
|
+
def assert_has_no_tag(name, attributes = {}, &block)
|
84
|
+
html = block && block.call
|
85
|
+
attributes.merge!(:count => 0)
|
86
|
+
matcher = HaveSelector.new(name, attributes)
|
87
|
+
raise "Please specify a block!" if html.blank?
|
88
|
+
assert matcher.matches?(html), matcher.failure_message
|
89
|
+
end
|
90
|
+
|
91
|
+
# Silences the output by redirecting to stringIO
|
92
|
+
# silence_logger { ...commands... } => "...output..."
|
93
|
+
def silence_logger(&block)
|
94
|
+
orig_stdout = $stdout
|
95
|
+
$stdout = log_buffer = StringIO.new
|
96
|
+
block.call
|
97
|
+
$stdout = orig_stdout
|
98
|
+
log_buffer.rewind && log_buffer.read
|
99
|
+
end
|
100
|
+
|
101
|
+
# Asserts that a file matches the pattern
|
102
|
+
def assert_match_in_file(pattern, file)
|
103
|
+
assert File.exist?(file), "File '#{file}' does not exist!"
|
104
|
+
assert_match pattern, File.read(file)
|
105
|
+
end
|
106
|
+
|
107
|
+
# mock_model("Business", :new_record? => true) => <Business>
|
108
|
+
def mock_model(klazz, options={})
|
109
|
+
options.reverse_merge!(:class => klazz, :new_record? => false, :id => 20, :errors => {})
|
110
|
+
record = stub(options)
|
111
|
+
record.stubs(:to_ary => [record])
|
112
|
+
record
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
module Webrat
|
117
|
+
module Logging
|
118
|
+
def logger # :nodoc:
|
119
|
+
@logger = nil
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
class Padrino::Helpers::FormBuilder::PadrinoFieldsBuilder
|
125
|
+
|
126
|
+
public :setup_label, :hint, :default_radios, :domize
|
127
|
+
|
128
|
+
end
|