Commit d7a79ac553650528cd996379479c65db38079908
Committed by
Paulo Meireles
1 parent
92ed6364
Exists in
master
and in
29 other branches
[Mezuro] Split controller in two <not working yet>
Showing
2 changed files
with
1 additions
and
226 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
@@ -40,139 +40,5 @@ class MezuroPluginProfileController < ProfileController | @@ -40,139 +40,5 @@ class MezuroPluginProfileController < ProfileController | ||
40 | source_tree = project_result.node_of(params[:module_name]) | 40 | source_tree = project_result.node_of(params[:module_name]) |
41 | render :partial =>'content_viewer/source_tree', :locals => { :source_tree => source_tree, :project_name => content.project.name} | 41 | render :partial =>'content_viewer/source_tree', :locals => { :source_tree => source_tree, :project_name => content.project.name} |
42 | end | 42 | end |
43 | - def choose_base_tool | ||
44 | - @configuration_name = params[:configuration_name] | ||
45 | - @tool_names = Kalibro::Client::BaseToolClient.new | ||
46 | - end | ||
47 | - | ||
48 | - def choose_metric | ||
49 | - @configuration_name = params[:configuration_name] | ||
50 | - @collector_name = params[:collector_name] | ||
51 | - @collector = Kalibro::Client::BaseToolClient.new.base_tool(@collector_name) | ||
52 | - end | ||
53 | - def new_metric_configuration | ||
54 | - metric_name = params[:metric_name] | ||
55 | - collector_name = params[:collector_name] | ||
56 | - collector = Kalibro::Client::BaseToolClient.new.base_tool(collector_name) | ||
57 | - @metric = collector.supported_metrics.find {|metric| metric.name == metric_name} | ||
58 | - @configuration_name = params[:configuration_name] | ||
59 | - end | ||
60 | - def edit_metric_configuration | ||
61 | - metric_name = params[:metric_name] | ||
62 | - @configuration_name = params[:configuration_name] | ||
63 | - @metric_configuration = Kalibro::Client::MetricConfigurationClient.new.metric_configuration(@configuration_name, metric_name) | ||
64 | - @metric = @metric_configuration.metric | ||
65 | - end | ||
66 | - def create_metric_configuration | ||
67 | - @configuration_name = params[:configuration_name] | ||
68 | - metric_configuration = new_metric_configuration_instance | ||
69 | - Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, @configuration_name) | ||
70 | - redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}" | ||
71 | - end | ||
72 | - | ||
73 | - def update_metric_configuration | ||
74 | - @configuration_name = params[:configuration_name] | ||
75 | - metric_name = params[:metric][:name] | ||
76 | - metric_configuration = Kalibro::Client::MetricConfigurationClient.new.metric_configuration(@configuration_name, metric_name) | ||
77 | - assign_metric_configuration_instance (metric_configuration) | ||
78 | - Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, @configuration_name) | ||
79 | - redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}" | ||
80 | - end | ||
81 | - | ||
82 | - def new_range | ||
83 | - @metric_name = params[:metric_name] | ||
84 | - @configuration_name = params[:configuration_name] | ||
85 | - end | ||
86 | - | ||
87 | - def edit_range | ||
88 | - @metric_name = params[:metric_name] | ||
89 | - @configuration_name = params[:configuration_name] | ||
90 | - @beginning_id = params[:beginning_id] | ||
91 | - | ||
92 | - metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new | ||
93 | - metric_configuration = metric_configuration_client.metric_configuration(@configuration_name, @metric_name) | ||
94 | - @range = metric_configuration.ranges.find{ |range| range.beginning == @beginning_id.to_f } | ||
95 | - end | ||
96 | - | ||
97 | - def create_range | ||
98 | - @range = new_range_instance | ||
99 | - configuration_name = params[:configuration_name] | ||
100 | - metric_name = params[:metric_name] | ||
101 | - beginning_id = params[:beginning_id] | ||
102 | - metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new | ||
103 | - metric_configuration = metric_configuration_client.metric_configuration(configuration_name, metric_name) | ||
104 | - metric_configuration.add_range(@range) | ||
105 | - metric_configuration_client.save(metric_configuration, configuration_name) | ||
106 | - end | ||
107 | 43 | ||
108 | - def update_range | ||
109 | - metric_name = params[:metric_name] | ||
110 | - configuration_name = params[:configuration_name] | ||
111 | - beginning_id = params[:beginning_id] | ||
112 | - metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new | ||
113 | - metric_configuration = metric_configuration_client.metric_configuration(configuration_name, metric_name) | ||
114 | - index = metric_configuration.ranges.index{ |range| range.beginning == beginning_id.to_f } | ||
115 | - metric_configuration.ranges[index] = new_range_instance | ||
116 | - Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, configuration_name) | ||
117 | - end | ||
118 | - | ||
119 | - def remove_range | ||
120 | - configuration_name = params[:configuration_name] | ||
121 | - metric_name = params[:metric_name] | ||
122 | - beginning_id = params[:range_beginning] | ||
123 | - metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new | ||
124 | - metric_configuration = metric_configuration_client.metric_configuration(configuration_name, metric_name) | ||
125 | - metric_configuration.ranges.delete_if { |range| range.beginning == beginning_id.to_f }.inspect | ||
126 | - Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, configuration_name) | ||
127 | - formatted_configuration_name = configuration_name.gsub(/\s/, '+') | ||
128 | - formatted_metric_name = metric_name.gsub(/\s/, '+') | ||
129 | - redirect_to "/profile/#{profile.identifier}/plugins/mezuro/edit_metric_configuration?configuration_name=#{formatted_configuration_name}&metric_name=#{formatted_metric_name}" | ||
130 | - end | ||
131 | - | ||
132 | - def remove_metric_configuration | ||
133 | - configuration_name = params[:configuration_name] | ||
134 | - metric_name = params[:metric_name] | ||
135 | - Kalibro::Client::MetricConfigurationClient.new.remove(configuration_name, metric_name) | ||
136 | - redirect_to "/#{profile.identifier}/#{configuration_name.downcase.gsub(/\s/, '-')}" | ||
137 | - end | ||
138 | - | ||
139 | - def module_metrics_history | ||
140 | - metric_name = params[:metric_name] | ||
141 | - content = profile.articles.find(params[:id]) | ||
142 | - module_history = content.result_history(params[:module_name]) | ||
143 | - date_history = module_history.collect { |x| x.date } | ||
144 | - metric_history = module_history.collect { |x| (x.metric_results.select { |y| y.metric.name.delete("() ") == metric_name })[0] } | ||
145 | - render :partial => 'content_viewer/metric_history', :locals => {:metric_history => metric_history, :date_history => date_history } | ||
146 | - end | ||
147 | - private | ||
148 | - | ||
149 | - def new_metric_configuration_instance | ||
150 | - metric_configuration = Kalibro::Entities::MetricConfiguration.new | ||
151 | - metric_configuration.metric = Kalibro::Entities::NativeMetric.new | ||
152 | - assign_metric_configuration_instance (metric_configuration) | ||
153 | - end | ||
154 | - | ||
155 | - def assign_metric_configuration_instance (metric_configuration) | ||
156 | - metric_configuration.metric.name = params[:metric][:name] | ||
157 | - metric_configuration.metric.description = params[:description] | ||
158 | - metric_configuration.metric.origin = params[:metric][:origin] | ||
159 | - metric_configuration.metric.scope = params[:scope] | ||
160 | - metric_configuration.metric.language = params[:language] | ||
161 | - metric_configuration.code = params[:metric_configuration][:code] | ||
162 | - metric_configuration.weight = params[:metric_configuration][:weight] | ||
163 | - metric_configuration.aggregation_form = params[:metric_configuration][:aggregation_form] | ||
164 | - metric_configuration | ||
165 | - end | ||
166 | - | ||
167 | - def new_range_instance | ||
168 | - range = Kalibro::Entities::Range.new | ||
169 | - range.beginning = params[:range][:beginning] | ||
170 | - range.end = params[:range][:end] | ||
171 | - range.label = params[:range][:label] | ||
172 | - range.grade = params[:range][:grade] | ||
173 | - range.color = params[:range][:color] | ||
174 | - range.comments = params[:range][:comments] | ||
175 | - range | ||
176 | - end | ||
177 | - | ||
178 | end | 44 | end |
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
@@ -20,13 +20,7 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase | @@ -20,13 +20,7 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase | ||
20 | @project = @project_result.project | 20 | @project = @project_result.project |
21 | @name = @project.name | 21 | @name = @project.name |
22 | 22 | ||
23 | - @collector = BaseToolFixtures.analizo | ||
24 | - @base_tool_client = Kalibro::Client::BaseToolClient.new | ||
25 | - @metric = NativeMetricFixtures.amloc | ||
26 | - @metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new | ||
27 | - @metric_configuration = MetricConfigurationFixtures.amloc_configuration | ||
28 | - | ||
29 | - @date = "2012-04-13T20:39:41+04:00" | 23 | + @date = "2012-04-13T20:39:41+04:00" |
30 | end | 24 | end |
31 | 25 | ||
32 | should 'not find module result for inexistent project content' do | 26 | should 'not find module result for inexistent project content' do |
@@ -81,91 +75,6 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase | @@ -81,91 +75,6 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase | ||
81 | assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)') | 75 | assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)') |
82 | end | 76 | end |
83 | 77 | ||
84 | - should 'assign configuration name in choose_base_tool' do | ||
85 | - get :choose_base_tool, :profile => @profile.identifier, :configuration_name => "test name" | ||
86 | - assert_equal assigns(:configuration_name), "test name" | ||
87 | - end | ||
88 | - | ||
89 | - should 'create base tool client' do | ||
90 | - get :choose_base_tool, :profile => @profile.identifier, :configuration_name => "test name" | ||
91 | - assert assigns(:tool_names).instance_of?(Kalibro::Client::BaseToolClient) | ||
92 | - end | ||
93 | - | ||
94 | - should 'assign configuration and collector name in choose_metric' do | ||
95 | - Kalibro::Client::BaseToolClient.expects(:new).returns(@base_tool_client) | ||
96 | - @base_tool_client.expects(:base_tool).with(@collector.name).returns(@collector) | ||
97 | - get :choose_metric, :profile => @profile.identifier, :configuration_name => "test name", :collector_name => "Analizo" | ||
98 | - assert_equal assigns(:configuration_name), "test name" | ||
99 | - assert_equal assigns(:collector_name), "Analizo" | ||
100 | - end | ||
101 | - | ||
102 | - should 'get collector by name' do | ||
103 | - Kalibro::Client::BaseToolClient.expects(:new).returns(@base_tool_client) | ||
104 | - @base_tool_client.expects(:base_tool).with(@collector.name).returns(@collector) | ||
105 | - get :choose_metric, :profile => @profile.identifier, :configuration_name => "test name", :collector_name => "Analizo" | ||
106 | - assert_equal assigns(:collector), @collector | ||
107 | - end | ||
108 | - | ||
109 | - should 'get choosed native metric and configuration name' do | ||
110 | - Kalibro::Client::BaseToolClient.expects(:new).returns(@base_tool_client) | ||
111 | - @base_tool_client.expects(:base_tool).with(@collector.name).returns(@collector) | ||
112 | - get :new_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :collector_name => "Analizo", :metric_name => @metric.name | ||
113 | - assert_equal assigns(:configuration_name), "test name" | ||
114 | - assert_equal assigns(:metric), @metric | ||
115 | - end | ||
116 | - | ||
117 | - should 'assign configuration name and get metric_configuration' do | ||
118 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | ||
119 | - @metric_configuration_client.expects(:metric_configuration).with("test name", @metric.name).returns(@metric_configuration) | ||
120 | - get :edit_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :metric_name => @metric.name | ||
121 | - assert_equal assigns(:configuration_name), "test name" | ||
122 | - assert_equal assigns(:metric_configuration), @metric_configuration | ||
123 | - assert_equal assigns(:metric), @metric_configuration.metric | ||
124 | - end | ||
125 | - | ||
126 | - should 'test metric creation' do | ||
127 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | ||
128 | - @metric_configuration_client.expects(:save) | ||
129 | - get :create_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :description => @metric.description, | ||
130 | - :scope => @metric.scope, :language => @metric.language, :metric => { :name => @metric.name, :origin => @metric.origin}, | ||
131 | - :metric_configuration => { :code => @metric_configuration.code, :weight => @metric_configuration.code, :aggregation => @metric_configuration.aggregation_form } | ||
132 | - assert_equal assigns(:configuration_name), "test name" | ||
133 | - assert_response 302 | ||
134 | - end | ||
135 | - | ||
136 | - should 'test metric edition' do | ||
137 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | ||
138 | - @metric_configuration_client.expects(:save) | ||
139 | - get :create_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :description => @metric.description, | ||
140 | - :scope => @metric.scope, :language => @metric.language, :metric => { :name => @metric.name, :origin => @metric.origin}, | ||
141 | - :metric_configuration => { :code => @metric_configuration.code, :weight => @metric_configuration.code, :aggregation => @metric_configuration.aggregation_form } | ||
142 | - assert_equal assigns(:configuration_name), "test name" | ||
143 | - assert_response 302 | ||
144 | - end | ||
145 | - | ||
146 | - should 'assign configuration name and metric name to new range' do | ||
147 | - get :new_range, :profile => @profile.identifier, :configuration_name => "test name", :metric_name => @metric.name | ||
148 | - assert_equal assigns(:configuration_name), "test name" | ||
149 | - assert_equal assigns(:metric_name), @metric.name | ||
150 | - end | ||
151 | - | ||
152 | - should 'create instance range' do | ||
153 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | ||
154 | - @metric_configuration_client.expects(:metric_configuration).with("test name", @metric.name).returns(@metric_configuration) | ||
155 | - @metric_configuration_client.expects(:save) | ||
156 | - range = @metric_configuration.ranges[0] | ||
157 | - get :create_range, :profile => @profile.identifier, :range => { :beginning => range.beginning, :end => range.end, :label => range.label, | ||
158 | - :grade => range.grade, :color => range.color, :comments => range.comments }, :configuration_name => "test name", :metric_name => @metric.name | ||
159 | - assert assigns(:range).instance_of?(Kalibro::Entities::Range) | ||
160 | - end | ||
161 | - | ||
162 | - should 'redirect from remove metric configuration' do | ||
163 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | ||
164 | - @metric_configuration_client.expects(:remove) | ||
165 | - get :remove_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :metric_name => @metric.name | ||
166 | - assert_response 302 | ||
167 | - end | ||
168 | - | ||
169 | private | 78 | private |
170 | 79 | ||
171 | def create_project_content | 80 | def create_project_content |