Commit 843344641754928922af8c5c7aba52be52862f0e

Authored by AntonioTerceiro
1 parent e3405472

ActionItem152: adding ArticleBlock; first try


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1236 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/article_block.rb 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +class ArticleBlock < Block
  2 +
  3 + def self.description
  4 + _('Display one of your contents.')
  5 + end
  6 +
  7 + def content
  8 + article.to_html
  9 + end
  10 +
  11 + def article_id
  12 + self.settings[:article_id]
  13 + end
  14 +
  15 + def article_id= value
  16 + self.settings[:article_id] = value
  17 + end
  18 +
  19 + def article(reload = false)
  20 + @article = nil if reload
  21 + if @article || article_id
  22 + @article = Article.find(article_id)
  23 + end
  24 + @article
  25 + end
  26 +
  27 + def article=(obj)
  28 + self.article_id = obj.id
  29 + @article = obj
  30 + end
  31 +
  32 +end
... ...
test/unit/article_block_test.rb 0 → 100644
... ... @@ -0,0 +1,33 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ArticleBlockTest < Test::Unit::TestCase
  4 +
  5 + should 'describe itself' do
  6 + assert_not_equal Block.description, ArticleBlock.description
  7 + end
  8 +
  9 + should "take article's content" do
  10 + block = ArticleBlock.new
  11 + html = mock
  12 + article = mock
  13 + article.expects(:to_html).returns(html)
  14 + block.stubs(:article).returns(article)
  15 +
  16 + assert_same html, block.content
  17 + end
  18 +
  19 + should 'refer to an article' do
  20 + profile = create_user('testuser').person
  21 + article = profile.articles.build(:name => 'test article')
  22 + article.save!
  23 +
  24 + block = ArticleBlock.new
  25 + block.article = article
  26 +
  27 + block.save!
  28 +
  29 + assert_equal article, Block.find(block.id).article
  30 +
  31 + end
  32 +
  33 +end
... ...