diff --git a/app/controllers/admin/environment_design_controller.rb b/app/controllers/admin/environment_design_controller.rb index f033ced..c5d21ec 100644 --- a/app/controllers/admin/environment_design_controller.rb +++ b/app/controllers/admin/environment_design_controller.rb @@ -1,7 +1,7 @@ class EnvironmentDesignController < BoxOrganizerController def available_blocks - @available_blocks ||= [ LoginBlock ] + @available_blocks ||= [ LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock ] end end diff --git a/app/models/environment.rb b/app/models/environment.rb index 8f1ec6f..8cbb3ab 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -180,4 +180,9 @@ class Environment < ActiveRecord::Base self.name || '?' end + has_many :articles, :through => :profiles + def recent_documents(limit = 10) + self.articles.recent(limit) + end + end diff --git a/test/functional/environment_design_controller_test.rb b/test/functional/environment_design_controller_test.rb index 9c89fe6..04193ad 100644 --- a/test/functional/environment_design_controller_test.rb +++ b/test/functional/environment_design_controller_test.rb @@ -11,8 +11,7 @@ class EnvironmentDesignControllerTest < Test::Unit::TestCase @response = ActionController::TestResponse.new end - # Replace this with your real tests. - def test_truth - assert true + should 'have tests' do + flunk 'add some real test here' end end diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index 5f8d644..51338ac 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -219,4 +219,25 @@ class EnvironmentTest < Test::Unit::TestCase assert(environment.blocks.any? { |block| block.kind_of? MainBlock }) end + should 'provide recent_documents' do + environment = Environment.create(:name => 'a test environment') + + # p1 creates one article + p1 = environment.profiles.build(:identifier => 'testprofile1', :name => 'test profile 1') + p1.save! + doc1 = p1.articles.build(:name => 'text 1'); doc1.save! + + # p2 creates two articles + p2 = environment.profiles.build(:identifier => 'testprofile2', :name => 'test profile 2') + p2.save! + doc2 = p2.articles.build(:name => 'text 2'); doc2.save! + doc3 = p2.articles.build(:name => 'text 3'); doc3.save! + + # p1 creates another article + doc4 = p1.articles.build(:name => 'text 4'); doc4.save! + + assert_equivalent [doc1,doc2,doc3,doc4], environment.recent_documents + assert_equivalent [doc1,doc2,doc3], environment.recent_documents(3) + end + end -- libgit2 0.21.2