Commit 8cf59529a169ff0eb78e8a62b86867fe4f9439e9

Authored by João M. M. Silva + Diego Araújo
Committed by Alessandro Palmeira
1 parent e43e7fec

[Mezuro] Completed to write tests for controller

plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
... ... @@ -119,7 +119,7 @@ class MezuroPluginProfileController < ProfileController
119 119 range.end = params[:range][:end]
120 120 range.label = params[:range][:label]
121 121 range.grade = params[:range][:grade]
122   - range.color = "10" + params[:range][:color] #FIXME when you have js color pallete
  122 + range.color = params[:range][:color]
123 123 range.comments = params[:range][:comments]
124 124 range
125 125 end
... ...
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
... ... @@ -3,6 +3,9 @@ require 'test_helper'
3 3 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures"
4 4 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures"
5 5 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/error_fixtures"
  6 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures"
  7 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/native_metric_fixtures"
  8 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures"
6 9  
7 10 class MezuroPluginProfileControllerTest < ActionController::TestCase
8 11  
... ... @@ -17,8 +20,11 @@ class MezuroPluginProfileControllerTest &lt; ActionController::TestCase
17 20 @project = @project_result.project
18 21 @name = @project.name
19 22  
20   - @collector = create_collector
21   - @client = Kalibro::Client::BaseToolClient.new
  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
22 28 end
23 29  
24 30 should 'not find module result for inexistent project content' do
... ... @@ -79,11 +85,78 @@ class MezuroPluginProfileControllerTest &lt; ActionController::TestCase
79 85 end
80 86  
81 87 should 'assign configuration and collector name in choose_metric' do
82   - Kalibro::Client::BaseToolClient.expects(:new).returns(@client)
83   - @client.expects(:base_tool).with(@collector.name).returns(@collector)
84   - get :choose_metric, :profile => @profile.identifier, :configuration_name => "test name", :collector_name => "Collector A"
  88 + Kalibro::Client::BaseToolClient.expects(:new).returns(@base_tool_client)
  89 + @base_tool_client.expects(:base_tool).with(@collector.name).returns(@collector)
  90 + get :choose_metric, :profile => @profile.identifier, :configuration_name => "test name", :collector_name => "Analizo"
85 91 assert_equal assigns(:configuration_name), "test name"
86   - assert_equal assigns(:collector_name), "Collector A"
  92 + assert_equal assigns(:collector_name), "Analizo"
  93 + end
  94 +
  95 + should 'get collector by name' do
  96 + Kalibro::Client::BaseToolClient.expects(:new).returns(@base_tool_client)
  97 + @base_tool_client.expects(:base_tool).with(@collector.name).returns(@collector)
  98 + get :choose_metric, :profile => @profile.identifier, :configuration_name => "test name", :collector_name => "Analizo"
  99 + assert_equal assigns(:collector), @collector
  100 + end
  101 +
  102 + should 'get choosed native metric and configuration 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 :new_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :collector_name => "Analizo", :metric_name => @metric.name
  106 + assert_equal assigns(:configuration_name), "test name"
  107 + assert_equal assigns(:metric), @metric
  108 + end
  109 +
  110 + should 'assign configuration name and get metric_configuration' do
  111 + Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client)
  112 + @metric_configuration_client.expects(:metric_configuration).with("test name", @metric.name).returns(@metric_configuration)
  113 + get :edit_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :metric_name => @metric.name
  114 + assert_equal assigns(:configuration_name), "test name"
  115 + assert_equal assigns(:metric_configuration), @metric_configuration
  116 + assert_equal assigns(:metric), @metric_configuration.metric
  117 + end
  118 +
  119 + should 'test metric creation' do
  120 + Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client)
  121 + @metric_configuration_client.expects(:save)
  122 + get :create_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :description => @metric.description,
  123 + :scope => @metric.scope, :language => @metric.language, :metric => { :name => @metric.name, :origin => @metric.origin},
  124 + :metric_configuration => { :code => @metric_configuration.code, :weight => @metric_configuration.code, :aggregation => @metric_configuration.aggregation_form }
  125 + assert_equal assigns(:configuration_name), "test name"
  126 + assert_response 302
  127 + end
  128 +
  129 + should 'test metric edition' do
  130 + Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client)
  131 + @metric_configuration_client.expects(:save)
  132 + get :create_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :description => @metric.description,
  133 + :scope => @metric.scope, :language => @metric.language, :metric => { :name => @metric.name, :origin => @metric.origin},
  134 + :metric_configuration => { :code => @metric_configuration.code, :weight => @metric_configuration.code, :aggregation => @metric_configuration.aggregation_form }
  135 + assert_equal assigns(:configuration_name), "test name"
  136 + assert_response 302
  137 + end
  138 +
  139 + should 'assign configuration name and metric name to new range' do
  140 + get :new_range, :profile => @profile.identifier, :configuration_name => "test name", :metric_name => @metric.name
  141 + assert_equal assigns(:configuration_name), "test name"
  142 + assert_equal assigns(:metric_name), @metric.name
  143 + end
  144 +
  145 + should 'create instance range' do
  146 + Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client)
  147 + @metric_configuration_client.expects(:metric_configuration).with("test name", @metric.name).returns(@metric_configuration)
  148 + @metric_configuration_client.expects(:save)
  149 + range = @metric_configuration.ranges[0]
  150 + get :create_range, :profile => @profile.identifier, :range => { :beginning => range.beginning, :end => range.end, :label => range.label,
  151 + :grade => range.grade, :color => range.color, :comments => range.comments }, :configuration_name => "test name", :metric_name => @metric.name
  152 + assert assigns(:range).instance_of?(Kalibro::Entities::Range)
  153 + end
  154 +
  155 + should 'redirect from remove metric configuration' do
  156 + Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client)
  157 + @metric_configuration_client.expects(:remove)
  158 + get :remove_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :metric_name => @metric.name
  159 + assert_response 302
87 160 end
88 161  
89 162 private
... ... @@ -94,10 +167,4 @@ class MezuroPluginProfileControllerTest &lt; ActionController::TestCase
94 167 @content.save
95 168 end
96 169  
97   - def create_collector
98   - collector = Kalibro::Entities::BaseTool.new
99   - collector.name = "Collector A"
100   - collector.supported_metrics = []
101   - collector
102   - end
103 170 end
... ...