Commit 0532543b96923dff9e6d0da15b652ea52d3d97d9

Authored by Diego Camarinha
Committed by Diego Camarinha
1 parent df4312de

[Mezuro] Testing setters.

plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb
@@ -2,6 +2,10 @@ class Kalibro::MetricConfigurationSnapshot < Kalibro::Model @@ -2,6 +2,10 @@ class Kalibro::MetricConfigurationSnapshot < Kalibro::Model
2 2
3 attr_accessor :code, :weight, :aggregation_form, :metric, :base_tool_name, :range 3 attr_accessor :code, :weight, :aggregation_form, :metric, :base_tool_name, :range
4 4
  5 + def weight=(value)
  6 + @weight = value.to_f
  7 + end
  8 +
5 def metric=(value) 9 def metric=(value)
6 if value.kind_of?(Hash) 10 if value.kind_of?(Hash)
7 @metric = Kalibro::Metric.to_object(value) 11 @metric = Kalibro::Metric.to_object(value)
plugins/mezuro/lib/kalibro/metric_result.rb
@@ -13,6 +13,10 @@ class Kalibro::MetricResult < Kalibro::Model @@ -13,6 +13,10 @@ class Kalibro::MetricResult < Kalibro::Model
13 @errors = [] 13 @errors = []
14 end 14 end
15 15
  16 + def id=(value)
  17 + @id = value.to_i
  18 + end
  19 +
16 def configuration=(value) 20 def configuration=(value)
17 @configuration = Kalibro::MetricConfigurationSnapshot.to_object value 21 @configuration = Kalibro::MetricConfigurationSnapshot.to_object value
18 end 22 end
@@ -21,6 +25,10 @@ class Kalibro::MetricResult < Kalibro::Model @@ -21,6 +25,10 @@ class Kalibro::MetricResult < Kalibro::Model
21 configuration 25 configuration
22 end 26 end
23 27
  28 + def value=(value)
  29 + @value = value.to_f
  30 + end
  31 +
24 def error=(value) 32 def error=(value)
25 @error = Kalibro::Throwable.to_object value 33 @error = Kalibro::Throwable.to_object value
26 end 34 end
plugins/mezuro/lib/kalibro/model.rb
@@ -7,6 +7,7 @@ class Kalibro::Model @@ -7,6 +7,7 @@ class Kalibro::Model
7 @errors = [] 7 @errors = []
8 end 8 end
9 9
  10 +
10 def to_hash(options={}) 11 def to_hash(options={})
11 hash = Hash.new 12 hash = Hash.new
12 excepts = options[:except].nil? ? [] : options[:except] 13 excepts = options[:except].nil? ? [] : options[:except]
plugins/mezuro/lib/kalibro/module_result.rb
@@ -22,6 +22,10 @@ class Kalibro::ModuleResult < Kalibro::Model @@ -22,6 +22,10 @@ class Kalibro::ModuleResult < Kalibro::Model
22 end 22 end
23 end 23 end
24 24
  25 + def id=(value)
  26 + @id = value.to_i
  27 + end
  28 +
25 def module=(value) 29 def module=(value)
26 @module = Kalibro::Module.to_object value 30 @module = Kalibro::Module.to_object value
27 end 31 end
@@ -30,6 +34,10 @@ class Kalibro::ModuleResult < Kalibro::Model @@ -30,6 +34,10 @@ class Kalibro::ModuleResult < Kalibro::Model
30 @grade = value.to_f 34 @grade = value.to_f
31 end 35 end
32 36
  37 + def parent_id=(value)
  38 + @parent_id = value.to_i
  39 + end
  40 +
33 def self.history_of(module_result_id) 41 def self.history_of(module_result_id)
34 response = self.request(:history_of_module, {:module_result_id => module_result_id})[:date_module_result] 42 response = self.request(:history_of_module, {:module_result_id => module_result_id})[:date_module_result]
35 response = [] if response.nil? 43 response = [] if response.nil?
plugins/mezuro/lib/kalibro/processing.rb
1 -#TODO arrumar esse modelo e seus testes de unidade  
2 class Kalibro::Processing < Kalibro::Model 1 class Kalibro::Processing < Kalibro::Model
3 2
4 attr_accessor :id, :date, :state, :error, :process_time, :results_root_id 3 attr_accessor :id, :date, :state, :error, :process_time, :results_root_id
@@ -22,6 +21,10 @@ class Kalibro::Processing &lt; Kalibro::Model @@ -22,6 +21,10 @@ class Kalibro::Processing &lt; Kalibro::Model
22 end 21 end
23 end 22 end
24 23
  24 + def id=(value)
  25 + @id = value.to_i
  26 + end
  27 +
25 def date=(value) 28 def date=(value)
26 @date = value.is_a?(String) ? DateTime.parse(value) : value 29 @date = value.is_a?(String) ? DateTime.parse(value) : value
27 end 30 end
@@ -42,6 +45,10 @@ class Kalibro::Processing &lt; Kalibro::Model @@ -42,6 +45,10 @@ class Kalibro::Processing &lt; Kalibro::Model
42 @error = Kalibro::Throwable.to_object value 45 @error = Kalibro::Throwable.to_object value
43 end 46 end
44 47
  48 + def results_root_id=(value)
  49 + @results_root_id = value.to_i
  50 + end
  51 +
45 private 52 private
46 53
47 def self.has_processing(repository_id) 54 def self.has_processing(repository_id)
plugins/mezuro/lib/kalibro/project.rb
@@ -2,6 +2,10 @@ class Kalibro::Project &lt; Kalibro::Model @@ -2,6 +2,10 @@ class Kalibro::Project &lt; Kalibro::Model
2 2
3 attr_accessor :id, :name, :description 3 attr_accessor :id, :name, :description
4 4
  5 + def id=(value)
  6 + @id = value.to_i
  7 + end
  8 +
5 def self.all 9 def self.all
6 response = request(:all_projects)[:project] 10 response = request(:all_projects)[:project]
7 response = [] if response.nil? 11 response = [] if response.nil?
plugins/mezuro/lib/kalibro/range_snapshot.rb
@@ -2,4 +2,16 @@ class Kalibro::RangeSnapshot &lt; Kalibro::Model @@ -2,4 +2,16 @@ class Kalibro::RangeSnapshot &lt; Kalibro::Model
2 2
3 attr_accessor :beginning, :end, :label, :grade, :color, :comments 3 attr_accessor :beginning, :end, :label, :grade, :color, :comments
4 4
  5 + def beginning=(value)
  6 + @beginning = ((value == "-INF") ? -1.0/0 : value.to_f)
  7 + end
  8 +
  9 + def end=(value)
  10 + @end = ((value == "INF") ? 1.0/0 : value.to_f)
  11 + end
  12 +
  13 + def grade=(value)
  14 + @grade = value.to_f
  15 + end
  16 +
5 end 17 end
plugins/mezuro/lib/kalibro/repository.rb
@@ -17,6 +17,18 @@ class Kalibro::Repository &lt; Kalibro::Model @@ -17,6 +17,18 @@ class Kalibro::Repository &lt; Kalibro::Model
17 response.map {|repository| new repository} 17 response.map {|repository| new repository}
18 end 18 end
19 19
  20 + def id=(value)
  21 + @id = value.to_i
  22 + end
  23 +
  24 + def process_period=(value)
  25 + @process_period = value.to_i
  26 + end
  27 +
  28 + def configuration_id=(value)
  29 + @configuration_id = value.to_i
  30 + end
  31 +
20 def process 32 def process
21 self.class.request(:process_repository, {:repository_id => self.id}) 33 self.class.request(:process_repository, {:repository_id => self.id})
22 end 34 end
plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb
@@ -10,7 +10,7 @@ class MetricConfigurationSnapshotFixtures @@ -10,7 +10,7 @@ class MetricConfigurationSnapshotFixtures
10 def self.metric_configuration_snapshot_hash 10 def self.metric_configuration_snapshot_hash
11 { 11 {
12 :code => "code", 12 :code => "code",
13 - :weight => "1", 13 + :weight => "1.0",
14 :aggregation_form => 'AVERAGE', 14 :aggregation_form => 'AVERAGE',
15 :metric => MetricFixtures.amloc_hash, 15 :metric => MetricFixtures.amloc_hash,
16 :base_tool_name => "Analizo", 16 :base_tool_name => "Analizo",
@@ -43,7 +43,7 @@ class MetricConfigurationSnapshotFixtures @@ -43,7 +43,7 @@ class MetricConfigurationSnapshotFixtures
43 def self.compound_metric_configuration_snapshot_hash 43 def self.compound_metric_configuration_snapshot_hash
44 { 44 {
45 :code => "code", 45 :code => "code",
46 - :weight => "1", 46 + :weight => "1.0",
47 :aggregation_form => 'AVERAGE', 47 :aggregation_form => 'AVERAGE',
48 :metric => MetricFixtures.compound_metric, 48 :metric => MetricFixtures.compound_metric,
49 :base_tool_name => "Analizo", 49 :base_tool_name => "Analizo",
plugins/mezuro/test/fixtures/range_snapshot_fixtures.rb
@@ -4,8 +4,16 @@ class RangeSnapshotFixtures @@ -4,8 +4,16 @@ class RangeSnapshotFixtures
4 Kalibro::RangeSnapshot.new range_snapshot_hash 4 Kalibro::RangeSnapshot.new range_snapshot_hash
5 end 5 end
6 6
  7 + def self.range_snapshot_with_infinite_range
  8 + Kalibro::RangeSnapshot.new range_snapshot_with_infinite_range_hash
  9 + end
  10 +
7 def self.range_snapshot_hash 11 def self.range_snapshot_hash
8 - { :end => "5", :label => "snapshot", :grade => "10", :color => "FF2284", :comments => "comment" } 12 + { :beginning => "1.1", :end => "5.1", :label => "snapshot", :grade => "10.1", :color => "FF2284", :comments => "comment" }
9 end 13 end
10 14
  15 + def self.range_snapshot_with_infinite_range_hash
  16 + { :beginning => "-INF", :end => "INF", :label => "snapshot", :grade => "10.1", :color => "FF2284", :comments => "comment" }
  17 + end
  18 +
11 end 19 end
plugins/mezuro/test/unit/kalibro/date_metric_result_test.rb
@@ -10,7 +10,7 @@ class DateMetricResultTest &lt; ActiveSupport::TestCase @@ -10,7 +10,7 @@ class DateMetricResultTest &lt; ActiveSupport::TestCase
10 end 10 end
11 11
12 should 'create date_metric_result from hash' do 12 should 'create date_metric_result from hash' do
13 - assert_equal @hash[:metric_result][:id], Kalibro::DateMetricResult.new(@hash).metric_result.id 13 + assert_equal @hash[:metric_result][:id].to_i, Kalibro::DateMetricResult.new(@hash).metric_result.id
14 end 14 end
15 15
16 should 'convert date_metric_result to hash' do 16 should 'convert date_metric_result to hash' do
plugins/mezuro/test/unit/kalibro/date_module_result_test.rb
@@ -10,7 +10,7 @@ class DateModuleResultTest &lt; ActiveSupport::TestCase @@ -10,7 +10,7 @@ class DateModuleResultTest &lt; ActiveSupport::TestCase
10 end 10 end
11 11
12 should 'create date_module_result from hash' do 12 should 'create date_module_result from hash' do
13 - assert_equal @hash[:module_result][:id], Kalibro::DateModuleResult.new(@hash).module_result.id 13 + assert_equal @hash[:module_result][:id].to_i, Kalibro::DateModuleResult.new(@hash).module_result.id
14 end 14 end
15 15
16 should 'convert date_module_result to hash' do 16 should 'convert date_module_result to hash' do
plugins/mezuro/test/unit/kalibro/metric_configuration_snapshot_test.rb
@@ -13,7 +13,7 @@ class MetricConfigurationSnapshotTest &lt; ActiveSupport::TestCase @@ -13,7 +13,7 @@ class MetricConfigurationSnapshotTest &lt; ActiveSupport::TestCase
13 13
14 should 'create and convert metric configuration snapshot from hash' do 14 should 'create and convert metric configuration snapshot from hash' do
15 assert_equal @hash[:code], Kalibro::MetricConfigurationSnapshot.new(@hash).code 15 assert_equal @hash[:code], Kalibro::MetricConfigurationSnapshot.new(@hash).code
16 - assert_equal @hash, @metric_configuration_snapshot.to_hash 16 + assert_equal @hash[:weight].to_f, @metric_configuration_snapshot.weight
17 end 17 end
18 18
19 should 'create and convert metric configuration snapshot from hash with 2 elements' do 19 should 'create and convert metric configuration snapshot from hash with 2 elements' do
plugins/mezuro/test/unit/kalibro/metric_result_test.rb
@@ -12,7 +12,10 @@ class MetricResultTest &lt; ActiveSupport::TestCase @@ -12,7 +12,10 @@ class MetricResultTest &lt; ActiveSupport::TestCase
12 end 12 end
13 13
14 should 'create metric result from hash' do 14 should 'create metric result from hash' do
15 - assert_equal @native_hash[:configuration][:code], Kalibro::MetricResult.new(@native_hash).configuration.code 15 + metric_result = Kalibro::MetricResult.new(@native_hash)
  16 + assert_equal @native_hash[:configuration][:code], metric_result.configuration.code
  17 + assert_equal @native_hash[:id].to_i, metric_result.id
  18 + assert_equal @native_hash[:value].to_f, metric_result.value
16 end 19 end
17 20
18 should 'convert metric result to hash' do 21 should 'convert metric result to hash' do
@@ -28,13 +31,13 @@ class MetricResultTest &lt; ActiveSupport::TestCase @@ -28,13 +31,13 @@ class MetricResultTest &lt; ActiveSupport::TestCase
28 should 'return metric results of a module result' do 31 should 'return metric results of a module result' do
29 id = 31 32 id = 31
30 Kalibro::MetricResult.expects(:request).with(:metric_results_of, {:module_result_id => id}).returns(:metric_result => [@native_hash, @compound_hash]) 33 Kalibro::MetricResult.expects(:request).with(:metric_results_of, {:module_result_id => id}).returns(:metric_result => [@native_hash, @compound_hash])
31 - assert_equal @native_hash[:id], Kalibro::MetricResult.metric_results_of(id).first.id 34 + assert_equal @native_hash[:id].to_i, Kalibro::MetricResult.metric_results_of(id).first.id
32 end 35 end
33 36
34 should 'return history of a metric with a module result id' do 37 should 'return history of a metric with a module result id' do
35 module_result_id = 31 38 module_result_id = 31
36 Kalibro::MetricResult.expects(:request).with(:history_of_metric, {:metric_name => @result.configuration.metric.name, :module_result_id => module_result_id}).returns({:date_metric_result => DateMetricResultFixtures.date_metric_result_hash}) 39 Kalibro::MetricResult.expects(:request).with(:history_of_metric, {:metric_name => @result.configuration.metric.name, :module_result_id => module_result_id}).returns({:date_metric_result => DateMetricResultFixtures.date_metric_result_hash})
37 - assert_equal DateMetricResultFixtures.date_metric_result_hash[:metric_result][:id], Kalibro::MetricResult.history_of(@result.configuration.metric.name, module_result_id).first.metric_result.id 40 + assert_equal DateMetricResultFixtures.date_metric_result_hash[:metric_result][:id].to_i, Kalibro::MetricResult.history_of(@result.configuration.metric.name, module_result_id).first.metric_result.id
38 end 41 end
39 42
40 end 43 end
plugins/mezuro/test/unit/kalibro/module_result_test.rb
@@ -11,7 +11,10 @@ class ModuleResultTest &lt; ActiveSupport::TestCase @@ -11,7 +11,10 @@ class ModuleResultTest &lt; ActiveSupport::TestCase
11 end 11 end
12 12
13 should 'create module result' do 13 should 'create module result' do
14 - assert_equal @hash[:id] , Kalibro::ModuleResult.new(@hash).id 14 + module_result = Kalibro::ModuleResult.new(@hash)
  15 + assert_equal @hash[:id].to_i , module_result.id
  16 + assert_equal @hash[:grade].to_f , module_result.grade
  17 + assert_equal @hash[:parent_id].to_i , module_result.parent_id
15 end 18 end
16 19
17 should 'convert module result to hash' do 20 should 'convert module result to hash' do
@@ -41,7 +44,7 @@ class ModuleResultTest &lt; ActiveSupport::TestCase @@ -41,7 +44,7 @@ class ModuleResultTest &lt; ActiveSupport::TestCase
41 44
42 should 'return history of a module result' do 45 should 'return history of a module result' do
43 Kalibro::ModuleResult.expects(:request).with(:history_of_module, {:module_result_id => @module_result.id}).returns({:date_module_result => [DateModuleResultFixtures.date_module_result_hash]}) 46 Kalibro::ModuleResult.expects(:request).with(:history_of_module, {:module_result_id => @module_result.id}).returns({:date_module_result => [DateModuleResultFixtures.date_module_result_hash]})
44 - assert_equal DateModuleResultFixtures.date_module_result_hash[:module_result][:id], Kalibro::ModuleResult.history_of(@module_result.id).first.module_result.id 47 + assert_equal DateModuleResultFixtures.date_module_result_hash[:module_result][:id].to_i, Kalibro::ModuleResult.history_of(@module_result.id).first.module_result.id
45 end 48 end
46 49
47 end 50 end
plugins/mezuro/test/unit/kalibro/process_time_test.rb
@@ -11,6 +11,7 @@ class ProcessTimeTest &lt; ActiveSupport::TestCase @@ -11,6 +11,7 @@ class ProcessTimeTest &lt; ActiveSupport::TestCase
11 11
12 should 'create process time from hash' do 12 should 'create process time from hash' do
13 assert_equal @hash[:state], Kalibro::ProcessTime.new(@hash).state 13 assert_equal @hash[:state], Kalibro::ProcessTime.new(@hash).state
  14 + assert_equal @hash[:time].to_i, Kalibro::ProcessTime.new(@hash).time
14 end 15 end
15 16
16 should 'convert process time to hash' do 17 should 'convert process time to hash' do
plugins/mezuro/test/unit/kalibro/processing_test.rb
@@ -11,8 +11,10 @@ class ProcessingTest &lt; ActiveSupport::TestCase @@ -11,8 +11,10 @@ class ProcessingTest &lt; ActiveSupport::TestCase
11 end 11 end
12 12
13 should 'create processing from hash' do 13 should 'create processing from hash' do
14 - assert_equal @hash[:results_root_id], Kalibro::Processing.new(@hash).results_root_id  
15 - assert_equal @hash[:process_time].first[:state], Kalibro::Processing.new(@hash).process_times.first.state 14 + processing = Kalibro::Processing.new(@hash)
  15 + assert_equal @hash[:results_root_id].to_i, processing.results_root_id
  16 + assert_equal @hash[:process_time].first[:state], processing.process_times.first.state
  17 + assert_equal @hash[:id].to_i, processing.id
16 end 18 end
17 19
18 should 'convert processing to hash' do 20 should 'convert processing to hash' do
plugins/mezuro/test/unit/kalibro/project_test.rb
@@ -13,6 +13,7 @@ class ProjectTest &lt; ActiveSupport::TestCase @@ -13,6 +13,7 @@ class ProjectTest &lt; ActiveSupport::TestCase
13 should 'initialize new project from hash' do 13 should 'initialize new project from hash' do
14 project = Kalibro::Project.new @hash 14 project = Kalibro::Project.new @hash
15 assert_equal @hash[:name], project.name 15 assert_equal @hash[:name], project.name
  16 + assert_equal @hash[:id].to_i, project.id
16 end 17 end
17 18
18 should 'convert project to hash' do 19 should 'convert project to hash' do
plugins/mezuro/test/unit/kalibro/range_snapshot_test.rb
@@ -6,11 +6,23 @@ class RangeSnapshotTest &lt; ActiveSupport::TestCase @@ -6,11 +6,23 @@ class RangeSnapshotTest &lt; ActiveSupport::TestCase
6 6
7 def setup 7 def setup
8 @hash = RangeSnapshotFixtures.range_snapshot_hash 8 @hash = RangeSnapshotFixtures.range_snapshot_hash
  9 + @range_snapshot_with_infinite_range_hash = RangeSnapshotFixtures.range_snapshot_with_infinite_range_hash
9 @range_snapshot = RangeSnapshotFixtures.range_snapshot 10 @range_snapshot = RangeSnapshotFixtures.range_snapshot
  11 + @range_snapshot_with_infinite_range = RangeSnapshotFixtures.range_snapshot_with_infinite_range
10 end 12 end
11 13
12 should 'create range_snapshot from hash' do 14 should 'create range_snapshot from hash' do
13 - assert_equal @hash[:comments], Kalibro::RangeSnapshot.new(@hash).comments 15 + range_snapshot = Kalibro::RangeSnapshot.new(@hash)
  16 + assert_equal @hash[:comments], range_snapshot.comments
  17 + assert_equal @hash[:beginning].to_f, range_snapshot.beginning
  18 + assert_equal @hash[:end].to_f, range_snapshot.end
  19 + assert_equal @hash[:grade].to_f, range_snapshot.grade
  20 + end
  21 +
  22 + should 'create range_snapshot from hash with infinity values' do
  23 + range_snapshot = Kalibro::RangeSnapshot.new(@range_snapshot_with_infinite_range_hash)
  24 + assert_equal -1.0/0, range_snapshot.beginning
  25 + assert_equal 1.0/0, range_snapshot.end
14 end 26 end
15 27
16 should 'convert range_snapshot to hash' do 28 should 'convert range_snapshot to hash' do
plugins/mezuro/test/unit/kalibro/repository_test.rb
@@ -11,7 +11,11 @@ class RepositoryTest &lt; ActiveSupport::TestCase @@ -11,7 +11,11 @@ class RepositoryTest &lt; ActiveSupport::TestCase
11 end 11 end
12 12
13 should 'new repository from hash' do 13 should 'new repository from hash' do
14 - assert_equal @repository.type, Kalibro::Repository.new(@hash).type 14 + repository = Kalibro::Repository.new(@hash)
  15 + assert_equal @hash[:type], repository.type
  16 + assert_equal @hash[:id].to_i, repository.id
  17 + assert_equal @hash[:process_period].to_i, repository.process_period
  18 + assert_equal @hash[:configuration_id].to_i, repository.configuration_id
15 end 19 end
16 20
17 should 'convert repository to hash' do 21 should 'convert repository to hash' do