From 45077a0cc553f08865913696a21f2ef1eb79bc9d Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Tue, 3 Jun 2008 23:45:19 +0000 Subject: [PATCH] ActionItem392: fixing tests by reworking articles's description/short_description --- app/models/article.rb | 22 +++++----------------- app/models/profile.rb | 3 ++- db/migrate/035_specialize_articles.rb | 9 +++++++++ test/unit/article_test.rb | 20 +++++++++----------- test/unit/folder_test.rb | 6 ++---- test/unit/image_gallery_test.rb | 6 ++---- test/unit/rss_feed_test.rb | 6 ++---- test/unit/textile_article_test.rb | 8 ++------ test/unit/tiny_mce_article_test.rb | 8 ++++++++ test/unit/uploaded_file_test.rb | 6 ++---- 10 files changed, 43 insertions(+), 51 deletions(-) create mode 100644 db/migrate/035_specialize_articles.rb diff --git a/app/models/article.rb b/app/models/article.rb index 1f72120..19be54c 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -80,28 +80,16 @@ class Article < ActiveRecord::Base _('HTML Text document') end - def title - name + def self.description + raise NotImplementedError, "#{self} does not implement #description" end def self.short_description - if self == Article - _('Article') - else - _('"%s" article') % self.article_type_name - end - end - - def self.description - if self == Article - _('An ordinary article') - else - _('An article of type "%s"') % self.article_type_name - end + raise NotImplementedError, "#{self} does not implement #short_description" end - def self.article_type_name - self.name.gsub(/article$/i, '') + def title + name end def url diff --git a/app/models/profile.rb b/app/models/profile.rb index 3a39350..598efe2 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -257,7 +257,8 @@ class Profile < ActiveRecord::Base hacked_after_create :insert_default_homepage_and_feed def insert_default_homepage_and_feed - hp = self.articles.build(:name => _("%s's home page") % self.name, :body => _("

This is a default homepage created for %s. It can be changed though the control panel.

") % self.name, :advertise => false) + hp = TinyMceArticle.new(:name => _("%s's home page") % self.name, :body => _("

This is a default homepage created for %s. It can be changed though the control panel.

") % self.name, :advertise => false) + hp.profile = self hp.save! self.home_page = hp self.save! diff --git a/db/migrate/035_specialize_articles.rb b/db/migrate/035_specialize_articles.rb new file mode 100644 index 0000000..9fbaa3e --- /dev/null +++ b/db/migrate/035_specialize_articles.rb @@ -0,0 +1,9 @@ +class SpecializeArticles < ActiveRecord::Migration + def self.up + execute "update articles set type = 'TinyMceArticle' where type = 'Article'" + end + + def self.down + raise ActiveRecord::Migration::IrreversibleMigration, 'cannot reverse this' + end +end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 8454f13..01f0131 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -136,19 +136,16 @@ class ArticleTest < Test::Unit::TestCase assert_equal [other_first, fifth, fourth, third, second, first], Article.recent(6) end - should 'provied proper descriptions' do - assert_equal "Article", Article.short_description - assert_equal "An ordinary article", Article.description + should 'require that subclasses define description' do + assert_raise NotImplementedError do + Article.description + end end - should 'provide a usable descriptions to subclasses that don\'t override them' do - klass = Class.new(Article) - klass.stubs(:name).returns("MyClass") - klass.expects(:_).with('"%s" article').returns('"%s" article') - klass.expects(:_).with('An article of type "%s"').returns('An article of type "%s"') - - assert_equal '"MyClass" article', klass.short_description - assert_equal 'An article of type "MyClass"', klass.description + should 'require that subclasses define short description' do + assert_raise NotImplementedError do + Article.short_description + end end should 'indicate wheter children articles are allowed or not' do @@ -289,4 +286,5 @@ class ArticleTest < Test::Unit::TestCase assert_equal true, a1.display_to?(member) end + end diff --git a/test/unit/folder_test.rb b/test/unit/folder_test.rb index 02823a9..7b73daf 100644 --- a/test/unit/folder_test.rb +++ b/test/unit/folder_test.rb @@ -7,13 +7,11 @@ class FolderTest < ActiveSupport::TestCase end should 'provide proper description' do - Folder.stubs(:==).with(Article).returns(true) - assert_not_equal Article.description, Folder.description + assert_kind_of String, Folder.description end should 'provide proper short description' do - Folder.stubs(:==).with(Article).returns(true) - assert_not_equal Article.short_description, Folder.short_description + assert_kind_of String, Folder.short_description end should 'provide own icon name' do diff --git a/test/unit/image_gallery_test.rb b/test/unit/image_gallery_test.rb index ed7dea0..05cad00 100644 --- a/test/unit/image_gallery_test.rb +++ b/test/unit/image_gallery_test.rb @@ -7,13 +7,11 @@ class ImageGalleryTest < Test::Unit::TestCase end should 'provide description' do - ImageGallery.stubs(:==).with(Article).returns(true) - assert_not_equal Article.description, ImageGallery.description + assert_kind_of String, ImageGallery.description end should 'provide short description' do - ImageGallery.stubs(:==).with(Article).returns(true) - assert_not_equal Article.short_description, ImageGallery.short_description + assert_kind_of String, ImageGallery.short_description end end diff --git a/test/unit/rss_feed_test.rb b/test/unit/rss_feed_test.rb index 1de19eb..45be7c2 100644 --- a/test/unit/rss_feed_test.rb +++ b/test/unit/rss_feed_test.rb @@ -188,13 +188,11 @@ class RssFeedTest < Test::Unit::TestCase end should 'provide proper short description' do - RssFeed.stubs(:==).with(Article).returns(true) - assert_not_equal Article.short_description, RssFeed.short_description + assert_kind_of String, RssFeed.short_description end should 'provide proper description' do - RssFeed.stubs(:==).with(Article).returns(true) - assert_not_equal Article.description, RssFeed.description + assert_kind_of String, RssFeed.description end should 'provide the correct icon name' do diff --git a/test/unit/textile_article_test.rb b/test/unit/textile_article_test.rb index 7e17f78..e2a90b7 100644 --- a/test/unit/textile_article_test.rb +++ b/test/unit/textile_article_test.rb @@ -8,15 +8,11 @@ class TextileArticleTest < Test::Unit::TestCase attr_reader :profile should 'provide a proper short description' do - # not test the actual text, though - TextileArticle.stubs(:==).with(Article).returns(true) - assert_not_equal Article.short_description, TextileArticle.short_description + assert_kind_of String, TextileArticle.short_description end should 'provide a proper description' do - # not test the actual text, though - TextileArticle.stubs(:==).with(Article).returns(true) - assert_not_equal Article.description, TextileArticle.description + assert_kind_of String, TextileArticle.description end should 'convert Textile to HTML' do diff --git a/test/unit/tiny_mce_article_test.rb b/test/unit/tiny_mce_article_test.rb index f83fab4..ef6c979 100644 --- a/test/unit/tiny_mce_article_test.rb +++ b/test/unit/tiny_mce_article_test.rb @@ -7,4 +7,12 @@ class TinyMceArticleTest < Test::Unit::TestCase assert_subclass TextArticle, TinyMceArticle end + should 'define description' do + assert_kind_of String, TinyMceArticle.description + end + + should 'define short description' do + assert_kind_of String, TinyMceArticle.short_description + end + end diff --git a/test/unit/uploaded_file_test.rb b/test/unit/uploaded_file_test.rb index a99e206..2497bba 100644 --- a/test/unit/uploaded_file_test.rb +++ b/test/unit/uploaded_file_test.rb @@ -28,13 +28,11 @@ class UploadedFileTest < Test::Unit::TestCase end should 'provide proper description' do - UploadedFile.stubs(:==).with(Article).returns(true) - assert_not_equal Article.description, UploadedFile.description + assert_kind_of String, UploadedFile.description end should 'provide proper short description' do - UploadedFile.stubs(:==).with(Article).returns(true) - assert_not_equal Article.short_description, UploadedFile.short_description + assert_kind_of String, UploadedFile.short_description end should 'set name from uploaded filename' do -- libgit2 0.21.2