diff --git a/plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb b/plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb index 99c3628..ae1a5b2 100644 --- a/plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb +++ b/plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb @@ -2,6 +2,10 @@ class Kalibro::MetricConfigurationSnapshot < Kalibro::Model attr_accessor :code, :weight, :aggregation_form, :metric, :base_tool_name, :range + def weight=(value) + @weight = value.to_f + end + def metric=(value) if value.kind_of?(Hash) @metric = Kalibro::Metric.to_object(value) diff --git a/plugins/mezuro/lib/kalibro/metric_result.rb b/plugins/mezuro/lib/kalibro/metric_result.rb index bbaa418..7b58ce7 100644 --- a/plugins/mezuro/lib/kalibro/metric_result.rb +++ b/plugins/mezuro/lib/kalibro/metric_result.rb @@ -13,6 +13,10 @@ class Kalibro::MetricResult < Kalibro::Model @errors = [] end + def id=(value) + @id = value.to_i + end + def configuration=(value) @configuration = Kalibro::MetricConfigurationSnapshot.to_object value end @@ -21,6 +25,10 @@ class Kalibro::MetricResult < Kalibro::Model configuration end + def value=(value) + @value = value.to_f + end + def error=(value) @error = Kalibro::Throwable.to_object value end diff --git a/plugins/mezuro/lib/kalibro/model.rb b/plugins/mezuro/lib/kalibro/model.rb index 3987145..e7ef547 100644 --- a/plugins/mezuro/lib/kalibro/model.rb +++ b/plugins/mezuro/lib/kalibro/model.rb @@ -7,6 +7,7 @@ class Kalibro::Model @errors = [] end + def to_hash(options={}) hash = Hash.new excepts = options[:except].nil? ? [] : options[:except] diff --git a/plugins/mezuro/lib/kalibro/module_result.rb b/plugins/mezuro/lib/kalibro/module_result.rb index d90d6af..c61d3ad 100644 --- a/plugins/mezuro/lib/kalibro/module_result.rb +++ b/plugins/mezuro/lib/kalibro/module_result.rb @@ -22,6 +22,10 @@ class Kalibro::ModuleResult < Kalibro::Model end end + def id=(value) + @id = value.to_i + end + def module=(value) @module = Kalibro::Module.to_object value end @@ -30,6 +34,10 @@ class Kalibro::ModuleResult < Kalibro::Model @grade = value.to_f end + def parent_id=(value) + @parent_id = value.to_i + end + def self.history_of(module_result_id) response = self.request(:history_of_module, {:module_result_id => module_result_id})[:date_module_result] response = [] if response.nil? diff --git a/plugins/mezuro/lib/kalibro/processing.rb b/plugins/mezuro/lib/kalibro/processing.rb index 4842ed4..9602fee 100644 --- a/plugins/mezuro/lib/kalibro/processing.rb +++ b/plugins/mezuro/lib/kalibro/processing.rb @@ -1,4 +1,3 @@ -#TODO arrumar esse modelo e seus testes de unidade class Kalibro::Processing < Kalibro::Model attr_accessor :id, :date, :state, :error, :process_time, :results_root_id @@ -22,6 +21,10 @@ class Kalibro::Processing < Kalibro::Model end end + def id=(value) + @id = value.to_i + end + def date=(value) @date = value.is_a?(String) ? DateTime.parse(value) : value end @@ -42,6 +45,10 @@ class Kalibro::Processing < Kalibro::Model @error = Kalibro::Throwable.to_object value end + def results_root_id=(value) + @results_root_id = value.to_i + end + private def self.has_processing(repository_id) diff --git a/plugins/mezuro/lib/kalibro/project.rb b/plugins/mezuro/lib/kalibro/project.rb index eef43f7..afb2721 100644 --- a/plugins/mezuro/lib/kalibro/project.rb +++ b/plugins/mezuro/lib/kalibro/project.rb @@ -2,6 +2,10 @@ class Kalibro::Project < Kalibro::Model attr_accessor :id, :name, :description + def id=(value) + @id = value.to_i + end + def self.all response = request(:all_projects)[:project] response = [] if response.nil? diff --git a/plugins/mezuro/lib/kalibro/range_snapshot.rb b/plugins/mezuro/lib/kalibro/range_snapshot.rb index b9a30c8..14f0074 100644 --- a/plugins/mezuro/lib/kalibro/range_snapshot.rb +++ b/plugins/mezuro/lib/kalibro/range_snapshot.rb @@ -2,4 +2,16 @@ class Kalibro::RangeSnapshot < Kalibro::Model attr_accessor :beginning, :end, :label, :grade, :color, :comments + def beginning=(value) + @beginning = ((value == "-INF") ? -1.0/0 : value.to_f) + end + + def end=(value) + @end = ((value == "INF") ? 1.0/0 : value.to_f) + end + + def grade=(value) + @grade = value.to_f + end + end diff --git a/plugins/mezuro/lib/kalibro/repository.rb b/plugins/mezuro/lib/kalibro/repository.rb index f2a5cd8..6e0581d 100644 --- a/plugins/mezuro/lib/kalibro/repository.rb +++ b/plugins/mezuro/lib/kalibro/repository.rb @@ -17,6 +17,18 @@ class Kalibro::Repository < Kalibro::Model response.map {|repository| new repository} end + def id=(value) + @id = value.to_i + end + + def process_period=(value) + @process_period = value.to_i + end + + def configuration_id=(value) + @configuration_id = value.to_i + end + def process self.class.request(:process_repository, {:repository_id => self.id}) end diff --git a/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb b/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb index b4dd198..1aae495 100644 --- a/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb +++ b/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb @@ -10,7 +10,7 @@ class MetricConfigurationSnapshotFixtures def self.metric_configuration_snapshot_hash { :code => "code", - :weight => "1", + :weight => "1.0", :aggregation_form => 'AVERAGE', :metric => MetricFixtures.amloc_hash, :base_tool_name => "Analizo", @@ -43,7 +43,7 @@ class MetricConfigurationSnapshotFixtures def self.compound_metric_configuration_snapshot_hash { :code => "code", - :weight => "1", + :weight => "1.0", :aggregation_form => 'AVERAGE', :metric => MetricFixtures.compound_metric, :base_tool_name => "Analizo", diff --git a/plugins/mezuro/test/fixtures/range_snapshot_fixtures.rb b/plugins/mezuro/test/fixtures/range_snapshot_fixtures.rb index bd6a75b..6e0c236 100644 --- a/plugins/mezuro/test/fixtures/range_snapshot_fixtures.rb +++ b/plugins/mezuro/test/fixtures/range_snapshot_fixtures.rb @@ -4,8 +4,16 @@ class RangeSnapshotFixtures Kalibro::RangeSnapshot.new range_snapshot_hash end + def self.range_snapshot_with_infinite_range + Kalibro::RangeSnapshot.new range_snapshot_with_infinite_range_hash + end + def self.range_snapshot_hash - { :end => "5", :label => "snapshot", :grade => "10", :color => "FF2284", :comments => "comment" } + { :beginning => "1.1", :end => "5.1", :label => "snapshot", :grade => "10.1", :color => "FF2284", :comments => "comment" } end + def self.range_snapshot_with_infinite_range_hash + { :beginning => "-INF", :end => "INF", :label => "snapshot", :grade => "10.1", :color => "FF2284", :comments => "comment" } + end + end diff --git a/plugins/mezuro/test/unit/kalibro/date_metric_result_test.rb b/plugins/mezuro/test/unit/kalibro/date_metric_result_test.rb index 5bd3413..18218c5 100644 --- a/plugins/mezuro/test/unit/kalibro/date_metric_result_test.rb +++ b/plugins/mezuro/test/unit/kalibro/date_metric_result_test.rb @@ -10,7 +10,7 @@ class DateMetricResultTest < ActiveSupport::TestCase end should 'create date_metric_result from hash' do - assert_equal @hash[:metric_result][:id], Kalibro::DateMetricResult.new(@hash).metric_result.id + assert_equal @hash[:metric_result][:id].to_i, Kalibro::DateMetricResult.new(@hash).metric_result.id end should 'convert date_metric_result to hash' do diff --git a/plugins/mezuro/test/unit/kalibro/date_module_result_test.rb b/plugins/mezuro/test/unit/kalibro/date_module_result_test.rb index e409fff..97a482c 100644 --- a/plugins/mezuro/test/unit/kalibro/date_module_result_test.rb +++ b/plugins/mezuro/test/unit/kalibro/date_module_result_test.rb @@ -10,7 +10,7 @@ class DateModuleResultTest < ActiveSupport::TestCase end should 'create date_module_result from hash' do - assert_equal @hash[:module_result][:id], Kalibro::DateModuleResult.new(@hash).module_result.id + assert_equal @hash[:module_result][:id].to_i, Kalibro::DateModuleResult.new(@hash).module_result.id end should 'convert date_module_result to hash' do diff --git a/plugins/mezuro/test/unit/kalibro/metric_configuration_snapshot_test.rb b/plugins/mezuro/test/unit/kalibro/metric_configuration_snapshot_test.rb index acab488..a8f1018 100644 --- a/plugins/mezuro/test/unit/kalibro/metric_configuration_snapshot_test.rb +++ b/plugins/mezuro/test/unit/kalibro/metric_configuration_snapshot_test.rb @@ -13,7 +13,7 @@ class MetricConfigurationSnapshotTest < ActiveSupport::TestCase should 'create and convert metric configuration snapshot from hash' do assert_equal @hash[:code], Kalibro::MetricConfigurationSnapshot.new(@hash).code - assert_equal @hash, @metric_configuration_snapshot.to_hash + assert_equal @hash[:weight].to_f, @metric_configuration_snapshot.weight end should 'create and convert metric configuration snapshot from hash with 2 elements' do diff --git a/plugins/mezuro/test/unit/kalibro/metric_result_test.rb b/plugins/mezuro/test/unit/kalibro/metric_result_test.rb index 5b610b1..dc2b6bf 100644 --- a/plugins/mezuro/test/unit/kalibro/metric_result_test.rb +++ b/plugins/mezuro/test/unit/kalibro/metric_result_test.rb @@ -12,7 +12,10 @@ class MetricResultTest < ActiveSupport::TestCase end should 'create metric result from hash' do - assert_equal @native_hash[:configuration][:code], Kalibro::MetricResult.new(@native_hash).configuration.code + metric_result = Kalibro::MetricResult.new(@native_hash) + assert_equal @native_hash[:configuration][:code], metric_result.configuration.code + assert_equal @native_hash[:id].to_i, metric_result.id + assert_equal @native_hash[:value].to_f, metric_result.value end should 'convert metric result to hash' do @@ -28,13 +31,13 @@ class MetricResultTest < ActiveSupport::TestCase should 'return metric results of a module result' do id = 31 Kalibro::MetricResult.expects(:request).with(:metric_results_of, {:module_result_id => id}).returns(:metric_result => [@native_hash, @compound_hash]) - assert_equal @native_hash[:id], Kalibro::MetricResult.metric_results_of(id).first.id + assert_equal @native_hash[:id].to_i, Kalibro::MetricResult.metric_results_of(id).first.id end should 'return history of a metric with a module result id' do module_result_id = 31 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}) - 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 + 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 end end diff --git a/plugins/mezuro/test/unit/kalibro/module_result_test.rb b/plugins/mezuro/test/unit/kalibro/module_result_test.rb index a389b01..6d91a58 100644 --- a/plugins/mezuro/test/unit/kalibro/module_result_test.rb +++ b/plugins/mezuro/test/unit/kalibro/module_result_test.rb @@ -11,7 +11,10 @@ class ModuleResultTest < ActiveSupport::TestCase end should 'create module result' do - assert_equal @hash[:id] , Kalibro::ModuleResult.new(@hash).id + module_result = Kalibro::ModuleResult.new(@hash) + assert_equal @hash[:id].to_i , module_result.id + assert_equal @hash[:grade].to_f , module_result.grade + assert_equal @hash[:parent_id].to_i , module_result.parent_id end should 'convert module result to hash' do @@ -41,7 +44,7 @@ class ModuleResultTest < ActiveSupport::TestCase should 'return history of a module result' do Kalibro::ModuleResult.expects(:request).with(:history_of_module, {:module_result_id => @module_result.id}).returns({:date_module_result => [DateModuleResultFixtures.date_module_result_hash]}) - assert_equal DateModuleResultFixtures.date_module_result_hash[:module_result][:id], Kalibro::ModuleResult.history_of(@module_result.id).first.module_result.id + assert_equal DateModuleResultFixtures.date_module_result_hash[:module_result][:id].to_i, Kalibro::ModuleResult.history_of(@module_result.id).first.module_result.id end end diff --git a/plugins/mezuro/test/unit/kalibro/process_time_test.rb b/plugins/mezuro/test/unit/kalibro/process_time_test.rb index 9d4aa6c..449e425 100644 --- a/plugins/mezuro/test/unit/kalibro/process_time_test.rb +++ b/plugins/mezuro/test/unit/kalibro/process_time_test.rb @@ -11,6 +11,7 @@ class ProcessTimeTest < ActiveSupport::TestCase should 'create process time from hash' do assert_equal @hash[:state], Kalibro::ProcessTime.new(@hash).state + assert_equal @hash[:time].to_i, Kalibro::ProcessTime.new(@hash).time end should 'convert process time to hash' do diff --git a/plugins/mezuro/test/unit/kalibro/processing_test.rb b/plugins/mezuro/test/unit/kalibro/processing_test.rb index ac36253..22b63a3 100644 --- a/plugins/mezuro/test/unit/kalibro/processing_test.rb +++ b/plugins/mezuro/test/unit/kalibro/processing_test.rb @@ -11,8 +11,10 @@ class ProcessingTest < ActiveSupport::TestCase end should 'create processing from hash' do - assert_equal @hash[:results_root_id], Kalibro::Processing.new(@hash).results_root_id - assert_equal @hash[:process_time].first[:state], Kalibro::Processing.new(@hash).process_times.first.state + processing = Kalibro::Processing.new(@hash) + assert_equal @hash[:results_root_id].to_i, processing.results_root_id + assert_equal @hash[:process_time].first[:state], processing.process_times.first.state + assert_equal @hash[:id].to_i, processing.id end should 'convert processing to hash' do diff --git a/plugins/mezuro/test/unit/kalibro/project_test.rb b/plugins/mezuro/test/unit/kalibro/project_test.rb index 7f5bf1a..0e24abf 100644 --- a/plugins/mezuro/test/unit/kalibro/project_test.rb +++ b/plugins/mezuro/test/unit/kalibro/project_test.rb @@ -13,6 +13,7 @@ class ProjectTest < ActiveSupport::TestCase should 'initialize new project from hash' do project = Kalibro::Project.new @hash assert_equal @hash[:name], project.name + assert_equal @hash[:id].to_i, project.id end should 'convert project to hash' do diff --git a/plugins/mezuro/test/unit/kalibro/range_snapshot_test.rb b/plugins/mezuro/test/unit/kalibro/range_snapshot_test.rb index 09c3ebb..2b9a42d 100644 --- a/plugins/mezuro/test/unit/kalibro/range_snapshot_test.rb +++ b/plugins/mezuro/test/unit/kalibro/range_snapshot_test.rb @@ -6,11 +6,23 @@ class RangeSnapshotTest < ActiveSupport::TestCase def setup @hash = RangeSnapshotFixtures.range_snapshot_hash + @range_snapshot_with_infinite_range_hash = RangeSnapshotFixtures.range_snapshot_with_infinite_range_hash @range_snapshot = RangeSnapshotFixtures.range_snapshot + @range_snapshot_with_infinite_range = RangeSnapshotFixtures.range_snapshot_with_infinite_range end should 'create range_snapshot from hash' do - assert_equal @hash[:comments], Kalibro::RangeSnapshot.new(@hash).comments + range_snapshot = Kalibro::RangeSnapshot.new(@hash) + assert_equal @hash[:comments], range_snapshot.comments + assert_equal @hash[:beginning].to_f, range_snapshot.beginning + assert_equal @hash[:end].to_f, range_snapshot.end + assert_equal @hash[:grade].to_f, range_snapshot.grade + end + + should 'create range_snapshot from hash with infinity values' do + range_snapshot = Kalibro::RangeSnapshot.new(@range_snapshot_with_infinite_range_hash) + assert_equal -1.0/0, range_snapshot.beginning + assert_equal 1.0/0, range_snapshot.end end should 'convert range_snapshot to hash' do diff --git a/plugins/mezuro/test/unit/kalibro/repository_test.rb b/plugins/mezuro/test/unit/kalibro/repository_test.rb index 9d2c7ad..8e28dd2 100644 --- a/plugins/mezuro/test/unit/kalibro/repository_test.rb +++ b/plugins/mezuro/test/unit/kalibro/repository_test.rb @@ -11,7 +11,11 @@ class RepositoryTest < ActiveSupport::TestCase end should 'new repository from hash' do - assert_equal @repository.type, Kalibro::Repository.new(@hash).type + repository = Kalibro::Repository.new(@hash) + assert_equal @hash[:type], repository.type + assert_equal @hash[:id].to_i, repository.id + assert_equal @hash[:process_period].to_i, repository.process_period + assert_equal @hash[:configuration_id].to_i, repository.configuration_id end should 'convert repository to hash' do -- libgit2 0.21.2