Commit 45077a0cc553f08865913696a21f2ef1eb79bc9d
1 parent
d0a31efb
Exists in
master
and in
29 other branches
ActionItem392: fixing tests by reworking articles's
description/short_description git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1856 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
10 changed files
with
43 additions
and
51 deletions
Show diff stats
app/models/article.rb
... | ... | @@ -80,28 +80,16 @@ class Article < ActiveRecord::Base |
80 | 80 | _('HTML Text document') |
81 | 81 | end |
82 | 82 | |
83 | - def title | |
84 | - name | |
83 | + def self.description | |
84 | + raise NotImplementedError, "#{self} does not implement #description" | |
85 | 85 | end |
86 | 86 | |
87 | 87 | def self.short_description |
88 | - if self == Article | |
89 | - _('Article') | |
90 | - else | |
91 | - _('"%s" article') % self.article_type_name | |
92 | - end | |
93 | - end | |
94 | - | |
95 | - def self.description | |
96 | - if self == Article | |
97 | - _('An ordinary article') | |
98 | - else | |
99 | - _('An article of type "%s"') % self.article_type_name | |
100 | - end | |
88 | + raise NotImplementedError, "#{self} does not implement #short_description" | |
101 | 89 | end |
102 | 90 | |
103 | - def self.article_type_name | |
104 | - self.name.gsub(/article$/i, '') | |
91 | + def title | |
92 | + name | |
105 | 93 | end |
106 | 94 | |
107 | 95 | def url | ... | ... |
app/models/profile.rb
... | ... | @@ -257,7 +257,8 @@ class Profile < ActiveRecord::Base |
257 | 257 | |
258 | 258 | hacked_after_create :insert_default_homepage_and_feed |
259 | 259 | def insert_default_homepage_and_feed |
260 | - hp = self.articles.build(:name => _("%s's home page") % self.name, :body => _("<p>This is a default homepage created for %s. It can be changed though the control panel.</p>") % self.name, :advertise => false) | |
260 | + hp = TinyMceArticle.new(:name => _("%s's home page") % self.name, :body => _("<p>This is a default homepage created for %s. It can be changed though the control panel.</p>") % self.name, :advertise => false) | |
261 | + hp.profile = self | |
261 | 262 | hp.save! |
262 | 263 | self.home_page = hp |
263 | 264 | self.save! | ... | ... |
... | ... | @@ -0,0 +1,9 @@ |
1 | +class SpecializeArticles < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + execute "update articles set type = 'TinyMceArticle' where type = 'Article'" | |
4 | + end | |
5 | + | |
6 | + def self.down | |
7 | + raise ActiveRecord::Migration::IrreversibleMigration, 'cannot reverse this' | |
8 | + end | |
9 | +end | ... | ... |
test/unit/article_test.rb
... | ... | @@ -136,19 +136,16 @@ class ArticleTest < Test::Unit::TestCase |
136 | 136 | assert_equal [other_first, fifth, fourth, third, second, first], Article.recent(6) |
137 | 137 | end |
138 | 138 | |
139 | - should 'provied proper descriptions' do | |
140 | - assert_equal "Article", Article.short_description | |
141 | - assert_equal "An ordinary article", Article.description | |
139 | + should 'require that subclasses define description' do | |
140 | + assert_raise NotImplementedError do | |
141 | + Article.description | |
142 | + end | |
142 | 143 | end |
143 | 144 | |
144 | - should 'provide a usable descriptions to subclasses that don\'t override them' do | |
145 | - klass = Class.new(Article) | |
146 | - klass.stubs(:name).returns("MyClass") | |
147 | - klass.expects(:_).with('"%s" article').returns('"%s" article') | |
148 | - klass.expects(:_).with('An article of type "%s"').returns('An article of type "%s"') | |
149 | - | |
150 | - assert_equal '"MyClass" article', klass.short_description | |
151 | - assert_equal 'An article of type "MyClass"', klass.description | |
145 | + should 'require that subclasses define short description' do | |
146 | + assert_raise NotImplementedError do | |
147 | + Article.short_description | |
148 | + end | |
152 | 149 | end |
153 | 150 | |
154 | 151 | should 'indicate wheter children articles are allowed or not' do |
... | ... | @@ -289,4 +286,5 @@ class ArticleTest < Test::Unit::TestCase |
289 | 286 | assert_equal true, a1.display_to?(member) |
290 | 287 | end |
291 | 288 | |
289 | + | |
292 | 290 | end | ... | ... |
test/unit/folder_test.rb
... | ... | @@ -7,13 +7,11 @@ class FolderTest < ActiveSupport::TestCase |
7 | 7 | end |
8 | 8 | |
9 | 9 | should 'provide proper description' do |
10 | - Folder.stubs(:==).with(Article).returns(true) | |
11 | - assert_not_equal Article.description, Folder.description | |
10 | + assert_kind_of String, Folder.description | |
12 | 11 | end |
13 | 12 | |
14 | 13 | should 'provide proper short description' do |
15 | - Folder.stubs(:==).with(Article).returns(true) | |
16 | - assert_not_equal Article.short_description, Folder.short_description | |
14 | + assert_kind_of String, Folder.short_description | |
17 | 15 | end |
18 | 16 | |
19 | 17 | should 'provide own icon name' do | ... | ... |
test/unit/image_gallery_test.rb
... | ... | @@ -7,13 +7,11 @@ class ImageGalleryTest < Test::Unit::TestCase |
7 | 7 | end |
8 | 8 | |
9 | 9 | should 'provide description' do |
10 | - ImageGallery.stubs(:==).with(Article).returns(true) | |
11 | - assert_not_equal Article.description, ImageGallery.description | |
10 | + assert_kind_of String, ImageGallery.description | |
12 | 11 | end |
13 | 12 | |
14 | 13 | should 'provide short description' do |
15 | - ImageGallery.stubs(:==).with(Article).returns(true) | |
16 | - assert_not_equal Article.short_description, ImageGallery.short_description | |
14 | + assert_kind_of String, ImageGallery.short_description | |
17 | 15 | end |
18 | 16 | |
19 | 17 | end | ... | ... |
test/unit/rss_feed_test.rb
... | ... | @@ -188,13 +188,11 @@ class RssFeedTest < Test::Unit::TestCase |
188 | 188 | end |
189 | 189 | |
190 | 190 | should 'provide proper short description' do |
191 | - RssFeed.stubs(:==).with(Article).returns(true) | |
192 | - assert_not_equal Article.short_description, RssFeed.short_description | |
191 | + assert_kind_of String, RssFeed.short_description | |
193 | 192 | end |
194 | 193 | |
195 | 194 | should 'provide proper description' do |
196 | - RssFeed.stubs(:==).with(Article).returns(true) | |
197 | - assert_not_equal Article.description, RssFeed.description | |
195 | + assert_kind_of String, RssFeed.description | |
198 | 196 | end |
199 | 197 | |
200 | 198 | should 'provide the correct icon name' do | ... | ... |
test/unit/textile_article_test.rb
... | ... | @@ -8,15 +8,11 @@ class TextileArticleTest < Test::Unit::TestCase |
8 | 8 | attr_reader :profile |
9 | 9 | |
10 | 10 | should 'provide a proper short description' do |
11 | - # not test the actual text, though | |
12 | - TextileArticle.stubs(:==).with(Article).returns(true) | |
13 | - assert_not_equal Article.short_description, TextileArticle.short_description | |
11 | + assert_kind_of String, TextileArticle.short_description | |
14 | 12 | end |
15 | 13 | |
16 | 14 | should 'provide a proper description' do |
17 | - # not test the actual text, though | |
18 | - TextileArticle.stubs(:==).with(Article).returns(true) | |
19 | - assert_not_equal Article.description, TextileArticle.description | |
15 | + assert_kind_of String, TextileArticle.description | |
20 | 16 | end |
21 | 17 | |
22 | 18 | should 'convert Textile to HTML' do | ... | ... |
test/unit/tiny_mce_article_test.rb
... | ... | @@ -7,4 +7,12 @@ class TinyMceArticleTest < Test::Unit::TestCase |
7 | 7 | assert_subclass TextArticle, TinyMceArticle |
8 | 8 | end |
9 | 9 | |
10 | + should 'define description' do | |
11 | + assert_kind_of String, TinyMceArticle.description | |
12 | + end | |
13 | + | |
14 | + should 'define short description' do | |
15 | + assert_kind_of String, TinyMceArticle.short_description | |
16 | + end | |
17 | + | |
10 | 18 | end | ... | ... |
test/unit/uploaded_file_test.rb
... | ... | @@ -28,13 +28,11 @@ class UploadedFileTest < Test::Unit::TestCase |
28 | 28 | end |
29 | 29 | |
30 | 30 | should 'provide proper description' do |
31 | - UploadedFile.stubs(:==).with(Article).returns(true) | |
32 | - assert_not_equal Article.description, UploadedFile.description | |
31 | + assert_kind_of String, UploadedFile.description | |
33 | 32 | end |
34 | 33 | |
35 | 34 | should 'provide proper short description' do |
36 | - UploadedFile.stubs(:==).with(Article).returns(true) | |
37 | - assert_not_equal Article.short_description, UploadedFile.short_description | |
35 | + assert_kind_of String, UploadedFile.short_description | |
38 | 36 | end |
39 | 37 | |
40 | 38 | should 'set name from uploaded filename' do | ... | ... |