Commit 584df3ec767ea38be6283291d499b851312cc8c7
1 parent
195e425b
Exists in
master
and in
28 other branches
Moving HTML generation tests to helper tests
(ActionItem1396)
Showing
3 changed files
with
21 additions
and
33 deletions
Show diff stats
app/models/folder.rb
@@ -28,13 +28,6 @@ class Folder < Article | @@ -28,13 +28,6 @@ class Folder < Article | ||
28 | 'folder' | 28 | 'folder' |
29 | end | 29 | end |
30 | 30 | ||
31 | - # FIXME isn't this too much including just to be able to generate some HTML? | ||
32 | - include ActionView::Helpers::TagHelper | ||
33 | - include ActionView::Helpers::UrlHelper | ||
34 | - include ActionController::UrlWriter | ||
35 | - include ActionView::Helpers::AssetTagHelper | ||
36 | - include FolderHelper | ||
37 | - include DatesHelper | ||
38 | 31 | ||
39 | def to_html(options = {}) | 32 | def to_html(options = {}) |
40 | send(view_as) | 33 | send(view_as) |
test/unit/folder_helper_test.rb
@@ -2,6 +2,12 @@ require File.dirname(__FILE__) + '/../test_helper' | @@ -2,6 +2,12 @@ require File.dirname(__FILE__) + '/../test_helper' | ||
2 | 2 | ||
3 | class FolderHelperTest < Test::Unit::TestCase | 3 | class FolderHelperTest < Test::Unit::TestCase |
4 | 4 | ||
5 | + include ActionView::Helpers::TagHelper | ||
6 | + include ActionView::Helpers::UrlHelper | ||
7 | + include ActionController::UrlWriter | ||
8 | + include ActionView::Helpers::AssetTagHelper | ||
9 | + include DatesHelper | ||
10 | + | ||
5 | include FolderHelper | 11 | include FolderHelper |
6 | 12 | ||
7 | should 'display icon for articles' do | 13 | should 'display icon for articles' do |
@@ -74,7 +80,7 @@ class FolderHelperTest < Test::Unit::TestCase | @@ -74,7 +80,7 @@ class FolderHelperTest < Test::Unit::TestCase | ||
74 | article = fast_create(Article, {:name => 'Article1', :parent_id => folder.id, :profile_id => profile.id}) | 80 | article = fast_create(Article, {:name => 'Article1', :parent_id => folder.id, :profile_id => profile.id}) |
75 | article = fast_create(Article, {:name => 'Article2', :parent_id => folder.id, :profile_id => profile.id}) | 81 | article = fast_create(Article, {:name => 'Article2', :parent_id => folder.id, :profile_id => profile.id}) |
76 | 82 | ||
77 | - result = folder.list_articles(folder.children) | 83 | + result = list_articles(folder.children) |
78 | 84 | ||
79 | assert_tag_in_string result, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/folder-owner\/my-article-[0-9]*(\?|$)/ } }, :content => /Article1/ | 85 | assert_tag_in_string result, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/folder-owner\/my-article-[0-9]*(\?|$)/ } }, :content => /Article1/ |
80 | assert_tag_in_string result, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/folder-owner\/my-article-[0-9]*(\?|$)/ } }, :content => /Article2/ | 86 | assert_tag_in_string result, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/folder-owner\/my-article-[0-9]*(\?|$)/ } }, :content => /Article2/ |
@@ -83,9 +89,22 @@ class FolderHelperTest < Test::Unit::TestCase | @@ -83,9 +89,22 @@ class FolderHelperTest < Test::Unit::TestCase | ||
83 | should 'explictly advise if empty' do | 89 | should 'explictly advise if empty' do |
84 | profile = create_user('folder-owner').person | 90 | profile = create_user('folder-owner').person |
85 | folder = fast_create(Folder, {:name => 'Parent Folder', :profile_id => profile.id}) | 91 | folder = fast_create(Folder, {:name => 'Parent Folder', :profile_id => profile.id}) |
86 | - result = folder.list_articles(folder.children) | 92 | + result = render 'content_viewer/folder', binding |
87 | 93 | ||
88 | assert_match '(empty folder)', result | 94 | assert_match '(empty folder)', result |
89 | end | 95 | end |
90 | 96 | ||
97 | + should 'show body (folder description)' do | ||
98 | + profile = create_user('folder-owner').person | ||
99 | + folder = fast_create(Folder, {:name => 'Parent Folder', :profile_id => profile.id, :body => "This is the folder description"}) | ||
100 | + result = render 'content_viewer/folder', binding | ||
101 | + assert_match 'This is the folder description', result | ||
102 | + end | ||
103 | + | ||
104 | + | ||
105 | + private | ||
106 | + def render(template, the_binding) | ||
107 | + ERB.new(File.read(RAILS_ROOT + '/app/views/' + template + '.rhtml')).result(the_binding) | ||
108 | + end | ||
109 | + | ||
91 | end | 110 | end |
test/unit/folder_test.rb
@@ -18,30 +18,6 @@ class FolderTest < ActiveSupport::TestCase | @@ -18,30 +18,6 @@ class FolderTest < ActiveSupport::TestCase | ||
18 | assert_not_equal Article.new.icon_name, Folder.new.icon_name | 18 | assert_not_equal Article.new.icon_name, Folder.new.icon_name |
19 | end | 19 | end |
20 | 20 | ||
21 | - should 'list subitems as HTML content' do | ||
22 | - p = create_user('testuser').person | ||
23 | - f = Folder.create!(:profile => p, :name => 'f') | ||
24 | - f.children.create!(:profile => p, :name => 'onearticle') | ||
25 | - f.children.create!(:profile => p, :name => 'otherarticle') | ||
26 | - f.reload | ||
27 | - | ||
28 | - assert_tag_in_string f.to_html, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/testuser\/f\/onearticle(\?|$)/ } }, :content => /onearticle/ | ||
29 | - assert_tag_in_string f.to_html, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/testuser\/f\/otherarticle(\?|$)/ } }, :content => /otherarticle/ | ||
30 | - end | ||
31 | - | ||
32 | - should 'explictly advise if empty' do | ||
33 | - p = create_user('testuser').person | ||
34 | - f = Folder.create!(:profile => p, :name => 'f') | ||
35 | - assert_tag_in_string f.to_html, :content => '(empty folder)' | ||
36 | - end | ||
37 | - | ||
38 | - should 'show text body in HTML content' do | ||
39 | - p = create_user('testuser').person | ||
40 | - f = Folder.create!(:name => 'f', :profile => p, :body => 'this-is-the-text') | ||
41 | - | ||
42 | - assert_match(/this-is-the-text/, f.to_html) | ||
43 | - end | ||
44 | - | ||
45 | should 'identify as folder' do | 21 | should 'identify as folder' do |
46 | assert Folder.new.folder?, 'folder must identity itself as folder' | 22 | assert Folder.new.folder?, 'folder must identity itself as folder' |
47 | end | 23 | end |