Commit de5e9ad086cf1834ffd5809d1d9d643a0cb9d12a

Authored by Carlos Morais
2 parents d493cc56 f5c09269

Merge branch 'merging_configuration' of gitorious.org:+mezuro/noosfero/mezuro in…

…to merging_configuration
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
@@ -43,7 +43,6 @@ class MezuroPluginProfileController < ProfileController @@ -43,7 +43,6 @@ class MezuroPluginProfileController < ProfileController
43 def choose_metric 43 def choose_metric
44 @configuration_name = params[:configuration_name] 44 @configuration_name = params[:configuration_name]
45 @collector_name = params[:collector_name] 45 @collector_name = params[:collector_name]
46 -  
47 @collector = Kalibro::Client::BaseToolClient.new.base_tool(@collector_name) 46 @collector = Kalibro::Client::BaseToolClient.new.base_tool(@collector_name)
48 end 47 end
49 48
@@ -64,29 +63,31 @@ class MezuroPluginProfileController < ProfileController @@ -64,29 +63,31 @@ class MezuroPluginProfileController < ProfileController
64 63
65 def create_metric_configuration 64 def create_metric_configuration
66 @configuration_name = params[:configuration_name] 65 @configuration_name = params[:configuration_name]
67 - metric_configuration = set_metric_configuration(params) 66 + metric_configuration = new_metric_configuration_instance
68 Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, @configuration_name) 67 Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, @configuration_name)
69 redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}" 68 redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}"
70 end 69 end
71 70
72 def update_metric_configuration 71 def update_metric_configuration
73 @configuration_name = params[:configuration_name] 72 @configuration_name = params[:configuration_name]
74 - metric_configuration = set_metric_configuration(params) 73 + metric_configuration = new_metric_configuration_instance
75 Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, @configuration_name) 74 Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, @configuration_name)
76 redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}" 75 redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}"
77 end 76 end
78 77
79 def new_range 78 def new_range
  79 + @metric_name = params[:metric_name]
  80 + @configuration_name = params[:configuration_name]
80 end 81 end
81 82
82 def create_range 83 def create_range
83 - @range = Kalibro::Entities::Range.new  
84 - @range.beginning = params[:range][:beginning]  
85 - @range.end = params[:range][:end]  
86 - @range.label = params[:range][:label]  
87 - @range.grade = params[:range][:grade]  
88 - @range.color = params[:range][:color]  
89 - @range.comments = params[:range][:comments] 84 + @range = new_range_instance
  85 + configuration_name = params[:configuration_name]
  86 + metric_name = params[:metric_name]
  87 + metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new
  88 + metric_configuration = metric_configuration_client.metric_configuration(configuration_name, metric_name)
  89 + metric_configuration.add_range(@range)
  90 + #metric_configuration_client.save(metric_configuration, configuration_name)
90 end 91 end
91 92
92 def remove_metric_configuration 93 def remove_metric_configuration
@@ -98,7 +99,7 @@ class MezuroPluginProfileController < ProfileController @@ -98,7 +99,7 @@ class MezuroPluginProfileController < ProfileController
98 99
99 private 100 private
100 101
101 - def set_metric_configuration(params) #FIXME isso foi feito para evitar duplicar o codigo de create e update metric configuration, faça de um jeito melhor 102 + def new_metric_configuration_instance
102 metric_configuration = Kalibro::Entities::MetricConfiguration.new 103 metric_configuration = Kalibro::Entities::MetricConfiguration.new
103 metric_configuration.metric = Kalibro::Entities::NativeMetric.new 104 metric_configuration.metric = Kalibro::Entities::NativeMetric.new
104 metric_configuration.metric.name = params[:metric][:name] 105 metric_configuration.metric.name = params[:metric][:name]
@@ -109,9 +110,18 @@ class MezuroPluginProfileController < ProfileController @@ -109,9 +110,18 @@ class MezuroPluginProfileController < ProfileController
109 metric_configuration.code = params[:metric_configuration][:code] 110 metric_configuration.code = params[:metric_configuration][:code]
110 metric_configuration.weight = params[:metric_configuration][:weight] 111 metric_configuration.weight = params[:metric_configuration][:weight]
111 metric_configuration.aggregation_form = params[:metric_configuration][:aggregation] 112 metric_configuration.aggregation_form = params[:metric_configuration][:aggregation]
112 -  
113 metric_configuration 113 metric_configuration
114 end 114 end
115 115
  116 + def new_range_instance
  117 + range = Kalibro::Entities::Range.new
  118 + range.beginning = params[:range][:beginning]
  119 + range.end = params[:range][:end]
  120 + range.label = params[:range][:label]
  121 + range.grade = params[:range][:grade]
  122 + range.color = params[:range][:color]
  123 + range.comments = params[:range][:comments]
  124 + range
  125 + end
116 end 126 end
117 127
plugins/mezuro/lib/kalibro/entities/configuration.rb
@@ -14,11 +14,4 @@ class Kalibro::Entities::Configuration < Kalibro::Entities::Entity @@ -14,11 +14,4 @@ class Kalibro::Entities::Configuration < Kalibro::Entities::Entity
14 @metric_configuration = metric_configurations 14 @metric_configuration = metric_configurations
15 end 15 end
16 16
17 - def create_metric_configurations(metrics)  
18 - @metric_configuration = []  
19 - metrics.each do |metric|  
20 - @metric_configuration << create_metric_configuration(metric)  
21 - end  
22 - end  
23 -  
24 end 17 end
plugins/mezuro/lib/kalibro/entities/metric_configuration.rb
@@ -19,6 +19,11 @@ class Kalibro::Entities::MetricConfiguration &lt; Kalibro::Entities::Entity @@ -19,6 +19,11 @@ class Kalibro::Entities::MetricConfiguration &lt; Kalibro::Entities::Entity
19 @range = to_entity_array(value, Kalibro::Entities::Range) 19 @range = to_entity_array(value, Kalibro::Entities::Range)
20 end 20 end
21 21
  22 + def add_range(new_range)
  23 + @range = [] if @range.nil?
  24 + @range << new_range
  25 + end
  26 +
22 def ranges 27 def ranges
23 @range 28 @range
24 end 29 end
plugins/mezuro/test/fixtures/metric_configuration_fixtures.rb
@@ -14,6 +14,15 @@ class MetricConfigurationFixtures @@ -14,6 +14,15 @@ class MetricConfigurationFixtures
14 amloc 14 amloc
15 end 15 end
16 16
  17 + def self.metric_configuration_without_ranges
  18 + amloc = Kalibro::Entities::MetricConfiguration.new
  19 + amloc.metric = NativeMetricFixtures.amloc
  20 + amloc.code = 'amloc'
  21 + amloc.weight = 1.0
  22 + amloc.aggregation_form = 'AVERAGE'
  23 + amloc
  24 + end
  25 +
17 def self.sc_configuration 26 def self.sc_configuration
18 sc = Kalibro::Entities::MetricConfiguration.new 27 sc = Kalibro::Entities::MetricConfiguration.new
19 sc.metric = CompoundMetricFixtures.sc 28 sc.metric = CompoundMetricFixtures.sc
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
@@ -65,6 +65,23 @@ class MezuroPluginProfileControllerTest &lt; ActionController::TestCase @@ -65,6 +65,23 @@ class MezuroPluginProfileControllerTest &lt; ActionController::TestCase
65 assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)') 65 assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)')
66 end 66 end
67 67
  68 + should 'assign configuration name in choose_base_tool' do
  69 + get :choose_base_tool, :profile => @profile.identifier, :configuration_name => "test name"
  70 + assert_equal assigns(:configuration_name), "test name"
  71 + end
  72 +
  73 + should 'create base tool client' do
  74 + get :choose_base_tool, :profile => @profile.identifier, :configuration_name => "test name"
  75 + assert assigns(:tool_names).instance_of?(Kalibro::Client::BaseToolClient)
  76 + end
  77 +
  78 + should 'assign configuration and collector name in choose_metric' do
  79 + #TODO Mockar cliente
  80 + get :choose_metric, :profile => @profile.identifier, :configuration_name => "test name", :collector_name => "Collector A"
  81 + assert_equal assigns(:configuration_name), "test name"
  82 + assert_equal assigns(:collector_name), "Collector A"
  83 + end
  84 +
68 private 85 private
69 86
70 def create_project_content 87 def create_project_content
plugins/mezuro/test/unit/kalibro/entities/configuration_test.rb
@@ -17,13 +17,4 @@ class ConfigurationTest &lt; ActiveSupport::TestCase @@ -17,13 +17,4 @@ class ConfigurationTest &lt; ActiveSupport::TestCase
17 assert_equal @hash, @configuration.to_hash 17 assert_equal @hash, @configuration.to_hash
18 end 18 end
19 19
20 - should 'create metric configuration' do  
21 - configuration = Kalibro::Entities::Configuration.new  
22 - configuration.create_metric_configurations(["Analizo:Metric Name"])  
23 - metric_configuration = configuration.metric_configurations[0]  
24 - assert_equal metric_configuration.code, "Metric Name"  
25 - assert_equal metric_configuration.metric.name, "Metric Name"  
26 - assert_equal metric_configuration.metric.origin, "Analizo"  
27 - end  
28 -  
29 end 20 end
plugins/mezuro/test/unit/kalibro/entities/metric_configuration_test.rb
1 require "test_helper" 1 require "test_helper"
2 2
3 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures" 3 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures"
  4 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures"
4 5
5 class MetricConfigurationTest < ActiveSupport::TestCase 6 class MetricConfigurationTest < ActiveSupport::TestCase
6 7
7 def setup 8 def setup
8 @hash = MetricConfigurationFixtures.amloc_configuration_hash 9 @hash = MetricConfigurationFixtures.amloc_configuration_hash
9 - @range = MetricConfigurationFixtures.amloc_configuration 10 + @metric_configuration = MetricConfigurationFixtures.amloc_configuration
  11 + @metric_configuration_without_ranges = MetricConfigurationFixtures.metric_configuration_without_ranges
  12 + @range1 = RangeFixtures.amloc_excellent
  13 + @range2 = RangeFixtures.amloc_bad
10 end 14 end
11 15
12 should 'create metric configuration from hash' do 16 should 'create metric configuration from hash' do
13 - assert_equal @range, Kalibro::Entities::MetricConfiguration.from_hash(@hash) 17 + assert_equal @metric_configuration, Kalibro::Entities::MetricConfiguration.from_hash(@hash)
14 end 18 end
15 19
16 should 'convert metric configuration to hash' do 20 should 'convert metric configuration to hash' do
17 - assert_equal @hash, @range.to_hash 21 + assert_equal @hash, @metric_configuration.to_hash
18 end 22 end
19 23
20 should 'create appropriate metric type' do 24 should 'create appropriate metric type' do
@@ -24,4 +28,16 @@ class MetricConfigurationTest &lt; ActiveSupport::TestCase @@ -24,4 +28,16 @@ class MetricConfigurationTest &lt; ActiveSupport::TestCase
24 assert sc.metric.instance_of?(Kalibro::Entities::CompoundMetric) 28 assert sc.metric.instance_of?(Kalibro::Entities::CompoundMetric)
25 end 29 end
26 30
  31 + should 'add a range to an empty range list' do
  32 + @metric_configuration_without_ranges.add_range @range1
  33 + assert_equal @metric_configuration_without_ranges.ranges, [@range1]
  34 + end
  35 +
  36 + should 'add a range to an non-empty range list' do
  37 + @metric_configuration_without_ranges.ranges = [@range1]
  38 + @metric_configuration_without_ranges.add_range @range2
  39 + assert_equal @metric_configuration_without_ranges.ranges, [@range1, @range2]
  40 + end
  41 +
  42 +
27 end 43 end
plugins/mezuro/views/mezuro_plugin_profile/_new_range.html.erb
1 <% remote_form_for :range, :url => {:action =>"create_range", :controller => "mezuro_plugin_profile"}, :method => :get do |f| %> 1 <% remote_form_for :range, :url => {:action =>"create_range", :controller => "mezuro_plugin_profile"}, :method => :get do |f| %>
2 - <%= hidden_field_tag :configuration_name, @configuration_name %>  
3 - <%= hidden_field_tag :metric_name, @metric_name %> 2 + <%= hidden_field_tag :configuration_name, configuration_name %>
  3 + <%= hidden_field_tag :metric_name, metric_name %>
4 <table> 4 <table>
5 <tr> 5 <tr>
6 <td> 6 <td>
plugins/mezuro/views/mezuro_plugin_profile/edit_metric_configuration.html.erb
@@ -72,6 +72,6 @@ @@ -72,6 +72,6 @@
72 </table> 72 </table>
73 73
74 <br/> 74 <br/>
75 -<%= link_to_remote "New Range", :url => {:action =>"new_range", :controller => "mezuro_plugin_profile"} %> 75 +<%= link_to_remote "New Range", :url => {:action =>"new_range", :controller => "mezuro_plugin_profile", :configuration_name => @configuration_name, :metric_name => @metric.name} %>
76 <div id="new_range" style="display:none"></div> 76 <div id="new_range" style="display:none"></div>
77 77
plugins/mezuro/views/mezuro_plugin_profile/new_range.rjs
1 -page.replace_html 'new_range', :partial => "new_range" 1 +page.replace_html 'new_range', :partial => "new_range", :locals => {:metric_name => @metric_name, :configuration_name => @configuration_name}
2 page.visual_effect :toggle_slide, "new_range" 2 page.visual_effect :toggle_slide, "new_range"