diff --git a/app/controllers/environment_admin/features_controller.rb b/app/controllers/environment_admin/features_controller.rb index 1ca2db6..3213242 100644 --- a/app/controllers/environment_admin/features_controller.rb +++ b/app/controllers/environment_admin/features_controller.rb @@ -8,15 +8,12 @@ class FeaturesController < EnvironmentAdminController post_only :update def update - features = if params[:features].nil? - [] - else - params[:features].keys - end - @environment.enabled_features = features - @environment.save! - flash[:notice] = _('Features updated successfully.') - redirect_to :action => 'index' + if @environment.update_attributes(params[:environment]) + flash[:notice] = _('Features updated successfully.') + redirect_to :action => 'index' + else + render :action => 'index' + end end end diff --git a/app/helpers/features_helper.rb b/app/helpers/features_helper.rb index 1a5e6b2..98a79bb 100644 --- a/app/helpers/features_helper.rb +++ b/app/helpers/features_helper.rb @@ -1,2 +1,10 @@ module FeaturesHelper + def select_organization_approval_method(object, method) + choices = [ + [ _('Administrator must approve all new organizations'), 'admin'], + [ _('Administrator assigns validator organizations per region.'), 'region'], + ] + value = instance_variable_get("@#{object}").send(method).to_s + select_tag("#{object}[#{method}]", options_for_select(choices, value)) + end end diff --git a/app/views/features/_features_table.rhtml b/app/views/features/_features_table.rhtml index 3e1175e..cdda609 100644 --- a/app/views/features/_features_table.rhtml +++ b/app/views/features/_features_table.rhtml @@ -1,11 +1,18 @@ +<% labelled_form_for(:environment, @environment, :url => {:action => 'update'}) do |f| %> + - <% form_tag({:action => 'update'}) do %> <% @features.each do |feature, text| %> - + <% end %> - - <% end %>
<%= text %><%= check_box_tag "features[#{feature}]", '1', @environment.enabled?(feature) %><%= check_box_tag "environment[enabled_features][]", feature, @environment.enabled?(feature) %>
<%= submit_tag _('Save changes') %>
+ +<%= labelled_form_field(_('Organization Approval Method'), select_organization_approval_method('environment', 'organization_approval_method')) %> + +
+ <%= submit_tag _('Save changes') %> +
+ +<% end %> diff --git a/test/functional/features_controller_test.rb b/test/functional/features_controller_test.rb index 50bb285..fb8dfd4 100644 --- a/test/functional/features_controller_test.rb +++ b/test/functional/features_controller_test.rb @@ -19,13 +19,13 @@ class FeaturesControllerTest < Test::Unit::TestCase get :index assert_template 'index' Environment.available_features.each do |feature, text| - assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "features[#{feature}]" }) + assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "environment[enabled_features][]", :value => feature}) end end - def test_update + def test_updates_enabled_features uses_host 'anhetegua.net' - post :update, :features => { 'feature1' => '1', 'feature2' => '1' } + post :update, :environment => { :enabled_features => [ 'feature1', 'feature2' ] } assert_redirected_to :action => 'index' assert_kind_of String, flash[:notice] v = Environment.find(environments(:anhetegua_net).id) @@ -51,4 +51,24 @@ class FeaturesControllerTest < Test::Unit::TestCase assert_redirected_to :action => 'index' end + def test_updates_organization_approval_method + uses_host 'anhetegua.net' + post :update, :environment => { :organization_approval_method => 'region' } + assert_redirected_to :action => 'index' + assert_kind_of String, flash[:notice] + v = Environment.find(environments(:anhetegua_net).id) + assert_equal :region, v.organization_approval_method + end + + def test_should_mark_current_organization_approval_method_in_view + uses_host 'anhetegua.net' + Environment.find(environments(:anhetegua_net).id).update_attributes(:organization_approval_method => :region) + + post :index + + assert_tag :tag => 'select', :attributes => { :name => 'environment[organization_approval_method]' }, :descendant => { :tag => 'option', :attributes => { :value => 'region', :selected => true } } + + + end + end diff --git a/test/integration/enable_disable_features_test.rb b/test/integration/enable_disable_features_test.rb index eb330d2..498edc6 100644 --- a/test/integration/enable_disable_features_test.rb +++ b/test/integration/enable_disable_features_test.rb @@ -9,9 +9,9 @@ class EnableDisableFeaturesTest < ActionController::IntegrationTest get '/admin/features' assert_response :success - assert_tag :tag => 'input', :attributes => { :name => 'features[feature1]' } - assert_tag :tag => 'input', :attributes => { :name => 'features[feature2]' } - assert_tag :tag => 'input', :attributes => { :name => 'features[feature3]' } + assert_tag :tag => 'input', :attributes => { :name => 'environment[enabled_features][]', :value => 'feature1' } + assert_tag :tag => 'input', :attributes => { :name => 'environment[enabled_features][]', :value => 'feature2' } + assert_tag :tag => 'input', :attributes => { :name => 'environment[enabled_features][]', :value => 'feature3' } post '/admin/features/update' assert_response :redirect @@ -20,7 +20,7 @@ class EnableDisableFeaturesTest < ActionController::IntegrationTest assert_response :success assert_equal '/admin/features', path - post '/admin/features/update', :features => { 'feature1' => '1' } + post '/admin/features/update', :environments => { :enabled_features => [ 'feature1' ], :organization_approval_method => 'region' } assert_response :redirect follow_redirect! -- libgit2 0.21.2