Commit 956cd5b1de57f0b03da6b25de66cf62a2d67122f
Committed by
Antonio Terceiro
1 parent
941acfdc
Exists in
master
and in
23 other branches
ActionItem1218: allowing admin change portal folder
Showing
2 changed files
with
30 additions
and
2 deletions
Show diff stats
app/controllers/admin/admin_panel_controller.rb
| @@ -22,8 +22,11 @@ class AdminPanelController < AdminController | @@ -22,8 +22,11 @@ class AdminPanelController < AdminController | ||
| 22 | if request.post? | 22 | if request.post? |
| 23 | portal_community = env.communities.find_by_identifier(params[:portal_community_identifier]) | 23 | portal_community = env.communities.find_by_identifier(params[:portal_community_identifier]) |
| 24 | if portal_community | 24 | if portal_community |
| 25 | - env.portal_community = portal_community | ||
| 26 | - env.save | 25 | + if (env.portal_community != portal_community) |
| 26 | + env.portal_community = portal_community | ||
| 27 | + env.portal_folders = [] | ||
| 28 | + env.save | ||
| 29 | + end | ||
| 27 | redirect_to :action => 'set_portal_folders' | 30 | redirect_to :action => 'set_portal_folders' |
| 28 | else | 31 | else |
| 29 | flash[:notice] = __('Community not found. You must insert the identifier of a community from this environment') | 32 | flash[:notice] = __('Community not found. You must insert the identifier of a community from this environment') |
test/functional/admin_panel_controller_test.rb
| @@ -121,6 +121,31 @@ class AdminPanelControllerTest < Test::Unit::TestCase | @@ -121,6 +121,31 @@ class AdminPanelControllerTest < Test::Unit::TestCase | ||
| 121 | assert_equal c, e.portal_community | 121 | assert_equal c, e.portal_community |
| 122 | end | 122 | end |
| 123 | 123 | ||
| 124 | + should 'change portal_community and list new portal folders as options' do | ||
| 125 | + env = Environment.default | ||
| 126 | + old = Community.create!(:name => 'old_portal') | ||
| 127 | + env.portal_community = old | ||
| 128 | + local = Folder.create!(:profile => old, :name => 'local news') | ||
| 129 | + tech = Folder.create!(:profile => old, :name => 'tech news') | ||
| 130 | + env.portal_folders = [local, tech] | ||
| 131 | + env.save! | ||
| 132 | + | ||
| 133 | + new = Community.create!(:name => 'new_portal') | ||
| 134 | + politics = Folder.create!(:profile => new, :name => 'politics news') | ||
| 135 | + | ||
| 136 | + post :set_portal_community, :portal_community_identifier => new.identifier | ||
| 137 | + | ||
| 138 | + follow_redirect! | ||
| 139 | + assert_tag :tag => 'div', :attributes => {:id => 'available-folders'}, :descendant => {:tag => 'option', :attributes => {:value => politics.id}, :content => politics.name} | ||
| 140 | + end | ||
| 141 | + | ||
| 142 | + [local, tech].each do |folder| | ||
| 143 | + assert_no_tag :tag => 'div', :attributes => {:id => 'available-folders'}, :descendant => {:tag => 'option', :attributes => {:value => folder.id}, :content => folder.name} | ||
| 144 | + end | ||
| 145 | + | ||
| 146 | + end | ||
| 147 | + | ||
| 148 | + | ||
| 124 | should 'redirect to set portal folders' do | 149 | should 'redirect to set portal folders' do |
| 125 | e = Environment.default | 150 | e = Environment.default |
| 126 | @controller.stubs(:environment).returns(e) | 151 | @controller.stubs(:environment).returns(e) |