Commit 7712c7369d0d3a55458548641dd97919b9a4b03d

Authored by AntonioTerceiro
1 parent 892e18f7

ActionItem153: adding recent documents support for environments


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1281 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/admin/environment_design_controller.rb
1 1 class EnvironmentDesignController < BoxOrganizerController
2 2  
3 3 def available_blocks
4   - @available_blocks ||= [ LoginBlock ]
  4 + @available_blocks ||= [ LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock ]
5 5 end
6 6  
7 7 end
... ...
app/models/environment.rb
... ... @@ -180,4 +180,9 @@ class Environment &lt; ActiveRecord::Base
180 180 self.name || '?'
181 181 end
182 182  
  183 + has_many :articles, :through => :profiles
  184 + def recent_documents(limit = 10)
  185 + self.articles.recent(limit)
  186 + end
  187 +
183 188 end
... ...
test/functional/environment_design_controller_test.rb
... ... @@ -11,8 +11,7 @@ class EnvironmentDesignControllerTest &lt; Test::Unit::TestCase
11 11 @response = ActionController::TestResponse.new
12 12 end
13 13  
14   - # Replace this with your real tests.
15   - def test_truth
16   - assert true
  14 + should 'have tests' do
  15 + flunk 'add some real test here'
17 16 end
18 17 end
... ...
test/unit/environment_test.rb
... ... @@ -219,4 +219,25 @@ class EnvironmentTest &lt; Test::Unit::TestCase
219 219 assert(environment.blocks.any? { |block| block.kind_of? MainBlock })
220 220 end
221 221  
  222 + should 'provide recent_documents' do
  223 + environment = Environment.create(:name => 'a test environment')
  224 +
  225 + # p1 creates one article
  226 + p1 = environment.profiles.build(:identifier => 'testprofile1', :name => 'test profile 1')
  227 + p1.save!
  228 + doc1 = p1.articles.build(:name => 'text 1'); doc1.save!
  229 +
  230 + # p2 creates two articles
  231 + p2 = environment.profiles.build(:identifier => 'testprofile2', :name => 'test profile 2')
  232 + p2.save!
  233 + doc2 = p2.articles.build(:name => 'text 2'); doc2.save!
  234 + doc3 = p2.articles.build(:name => 'text 3'); doc3.save!
  235 +
  236 + # p1 creates another article
  237 + doc4 = p1.articles.build(:name => 'text 4'); doc4.save!
  238 +
  239 + assert_equivalent [doc1,doc2,doc3,doc4], environment.recent_documents
  240 + assert_equivalent [doc1,doc2,doc3], environment.recent_documents(3)
  241 + end
  242 +
222 243 end
... ...