Commit bee62675c7b52c4c22c7820c5f4db20a77a79f41
Committed by
João da Silva
1 parent
9f31b259
Exists in
master
and in
28 other branches
[Mezuro] Finished compound_metrics with functionalities and tests
Showing
6 changed files
with
110 additions
and
73 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb
... | ... | @@ -22,6 +22,11 @@ class MezuroPluginMyprofileController < ProfileController |
22 | 22 | @configuration_name = params[:configuration_name] |
23 | 23 | end |
24 | 24 | |
25 | + def new_compound_metric_configuration | |
26 | + @configuration_name = params[:configuration_name] | |
27 | + @metric_configurations = Kalibro::Client::ConfigurationClient.new.configuration(@configuration_name).metric_configurations | |
28 | + end | |
29 | + | |
25 | 30 | def edit_metric_configuration |
26 | 31 | metric_name = params[:metric_name] |
27 | 32 | @configuration_name = params[:configuration_name] |
... | ... | @@ -43,11 +48,6 @@ class MezuroPluginMyprofileController < ProfileController |
43 | 48 | redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}" |
44 | 49 | end |
45 | 50 | |
46 | - def new_compound_metric | |
47 | - @configuration_name = params[:configuration_name] | |
48 | - @metric_configurations = Kalibro::Client::ConfigurationClient.new.configuration(@configuration_name).metric_configurations | |
49 | - end | |
50 | - | |
51 | 51 | def create_compound_metric_configuration |
52 | 52 | @configuration_name = params[:configuration_name] |
53 | 53 | compound_metric_configuration = new_compound_metric_configuration_instance |
... | ... | @@ -57,19 +57,21 @@ class MezuroPluginMyprofileController < ProfileController |
57 | 57 | |
58 | 58 | def update_metric_configuration |
59 | 59 | @configuration_name = params[:configuration_name] |
60 | + metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new | |
60 | 61 | metric_name = params[:metric][:name] |
61 | - metric_configuration = Kalibro::Client::MetricConfigurationClient.new.metric_configuration(@configuration_name, metric_name) | |
62 | - metric_configuration = assign_metric_configuration_instance (metric_configuration) | |
63 | - Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, @configuration_name) | |
62 | + metric_configuration = metric_configuration_client.metric_configuration(@configuration_name, metric_name) | |
63 | + metric_configuration = assign_metric_configuration_instance(metric_configuration) | |
64 | + metric_configuration_client.save(metric_configuration, @configuration_name) | |
64 | 65 | redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}" |
65 | 66 | end |
66 | 67 | |
67 | 68 | def update_compound_metric_configuration |
68 | 69 | @configuration_name = params[:configuration_name] |
70 | + metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new | |
69 | 71 | metric_name = params[:metric_configuration][:metric][:name] |
70 | - compound_metric_configuration = Kalibro::Client::MetricConfigurationClient.new.metric_configuration(@configuration_name, metric_name) | |
71 | - compound_metric_configuration = assign_compound_metric_configuration_instance (compound_metric_configuration) | |
72 | - Kalibro::Client::MetricConfigurationClient.new.save(compound_metric_configuration, @configuration_name) | |
72 | + compound_metric_configuration = metric_configuration_client.metric_configuration(@configuration_name, metric_name) | |
73 | + compound_metric_configuration = assign_compound_metric_configuration_instance(compound_metric_configuration) | |
74 | + metric_configuration_client.save(compound_metric_configuration, @configuration_name) | |
73 | 75 | redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}" |
74 | 76 | end |
75 | 77 | ... | ... |
plugins/mezuro/test/fixtures/compound_metric_fixtures.rb
... | ... | @@ -2,6 +2,7 @@ class CompoundMetricFixtures |
2 | 2 | |
3 | 3 | def self.sc |
4 | 4 | sc = Kalibro::Entities::CompoundMetric.new |
5 | + sc.description = 'Calculate the Structural Complexity of the Code' | |
5 | 6 | sc.name = 'Structural Complexity' |
6 | 7 | sc.scope = 'CLASS' |
7 | 8 | sc.script = 'return 42;' |
... | ... | @@ -9,7 +10,7 @@ class CompoundMetricFixtures |
9 | 10 | end |
10 | 11 | |
11 | 12 | def self.sc_hash |
12 | - {:name => 'Structural Complexity', :scope => 'CLASS', :script => 'return 42;'} | |
13 | + {:name => 'Structural Complexity', :scope => 'CLASS', :script => 'return 42;', :description => 'Calculate the Structural Complexity of the Code'} | |
13 | 14 | end |
14 | 15 | |
15 | 16 | end | ... | ... |
plugins/mezuro/test/functional/mezuro_plugin_myprofile_controller_test.rb
... | ... | @@ -4,6 +4,7 @@ require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/error_fixtures" |
4 | 4 | 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 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" | |
7 | 8 | |
8 | 9 | class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
9 | 10 | |
... | ... | @@ -19,6 +20,7 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
19 | 20 | @metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new |
20 | 21 | @metric_configuration = MetricConfigurationFixtures.amloc_configuration |
21 | 22 | @compound_metric_configuration = MetricConfigurationFixtures.sc_configuration |
23 | + @configuration = ConfigurationFixtures.kalibro_configuration | |
22 | 24 | end |
23 | 25 | |
24 | 26 | should 'assign configuration name in choose_base_tool' do |
... | ... | @@ -46,13 +48,21 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
46 | 48 | assert_equal assigns(:collector), @collector |
47 | 49 | end |
48 | 50 | |
49 | - should 'get choosed native metric and configuration name' do | |
51 | + should 'get chosen native metric and configuration name' do | |
50 | 52 | Kalibro::Client::BaseToolClient.expects(:new).returns(@base_tool_client) |
51 | 53 | @base_tool_client.expects(:base_tool).with(@collector.name).returns(@collector) |
52 | 54 | get :new_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :collector_name => "Analizo", :metric_name => @metric.name |
53 | 55 | assert_equal assigns(:configuration_name), "test name" |
54 | 56 | assert_equal assigns(:metric), @metric |
55 | 57 | end |
58 | + | |
59 | + should 'call configuration client in new_compound_metric_configuration method' do | |
60 | + configuration_client = mock | |
61 | + Kalibro::Client::ConfigurationClient.expects(:new).returns(configuration_client) | |
62 | + configuration_client.expects(:configuration).with(@configuration.name).returns(@configuration) | |
63 | + get :new_compound_metric_configuration, :profile => @profile.identifier, :configuration_name => @configuration.name | |
64 | + assert_response 200 | |
65 | + end | |
56 | 66 | |
57 | 67 | should 'assign configuration name and get metric_configuration' do |
58 | 68 | Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) |
... | ... | @@ -62,7 +72,7 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
62 | 72 | assert_equal assigns(:metric_configuration), @metric_configuration |
63 | 73 | assert_equal assigns(:metric), @metric_configuration.metric |
64 | 74 | end |
65 | - | |
75 | + | |
66 | 76 | should 'test metric creation' do |
67 | 77 | Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) |
68 | 78 | @metric_configuration_client.expects(:save) |
... | ... | @@ -76,9 +86,11 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
76 | 86 | should 'test compound metric creation' do |
77 | 87 | Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) |
78 | 88 | @metric_configuration_client.expects(:save) |
79 | - get :create_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :description => @metric.description, | |
80 | - :scope => @metric.scope, :language => @metric.language, :metric => { :name => @metric.name}, | |
81 | - :metric_configuration => { :script => @compound_metric_configuration.metric.script, :code => @compound_metric_configuration.code, :weight => @compound_metric_configuration.code, :aggregation => @compound_metric_configuration.aggregation_form} | |
89 | + get :create_compound_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", | |
90 | + :metric_configuration => { :code => @compound_metric_configuration.code, :weight => @compound_metric_configuration.weight, | |
91 | + :aggregation_form => @compound_metric_configuration.aggregation_form, :metric => { :name => @compound_metric_configuration.metric.name , | |
92 | + :description => @compound_metric_configuration.metric.description, :scope => @compound_metric_configuration.metric.scope, | |
93 | + :script => @compound_metric_configuration.metric.script}} | |
82 | 94 | assert_response 302 |
83 | 95 | end |
84 | 96 | |
... | ... | @@ -96,6 +108,28 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
96 | 108 | assert_response 200 |
97 | 109 | end |
98 | 110 | |
111 | + should 'update metric configuration' do | |
112 | + Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | |
113 | + @metric_configuration_client.expects(:metric_configuration).with(@configuration.name, @metric_configuration.metric.name).returns(@metric_configuration) | |
114 | + @metric_configuration_client.expects(:save) | |
115 | + get :update_metric_configuration, :profile => @profile.identifier, :configuration_name => @configuration.name, :description => @metric.description, | |
116 | + :scope => @metric.scope, :language => @metric.language, :metric => { :name => @metric.name, :origin => @metric.origin}, | |
117 | + :metric_configuration => { :code => @metric_configuration.code, :weight => @metric_configuration.code, :aggregation => @metric_configuration.aggregation_form } | |
118 | + assert_response 302 | |
119 | + end | |
120 | + | |
121 | + should 'update compound metric configuration' do | |
122 | + Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | |
123 | + @metric_configuration_client.expects(:metric_configuration).with(@configuration.name, @compound_metric_configuration.metric.name).returns(@compound_metric_configuration) | |
124 | + @metric_configuration_client.expects(:save) | |
125 | + get :update_compound_metric_configuration, :profile => @profile.identifier, :configuration_name => @configuration.name, | |
126 | + :metric_configuration => { :code => @compound_metric_configuration.code, :weight => @compound_metric_configuration.weight, | |
127 | + :aggregation_form => @compound_metric_configuration.aggregation_form, :metric => { :name => @compound_metric_configuration.metric.name , | |
128 | + :description => @compound_metric_configuration.metric.description, :scope => @compound_metric_configuration.metric.scope, | |
129 | + :script => @compound_metric_configuration.metric.script}} | |
130 | + assert_response 302 | |
131 | + end | |
132 | + | |
99 | 133 | should 'assign configuration name and metric name to new range' do |
100 | 134 | get :new_range, :profile => @profile.identifier, :configuration_name => "test name", :metric_name => @metric.name |
101 | 135 | assert_equal assigns(:configuration_name), "test name" |
... | ... | @@ -119,4 +153,4 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
119 | 153 | assert_response 302 |
120 | 154 | end |
121 | 155 | |
122 | -end | |
156 | +endgit | ... | ... |
plugins/mezuro/views/mezuro_plugin_myprofile/choose_base_tool.html.erb
1 | 1 | <h2><%= @configuration_name%> Configuration</h2> |
2 | 2 | |
3 | -<%= link_to "* New Compound Metric *", :controller => "mezuro_plugin_myprofile", :action => "new_compound_metric", :params => | |
3 | +<%= link_to "* New Compound Metric *", :controller => "mezuro_plugin_myprofile", :action => "new_compound_metric_configuration", :params => | |
4 | 4 | {:configuration_name => @configuration_name} %> |
5 | 5 | |
6 | 6 | <h5>Base Tools:</h5> | ... | ... |
plugins/mezuro/views/mezuro_plugin_myprofile/new_compound_metric.html.erb
... | ... | @@ -1,54 +0,0 @@ |
1 | -<h2><%= @configuration_name %> Configuration</h2> | |
2 | - | |
3 | -<% form_for :metric_configuration, :url => {:action =>"create_compound_metric_configuration", | |
4 | -:controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> | |
5 | - <%= hidden_field_tag :configuration_name, @configuration_name %> | |
6 | - <% f.fields_for :metric do |m| %> | |
7 | - <p> | |
8 | - <%= m.label :name, "Name:" %> | |
9 | - <%= m.text_field "name" %> | |
10 | - </p> | |
11 | - <p> | |
12 | - <%= m.label :description, "Description:" %> | |
13 | - <%= m.text_field "description" %> | |
14 | - </p> | |
15 | - <p> | |
16 | - <%= m.label :scope, "Scope:" %> | |
17 | - <%= m.select :scope, [["Class", "CLASS"]] %> | |
18 | - </p> | |
19 | - <p> | |
20 | - <%= m.label :script, "Script:" %> | |
21 | - <%= m.text_area "script" %> | |
22 | - </p> | |
23 | - <% end %> | |
24 | - <p> | |
25 | - <%= f.label :code, "Code:" %> | |
26 | - <%= f.text_field "code" %> | |
27 | - </p> | |
28 | - <p> | |
29 | - <%= f.label :aggregation_form, "Aggregation Form:" %> | |
30 | - <%= f.select :aggregation_form, [["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"], | |
31 | - ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]] %> | |
32 | - </p> | |
33 | - <p> | |
34 | - <%= f.label :weight, "Weight:" %> | |
35 | - <%= f.text_field :weight %> | |
36 | - </p> | |
37 | - <p> | |
38 | - <%= f.submit "Save" %> | |
39 | - </p> | |
40 | -<% end %> | |
41 | - | |
42 | -<!-- make this prettier --> | |
43 | -<table> | |
44 | - <tr class="titles"> | |
45 | - <td><h5>Metric Name</h5></td> | |
46 | - <td><h5>Metric Code</h5></td> | |
47 | - </tr> | |
48 | - <% @metric_configurations.each do |metric_configuration| %> | |
49 | - <tr class="metric"> | |
50 | - <td><%= metric_configuration.metric.name %></td> | |
51 | - <td><%= metric_configuration.code %></td> | |
52 | - </tr> | |
53 | - <% end %> | |
54 | -</table> |
plugins/mezuro/views/mezuro_plugin_myprofile/new_compound_metric_configuration.html.erb
0 → 100644
... | ... | @@ -0,0 +1,54 @@ |
1 | +<h2><%= @configuration_name %> Configuration</h2> | |
2 | + | |
3 | +<% form_for :metric_configuration, :url => {:action =>"create_compound_metric_configuration", | |
4 | +:controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> | |
5 | + <%= hidden_field_tag :configuration_name, @configuration_name %> | |
6 | + <% f.fields_for :metric do |m| %> | |
7 | + <p> | |
8 | + <%= m.label :name, "Name:" %> | |
9 | + <%= m.text_field "name" %> | |
10 | + </p> | |
11 | + <p> | |
12 | + <%= m.label :description, "Description:" %> | |
13 | + <%= m.text_field "description" %> | |
14 | + </p> | |
15 | + <p> | |
16 | + <%= m.label :scope, "Scope:" %> | |
17 | + <%= m.select :scope, [["Class", "CLASS"]] %> | |
18 | + </p> | |
19 | + <p> | |
20 | + <%= m.label :script, "Script:" %> | |
21 | + <%= m.text_area "script" %> | |
22 | + </p> | |
23 | + <% end %> | |
24 | + <p> | |
25 | + <%= f.label :code, "Code:" %> | |
26 | + <%= f.text_field "code" %> | |
27 | + </p> | |
28 | + <p> | |
29 | + <%= f.label :aggregation_form, "Aggregation Form:" %> | |
30 | + <%= f.select :aggregation_form, [["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"], | |
31 | + ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]] %> | |
32 | + </p> | |
33 | + <p> | |
34 | + <%= f.label :weight, "Weight:" %> | |
35 | + <%= f.text_field :weight %> | |
36 | + </p> | |
37 | + <p> | |
38 | + <%= f.submit "Save" %> | |
39 | + </p> | |
40 | +<% end %> | |
41 | + | |
42 | +<!-- make this prettier --> | |
43 | +<table> | |
44 | + <tr class="titles"> | |
45 | + <td><h5>Metric Name</h5></td> | |
46 | + <td><h5>Metric Code</h5></td> | |
47 | + </tr> | |
48 | + <% @metric_configurations.each do |metric_configuration| %> | |
49 | + <tr class="metric"> | |
50 | + <td><%= metric_configuration.metric.name %></td> | |
51 | + <td><%= metric_configuration.code %></td> | |
52 | + </tr> | |
53 | + <% end %> | |
54 | +</table> | ... | ... |