Commit a6cc76e43388f9f77a23ebf2942b71a91eda4e3d
Committed by
Paulo Meireles
1 parent
efcfcd45
Exists in
staging
and in
42 other branches
[Mezuro] Refactored configuration with tests
Showing
6 changed files
with
167 additions
and
132 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb
| ... | ... | @@ -40,7 +40,7 @@ class MezuroPluginMyprofileController < ProfileController |
| 40 | 40 | def create_metric_configuration |
| 41 | 41 | id = params[:id] |
| 42 | 42 | metric_name = params[:metric_configuration][:metric][:name] |
| 43 | - Kalibro::MetricConfiguration.new(params[:metric_configuration]).save | |
| 43 | + (Kalibro::MetricConfiguration.new(params[:metric_configuration])).save | |
| 44 | 44 | redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{id}&metric_name=#{metric_name.gsub(/\s/, '+')}" |
| 45 | 45 | end |
| 46 | 46 | |
| ... | ... | @@ -66,6 +66,14 @@ class MezuroPluginMyprofileController < ProfileController |
| 66 | 66 | metric_configuration.update_attributes params[:metric_configuration] |
| 67 | 67 | redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" |
| 68 | 68 | end |
| 69 | + | |
| 70 | + def remove_metric_configuration | |
| 71 | + configuration_content = profile.articles.find(params[:id]) | |
| 72 | + metric_name = params[:metric_name] | |
| 73 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) | |
| 74 | + metric_configuration.destroy | |
| 75 | + redirect_to "/#{profile.identifier}/#{configuration_content.slug}" | |
| 76 | + end | |
| 69 | 77 | |
| 70 | 78 | def new_range |
| 71 | 79 | @configuration_content = profile.articles.find(params[:id]) |
| ... | ... | @@ -104,9 +112,9 @@ class MezuroPluginMyprofileController < ProfileController |
| 104 | 112 | def remove_range |
| 105 | 113 | configuration_content = profile.articles.find(params[:id]) |
| 106 | 114 | metric_name = params[:metric_name] |
| 107 | - beginning_id = params[:range_beginning] | |
| 115 | + beginning_id = params[:beginning_id] | |
| 108 | 116 | metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) |
| 109 | - metric_configuration.ranges.delete_if { |range| range.beginning == beginning_id.to_f }.inspect | |
| 117 | + metric_configuration.ranges.delete_if { |range| range.beginning == beginning_id.to_f } | |
| 110 | 118 | metric_configuration.save |
| 111 | 119 | formatted_metric_name = metric_name.gsub(/\s/, '+') |
| 112 | 120 | if metric_configuration.metric.class == Kalibro::CompoundMetric |
| ... | ... | @@ -116,12 +124,4 @@ class MezuroPluginMyprofileController < ProfileController |
| 116 | 124 | end |
| 117 | 125 | end |
| 118 | 126 | |
| 119 | - def remove_metric_configuration | |
| 120 | - configuration_content = profile.articles.find(params[:id]) | |
| 121 | - metric_name = params[:metric_name] | |
| 122 | - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) | |
| 123 | - metric_configuration.destroy | |
| 124 | - redirect_to "/#{profile.identifier}/#{configuration_content.slug}" | |
| 125 | - end | |
| 126 | - | |
| 127 | 127 | end | ... | ... |
plugins/mezuro/lib/kalibro/metric_configuration.rb
| ... | ... | @@ -7,8 +7,8 @@ class Kalibro::MetricConfiguration < Kalibro::Model |
| 7 | 7 | |
| 8 | 8 | def metric=(value) |
| 9 | 9 | if value.kind_of?(Hash) |
| 10 | - @metric = to_object(value, Kalibro::CompoundMetric) if value.has_key?(:script) | |
| 11 | 10 | @metric = to_object(value, Kalibro::NativeMetric) if value.has_key?(:origin) |
| 11 | + @metric = to_object(value, Kalibro::CompoundMetric) if value.has_key?(:script) | |
| 12 | 12 | else |
| 13 | 13 | @metric = value |
| 14 | 14 | end | ... | ... |
plugins/mezuro/test/fixtures/configuration_fixtures.rb
| ... | ... | @@ -8,7 +8,7 @@ class ConfigurationFixtures |
| 8 | 8 | |
| 9 | 9 | def self.configuration_hash |
| 10 | 10 | { |
| 11 | - :name => 'Kalibro for Java', | |
| 11 | + :name => 'Sample Configuration', | |
| 12 | 12 | :description => 'Kalibro configuration for Java projects.', |
| 13 | 13 | :metric_configuration => [ |
| 14 | 14 | MetricConfigurationFixtures.amloc_metric_configuration_hash, | ... | ... |
plugins/mezuro/test/functional/mezuro_plugin_myprofile_controller_test.rb
| ... | ... | @@ -5,6 +5,7 @@ require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures" |
| 5 | 5 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/native_metric_fixtures" |
| 6 | 6 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures" |
| 7 | 7 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" |
| 8 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures" | |
| 8 | 9 | |
| 9 | 10 | class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
| 10 | 11 | |
| ... | ... | @@ -15,178 +16,212 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
| 15 | 16 | @profile = fast_create(Community) |
| 16 | 17 | |
| 17 | 18 | @base_tool = BaseToolFixtures.base_tool |
| 19 | + @base_tool_hash = BaseToolFixtures.base_tool_hash | |
| 18 | 20 | @metric = NativeMetricFixtures.amloc |
| 19 | 21 | @metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration |
| 20 | 22 | @metric_configuration_hash = MetricConfigurationFixtures.amloc_metric_configuration_hash |
| 21 | 23 | @compound_metric_configuration = MetricConfigurationFixtures.sc_metric_configuration |
| 24 | + @compound_metric_configuration_hash = MetricConfigurationFixtures.sc_metric_configuration_hash | |
| 22 | 25 | @configuration = ConfigurationFixtures.configuration |
| 26 | + @configuration_hash = ConfigurationFixtures.configuration_hash | |
| 27 | + | |
| 28 | + Kalibro::Configuration.expects(:all_names).returns([]) | |
| 29 | + @content = MezuroPlugin::ConfigurationContent.new(:profile => @profile, :name => @configuration.name) | |
| 30 | + @content.expects(:send_configuration_to_service).returns(nil) | |
| 31 | + @content.save | |
| 32 | + | |
| 33 | + @native_hash = @metric_configuration.to_hash.merge({:configuration_name => @metric_configuration.configuration_name}) | |
| 34 | + @native_hash.delete :attributes! | |
| 35 | + @compound_hash = @compound_metric_configuration.to_hash.merge({:configuration_name => @compound_metric_configuration.configuration_name}) | |
| 36 | + @compound_hash.delete :attributes! | |
| 37 | + | |
| 38 | + @range = RangeFixtures.range_excellent | |
| 39 | + @range_hash = RangeFixtures.range_excellent_hash | |
| 23 | 40 | end |
| 24 | 41 | |
| 25 | - should 'test choose_base_tool' do | |
| 26 | - create_configuration_content | |
| 27 | - Kalibro::BaseTool.expects(:all_names).returns(@base_tool.name) | |
| 42 | + should 'test choose base tool' do | |
| 43 | + Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool_names).returns({:base_tool_name => @base_tool.name}) | |
| 28 | 44 | get :choose_base_tool, :profile => @profile.identifier, :id => @content.id |
| 29 | - assert_equal @base_tool.name, assigns(:base_tools) | |
| 45 | + assert_equal [@base_tool.name], assigns(:base_tools) | |
| 30 | 46 | assert_equal @content, assigns(:configuration_content) |
| 31 | 47 | assert_response 200 |
| 32 | 48 | end |
| 33 | 49 | |
| 34 | - should 'test choose_metric' do | |
| 35 | - create_configuration_content | |
| 36 | - Kalibro::BaseTool.expects(:find_by_name).with(@base_tool.name).returns(@base_tool) | |
| 37 | - @base_tool.expects(:supported_metrics).returns(@base_tool.supported_metric) | |
| 50 | + should 'test choose metric' do | |
| 51 | + Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool, {:base_tool_name => @base_tool.name}).returns({:base_tool => @base_tool_hash}) | |
| 38 | 52 | get :choose_metric, :profile => @profile.identifier, :id => @content.id, :base_tool => @base_tool.name |
| 39 | 53 | assert_equal @content, assigns(:configuration_content) |
| 40 | 54 | assert_equal @base_tool.name, assigns(:base_tool) |
| 41 | - assert_equal @base_tool.supported_metric, assigns(:supported_metrics) | |
| 55 | + assert_equal @base_tool.supported_metric[0].name, assigns(:supported_metrics)[0].name | |
| 42 | 56 | assert_response 200 |
| 43 | 57 | end |
| 44 | 58 | |
| 45 | - should 'test new_metric_configuration' do | |
| 46 | - create_configuration_content | |
| 47 | - Kalibro::BaseTool.expects(:find_by_name).with(@base_tool.name).returns(@base_tool) | |
| 48 | - @base_tool.expects(:metric).with(@metric.name).returns(@metric) | |
| 59 | + should 'test new metric configuration' do | |
| 60 | + Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool, {:base_tool_name => @base_tool.name}).returns({:base_tool => @base_tool_hash}) | |
| 49 | 61 | get :new_metric_configuration, :profile => @profile.identifier, :id => @content.id, :base_tool => @base_tool.name, :metric_name => @metric.name |
| 50 | 62 | assert_equal @content, assigns(:configuration_content) |
| 51 | - assert_equal @metric, assigns(:metric) | |
| 63 | + assert_equal @metric.name, assigns(:metric).name | |
| 52 | 64 | assert_response 200 |
| 53 | 65 | end |
| 54 | 66 | |
| 55 | 67 | |
| 56 | - should 'test new_compound_metric_configuration' do | |
| 57 | - create_configuration_content | |
| 58 | - Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) | |
| 59 | - @configuration.expects(:metric_configurations).returns(@configuration.metric_configuration) | |
| 68 | + should 'test new compound metric configuration' do | |
| 69 | + Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, {:configuration_name => @content.name}).returns({:configuration => @configuration_hash}) | |
| 60 | 70 | get :new_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id |
| 61 | 71 | assert_equal @content, assigns(:configuration_content) |
| 62 | - assert_equal @configuration.metric_configuration, assigns(:metric_configurations) | |
| 72 | + assert_equal @configuration.metric_configuration[0].code, assigns(:metric_configurations)[0].code | |
| 63 | 73 | assert_response 200 |
| 64 | 74 | end |
| 65 | 75 | |
| 66 | - should 'test edit_metric_configuration' do | |
| 67 | - create_configuration_content | |
| 68 | - Kalibro::MetricConfiguration.expects(:find_by_configuration_name_and_metric_name).with(@configuration.name, @metric.name).returns(@metric_configuration) | |
| 76 | + should 'test edit metric configuration' do | |
| 77 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
| 78 | + :configuration_name => @content.name, | |
| 79 | + :metric_name => @metric_configuration.metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
| 69 | 80 | get :edit_metric_configuration, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name |
| 70 | 81 | assert_equal @content, assigns(:configuration_content) |
| 71 | - assert_equal @metric_configuration, assigns(:metric_configuration) | |
| 72 | - assert_equal @metric_configuration.metric, assigns(:metric) | |
| 82 | + assert_equal @metric_configuration.code, assigns(:metric_configuration).code | |
| 83 | + assert_equal @metric_configuration.metric.name, assigns(:metric).name | |
| 73 | 84 | assert_response 200 |
| 74 | 85 | end |
| 75 | 86 | |
| 76 | - should 'test edit_compound_metric_configuration' do | |
| 77 | - create_configuration_content | |
| 78 | - Kalibro::MetricConfiguration.expects(:find_by_configuration_name_and_metric_name).with(@configuration.name, @metric.name).returns(@compound_metric_configuration) | |
| 79 | - Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) | |
| 80 | - @configuration.expects(:metric_configurations).returns(@configuration.metric_configuration) | |
| 81 | - get :edit_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name | |
| 87 | + should 'test edit compound metric configuration' do | |
| 88 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
| 89 | + :configuration_name => @content.name, | |
| 90 | + :metric_name => @compound_metric_configuration.metric.name}).returns({:metric_configuration => @compound_metric_configuration_hash}) | |
| 91 | + Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, {:configuration_name => @content.name}).returns({:configuration => @configuration_hash}) | |
| 92 | + get :edit_compound_metric_configuration, | |
| 93 | + :profile => @profile.identifier, | |
| 94 | + :id => @content.id, | |
| 95 | + :metric_name => @compound_metric_configuration.metric.name | |
| 82 | 96 | assert_equal @content, assigns(:configuration_content) |
| 83 | - assert_equal @compound_metric_configuration, assigns(:metric_configuration) | |
| 84 | - assert_equal @compound_metric_configuration.metric, assigns(:metric) | |
| 85 | - assert_equal @configuration.metric_configuration, assigns(:metric_configurations) | |
| 97 | + assert_equal @compound_metric_configuration.code, assigns(:metric_configuration).code | |
| 98 | + assert_equal @compound_metric_configuration.metric.name, assigns(:metric).name | |
| 99 | + assert_equal @configuration.metric_configuration[0].code, assigns(:metric_configurations)[0].code | |
| 86 | 100 | assert_response 200 |
| 87 | 101 | end |
| 88 | 102 | |
| 89 | - should 'test create_metric_configuration' do | |
| 90 | - create_configuration_content | |
| 91 | - @metric_configuration.expects(:save).returns(true) | |
| 92 | - MezuroPlugin::ConfigurationContent.expects(:validate_kalibro_configuration_name).returns(true) | |
| 93 | - MezuroPlugin::ConfigurationContent.expects(:send_configuration_to_service).returns(true) | |
| 94 | - get :create_metric_configuration, :profile => @profile.identifier, :id => @content.id, :metric_configuration => @metric_configuration_hash | |
| 103 | + should 'test create native metric configuration' do | |
| 104 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
| 105 | + :metric_configuration => @metric_configuration.to_hash, | |
| 106 | + :configuration_name => @metric_configuration.configuration_name}) | |
| 107 | + get :create_metric_configuration, | |
| 108 | + :profile => @profile.identifier, | |
| 109 | + :id => @content.id, | |
| 110 | + :metric_configuration => @native_hash | |
| 95 | 111 | assert_response 302 |
| 96 | 112 | end |
| 97 | 113 | |
| 98 | -=begin | |
| 99 | 114 | should 'test compound metric creation' do |
| 100 | - create_configuration_content | |
| 101 | - Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
| 102 | - @metric_configuration_client.expects(:save) | |
| 115 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
| 116 | + :metric_configuration => @compound_metric_configuration.to_hash, | |
| 117 | + :configuration_name => @compound_metric_configuration.configuration_name}) | |
| 103 | 118 | get :create_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id, |
| 104 | - :metric_configuration => { :code => @compound_metric_configuration.code, :weight => @compound_metric_configuration.weight, | |
| 105 | - :aggregation_form => @compound_metric_configuration.aggregation_form, :metric => { :name => @compound_metric_configuration.metric.name , | |
| 106 | - :description => @compound_metric_configuration.metric.description, :scope => @compound_metric_configuration.metric.scope, | |
| 107 | - :script => @compound_metric_configuration.metric.script}} | |
| 119 | + :metric_configuration => @compound_hash | |
| 108 | 120 | assert_response 302 |
| 109 | 121 | end |
| 110 | 122 | |
| 111 | - should 'test metric edition' do | |
| 112 | - create_configuration_content | |
| 113 | - Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
| 114 | - @metric_configuration_client.expects(:metric_configuration).with(@configuration.name,@metric.name).returns(@metric_configuration) | |
| 115 | - get :edit_metric_configuration, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name | |
| 116 | - assert_response 200 | |
| 117 | - end | |
| 118 | - | |
| 119 | - should 'test compound metric edition' do | |
| 120 | - create_configuration_content | |
| 121 | - configuration_client = mock | |
| 122 | - Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
| 123 | - Kalibro::Configuration.expects(:new).returns(configuration_client) | |
| 124 | - configuration_client.expects(:configuration).with(@configuration.name).returns(@configuration) | |
| 125 | - @metric_configuration_client.expects(:metric_configuration).with(@configuration.name,@metric.name).returns(@compound_metric_configuration) | |
| 126 | - get :edit_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name | |
| 127 | - assert_response 200 | |
| 128 | - end | |
| 129 | - | |
| 130 | - should 'update metric configuration' do | |
| 131 | - create_configuration_content | |
| 132 | - Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
| 133 | - Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
| 134 | - @metric_configuration_client.expects(:metric_configuration).with(@configuration.name, @metric_configuration.metric.name).returns(@metric_configuration) | |
| 135 | - @metric_configuration_client.expects(:save) | |
| 123 | + should 'test update native metric configuration' do | |
| 124 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
| 125 | + :configuration_name => @content.name, | |
| 126 | + :metric_name => @metric_configuration.metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
| 127 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
| 128 | + :metric_configuration => @metric_configuration.to_hash, | |
| 129 | + :configuration_name => @metric_configuration.configuration_name}) | |
| 136 | 130 | get :update_metric_configuration, :profile => @profile.identifier, :id => @content.id, |
| 137 | - :metric_configuration => { :code => @metric_configuration.code, :weight => @metric_configuration.weight, :aggregation => @metric_configuration.aggregation_form, | |
| 138 | - :metric => { :name => @metric.name, :origin => @metric.origin, :description => @metric.description, :scope => @metric.scope, :language => @metric.language }} | |
| 131 | + :metric_configuration => @native_hash | |
| 132 | + assert_equal @content, assigns(:configuration_content) | |
| 139 | 133 | assert_response 302 |
| 140 | 134 | end |
| 141 | 135 | |
| 142 | - should 'update compound metric configuration' do | |
| 143 | - create_configuration_content | |
| 144 | - Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
| 145 | - Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
| 146 | - @metric_configuration_client.expects(:metric_configuration).with(@configuration.name, @compound_metric_configuration.metric.name).returns(@compound_metric_configuration) | |
| 147 | - @metric_configuration_client.expects(:save) | |
| 136 | + should 'test update compound metric configuration' do | |
| 137 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
| 138 | + :configuration_name => @content.name, | |
| 139 | + :metric_name => @compound_metric_configuration.metric.name}).returns({:metric_configuration => @compound_metric_configuration_hash}) | |
| 140 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
| 141 | + :metric_configuration => @compound_metric_configuration.to_hash, | |
| 142 | + :configuration_name => @compound_metric_configuration.configuration_name}) | |
| 148 | 143 | get :update_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id, |
| 149 | - :metric_configuration => { :code => @compound_metric_configuration.code, :weight => @compound_metric_configuration.weight, | |
| 150 | - :aggregation_form => @compound_metric_configuration.aggregation_form, :metric => { :name => @compound_metric_configuration.metric.name , | |
| 151 | - :description => @compound_metric_configuration.metric.description, :scope => @compound_metric_configuration.metric.scope, | |
| 152 | - :script => @compound_metric_configuration.metric.script}} | |
| 144 | + :metric_configuration => @compound_hash | |
| 145 | + assert_equal @content, assigns(:configuration_content) | |
| 153 | 146 | assert_response 302 |
| 154 | 147 | end |
| 155 | 148 | |
| 156 | - should 'assign configuration name and metric name to new range' do | |
| 157 | - create_configuration_content | |
| 158 | - get :new_range, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name | |
| 159 | - assert_equal assigns(:configuration_content), @content | |
| 160 | - assert_equal assigns(:metric_name), @metric.name | |
| 161 | - end | |
| 162 | - | |
| 163 | - should 'create instance range' do | |
| 164 | - create_configuration_content | |
| 165 | - Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
| 166 | - Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
| 167 | - @metric_configuration_client.expects(:metric_configuration).with(@configuration.name, @metric.name).returns(@metric_configuration) | |
| 168 | - @metric_configuration_client.expects(:save) | |
| 169 | - range = @metric_configuration.ranges[0] | |
| 170 | - get :create_range, :profile => @profile.identifier, :range => { :beginning => range.beginning, :end => range.end, :label => range.label, | |
| 171 | - :grade => range.grade, :color => range.color, :comments => range.comments }, :id => @content.id, :metric_name => @metric.name | |
| 172 | - assert assigns(:range).instance_of?(Kalibro::Range) | |
| 173 | - end | |
| 174 | - | |
| 175 | - should 'redirect from remove metric configuration' do | |
| 176 | - create_configuration_content | |
| 177 | - Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
| 178 | - @metric_configuration_client.expects(:remove) | |
| 149 | + should 'test remove metric configuration' do | |
| 150 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
| 151 | + :configuration_name => @content.name, | |
| 152 | + :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
| 153 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :remove_metric_configuration, { | |
| 154 | + :metric_name => @metric.name, | |
| 155 | + :configuration_name => @metric_configuration.configuration_name}) | |
| 179 | 156 | get :remove_metric_configuration, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name |
| 180 | 157 | assert_response 302 |
| 181 | 158 | end |
| 182 | - | |
| 183 | - private | |
| 184 | -=end | |
| 185 | - | |
| 186 | - def create_configuration_content | |
| 187 | - Kalibro::Configuration.expects(:all_names).returns([]) | |
| 188 | - @content = MezuroPlugin::ConfigurationContent.new(:profile => @profile, :name => @configuration.name) | |
| 189 | - @content.expects(:send_configuration_to_service).returns(nil) | |
| 190 | - @content.save | |
| 159 | + | |
| 160 | + should 'test new range' do | |
| 161 | + get :new_range, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name | |
| 162 | + assert_equal @content, assigns(:configuration_content) | |
| 163 | + assert_equal @metric.name, assigns(:metric_name) | |
| 164 | + assert_response 200 | |
| 165 | + end | |
| 166 | + | |
| 167 | + should 'test edit range' do | |
| 168 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
| 169 | + :configuration_name => @content.name, | |
| 170 | + :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
| 171 | + get :edit_range, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name, :beginning_id => @range.beginning | |
| 172 | + assert_equal @content, assigns(:configuration_content) | |
| 173 | + assert_equal @metric.name, assigns(:metric_name) | |
| 174 | + assert_equal @range.beginning, assigns(:beginning_id) | |
| 175 | + assert_equal @range.end, assigns(:range).end | |
| 176 | + assert_response 200 | |
| 191 | 177 | end |
| 178 | + | |
| 179 | + should 'test create instance range' do | |
| 180 | + metric_configuration = @metric_configuration | |
| 181 | + metric_configuration.add_range(@range) | |
| 182 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
| 183 | + :configuration_name => @content.name, | |
| 184 | + :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
| 185 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
| 186 | + :metric_configuration => metric_configuration.to_hash, | |
| 187 | + :configuration_name => metric_configuration.configuration_name}) | |
| 188 | + get :create_range, :profile => @profile.identifier, :range => @range_hash, :id => @content.id, :metric_name => @metric.name | |
| 189 | + assert_equal @content, assigns(:configuration_content) | |
| 190 | + assert_equal @range.end, assigns(:range).end | |
| 191 | + assert_response 200 | |
| 192 | + end | |
| 193 | + | |
| 194 | + should 'test update range' do | |
| 195 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
| 196 | + :configuration_name => @content.name, | |
| 197 | + :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
| 198 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
| 199 | + :metric_configuration => @metric_configuration.to_hash, | |
| 200 | + :configuration_name => @metric_configuration.configuration_name}) | |
| 201 | + get :update_range, | |
| 202 | + :profile => @profile.identifier, | |
| 203 | + :range => @range_hash, | |
| 204 | + :id => @content.id, | |
| 205 | + :metric_name => @metric.name, | |
| 206 | + :beginning_id => @range.beginning | |
| 207 | + assert_response 200 | |
| 208 | + end | |
| 209 | + | |
| 210 | + should 'test remove range' do | |
| 211 | + metric_configuration = @metric_configuration | |
| 212 | + metric_configuration.ranges.delete_if { |range| range.beginning == @range.beginning.to_f } | |
| 213 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
| 214 | + :configuration_name => @content.name, | |
| 215 | + :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
| 216 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
| 217 | + :metric_configuration => metric_configuration.to_hash, | |
| 218 | + :configuration_name => metric_configuration.configuration_name}) | |
| 219 | + get :remove_range, | |
| 220 | + :profile => @profile.identifier, | |
| 221 | + :id => @content.id, | |
| 222 | + :metric_name => @metric.name, | |
| 223 | + :beginning_id => @range.beginning | |
| 224 | + assert_response 302 | |
| 225 | + end | |
| 226 | + | |
| 192 | 227 | end | ... | ... |
plugins/mezuro/views/mezuro_plugin_myprofile/_range.html.erb
| ... | ... | @@ -13,5 +13,5 @@ |
| 13 | 13 | </td> |
| 14 | 14 | <td bgcolor="#<%= range.color[2..-1] %>"></td> |
| 15 | 15 | <td><%= link_to_remote "Edit", :url => {:action =>"edit_range", :controller => "mezuro_plugin_myprofile", :id => params[:id], :metric_name => params[:metric_name], :beginning_id => range.beginning} %></td> |
| 16 | - <td><%= link_to "Remove", :action =>"remove_range", :controller => "mezuro_plugin_myprofile", :id => params[:id], :metric_name => params[:metric_name], :range_beginning => range.beginning %></td> | |
| 16 | + <td><%= link_to "Remove", :action =>"remove_range", :controller => "mezuro_plugin_myprofile", :id => params[:id], :metric_name => params[:metric_name], :beginning_id => range.beginning %></td> | |
| 17 | 17 | </tr> | ... | ... |
plugins/mezuro/views/mezuro_plugin_myprofile/new_metric_configuration.html.erb
| 1 | 1 | <script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script> |
| 2 | 2 | |
| 3 | -<h2><%= @configuration_content.name %>Configuration</h2> | |
| 3 | +<h2><%= @configuration_content.name %> Configuration</h2> | |
| 4 | 4 | |
| 5 | 5 | <% form_for :metric_configuration, :url => {:action =>"create_metric_configuration", :controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> |
| 6 | 6 | <%= hidden_field_tag :id, @configuration_content.id %> |
| ... | ... | @@ -19,7 +19,7 @@ |
| 19 | 19 | <%= m.hidden_field "origin", :value => @metric.origin %> |
| 20 | 20 | </p> |
| 21 | 21 | <p> |
| 22 | - <%= m.label :metric_name, "Metric Name:" %> | |
| 22 | + <%= m.label :name, "Metric Name:" %> | |
| 23 | 23 | <%= @metric.name %> |
| 24 | 24 | <%= m.hidden_field "name", :value => @metric.name %> |
| 25 | 25 | </p> | ... | ... |