Commit 1f2785fc7ee54eed3ef6e4464c384f17b5014df9
Committed by
Paulo Meireles
1 parent
ea992c6b
Exists in
master
and in
22 other branches
[Mezuro] draft to range controller
Showing
6 changed files
with
166 additions
and
126 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb
| @@ -109,65 +109,7 @@ class MezuroPluginMyprofileController < ProfileController | @@ -109,65 +109,7 @@ class MezuroPluginMyprofileController < ProfileController | ||
| 109 | end | 109 | end |
| 110 | end | 110 | end |
| 111 | 111 | ||
| 112 | - def new_range | ||
| 113 | - @configuration_content = profile.articles.find(params[:id]) | ||
| 114 | - @metric_name = params[:metric_name] | ||
| 115 | - @range = Kalibro::Range.new | ||
| 116 | - @range_color = "#000000" | ||
| 117 | - end | ||
| 118 | - | ||
| 119 | - def edit_range | ||
| 120 | - @configuration_content = profile.articles.find(params[:id]) | ||
| 121 | - @metric_name = params[:metric_name] | ||
| 122 | - @beginning_id = params[:beginning_id] | ||
| 123 | - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, @metric_name) | ||
| 124 | - @range = metric_configuration.ranges.find{|range| range.beginning == @beginning_id.to_f || @beginning_id =="-INF" } | ||
| 125 | - @range_color = "#" + @range.color.to_s.gsub(/^ff/, "") | ||
| 126 | - end | ||
| 127 | - | ||
| 128 | - def create_range | ||
| 129 | - @configuration_content = profile.articles.find(params[:id]) | ||
| 130 | - @range = Kalibro::Range.new params[:range] | ||
| 131 | - metric_name = params[:metric_name] | ||
| 132 | - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name) | ||
| 133 | - metric_configuration.add_range(@range) | ||
| 134 | - metric_configuration.save | ||
| 135 | - if metric_configuration_has_errors? metric_configuration | ||
| 136 | - redirect_to_error_page metric_configuration.errors[0].message | ||
| 137 | - end | ||
| 138 | - end | ||
| 139 | - | ||
| 140 | - def update_range | ||
| 141 | - configuration_content = profile.articles.find(params[:id]) | ||
| 142 | - metric_name = params[:metric_name] | ||
| 143 | - beginning_id = params[:beginning_id] | ||
| 144 | - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) | ||
| 145 | - index = metric_configuration.ranges.index{ |range| range.beginning == beginning_id.to_f || beginning_id == "-INF" } | ||
| 146 | - metric_configuration.ranges[index] = Kalibro::Range.new params[:range] | ||
| 147 | - metric_configuration.save | ||
| 148 | - if metric_configuration_has_errors? metric_configuration | ||
| 149 | - redirect_to_error_page metric_configuration.errors[0].message | ||
| 150 | - end | ||
| 151 | - end | ||
| 152 | 112 | ||
| 153 | - def remove_range | ||
| 154 | - configuration_content = profile.articles.find(params[:id]) | ||
| 155 | - metric_name = params[:metric_name] | ||
| 156 | - beginning_id = params[:beginning_id] | ||
| 157 | - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) | ||
| 158 | - metric_configuration.ranges.delete_if { |range| range.beginning == beginning_id.to_f || beginning_id == "-INF" } | ||
| 159 | - metric_configuration.save | ||
| 160 | - if metric_configuration_has_errors? metric_configuration | ||
| 161 | - redirect_to_error_page metric_configuration.errors[0].message | ||
| 162 | - else | ||
| 163 | - formatted_metric_name = metric_name.gsub(/\s/, '+') | ||
| 164 | - if metric_configuration.metric.class == Kalibro::CompoundMetric | ||
| 165 | - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}" | ||
| 166 | - else | ||
| 167 | - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}" | ||
| 168 | - end | ||
| 169 | - end | ||
| 170 | - end | ||
| 171 | 113 | ||
| 172 | private | 114 | private |
| 173 | 115 |
plugins/mezuro/controllers/myprofile/mezuro_plugin_range_controller.rb
0 → 100644
| @@ -0,0 +1,65 @@ | @@ -0,0 +1,65 @@ | ||
| 1 | +class MezuroPluginRangeController < MezuroPluginMyprofileController | ||
| 2 | + | ||
| 3 | + append_view_path File.join(File.dirname(__FILE__) + '/../views') | ||
| 4 | + | ||
| 5 | + def new_range | ||
| 6 | + @configuration_content = profile.articles.find(params[:id]) | ||
| 7 | + @metric_name = params[:metric_name] | ||
| 8 | + @range = Kalibro::Range.new | ||
| 9 | + @range_color = "#000000" | ||
| 10 | + end | ||
| 11 | + | ||
| 12 | + def edit_range | ||
| 13 | + @configuration_content = profile.articles.find(params[:id]) | ||
| 14 | + @metric_name = params[:metric_name] | ||
| 15 | + @beginning_id = params[:beginning_id] | ||
| 16 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, @metric_name) | ||
| 17 | + @range = metric_configuration.ranges.find{|range| range.beginning == @beginning_id.to_f || @beginning_id =="-INF" } | ||
| 18 | + @range_color = "#" + @range.color.to_s.gsub(/^ff/, "") | ||
| 19 | + end | ||
| 20 | + | ||
| 21 | + def create_range | ||
| 22 | + @configuration_content = profile.articles.find(params[:id]) | ||
| 23 | + @range = Kalibro::Range.new params[:range] | ||
| 24 | + metric_name = params[:metric_name] | ||
| 25 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name) | ||
| 26 | + metric_configuration.add_range(@range) | ||
| 27 | + metric_configuration.save | ||
| 28 | + if metric_configuration_has_errors? metric_configuration | ||
| 29 | + redirect_to_error_page metric_configuration.errors[0].message | ||
| 30 | + end | ||
| 31 | + end | ||
| 32 | + | ||
| 33 | + def update_range | ||
| 34 | + configuration_content = profile.articles.find(params[:id]) | ||
| 35 | + metric_name = params[:metric_name] | ||
| 36 | + beginning_id = params[:beginning_id] | ||
| 37 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) | ||
| 38 | + index = metric_configuration.ranges.index{ |range| range.beginning == beginning_id.to_f || beginning_id == "-INF" } | ||
| 39 | + metric_configuration.ranges[index] = Kalibro::Range.new params[:range] | ||
| 40 | + metric_configuration.save | ||
| 41 | + if metric_configuration_has_errors? metric_configuration | ||
| 42 | + redirect_to_error_page metric_configuration.errors[0].message | ||
| 43 | + end | ||
| 44 | + end | ||
| 45 | + | ||
| 46 | + def remove_range | ||
| 47 | + configuration_content = profile.articles.find(params[:id]) | ||
| 48 | + metric_name = params[:metric_name] | ||
| 49 | + beginning_id = params[:beginning_id] | ||
| 50 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) | ||
| 51 | + metric_configuration.ranges.delete_if { |range| range.beginning == beginning_id.to_f || beginning_id == "-INF" } | ||
| 52 | + metric_configuration.save | ||
| 53 | + if metric_configuration_has_errors? metric_configuration | ||
| 54 | + redirect_to_error_page metric_configuration.errors[0].message | ||
| 55 | + else | ||
| 56 | + formatted_metric_name = metric_name.gsub(/\s/, '+') | ||
| 57 | + if metric_configuration.metric.class == Kalibro::CompoundMetric | ||
| 58 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}" | ||
| 59 | + else | ||
| 60 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}" | ||
| 61 | + end | ||
| 62 | + end | ||
| 63 | + end | ||
| 64 | + | ||
| 65 | +end |
plugins/mezuro/controllers/profile/mezuro_plugin_module_controller.rb
| 1 | class MezuroPluginModuleController < MezuroPluginProfileController | 1 | class MezuroPluginModuleController < MezuroPluginProfileController |
| 2 | + | ||
| 2 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') | 3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') |
| 3 | 4 | ||
| 4 | - def module_result | 5 | + def module_result |
| 5 | @content = profile.articles.find(params[:id]) | 6 | @content = profile.articles.find(params[:id]) |
| 6 | @module_result = @content.module_result(params) | 7 | @module_result = @content.module_result(params) |
| 7 | @module = @module_result.module | 8 | @module = @module_result.module |
plugins/mezuro/controllers/profile/mezuro_plugin_project_controller.rb
| 1 | class MezuroPluginProjectController < MezuroPluginProfileController | 1 | class MezuroPluginProjectController < MezuroPluginProfileController |
| 2 | + | ||
| 2 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') | 3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') |
| 3 | 4 | ||
| 4 | def project_state | 5 | def project_state |
plugins/mezuro/test/functional/mezuro_plugin_myprofile_controller_test.rb
| @@ -158,71 +158,4 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase | @@ -158,71 +158,4 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase | ||
| 158 | assert_response 302 | 158 | assert_response 302 |
| 159 | end | 159 | end |
| 160 | 160 | ||
| 161 | - should 'test new range' do | ||
| 162 | - get :new_range, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name | ||
| 163 | - assert_equal @content, assigns(:configuration_content) | ||
| 164 | - assert_equal @metric.name, assigns(:metric_name) | ||
| 165 | - assert_response 200 | ||
| 166 | - end | ||
| 167 | - | ||
| 168 | - should 'test edit range' do | ||
| 169 | - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | ||
| 170 | - :configuration_name => @content.name, | ||
| 171 | - :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | ||
| 172 | - get :edit_range, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name, :beginning_id => @range.beginning | ||
| 173 | - assert_equal @content, assigns(:configuration_content) | ||
| 174 | - assert_equal @metric.name, assigns(:metric_name) | ||
| 175 | - assert_equal @range.beginning, assigns(:beginning_id) | ||
| 176 | - assert_equal @range.end, assigns(:range).end | ||
| 177 | - assert_response 200 | ||
| 178 | - end | ||
| 179 | - | ||
| 180 | - should 'test create instance range' do | ||
| 181 | - metric_configuration = @metric_configuration | ||
| 182 | - metric_configuration.add_range(@range) | ||
| 183 | - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | ||
| 184 | - :configuration_name => @content.name, | ||
| 185 | - :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | ||
| 186 | - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | ||
| 187 | - :metric_configuration => metric_configuration.to_hash, | ||
| 188 | - :configuration_name => metric_configuration.configuration_name}) | ||
| 189 | - get :create_range, :profile => @profile.identifier, :range => @range_hash, :id => @content.id, :metric_name => @metric.name | ||
| 190 | - assert_equal @content, assigns(:configuration_content) | ||
| 191 | - assert_equal @range.end, assigns(:range).end | ||
| 192 | - assert_response 200 | ||
| 193 | - end | ||
| 194 | - | ||
| 195 | - should 'test update range' do | ||
| 196 | - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | ||
| 197 | - :configuration_name => @content.name, | ||
| 198 | - :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | ||
| 199 | - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | ||
| 200 | - :metric_configuration => @metric_configuration.to_hash, | ||
| 201 | - :configuration_name => @metric_configuration.configuration_name}) | ||
| 202 | - get :update_range, | ||
| 203 | - :profile => @profile.identifier, | ||
| 204 | - :range => @range_hash, | ||
| 205 | - :id => @content.id, | ||
| 206 | - :metric_name => @metric.name, | ||
| 207 | - :beginning_id => @range.beginning | ||
| 208 | - assert_response 200 | ||
| 209 | - end | ||
| 210 | - | ||
| 211 | - should 'test remove range' do | ||
| 212 | - metric_configuration = @metric_configuration | ||
| 213 | - metric_configuration.ranges.delete_if { |range| range.beginning == @range.beginning.to_f } | ||
| 214 | - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | ||
| 215 | - :configuration_name => @content.name, | ||
| 216 | - :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | ||
| 217 | - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | ||
| 218 | - :metric_configuration => metric_configuration.to_hash, | ||
| 219 | - :configuration_name => metric_configuration.configuration_name}) | ||
| 220 | - get :remove_range, | ||
| 221 | - :profile => @profile.identifier, | ||
| 222 | - :id => @content.id, | ||
| 223 | - :metric_name => @metric.name, | ||
| 224 | - :beginning_id => @range.beginning | ||
| 225 | - assert_response 302 | ||
| 226 | - end | ||
| 227 | - | ||
| 228 | end | 161 | end |
plugins/mezuro/test/functional/myprofile/mezuro_plugin_range_controller_test.rb
0 → 100644
| @@ -0,0 +1,98 @@ | @@ -0,0 +1,98 @@ | ||
| 1 | +require 'test_helper' | ||
| 2 | + | ||
| 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/error_fixtures" | ||
| 4 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures" | ||
| 5 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/native_metric_fixtures" | ||
| 6 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures" | ||
| 7 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" | ||
| 8 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures" | ||
| 9 | + | ||
| 10 | +class MezuroPluginRangeControllerTest < ActionController::TestCase | ||
| 11 | + | ||
| 12 | + def setup | ||
| 13 | + @controller = MezuroPluginRangeController.new | ||
| 14 | + @request = ActionController::TestRequest.new | ||
| 15 | + @response = ActionController::TestResponse.new | ||
| 16 | + @profile = fast_create(Community) | ||
| 17 | + | ||
| 18 | + @metric = NativeMetricFixtures.amloc | ||
| 19 | + @metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration | ||
| 20 | + @metric_configuration_hash = MetricConfigurationFixtures.amloc_metric_configuration_hash | ||
| 21 | + @configuration = ConfigurationFixtures.configuration | ||
| 22 | + | ||
| 23 | + Kalibro::Configuration.expects(:all_names).returns([]) | ||
| 24 | + @content = MezuroPlugin::ConfigurationContent.new(:profile => @profile, :name => @configuration.name) | ||
| 25 | + @content.expects(:send_kalibro_configuration_to_service).returns(nil) | ||
| 26 | + @content.stubs(:solr_save) | ||
| 27 | + @content.save | ||
| 28 | + | ||
| 29 | + @range = RangeFixtures.range_excellent | ||
| 30 | + @range_hash = RangeFixtures.range_excellent_hash | ||
| 31 | + end | ||
| 32 | + should 'test new range' do | ||
| 33 | + get :new_range, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name | ||
| 34 | + assert_equal @content, assigns(:configuration_content) | ||
| 35 | + assert_equal @metric.name, assigns(:metric_name) | ||
| 36 | + assert_response 200 | ||
| 37 | + end | ||
| 38 | + | ||
| 39 | + should 'test edit range' do | ||
| 40 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | ||
| 41 | + :configuration_name => @content.name, | ||
| 42 | + :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | ||
| 43 | + get :edit_range, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name, :beginning_id => @range.beginning | ||
| 44 | + assert_equal @content, assigns(:configuration_content) | ||
| 45 | + assert_equal @metric.name, assigns(:metric_name) | ||
| 46 | + assert_equal @range.beginning, assigns(:beginning_id) | ||
| 47 | + assert_equal @range.end, assigns(:range).end | ||
| 48 | + assert_response 200 | ||
| 49 | + end | ||
| 50 | + | ||
| 51 | + should 'test create instance range' do | ||
| 52 | + metric_configuration = @metric_configuration | ||
| 53 | + metric_configuration.add_range(@range) | ||
| 54 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | ||
| 55 | + :configuration_name => @content.name, | ||
| 56 | + :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | ||
| 57 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | ||
| 58 | + :metric_configuration => metric_configuration.to_hash, | ||
| 59 | + :configuration_name => metric_configuration.configuration_name}) | ||
| 60 | + get :create_range, :profile => @profile.identifier, :range => @range_hash, :id => @content.id, :metric_name => @metric.name | ||
| 61 | + assert_equal @content, assigns(:configuration_content) | ||
| 62 | + assert_equal @range.end, assigns(:range).end | ||
| 63 | + assert_response 200 | ||
| 64 | + end | ||
| 65 | + | ||
| 66 | + should 'test update range' do | ||
| 67 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | ||
| 68 | + :configuration_name => @content.name, | ||
| 69 | + :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | ||
| 70 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | ||
| 71 | + :metric_configuration => @metric_configuration.to_hash, | ||
| 72 | + :configuration_name => @metric_configuration.configuration_name}) | ||
| 73 | + get :update_range, | ||
| 74 | + :profile => @profile.identifier, | ||
| 75 | + :range => @range_hash, | ||
| 76 | + :id => @content.id, | ||
| 77 | + :metric_name => @metric.name, | ||
| 78 | + :beginning_id => @range.beginning | ||
| 79 | + assert_response 200 | ||
| 80 | + end | ||
| 81 | + | ||
| 82 | + should 'test remove range' do | ||
| 83 | + metric_configuration = @metric_configuration | ||
| 84 | + metric_configuration.ranges.delete_if { |range| range.beginning == @range.beginning.to_f } | ||
| 85 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | ||
| 86 | + :configuration_name => @content.name, | ||
| 87 | + :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | ||
| 88 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | ||
| 89 | + :metric_configuration => metric_configuration.to_hash, | ||
| 90 | + :configuration_name => metric_configuration.configuration_name}) | ||
| 91 | + get :remove_range, | ||
| 92 | + :profile => @profile.identifier, | ||
| 93 | + :id => @content.id, | ||
| 94 | + :metric_name => @metric.name, | ||
| 95 | + :beginning_id => @range.beginning | ||
| 96 | + assert_response 302 | ||
| 97 | + end | ||
| 98 | +end |