Commit 8d3d9809c585c3118b08de773e6bb5ef279ef2e5
1 parent
5760c6d0
Exists in
master
and in
29 other branches
ActionItem155: adding missing tests
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1636 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
65 additions
and
5 deletions
Show diff stats
app/models/comment.rb
test/functional/search_controller_test.rb
| ... | ... | @@ -131,6 +131,38 @@ class SearchControllerTest < Test::Unit::TestCase |
| 131 | 131 | assert_not_includes assigns(:results)[:comments], comment2 |
| 132 | 132 | end |
| 133 | 133 | |
| 134 | + # 'assets' menu outside any category | |
| 135 | + should 'list comments in general' do | |
| 136 | + person = create_user('teste').person | |
| 137 | + art = person.articles.build(:name => 'an article to be found'); art.save! | |
| 138 | + comment = art.comments.build(:title => 'comment to be found', :body => 'hfyfyh', :author => person); comment.save! | |
| 139 | + | |
| 140 | + get :assets, :asset => 'comments' | |
| 141 | + assert_includes assigns(:results)[:comments], comment | |
| 142 | + end | |
| 143 | + | |
| 144 | + # 'assets' menu inside a specific category | |
| 145 | + should 'list comments in a specified category' do | |
| 146 | + person = create_user('teste').person | |
| 147 | + | |
| 148 | + # in category | |
| 149 | + art1 = person.articles.build(:name => 'an article to be found') | |
| 150 | + art1.categories << @category | |
| 151 | + art1.save! | |
| 152 | + comment1 = art1.comments.build(:title => 'comment to be found', :body => 'hfyfyh', :author => person); comment1.save! | |
| 153 | + | |
| 154 | + # not in category | |
| 155 | + art2 = person.articles.build(:name => 'another article to be found') | |
| 156 | + art2.save! | |
| 157 | + comment2 = art2.comments.build(:title => 'comment to be found', :body => 'hfyfyh', :author => person); comment2.save! | |
| 158 | + | |
| 159 | + | |
| 160 | + get :assets, :asset => 'comments', :category_path => [ 'my-category' ] | |
| 161 | + | |
| 162 | + assert_includes assigns(:results)[:comments], comment1 | |
| 163 | + assert_not_includes assigns(:results)[:comments], comment2 | |
| 164 | + end | |
| 165 | + | |
| 134 | 166 | should 'find enterprises' do |
| 135 | 167 | ent = Enterprise.create!(:name => 'teste', :identifier => 'teste') |
| 136 | 168 | get 'index', :query => 'teste', :find_in => [ 'enterprises' ] |
| ... | ... | @@ -435,10 +467,5 @@ class SearchControllerTest < Test::Unit::TestCase |
| 435 | 467 | get :assets, :asset => 'products' |
| 436 | 468 | assert_equal 'Products', assigns(:asset_name) |
| 437 | 469 | end |
| 438 | - | |
| 439 | - should 'show assets comments' do | |
| 440 | - get :assets, :asset => 'comments' | |
| 441 | - assert_tag :tag => 'div', :attributes => {:id => 'boxes'}, :content => {:tag => 'h2', :content => "Comments"} | |
| 442 | - end | |
| 443 | 470 | |
| 444 | 471 | end | ... | ... |
test/unit/comment_test.rb
| ... | ... | @@ -109,4 +109,33 @@ class CommentTest < Test::Unit::TestCase |
| 109 | 109 | assert_includes Comment.find_by_contents('anything'), c1 |
| 110 | 110 | end |
| 111 | 111 | |
| 112 | + should 'be able to find recent comments' do | |
| 113 | + Comment.delete_all | |
| 114 | + | |
| 115 | + owner = create_user('testuser').person | |
| 116 | + art = owner.articles.build(:name => 'ytest'); art.save! | |
| 117 | + comments = [] | |
| 118 | + 3.times do | |
| 119 | + comments.unshift art.comments.create!(:title => 'a test comment', :body => 'bla', :author => owner) | |
| 120 | + end | |
| 121 | + | |
| 122 | + assert_equal comments, Comment.recent | |
| 123 | + end | |
| 124 | + | |
| 125 | + should 'be able to find recent comments with limit' do | |
| 126 | + Comment.delete_all | |
| 127 | + | |
| 128 | + owner = create_user('testuser').person | |
| 129 | + art = owner.articles.build(:name => 'ytest'); art.save! | |
| 130 | + comments = [] | |
| 131 | + 3.times do | |
| 132 | + comments.unshift art.comments.create!(:title => 'a test comment', :body => 'bla', :author => owner) | |
| 133 | + end | |
| 134 | + | |
| 135 | + comments.pop | |
| 136 | + | |
| 137 | + assert_equal comments, Comment.recent(2) | |
| 138 | + end | |
| 139 | + | |
| 140 | + | |
| 112 | 141 | end | ... | ... |