Commit d460a9ad9c2ec0d17c8dbce82c93667a2dfb02d9

Authored by AntonioTerceiro
1 parent 5bc53780

ActionItem114: abstracting needs_profile and making several tests pass



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@836 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/application.rb
@@ -12,14 +12,11 @@ class ApplicationController < ActionController::Base @@ -12,14 +12,11 @@ class ApplicationController < ActionController::Base
12 extend PermissionCheck 12 extend PermissionCheck
13 init_gettext 'noosfero' 13 init_gettext 'noosfero'
14 14
  15 + include NeedsProfile
  16 +
15 before_filter :detect_stuff_by_domain 17 before_filter :detect_stuff_by_domain
16 attr_reader :environment 18 attr_reader :environment
17 19
18 - def self.needs_profile  
19 - before_filter :load_profile  
20 - design :holder => 'profile'  
21 - end  
22 -  
23 def self.acts_as_environment_admin_controller 20 def self.acts_as_environment_admin_controller
24 before_filter :load_admin_controller 21 before_filter :load_admin_controller
25 end 22 end
@@ -32,10 +29,6 @@ class ApplicationController < ActionController::Base @@ -32,10 +29,6 @@ class ApplicationController < ActionController::Base
32 29
33 protected 30 protected
34 31
35 - def profile  
36 - @profile  
37 - end  
38 -  
39 # TODO: move this logic somewhere else (Domain class?) 32 # TODO: move this logic somewhere else (Domain class?)
40 def detect_stuff_by_domain 33 def detect_stuff_by_domain
41 @domain = Domain.find_by_name(request.host) 34 @domain = Domain.find_by_name(request.host)
app/controllers/profile_admin/cms_controller.rb
1 -class CmsController < ComatoseAdminController 1 +class CmsController < Comatose::AdminController
2 extend PermissionCheck 2 extend PermissionCheck
3 3
4 - ApplicationController.needs_profile 4 + needs_profile
5 5
6 define_option :page_class, Article 6 define_option :page_class, Article
7 7
config/environment.rb
@@ -84,6 +84,7 @@ Comatose.configure do |config| @@ -84,6 +84,7 @@ Comatose.configure do |config|
84 # FIXME: also check permissions 84 # FIXME: also check permissions
85 end 85 end
86 config.admin_includes << :authenticated_system 86 config.admin_includes << :authenticated_system
  87 + config.admin_includes << :needs_profile
87 config.admin_helpers << :application_helper 88 config.admin_helpers << :application_helper
88 config.admin_helpers << :document_helper 89 config.admin_helpers << :document_helper
89 config.admin_helpers << :language_helper 90 config.admin_helpers << :language_helper
lib/needs_profile.rb 0 → 100644
@@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
  1 +module NeedsProfile
  2 +
  3 + module ClassMethods
  4 + def needs_profile
  5 + before_filter :load_profile
  6 + design :holder => 'profile'
  7 + end
  8 + end
  9 +
  10 + def self.included(including)
  11 + including.send(:extend, NeedsProfile::ClassMethods)
  12 + end
  13 +
  14 + protected
  15 +
  16 + def profile
  17 + @profile
  18 + end
  19 +
  20 +end
test/functional/cms_controller_test.rb
@@ -11,8 +11,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase @@ -11,8 +11,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase
11 @response = ActionController::TestResponse.new 11 @response = ActionController::TestResponse.new
12 end 12 end
13 13
14 - # Replace this with your real tests.  
15 - def test_truth  
16 - assert true 14 + def test_missing
  15 + flunk 'need to add some tests for CmsController '
17 end 16 end
18 end 17 end