Commit de5e9ad086cf1834ffd5809d1d9d643a0cb9d12a
Exists in
master
and in
29 other branches
Merge branch 'merging_configuration' of gitorious.org:+mezuro/noosfero/mezuro in…
…to merging_configuration
Showing
10 changed files
with
76 additions
and
35 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
... | ... | @@ -43,7 +43,6 @@ class MezuroPluginProfileController < ProfileController |
43 | 43 | def choose_metric |
44 | 44 | @configuration_name = params[:configuration_name] |
45 | 45 | @collector_name = params[:collector_name] |
46 | - | |
47 | 46 | @collector = Kalibro::Client::BaseToolClient.new.base_tool(@collector_name) |
48 | 47 | end |
49 | 48 | |
... | ... | @@ -64,29 +63,31 @@ class MezuroPluginProfileController < ProfileController |
64 | 63 | |
65 | 64 | def create_metric_configuration |
66 | 65 | @configuration_name = params[:configuration_name] |
67 | - metric_configuration = set_metric_configuration(params) | |
66 | + metric_configuration = new_metric_configuration_instance | |
68 | 67 | Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, @configuration_name) |
69 | 68 | redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}" |
70 | 69 | end |
71 | 70 | |
72 | 71 | def update_metric_configuration |
73 | 72 | @configuration_name = params[:configuration_name] |
74 | - metric_configuration = set_metric_configuration(params) | |
73 | + metric_configuration = new_metric_configuration_instance | |
75 | 74 | Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, @configuration_name) |
76 | 75 | redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}" |
77 | 76 | end |
78 | 77 | |
79 | 78 | def new_range |
79 | + @metric_name = params[:metric_name] | |
80 | + @configuration_name = params[:configuration_name] | |
80 | 81 | end |
81 | 82 | |
82 | 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 | 91 | end |
91 | 92 | |
92 | 93 | def remove_metric_configuration |
... | ... | @@ -98,7 +99,7 @@ class MezuroPluginProfileController < ProfileController |
98 | 99 | |
99 | 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 | 103 | metric_configuration = Kalibro::Entities::MetricConfiguration.new |
103 | 104 | metric_configuration.metric = Kalibro::Entities::NativeMetric.new |
104 | 105 | metric_configuration.metric.name = params[:metric][:name] |
... | ... | @@ -109,9 +110,18 @@ class MezuroPluginProfileController < ProfileController |
109 | 110 | metric_configuration.code = params[:metric_configuration][:code] |
110 | 111 | metric_configuration.weight = params[:metric_configuration][:weight] |
111 | 112 | metric_configuration.aggregation_form = params[:metric_configuration][:aggregation] |
112 | - | |
113 | 113 | metric_configuration |
114 | 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 | 126 | end |
117 | 127 | ... | ... |
plugins/mezuro/lib/kalibro/entities/configuration.rb
... | ... | @@ -14,11 +14,4 @@ class Kalibro::Entities::Configuration < Kalibro::Entities::Entity |
14 | 14 | @metric_configuration = metric_configurations |
15 | 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 | 17 | end | ... | ... |
plugins/mezuro/lib/kalibro/entities/metric_configuration.rb
... | ... | @@ -19,6 +19,11 @@ class Kalibro::Entities::MetricConfiguration < Kalibro::Entities::Entity |
19 | 19 | @range = to_entity_array(value, Kalibro::Entities::Range) |
20 | 20 | end |
21 | 21 | |
22 | + def add_range(new_range) | |
23 | + @range = [] if @range.nil? | |
24 | + @range << new_range | |
25 | + end | |
26 | + | |
22 | 27 | def ranges |
23 | 28 | @range |
24 | 29 | end | ... | ... |
plugins/mezuro/test/fixtures/metric_configuration_fixtures.rb
... | ... | @@ -14,6 +14,15 @@ class MetricConfigurationFixtures |
14 | 14 | amloc |
15 | 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 | 26 | def self.sc_configuration |
18 | 27 | sc = Kalibro::Entities::MetricConfiguration.new |
19 | 28 | sc.metric = CompoundMetricFixtures.sc | ... | ... |
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
... | ... | @@ -65,6 +65,23 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase |
65 | 65 | assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)') |
66 | 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 | 85 | private |
69 | 86 | |
70 | 87 | def create_project_content | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/configuration_test.rb
... | ... | @@ -17,13 +17,4 @@ class ConfigurationTest < ActiveSupport::TestCase |
17 | 17 | assert_equal @hash, @configuration.to_hash |
18 | 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 | 20 | end | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/metric_configuration_test.rb
1 | 1 | require "test_helper" |
2 | 2 | |
3 | 3 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures" |
4 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures" | |
4 | 5 | |
5 | 6 | class MetricConfigurationTest < ActiveSupport::TestCase |
6 | 7 | |
7 | 8 | def setup |
8 | 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 | 14 | end |
11 | 15 | |
12 | 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 | 18 | end |
15 | 19 | |
16 | 20 | should 'convert metric configuration to hash' do |
17 | - assert_equal @hash, @range.to_hash | |
21 | + assert_equal @hash, @metric_configuration.to_hash | |
18 | 22 | end |
19 | 23 | |
20 | 24 | should 'create appropriate metric type' do |
... | ... | @@ -24,4 +28,16 @@ class MetricConfigurationTest < ActiveSupport::TestCase |
24 | 28 | assert sc.metric.instance_of?(Kalibro::Entities::CompoundMetric) |
25 | 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 | 43 | end | ... | ... |
plugins/mezuro/views/mezuro_plugin_profile/_new_range.html.erb
1 | 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 | 4 | <table> |
5 | 5 | <tr> |
6 | 6 | <td> | ... | ... |
plugins/mezuro/views/mezuro_plugin_profile/edit_metric_configuration.html.erb
... | ... | @@ -72,6 +72,6 @@ |
72 | 72 | </table> |
73 | 73 | |
74 | 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 | 76 | <div id="new_range" style="display:none"></div> |
77 | 77 | ... | ... |
plugins/mezuro/views/mezuro_plugin_profile/new_range.rjs