adva_cells 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/adva_cells.gemspec +20 -0
- data/app/cells/base_cell.rb +83 -0
- data/app/controllers/admin/cells_controller.rb +10 -0
- data/app/helpers/contact_mailer_helper.rb +7 -0
- data/config/routes.rb +6 -0
- data/lib/adva_cells.rb +13 -0
- data/lib/adva_cells/version.rb +3 -0
- data/lib/cells_ext.rb +18 -0
- data/lib/contact_mail_form_builder.rb +178 -0
- data/lib/output_filter/cells.rb +48 -0
- data/test/integration/article_with_contact_mailer_test.rb +81 -0
- data/test/test_helper.rb +11 -0
- data/test/unit/album_cell_test.rb +48 -0
- data/test/unit/base_cell_test.rb +83 -0
- data/test/unit/blog_cell_test.rb +27 -0
- data/test/unit/contact_mailer_cell_test.rb +43 -0
- data/test/unit/content_cell_test.rb +33 -0
- data/test/unit/helpers/contact_mail_helper_test.rb +84 -0
- data/test/unit/lib/contact_mail_form_builder_test.rb +288 -0
- data/test/unit/lib/output_filter/cells_test.rb +46 -0
- data/test/unit/section_cell_test.rb +30 -0
- data/test/unit/user_cell_test.rb +27 -0
- metadata +110 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper' ))
|
2
|
+
|
3
|
+
module IntegrationTest
|
4
|
+
class ArticleWithContactMailerTest < ActionController::IntegrationTest
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
@site = use_site! 'site with pages'
|
8
|
+
@page = @site.sections.root
|
9
|
+
@contact_mailer = @page.articles.build(:title => 'contact mailer',
|
10
|
+
:body => contact_mailer_cell,
|
11
|
+
:author => User.first,
|
12
|
+
:published_at => Time.now - 1.month)
|
13
|
+
@contact_mailer.save
|
14
|
+
end
|
15
|
+
|
16
|
+
test "article displays the contact mailer cell" do
|
17
|
+
login_as_user
|
18
|
+
|
19
|
+
# We have an article with contact mailer
|
20
|
+
assert_equal contact_mailer_cell, @contact_mailer.body
|
21
|
+
|
22
|
+
visit_contact_mailer_article
|
23
|
+
article_displays_contact_mailer
|
24
|
+
end
|
25
|
+
|
26
|
+
test "article displays the contact mailer cell - even after put through fckeditor" do
|
27
|
+
login_as_user
|
28
|
+
|
29
|
+
# Edited by fckeditor
|
30
|
+
@contact_mailer.update_attribute(:body, contact_mailer_cell_after_fckeditor)
|
31
|
+
|
32
|
+
# We have an article with contact mailer
|
33
|
+
assert_equal contact_mailer_cell_after_fckeditor, @contact_mailer.body
|
34
|
+
|
35
|
+
visit_contact_mailer_article
|
36
|
+
end
|
37
|
+
|
38
|
+
def visit_contact_mailer_article
|
39
|
+
visit page_article_path(@page, @contact_mailer.permalink)
|
40
|
+
assert_template 'articles/show'
|
41
|
+
end
|
42
|
+
|
43
|
+
def article_displays_contact_mailer
|
44
|
+
assert_select("form[action=?]", contact_mails_path(:return_to => '/articles/contact-mailer')) do
|
45
|
+
assert_select "input[name=?]", "contact_mail[recipients]"
|
46
|
+
assert_select "input[name=?]", "contact_mail[subject]"
|
47
|
+
assert_select "textarea[name=?]", "contact_mail[body]"
|
48
|
+
assert_select "input[name=?][checked=?]", "contact_mail[radio_button]", "checked"
|
49
|
+
assert_select "input[name=?][checked=?]", "contact_mail[check_box]", "checked"
|
50
|
+
assert_select "select[name=?]", "contact_mail[rating]"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def contact_mailer_cell
|
55
|
+
<<-XML
|
56
|
+
<cell name="contact_mailer/mailer_form" recipients="first@email.com, second@email.com">
|
57
|
+
<fields>
|
58
|
+
<field name="subject" label="Subject" type="text_field" value="default subject" />
|
59
|
+
<field name="body" label="Body" type="text_area" />
|
60
|
+
<field name="radio button" label="Radio button" type="radio_button" checked="true" value='100' />
|
61
|
+
<field name="check box" label="Checkbox" type="check_box" checked="true" value='100' />
|
62
|
+
<field name="rating" label="Rate us!" type="select">
|
63
|
+
<options>
|
64
|
+
<option value="1" label="Good" />
|
65
|
+
<option value="2" label="Bad" />
|
66
|
+
</options>
|
67
|
+
</field>
|
68
|
+
</fields>
|
69
|
+
</cell>
|
70
|
+
XML
|
71
|
+
end
|
72
|
+
|
73
|
+
def contact_mailer_cell_after_fckeditor
|
74
|
+
<<-XML
|
75
|
+
<cell name="contact_mailer/mailer_form" recipients="first@email.com, second@email.com"> <fields> <field name="subject" label="Subject" type="text_field" value="default subject"></field> <field name="body" label="Body" type="text_area"></field> <field name="radio button" label="Radio button" type="radio_button" checked="true" value="100"></field> <field name="check box" label="Checkbox" type="check_box" checked="true" value="100"></field> <field name="rating" label="Rate us!" type="select">
|
76
|
+
<options> </options>
|
77
|
+
</field> </fields> </cell>
|
78
|
+
XML
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
class AlbumCellTest < ActiveSupport::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@album = Album.first
|
7
|
+
@first_photo = @album.photos(:conditions => "published_at IS NOT NULL").first
|
8
|
+
@second_photo = Photo.find(@album.photos.second.id, :conditions => "published_at IS NOT NULL")
|
9
|
+
@controller = CellTestController.new
|
10
|
+
@cell = AlbumCell.new(@controller)
|
11
|
+
end
|
12
|
+
|
13
|
+
test "#single sets the album from options[:section] if available" do
|
14
|
+
@cell.instance_variable_set(:@opts, {:section => @album.id})
|
15
|
+
@cell.single
|
16
|
+
@cell.instance_variable_get(:@album).should == @album
|
17
|
+
end
|
18
|
+
|
19
|
+
test "#single sets the photo if album and photo_id is set and photo is published" do
|
20
|
+
@cell.instance_variable_set(:@opts, {:section => @album.id, :photo_id => @second_photo.id})
|
21
|
+
@cell.single
|
22
|
+
@cell.instance_variable_get(:@photo).should == @second_photo
|
23
|
+
end
|
24
|
+
|
25
|
+
test "#single sets the photo as first published album photo if only album is set" do
|
26
|
+
@cell.instance_variable_set(:@opts, {:section => @album.id})
|
27
|
+
@cell.single
|
28
|
+
@cell.instance_variable_get(:@photo).should == @first_photo
|
29
|
+
end
|
30
|
+
|
31
|
+
test "#single sets the photo if photo_id is set and photo is published" do
|
32
|
+
@cell.instance_variable_set(:@opts, {:photo_id => @first_photo.id})
|
33
|
+
@cell.single
|
34
|
+
@cell.instance_variable_get(:@photo).should == @first_photo
|
35
|
+
end
|
36
|
+
|
37
|
+
# FIXME test the cached_references
|
38
|
+
# FIXME test the has_state option
|
39
|
+
|
40
|
+
# FIXME should we just set the photo to nil or raise active_record::record_not_found like it is
|
41
|
+
# doing now?
|
42
|
+
#
|
43
|
+
# test "#single does not set the photo if photo_id is set and photo is unpublished" do
|
44
|
+
# @cell.instance_variable_set(:@opts, {:photo_id => @album.photos.last.id})
|
45
|
+
# @cell.single
|
46
|
+
# @cell.instance_variable_get(:@photo).should == nil
|
47
|
+
# end
|
48
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
class BaseCellTest < ActiveSupport::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@site = Site.first
|
7
|
+
@section = @site.sections.last
|
8
|
+
@root = @site.sections.root
|
9
|
+
@controller = CellTestController.new
|
10
|
+
@cell = BaseCell.new(@controller)
|
11
|
+
@cell.send(:set_site)
|
12
|
+
end
|
13
|
+
|
14
|
+
# .set_site
|
15
|
+
test "#set_site sets the site from the controller" do
|
16
|
+
@cell.instance_variable_get(:@site).should == @controller.site
|
17
|
+
end
|
18
|
+
|
19
|
+
# .set_section
|
20
|
+
test "#set_section sets the section from options[:section] if available" do
|
21
|
+
@cell.instance_variable_set(:@opts, {:section => @section.id})
|
22
|
+
@cell.send(:set_section)
|
23
|
+
@cell.instance_variable_get(:@section).should == @section
|
24
|
+
end
|
25
|
+
|
26
|
+
test "#set_section defaults the section to controller.section" do
|
27
|
+
@cell.send(:set_section)
|
28
|
+
@cell.instance_variable_get(:@section).should == @controller.section
|
29
|
+
end
|
30
|
+
|
31
|
+
test "#set_section defaults the section to the site's root section if controller.section is not set" do
|
32
|
+
stub(@controller).section.returns(nil)
|
33
|
+
@cell.send(:set_section)
|
34
|
+
@cell.instance_variable_get(:@section).should == @root
|
35
|
+
end
|
36
|
+
|
37
|
+
# .boolean_option
|
38
|
+
test "#boolean_option typecasts a string 'true' to true" do
|
39
|
+
@cell.instance_variable_set(:@opts, {:foo => 'true'})
|
40
|
+
@cell.send(:boolean_option, :foo).should == true
|
41
|
+
end
|
42
|
+
|
43
|
+
test "#boolean_option typecasts a string 'false' to false" do
|
44
|
+
@cell.instance_variable_set(:@opts, {:foo => 'false'})
|
45
|
+
@cell.send(:boolean_option, :foo).should == false
|
46
|
+
end
|
47
|
+
|
48
|
+
test "#boolean_option typecasts a string '1' to true" do
|
49
|
+
@cell.instance_variable_set(:@opts, {:foo => '1'})
|
50
|
+
@cell.send(:boolean_option, :foo).should == true
|
51
|
+
end
|
52
|
+
|
53
|
+
test "#boolean_option typecasts a string '0' to false" do
|
54
|
+
@cell.instance_variable_set(:@opts, {:foo => '0'})
|
55
|
+
@cell.send(:boolean_option, :foo).should == false
|
56
|
+
end
|
57
|
+
|
58
|
+
# .include_child_sections?
|
59
|
+
test "#include_child_sections is true when the option :include_child_sections typecasts to true" do
|
60
|
+
@cell.instance_variable_set(:@opts, {:include_child_sections => 'true'})
|
61
|
+
@cell.send(:include_child_sections?).should == true
|
62
|
+
end
|
63
|
+
|
64
|
+
# FIXME can not test expectations on Article class methods with RR's mock library?
|
65
|
+
#
|
66
|
+
# .with_sections_scope
|
67
|
+
# test "#with_sections_scope scopes ActiveRecord::Base.find to the current section
|
68
|
+
# when include_child_sections? is false" do
|
69
|
+
# @cell.send(:set_section)
|
70
|
+
# scope = hash_including(:find => { :conditions => { :section_id => @section.id}, :include => 'section' })
|
71
|
+
# mock(Article).scope(scope)
|
72
|
+
# @cell.send(Article, :with_sections_scope) { Article.all }
|
73
|
+
# end
|
74
|
+
#
|
75
|
+
# test "#with_sections_scope scopes ActiveRecord::Base.find to the current section and all child sections
|
76
|
+
# when include_child_sections? is true" do
|
77
|
+
# @cell.instance_variable_set(:@opts, {:include_child_sections => 'true'})
|
78
|
+
# @cell.send(:set_section)
|
79
|
+
# scope = hash_including(:find => { :conditions => { :section_id => @section.id }, :include => 'section' })
|
80
|
+
# mock(Article).scope(scope)
|
81
|
+
# @cell.send(Article, :with_sections_scope) { Article.all }
|
82
|
+
# end
|
83
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
class BlogCellTest < ActiveSupport::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@controller = CellTestController.new
|
7
|
+
@cell = BlogCell.new(@controller)
|
8
|
+
end
|
9
|
+
|
10
|
+
test "#recent_articles sets the articles from latest 5 articles, ordered by 'published_at DESC' as a default" do
|
11
|
+
@cell.recent_articles
|
12
|
+
@cell.instance_variable_get(:@articles).should == recent_articles
|
13
|
+
end
|
14
|
+
|
15
|
+
test "#recent_articles article amount can be altered by @opts[:count]" do
|
16
|
+
@cell.instance_variable_set(:@opts, { :count => 1 })
|
17
|
+
@cell.recent_articles
|
18
|
+
@cell.instance_variable_get(:@articles).should == recent_articles("published_at DESC", 1)
|
19
|
+
end
|
20
|
+
|
21
|
+
# FIXME test the cached_references
|
22
|
+
# FIXME test the has_state option
|
23
|
+
|
24
|
+
def recent_articles(order = "published_at DESC", limit = 5)
|
25
|
+
Article.all(:order => order, :limit => limit)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
include Authentication::HashHelper
|
3
|
+
|
4
|
+
class ContactMailerCellTest < ActiveSupport::TestCase
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
@controller = CellTestController.new
|
8
|
+
@cell = ContactMailerCell.new(@controller)
|
9
|
+
end
|
10
|
+
|
11
|
+
test '#mailer_form sets the recipients from @opts["recipients"] and encrypts them' do
|
12
|
+
@cell.instance_variable_set(:@opts, { "recipients" => 'user@test.com, another.user@test.com' })
|
13
|
+
@cell.mailer_form
|
14
|
+
@cell.instance_variable_get(:@recipients).should == encrypted_and_escaped('user@test.com, another.user@test.com')
|
15
|
+
end
|
16
|
+
|
17
|
+
test '#mailer_form sets the subjects from @opts["subjects"]' do
|
18
|
+
@cell.instance_variable_set(:@opts, { "subject" => 'bug report' })
|
19
|
+
@cell.mailer_form
|
20
|
+
@cell.instance_variable_get(:@subject).should == 'bug report'
|
21
|
+
end
|
22
|
+
|
23
|
+
test '#mailer_form sets the fields from @opts["fields"]' do
|
24
|
+
@cell.instance_variable_set(:@opts, { "fields" => fields_options })
|
25
|
+
form_fields = fields_options.delete("fields").delete("field")
|
26
|
+
@cell.mailer_form
|
27
|
+
@cell.instance_variable_get(:@fields).should == form_fields
|
28
|
+
end
|
29
|
+
# FIXME test the cached_references
|
30
|
+
# FIXME test the has_state option
|
31
|
+
|
32
|
+
def encrypted_and_escaped(string)
|
33
|
+
URI.escape(EzCrypto::Key.encrypt_with_password(ContactMail.password, send(:site_salt), string))
|
34
|
+
end
|
35
|
+
|
36
|
+
def fields_options
|
37
|
+
{ "fields" =>
|
38
|
+
{ "field"=> [ {"name"=>"subject", "type"=>"text_field"},
|
39
|
+
{"name"=>"body", "type"=>"text_area"} ]
|
40
|
+
}
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
class ContentCellTest < ActiveSupport::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@controller = CellTestController.new
|
7
|
+
@cell = ContentCell.new(@controller)
|
8
|
+
end
|
9
|
+
|
10
|
+
test "#recent sets the content from latest 10 published content items, ordered by 'created_at DESC' as a default" do
|
11
|
+
@cell.recent
|
12
|
+
@cell.instance_variable_get(:@content).should == recent_content
|
13
|
+
end
|
14
|
+
|
15
|
+
test "#recent content item amount can be altered by @opts[:limit]" do
|
16
|
+
@cell.instance_variable_set(:@opts, { :count => 1 })
|
17
|
+
@cell.recent
|
18
|
+
@cell.instance_variable_get(:@content).should == recent_content("created_at DESC", 1)
|
19
|
+
end
|
20
|
+
|
21
|
+
test "#recent content ordering can be altered by @opts[:order]" do
|
22
|
+
@cell.instance_variable_set(:@opts, { :order => "updated_at DESC" })
|
23
|
+
@cell.recent
|
24
|
+
@cell.instance_variable_get(:@content).should == recent_content("updated_at DESC")
|
25
|
+
end
|
26
|
+
|
27
|
+
# FIXME test the cached_references
|
28
|
+
# FIXME test the has_state option
|
29
|
+
|
30
|
+
def recent_content(order = "created_at DESC", limit = 5)
|
31
|
+
Content.published.order(order).limit(limit)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
class ContactMailerHelperTest < ActionView::TestCase
|
4
|
+
include ContactMailerHelper
|
5
|
+
|
6
|
+
test "#render renders the correct html" do
|
7
|
+
render_fields(fields_options).should == output_html
|
8
|
+
end
|
9
|
+
|
10
|
+
def fields_options
|
11
|
+
{ "fields" =>
|
12
|
+
{ "field"=> [ {"name"=>"subject", "type"=>"text_field"},
|
13
|
+
{"name"=>"body", "type"=>"text_area"},
|
14
|
+
{"checked"=>"true", "name"=>"check me", "type"=>"radio_button", "value"=>"100"},
|
15
|
+
{"checked"=>"true", "name"=>"check me", "type"=>"check_box", "value"=>"100"},
|
16
|
+
{"name"=>"rating", "options"=>
|
17
|
+
{"option"=> [{"value"=>"1", "label"=>"Very good"},
|
18
|
+
{"value"=>"5", "label"=>"Very bad"}
|
19
|
+
]},
|
20
|
+
"type"=>"select"
|
21
|
+
}
|
22
|
+
]
|
23
|
+
}
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def output_html
|
28
|
+
<<-HTML
|
29
|
+
<p>
|
30
|
+
<label for='contact_mail_subject'>subject</label>
|
31
|
+
<input id="contact_mail_subject" name="contact_mail[subject]" type="text" />
|
32
|
+
</p>
|
33
|
+
<p>
|
34
|
+
<label for='contact_mail_body'>body</label>
|
35
|
+
<textarea id="contact_mail_body" name="contact_mail[body]"></textarea>
|
36
|
+
</p>
|
37
|
+
<p>
|
38
|
+
<label for='contact_mail_check_me'>check me</label>
|
39
|
+
<input checked="checked" id="contact_mail_check_me_100" name="contact_mail[check_me]" type="radio" value="100" />
|
40
|
+
</p>
|
41
|
+
<p>
|
42
|
+
<label for='contact_mail_check_me'>check me</label>
|
43
|
+
<input checked="checked" id="contact_mail_check_me" name="contact_mail[check_me]" type="checkbox" value="100" />
|
44
|
+
</p>
|
45
|
+
<p>
|
46
|
+
<label for='contact_mail_rating'>rating</label>
|
47
|
+
<select id="contact_mail_rating" name="contact_mail[rating]"><option value="1">Very good</option>
|
48
|
+
<option value="5">Very bad</option></select>
|
49
|
+
</p>
|
50
|
+
HTML
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# require 'rubygems'
|
55
|
+
# require 'active_support'
|
56
|
+
#
|
57
|
+
# xml = %(
|
58
|
+
# <h2>Heading 2</h2>
|
59
|
+
# <div>
|
60
|
+
# <p>Some text ...</p>
|
61
|
+
# </div>
|
62
|
+
#
|
63
|
+
# <cell name="name/state">
|
64
|
+
# <fields>
|
65
|
+
# <field name="subject" type="text_field" />
|
66
|
+
# <field name="check me" type="radio_button" checked="true" value='100'" />
|
67
|
+
# <field name="check me" type="check_box" checked="true" value='100'" />
|
68
|
+
# <field name="rating" type="select">
|
69
|
+
# <options>
|
70
|
+
# <option value="1" label="Very good" />
|
71
|
+
# <option value="5" label="Very bad" />
|
72
|
+
# </options>
|
73
|
+
# </field>
|
74
|
+
# </fields>
|
75
|
+
# </cell>
|
76
|
+
#
|
77
|
+
# <div>
|
78
|
+
# <p>Some more text ...</p>
|
79
|
+
# </div>
|
80
|
+
# )
|
81
|
+
#
|
82
|
+
# xml.scan(/(<cell[^>]*\/\s*>|<cell[^>]*>.*?<\/cell>)/m).each do |matches|
|
83
|
+
# p Hash.from_xml(matches.first)
|
84
|
+
# end
|
@@ -0,0 +1,288 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
class ContactMailFormBuilderTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
@cm_builder = ContactMailFormBuilder.new
|
8
|
+
end
|
9
|
+
|
10
|
+
# add_field
|
11
|
+
|
12
|
+
test "adds text field to the fields" do
|
13
|
+
@cm_builder.add_field(text_field)
|
14
|
+
assert @cm_builder.fields.first.is_a?(Tags::TextField)
|
15
|
+
end
|
16
|
+
|
17
|
+
test "adds text area to the fields" do
|
18
|
+
@cm_builder.add_field(text_area)
|
19
|
+
assert @cm_builder.fields.first.is_a?(Tags::TextArea)
|
20
|
+
end
|
21
|
+
|
22
|
+
test "adds radio button to the fields" do
|
23
|
+
@cm_builder.add_field(radio_button)
|
24
|
+
assert @cm_builder.fields.first.is_a?(Tags::RadioButton)
|
25
|
+
end
|
26
|
+
|
27
|
+
test "adds check box to the fields" do
|
28
|
+
@cm_builder.add_field(check_box)
|
29
|
+
assert @cm_builder.fields.first.is_a?(Tags::CheckBox)
|
30
|
+
end
|
31
|
+
|
32
|
+
test "adds select field to the fields" do
|
33
|
+
@cm_builder.add_field(select)
|
34
|
+
assert @cm_builder.fields.first.is_a?(Tags::Select)
|
35
|
+
end
|
36
|
+
|
37
|
+
test "adds header to the fields" do
|
38
|
+
@cm_builder.add_field(header)
|
39
|
+
assert @cm_builder.fields.first.is_a?(Tags::Header)
|
40
|
+
end
|
41
|
+
|
42
|
+
# render_fields
|
43
|
+
|
44
|
+
test "properly renders a text field" do
|
45
|
+
expected = "<p>\n" + text_field_output + "</p>\n"
|
46
|
+
@cm_builder.add_field(text_field)
|
47
|
+
assert_equal expected, @cm_builder.render_fields
|
48
|
+
end
|
49
|
+
|
50
|
+
test "properly renders a text area" do
|
51
|
+
expected = "<p>\n" + text_area_output + "</p>\n"
|
52
|
+
@cm_builder.add_field(text_area)
|
53
|
+
assert_equal expected, @cm_builder.render_fields
|
54
|
+
end
|
55
|
+
|
56
|
+
test "properly renders a radio button" do
|
57
|
+
expected = "<p>\n" + radio_button_output + "</p>\n"
|
58
|
+
@cm_builder.add_field(radio_button)
|
59
|
+
assert_equal expected, @cm_builder.render_fields
|
60
|
+
end
|
61
|
+
|
62
|
+
test "properly renders a check box" do
|
63
|
+
expected = "<p>\n" + check_box_output + "</p>\n"
|
64
|
+
@cm_builder.add_field(check_box)
|
65
|
+
assert_equal expected, @cm_builder.render_fields
|
66
|
+
end
|
67
|
+
|
68
|
+
test "properly renders a select field" do
|
69
|
+
expected = "<p>\n" + select_output + "</p>\n"
|
70
|
+
@cm_builder.add_field(select)
|
71
|
+
assert_equal expected, @cm_builder.render_fields
|
72
|
+
end
|
73
|
+
|
74
|
+
test "does not render invalid fields" do
|
75
|
+
@cm_builder.add_field(:type => 'text_field')
|
76
|
+
assert_equal "", @cm_builder.render_fields
|
77
|
+
end
|
78
|
+
|
79
|
+
test "properly renders a header" do
|
80
|
+
expected = "\n<h2>Header</h2>\n"
|
81
|
+
@cm_builder.add_field(header)
|
82
|
+
assert_equal expected, @cm_builder.render_fields
|
83
|
+
end
|
84
|
+
|
85
|
+
# Tags::TextField
|
86
|
+
|
87
|
+
test "Tags::TextField creates a text field tag with a label" do
|
88
|
+
text_field_tag = Tags::TextField.new(:name => 'subject', :value => 'default subject').render
|
89
|
+
assert_equal text_field_output, text_field_tag
|
90
|
+
end
|
91
|
+
|
92
|
+
test "Tags::TextField is not valid without a name" do
|
93
|
+
text_field = Tags::TextField.new()
|
94
|
+
assert !text_field.valid?
|
95
|
+
end
|
96
|
+
|
97
|
+
# is stylable with css
|
98
|
+
|
99
|
+
test "Tags::TextField accepts a custom id and class" do
|
100
|
+
expected = "\t<label for='contact_mail_subject'>Subject</label>\n\t<input class=\"custom_class\" id=\"custom_id\" name=\"contact_mail[subject]\" type=\"text\" />\n"
|
101
|
+
text_field_tag = Tags::TextField.new(:name => 'subject', :options => {:id => 'custom_id', :class => 'custom_class'}).render
|
102
|
+
|
103
|
+
assert_equal expected, text_field_tag
|
104
|
+
end
|
105
|
+
|
106
|
+
# Tags::TextArea
|
107
|
+
|
108
|
+
test "Tags::TextArea creates a text area tag with a label" do
|
109
|
+
text_area_tag = Tags::TextArea.new(:name => 'body').render
|
110
|
+
assert_equal text_area_output, text_area_tag
|
111
|
+
end
|
112
|
+
|
113
|
+
test "Tags::TextArea is not valid without a name" do
|
114
|
+
text_area = Tags::TextArea.new()
|
115
|
+
assert !text_area.valid?
|
116
|
+
end
|
117
|
+
|
118
|
+
# is stylable with css
|
119
|
+
|
120
|
+
test "Tags::TextArea accepts a custom id and class" do
|
121
|
+
expected = "\t<label for='contact_mail_body'>Body</label>\n\t<textarea class=\"custom_class\" id=\"custom_id\" name=\"contact_mail[body]\"></textarea>\n"
|
122
|
+
text_area_tag = Tags::TextArea.new(:name => 'body', :options => {:id => 'custom_id', :class => 'custom_class'}).render
|
123
|
+
|
124
|
+
assert_equal expected, text_area_tag
|
125
|
+
end
|
126
|
+
|
127
|
+
# Tags::RadioButton
|
128
|
+
|
129
|
+
test "Tags::RadioButton creates a radio button tag with a label" do
|
130
|
+
radio_button_tag = Tags::RadioButton.new(:name => 'radio button', :checked => 'true', :value => '100').render
|
131
|
+
assert_equal radio_button_output, radio_button_tag
|
132
|
+
end
|
133
|
+
|
134
|
+
test "Tags::RadioButton is not valid without a name" do
|
135
|
+
radio_button = Tags::RadioButton.new(:value => '100')
|
136
|
+
assert !radio_button.valid?
|
137
|
+
end
|
138
|
+
|
139
|
+
test "Tags::RadioButton is not valid without a value" do
|
140
|
+
radio_button = Tags::RadioButton.new(:name => 'radio button')
|
141
|
+
assert !radio_button.valid?
|
142
|
+
end
|
143
|
+
|
144
|
+
# is stylable with css
|
145
|
+
|
146
|
+
test "Tags::RadioButton accepts a custom id and class" do
|
147
|
+
expected = "\t<label for='contact_mail_radio'>Radio</label>\n\t<input class=\"custom_class\" id=\"custom_id\" name=\"contact_mail[radio]\" type=\"radio\" />\n"
|
148
|
+
radio_button_tag = Tags::RadioButton.new(:name => 'radio', :options => {:id => 'custom_id', :class => 'custom_class'}).render
|
149
|
+
|
150
|
+
assert_equal expected, radio_button_tag
|
151
|
+
end
|
152
|
+
|
153
|
+
# Tags::CheckBox
|
154
|
+
|
155
|
+
test "Tags::CheckBox creates a check box tag with a label" do
|
156
|
+
check_box_tag = Tags::CheckBox.new(:name => 'check box', :label => 'Checkbox', :checked => 'true', :value => '100').render
|
157
|
+
assert_equal check_box_output, check_box_tag
|
158
|
+
end
|
159
|
+
|
160
|
+
test "Tags::CheckBox is not valid without a name" do
|
161
|
+
check_box = Tags::CheckBox.new(:value => '100')
|
162
|
+
assert !check_box.valid?
|
163
|
+
end
|
164
|
+
|
165
|
+
# is stylable with css
|
166
|
+
|
167
|
+
test "Tags::CheckBox accepts a custom id and class" do
|
168
|
+
expected = "\t<label for='contact_mail_check'>Check</label>\n\t<input class=\"custom_class\" id=\"custom_id\" name=\"contact_mail[check]\" type=\"checkbox\" />\n"
|
169
|
+
check_box_tag = Tags::CheckBox.new(:name => 'check', :options => {:id => 'custom_id', :class => 'custom_class'}).render
|
170
|
+
|
171
|
+
assert_equal expected, check_box_tag
|
172
|
+
end
|
173
|
+
|
174
|
+
# Tags::Select
|
175
|
+
|
176
|
+
test "Tags::Select creates a select tag with a label" do
|
177
|
+
options = { :option_tags => { "option" => [ { "value" => "1", "label" => "Good" },
|
178
|
+
{ "value" => "2", "label" => "Bad"} ] } }
|
179
|
+
select_tag = Tags::Select.new(options.merge(:name => "rating", :label => "Rate us!")).render
|
180
|
+
assert_equal select_output, select_tag
|
181
|
+
end
|
182
|
+
|
183
|
+
test "Tags::Select creates a select tag with a label - also if option tags are inside of options and not on option_tags" do
|
184
|
+
options = { :options => { "option" => [ { "value" => "1", "label" => "Good" },
|
185
|
+
{ "value" => "2", "label" => "Bad"} ] } }
|
186
|
+
select_tag = Tags::Select.new(options.merge(:name => "rating", :label => "Rate us!")).render
|
187
|
+
assert_equal select_output, select_tag
|
188
|
+
end
|
189
|
+
|
190
|
+
test "Tags::Select is not valid without a name" do
|
191
|
+
select = Tags::Select.new(:option_tags => { "option" => [ { "value" => "1", "label" => "Good" },
|
192
|
+
{ "value" => "2", "label" => "Bad"} ] })
|
193
|
+
assert !select.valid?
|
194
|
+
end
|
195
|
+
|
196
|
+
test "Tags::Select is not valid without options" do
|
197
|
+
select = Tags::Select.new(:name => "select")
|
198
|
+
assert !select.valid?
|
199
|
+
end
|
200
|
+
|
201
|
+
# is stylable with css
|
202
|
+
|
203
|
+
test "Tags::Select accepts a custom id and class" do
|
204
|
+
expected = "\t<label for='contact_mail_select'>Select</label>\n\t<select class=\"custom_class\" id=\"custom_id\" name=\"contact_mail[select]\"><option value=\"1\">Good</option>\n<option value=\"2\">Bad</option></select>\n"
|
205
|
+
|
206
|
+
assert_equal expected, custom_select.render
|
207
|
+
end
|
208
|
+
|
209
|
+
# Tags::Header
|
210
|
+
|
211
|
+
test "Tags::Header creates a header text" do
|
212
|
+
assert "<h1>Header</h1>", Tags::Header.new(:title => 'Header', :level => 1)
|
213
|
+
end
|
214
|
+
|
215
|
+
test "Tags::Header is invalid in level range below 1" do
|
216
|
+
assert !Tags::Header.new(:title => 'Header', :level => 0).valid?
|
217
|
+
end
|
218
|
+
|
219
|
+
test "Tags::Header is invalid in level range above 6" do
|
220
|
+
assert !Tags::Header.new(:title => 'Header', :level => 7).valid?
|
221
|
+
end
|
222
|
+
|
223
|
+
# is stylable with css
|
224
|
+
|
225
|
+
test "Tags::Header accepts a custom id and class" do
|
226
|
+
expected = "<h4 class=\"custom_class\" id=\"custom_id\">Header</h4>"
|
227
|
+
header = Tags::Header.new(:title => 'Header', :level => 4, :options => { :id => 'custom_id', :class => 'custom_class' })
|
228
|
+
assert_equal expected, header.render
|
229
|
+
end
|
230
|
+
|
231
|
+
def text_field
|
232
|
+
{ :name => "subject", :label => "Subject", :type => "text_field", :value => "default subject" }
|
233
|
+
end
|
234
|
+
|
235
|
+
def text_area
|
236
|
+
{ :name => "body", :label => "Body", :type => "text_area" }
|
237
|
+
end
|
238
|
+
|
239
|
+
def radio_button
|
240
|
+
{ :name => "radio button", :label => "Radio button", :type => "radio_button", :checked => "true", :value => '100' }
|
241
|
+
end
|
242
|
+
|
243
|
+
def check_box
|
244
|
+
{ :name => "check box", :label => "Checkbox", :type => "check_box", :checked => "true", :value => '100' }
|
245
|
+
end
|
246
|
+
|
247
|
+
def select
|
248
|
+
{ :type => "select", :name => "rating", :label=>"Rate us!",
|
249
|
+
:options => { "option" => [ { "value" => "1", "label" => "Good" },
|
250
|
+
{ "value" => "2", "label" => "Bad"} ] }
|
251
|
+
}
|
252
|
+
end
|
253
|
+
|
254
|
+
def header
|
255
|
+
{ :type => 'header', :title => 'Header', :level => 2 }
|
256
|
+
end
|
257
|
+
|
258
|
+
def custom_select
|
259
|
+
Tags::Select.new(:name => 'select', :options => {:id => 'custom_id', :class => 'custom_class'},
|
260
|
+
:option_tags => { "option" =>
|
261
|
+
[ { "value" => "1", "label" => "Good" },
|
262
|
+
{ "value" => "2", "label" => "Bad"} ] })
|
263
|
+
end
|
264
|
+
|
265
|
+
def label_output
|
266
|
+
"\t<label for='contact_mail_subject'>Subject</label>\n"
|
267
|
+
end
|
268
|
+
|
269
|
+
def text_field_output
|
270
|
+
label_output + "\t<input id=\"contact_mail_subject\" name=\"contact_mail[subject]\" type=\"text\" value=\"default subject\" />\n"
|
271
|
+
end
|
272
|
+
|
273
|
+
def text_area_output
|
274
|
+
"\t<label for='contact_mail_body'>Body</label>\n\t<textarea id=\"contact_mail_body\" name=\"contact_mail[body]\"></textarea>\n"
|
275
|
+
end
|
276
|
+
|
277
|
+
def radio_button_output
|
278
|
+
"\t<label for='contact_mail_radio_button'>Radio button</label>\n\t<input checked=\"checked\" id=\"contact_mail_radio_button_100\" name=\"contact_mail[radio_button]\" type=\"radio\" value=\"100\" />\n"
|
279
|
+
end
|
280
|
+
|
281
|
+
def check_box_output
|
282
|
+
"\t<label for='contact_mail_checkbox'>Checkbox</label>\n\t<input checked=\"checked\" id=\"contact_mail_check_box\" name=\"contact_mail[check_box]\" type=\"checkbox\" value=\"100\" />\n"
|
283
|
+
end
|
284
|
+
|
285
|
+
def select_output
|
286
|
+
"\t<label for='contact_mail_rate_us'>Rate us!</label>\n\t<select id=\"contact_mail_rating\" name=\"contact_mail[rating]\"><option value=\"1\">Good</option>\n<option value=\"2\">Bad</option></select>\n"
|
287
|
+
end
|
288
|
+
end
|