diff --git a/app/controllers/admin/admin_panel_controller.rb b/app/controllers/admin/admin_panel_controller.rb index 6fc0ade..1660e64 100644 --- a/app/controllers/admin/admin_panel_controller.rb +++ b/app/controllers/admin/admin_panel_controller.rb @@ -22,8 +22,11 @@ class AdminPanelController < AdminController if request.post? portal_community = env.communities.find_by_identifier(params[:portal_community_identifier]) if portal_community - env.portal_community = portal_community - env.save + if (env.portal_community != portal_community) + env.portal_community = portal_community + env.portal_folders = [] + env.save + end redirect_to :action => 'set_portal_folders' else flash[:notice] = __('Community not found. You must insert the identifier of a community from this environment') diff --git a/test/functional/admin_panel_controller_test.rb b/test/functional/admin_panel_controller_test.rb index bdf078b..d386517 100644 --- a/test/functional/admin_panel_controller_test.rb +++ b/test/functional/admin_panel_controller_test.rb @@ -121,6 +121,31 @@ class AdminPanelControllerTest < Test::Unit::TestCase assert_equal c, e.portal_community end + should 'change portal_community and list new portal folders as options' do + env = Environment.default + old = Community.create!(:name => 'old_portal') + env.portal_community = old + local = Folder.create!(:profile => old, :name => 'local news') + tech = Folder.create!(:profile => old, :name => 'tech news') + env.portal_folders = [local, tech] + env.save! + + new = Community.create!(:name => 'new_portal') + politics = Folder.create!(:profile => new, :name => 'politics news') + + post :set_portal_community, :portal_community_identifier => new.identifier + + follow_redirect! + assert_tag :tag => 'div', :attributes => {:id => 'available-folders'}, :descendant => {:tag => 'option', :attributes => {:value => politics.id}, :content => politics.name} + end + + [local, tech].each do |folder| + assert_no_tag :tag => 'div', :attributes => {:id => 'available-folders'}, :descendant => {:tag => 'option', :attributes => {:value => folder.id}, :content => folder.name} + end + + end + + should 'redirect to set portal folders' do e = Environment.default @controller.stubs(:environment).returns(e) -- libgit2 0.21.2