Commit 06b4d17aa5f84997438aae45addc2809efd3fd5d
1 parent
d88e7095
Exists in
master
and in
29 other branches
ActionItem103: adding organizanization_approval_method for environment features
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@655 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
52 additions
and
20 deletions
Show diff stats
app/controllers/environment_admin/features_controller.rb
... | ... | @@ -8,15 +8,12 @@ class FeaturesController < EnvironmentAdminController |
8 | 8 | |
9 | 9 | post_only :update |
10 | 10 | def update |
11 | - features = if params[:features].nil? | |
12 | - [] | |
13 | - else | |
14 | - params[:features].keys | |
15 | - end | |
16 | - @environment.enabled_features = features | |
17 | - @environment.save! | |
18 | - flash[:notice] = _('Features updated successfully.') | |
19 | - redirect_to :action => 'index' | |
11 | + if @environment.update_attributes(params[:environment]) | |
12 | + flash[:notice] = _('Features updated successfully.') | |
13 | + redirect_to :action => 'index' | |
14 | + else | |
15 | + render :action => 'index' | |
16 | + end | |
20 | 17 | end |
21 | 18 | |
22 | 19 | end | ... | ... |
app/helpers/features_helper.rb
1 | 1 | module FeaturesHelper |
2 | + def select_organization_approval_method(object, method) | |
3 | + choices = [ | |
4 | + [ _('Administrator must approve all new organizations'), 'admin'], | |
5 | + [ _('Administrator assigns validator organizations per region.'), 'region'], | |
6 | + ] | |
7 | + value = instance_variable_get("@#{object}").send(method).to_s | |
8 | + select_tag("#{object}[#{method}]", options_for_select(choices, value)) | |
9 | + end | |
2 | 10 | end | ... | ... |
app/views/features/_features_table.rhtml
1 | +<% labelled_form_for(:environment, @environment, :url => {:action => 'update'}) do |f| %> | |
2 | + | |
1 | 3 | <table> |
2 | - <% form_tag({:action => 'update'}) do %> | |
3 | 4 | <% @features.each do |feature, text| %> |
4 | 5 | <tr> |
5 | 6 | <td><%= text %></td> |
6 | - <td><%= check_box_tag "features[#{feature}]", '1', @environment.enabled?(feature) %></td> | |
7 | + <td><%= check_box_tag "environment[enabled_features][]", feature, @environment.enabled?(feature) %></td> | |
7 | 8 | </tr> |
8 | 9 | <% end %> |
9 | - <tr><td colspan='2'><%= submit_tag _('Save changes') %></td></tr> | |
10 | - <% end %> | |
11 | 10 | </table> |
11 | + | |
12 | +<%= labelled_form_field(_('Organization Approval Method'), select_organization_approval_method('environment', 'organization_approval_method')) %> | |
13 | + | |
14 | +<div> | |
15 | + <%= submit_tag _('Save changes') %> | |
16 | +</div> | |
17 | + | |
18 | +<% end %> | ... | ... |
test/functional/features_controller_test.rb
... | ... | @@ -19,13 +19,13 @@ class FeaturesControllerTest < Test::Unit::TestCase |
19 | 19 | get :index |
20 | 20 | assert_template 'index' |
21 | 21 | Environment.available_features.each do |feature, text| |
22 | - assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "features[#{feature}]" }) | |
22 | + assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "environment[enabled_features][]", :value => feature}) | |
23 | 23 | end |
24 | 24 | end |
25 | 25 | |
26 | - def test_update | |
26 | + def test_updates_enabled_features | |
27 | 27 | uses_host 'anhetegua.net' |
28 | - post :update, :features => { 'feature1' => '1', 'feature2' => '1' } | |
28 | + post :update, :environment => { :enabled_features => [ 'feature1', 'feature2' ] } | |
29 | 29 | assert_redirected_to :action => 'index' |
30 | 30 | assert_kind_of String, flash[:notice] |
31 | 31 | v = Environment.find(environments(:anhetegua_net).id) |
... | ... | @@ -51,4 +51,24 @@ class FeaturesControllerTest < Test::Unit::TestCase |
51 | 51 | assert_redirected_to :action => 'index' |
52 | 52 | end |
53 | 53 | |
54 | + def test_updates_organization_approval_method | |
55 | + uses_host 'anhetegua.net' | |
56 | + post :update, :environment => { :organization_approval_method => 'region' } | |
57 | + assert_redirected_to :action => 'index' | |
58 | + assert_kind_of String, flash[:notice] | |
59 | + v = Environment.find(environments(:anhetegua_net).id) | |
60 | + assert_equal :region, v.organization_approval_method | |
61 | + end | |
62 | + | |
63 | + def test_should_mark_current_organization_approval_method_in_view | |
64 | + uses_host 'anhetegua.net' | |
65 | + Environment.find(environments(:anhetegua_net).id).update_attributes(:organization_approval_method => :region) | |
66 | + | |
67 | + post :index | |
68 | + | |
69 | + assert_tag :tag => 'select', :attributes => { :name => 'environment[organization_approval_method]' }, :descendant => { :tag => 'option', :attributes => { :value => 'region', :selected => true } } | |
70 | + | |
71 | + | |
72 | + end | |
73 | + | |
54 | 74 | end | ... | ... |
test/integration/enable_disable_features_test.rb
... | ... | @@ -9,9 +9,9 @@ class EnableDisableFeaturesTest < ActionController::IntegrationTest |
9 | 9 | |
10 | 10 | get '/admin/features' |
11 | 11 | assert_response :success |
12 | - assert_tag :tag => 'input', :attributes => { :name => 'features[feature1]' } | |
13 | - assert_tag :tag => 'input', :attributes => { :name => 'features[feature2]' } | |
14 | - assert_tag :tag => 'input', :attributes => { :name => 'features[feature3]' } | |
12 | + assert_tag :tag => 'input', :attributes => { :name => 'environment[enabled_features][]', :value => 'feature1' } | |
13 | + assert_tag :tag => 'input', :attributes => { :name => 'environment[enabled_features][]', :value => 'feature2' } | |
14 | + assert_tag :tag => 'input', :attributes => { :name => 'environment[enabled_features][]', :value => 'feature3' } | |
15 | 15 | |
16 | 16 | post '/admin/features/update' |
17 | 17 | assert_response :redirect |
... | ... | @@ -20,7 +20,7 @@ class EnableDisableFeaturesTest < ActionController::IntegrationTest |
20 | 20 | assert_response :success |
21 | 21 | assert_equal '/admin/features', path |
22 | 22 | |
23 | - post '/admin/features/update', :features => { 'feature1' => '1' } | |
23 | + post '/admin/features/update', :environments => { :enabled_features => [ 'feature1' ], :organization_approval_method => 'region' } | |
24 | 24 | assert_response :redirect |
25 | 25 | |
26 | 26 | follow_redirect! | ... | ... |