Commit c91af6365361a18f426c6fc06d7fd78b79f1cdd7
Committed by
Rafael Manzo
1 parent
43a65639
Exists in
colab
and in
4 other branches
Add a redirect on hotspot metric configuration creation
Now it doesn't redirect to the tree metric configuration creation page after choosing a hotspot metric configuration Adds a bunch of code from removed commit ec4c3ef6f29aa34f3c58819df4f84725aff8bd60 that fixed the view after the modification introduced by 39bc97f568d6989ae98b1f5fd5452515ee54045f. It fixes the view to properly work with the path helper. This is a squash of two commits. Signed off by: Diego Araújo <diegoamc90@gmail.com> Signed off by: Heitor Reis <marcheing@gmail.com>
Showing
4 changed files
with
89 additions
and
6 deletions
Show diff stats
app/controllers/hotspot_metric_configurations_controller.rb
| 1 | 1 | class HotspotMetricConfigurationsController < BaseMetricConfigurationsController |
| 2 | - def create; end | |
| 3 | -end | |
| 4 | 2 | \ No newline at end of file |
| 3 | + def create | |
| 4 | + super | |
| 5 | + @metric_configuration.metric = KalibroClient::Entities::Processor::MetricCollectorDetails.find_by_name(params[:metric_collector_name]).find_metric_by_code params[:metric_code] | |
| 6 | + respond_to do |format| | |
| 7 | + if @metric_configuration.save | |
| 8 | + format.html do | |
| 9 | + redirect_to kalibro_configuration_path(@metric_configuration.kalibro_configuration_id), | |
| 10 | + notice: t('successfully_created', record: t(@metric_configuration.class)) | |
| 11 | + end | |
| 12 | + else | |
| 13 | + failed_action(format) | |
| 14 | + end | |
| 15 | + end | |
| 16 | + clear_caches | |
| 17 | + end | |
| 18 | + | |
| 19 | + protected | |
| 20 | + | |
| 21 | + def update_metric_configuration(new_metric_configuration) | |
| 22 | + @kalibro_configuration_id = params[:kalibro_configuration_id] | |
| 23 | + @metric_configuration = new_metric_configuration | |
| 24 | + end | |
| 25 | + | |
| 26 | + def metric_configuration_params | |
| 27 | + { kalibro_configuration_id: params[:kalibro_configuration_id] } | |
| 28 | + end | |
| 29 | + | |
| 30 | + private | |
| 31 | + | |
| 32 | + def failed_action(format) | |
| 33 | + @kalibro_configuration_id = params[:kalibro_configuration_id] | |
| 34 | + format.html { redirect_to kalibro_configuration_choose_metric_path } | |
| 35 | + format.json { render json: @metric_configuration.kalibro_errors, status: :unprocessable_entity } | |
| 36 | + end | |
| 37 | + | |
| 38 | + def clear_caches | |
| 39 | + Rails.cache.delete("#{params[:kalibro_configuration_id]}_tree_metric_configurations") | |
| 40 | + Rails.cache.delete("#{params[:kalibro_configuration_id]}_hotspot_metric_configurations") | |
| 41 | + end | |
| 42 | +end | ... | ... |
app/views/metric_configurations/choose_metric.html.erb
| ... | ... | @@ -12,7 +12,10 @@ |
| 12 | 12 | <h3 class="jquery-ui-accordion"><%= metric_collector_name %></h3> |
| 13 | 13 | <div> |
| 14 | 14 | <% supported_metrics_of(metric_collector_name).each do |code, metric| %> |
| 15 | - <%= link_to metric.name, '#', onclick: "MetricCollector.choose_metric(\"#{code}\", \"#{metric_collector_name}\");", remote: true %><br> | |
| 15 | + <%= metric.type %> | |
| 16 | + <%= link_to metric.name, "#", | |
| 17 | + onclick: "MetricCollector.choose_metric(\"#{code}\", \"#{metric_collector_name}\", \"#{choose_metric_path(metric, @kalibro_configuration.id)}\");", | |
| 18 | + remote: true %><br> | |
| 16 | 19 | <% end %> |
| 17 | 20 | </div> |
| 18 | 21 | <% end %> | ... | ... |
features/hotspot_metric_configuration/create.feature
| ... | ... | @@ -11,8 +11,6 @@ Feature: Hotspot Metric Configuration Creation |
| 11 | 11 | And I am at the Sample Configuration page |
| 12 | 12 | And I click the Add Metric link |
| 13 | 13 | And I click the "MetricFu" h3 |
| 14 | - And I click the Duplicate Code link | |
| 15 | - When I fill the Weight field with "2" | |
| 16 | - And I press the Save button | |
| 14 | + When I click the Duplicate Code link | |
| 17 | 15 | Then I should see "Hotspot Metrics" |
| 18 | 16 | And I should see "Duplicate Code" | ... | ... |
spec/controllers/hotspot_metric_configuration_controller_spec.rb
0 → 100644
| ... | ... | @@ -0,0 +1,44 @@ |
| 1 | +require 'rails_helper' | |
| 2 | + | |
| 3 | +describe HotspotMetricConfigurationsController, :type => :controller do | |
| 4 | + let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration, :with_id) } | |
| 5 | + describe 'create' do | |
| 6 | + let!(:metric_configuration) { FactoryGirl.build(:hotspot_metric_configuration) } | |
| 7 | + let(:metric_configuration_params) { metric_configuration.to_hash } | |
| 8 | + let(:metric_collector) { FactoryGirl.build(:metric_collector) } | |
| 9 | + | |
| 10 | + before do | |
| 11 | + sign_in FactoryGirl.create(:user) | |
| 12 | + end | |
| 13 | + | |
| 14 | + context 'when the current user owns the metric configuration' do | |
| 15 | + before :each do | |
| 16 | + subject.expects(:kalibro_configuration_owner?).returns true | |
| 17 | + end | |
| 18 | + | |
| 19 | + context 'with valid fields' do | |
| 20 | + before :each do | |
| 21 | + MetricConfiguration.any_instance.expects(:save).returns(true) | |
| 22 | + KalibroClient::Entities::Processor::MetricCollectorDetails.expects(:find_by_name).with(metric_collector.name).returns(metric_collector) | |
| 23 | + metric_collector.expects(:find_metric_by_code).with(metric_configuration.metric.code).returns(metric_configuration.metric) | |
| 24 | + | |
| 25 | + post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration: metric_configuration_params, metric_collector_name: metric_collector.name, metric_code: metric_configuration.metric.code | |
| 26 | + end | |
| 27 | + | |
| 28 | + it { is_expected.to respond_with(:redirect) } | |
| 29 | + end | |
| 30 | + | |
| 31 | + context 'with invalid fields' do | |
| 32 | + before :each do | |
| 33 | + MetricConfiguration.any_instance.expects(:save).returns(false) | |
| 34 | + KalibroClient::Entities::Processor::MetricCollectorDetails.expects(:find_by_name).with(metric_collector.name).returns(metric_collector) | |
| 35 | + metric_collector.expects(:find_metric_by_code).with(metric_configuration.metric.code).returns(metric_configuration.metric) | |
| 36 | + | |
| 37 | + post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration: metric_configuration_params, metric_collector_name: metric_collector.name, metric_code: metric_configuration.metric.code | |
| 38 | + end | |
| 39 | + | |
| 40 | + it { is_expected.to respond_with(:redirect) } | |
| 41 | + end | |
| 42 | + end | |
| 43 | + end | |
| 44 | +end | ... | ... |