Commit 0532543b96923dff9e6d0da15b652ea52d3d97d9
Committed by
Diego Camarinha
1 parent
df4312de
Exists in
master
and in
28 other branches
[Mezuro] Testing setters.
Showing
20 changed files
with
106 additions
and
16 deletions
Show diff stats
plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb
... | ... | @@ -2,6 +2,10 @@ class Kalibro::MetricConfigurationSnapshot < Kalibro::Model |
2 | 2 | |
3 | 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 | 9 | def metric=(value) |
6 | 10 | if value.kind_of?(Hash) |
7 | 11 | @metric = Kalibro::Metric.to_object(value) | ... | ... |
plugins/mezuro/lib/kalibro/metric_result.rb
... | ... | @@ -13,6 +13,10 @@ class Kalibro::MetricResult < Kalibro::Model |
13 | 13 | @errors = [] |
14 | 14 | end |
15 | 15 | |
16 | + def id=(value) | |
17 | + @id = value.to_i | |
18 | + end | |
19 | + | |
16 | 20 | def configuration=(value) |
17 | 21 | @configuration = Kalibro::MetricConfigurationSnapshot.to_object value |
18 | 22 | end |
... | ... | @@ -21,6 +25,10 @@ class Kalibro::MetricResult < Kalibro::Model |
21 | 25 | configuration |
22 | 26 | end |
23 | 27 | |
28 | + def value=(value) | |
29 | + @value = value.to_f | |
30 | + end | |
31 | + | |
24 | 32 | def error=(value) |
25 | 33 | @error = Kalibro::Throwable.to_object value |
26 | 34 | end | ... | ... |
plugins/mezuro/lib/kalibro/model.rb
plugins/mezuro/lib/kalibro/module_result.rb
... | ... | @@ -22,6 +22,10 @@ class Kalibro::ModuleResult < Kalibro::Model |
22 | 22 | end |
23 | 23 | end |
24 | 24 | |
25 | + def id=(value) | |
26 | + @id = value.to_i | |
27 | + end | |
28 | + | |
25 | 29 | def module=(value) |
26 | 30 | @module = Kalibro::Module.to_object value |
27 | 31 | end |
... | ... | @@ -30,6 +34,10 @@ class Kalibro::ModuleResult < Kalibro::Model |
30 | 34 | @grade = value.to_f |
31 | 35 | end |
32 | 36 | |
37 | + def parent_id=(value) | |
38 | + @parent_id = value.to_i | |
39 | + end | |
40 | + | |
33 | 41 | def self.history_of(module_result_id) |
34 | 42 | response = self.request(:history_of_module, {:module_result_id => module_result_id})[:date_module_result] |
35 | 43 | response = [] if response.nil? | ... | ... |
plugins/mezuro/lib/kalibro/processing.rb
1 | -#TODO arrumar esse modelo e seus testes de unidade | |
2 | 1 | class Kalibro::Processing < Kalibro::Model |
3 | 2 | |
4 | 3 | attr_accessor :id, :date, :state, :error, :process_time, :results_root_id |
... | ... | @@ -22,6 +21,10 @@ class Kalibro::Processing < Kalibro::Model |
22 | 21 | end |
23 | 22 | end |
24 | 23 | |
24 | + def id=(value) | |
25 | + @id = value.to_i | |
26 | + end | |
27 | + | |
25 | 28 | def date=(value) |
26 | 29 | @date = value.is_a?(String) ? DateTime.parse(value) : value |
27 | 30 | end |
... | ... | @@ -42,6 +45,10 @@ class Kalibro::Processing < Kalibro::Model |
42 | 45 | @error = Kalibro::Throwable.to_object value |
43 | 46 | end |
44 | 47 | |
48 | + def results_root_id=(value) | |
49 | + @results_root_id = value.to_i | |
50 | + end | |
51 | + | |
45 | 52 | private |
46 | 53 | |
47 | 54 | def self.has_processing(repository_id) | ... | ... |
plugins/mezuro/lib/kalibro/project.rb
plugins/mezuro/lib/kalibro/range_snapshot.rb
... | ... | @@ -2,4 +2,16 @@ class Kalibro::RangeSnapshot < Kalibro::Model |
2 | 2 | |
3 | 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 | 17 | end | ... | ... |
plugins/mezuro/lib/kalibro/repository.rb
... | ... | @@ -17,6 +17,18 @@ class Kalibro::Repository < Kalibro::Model |
17 | 17 | response.map {|repository| new repository} |
18 | 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 | 32 | def process |
21 | 33 | self.class.request(:process_repository, {:repository_id => self.id}) |
22 | 34 | end | ... | ... |
plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb
... | ... | @@ -10,7 +10,7 @@ class MetricConfigurationSnapshotFixtures |
10 | 10 | def self.metric_configuration_snapshot_hash |
11 | 11 | { |
12 | 12 | :code => "code", |
13 | - :weight => "1", | |
13 | + :weight => "1.0", | |
14 | 14 | :aggregation_form => 'AVERAGE', |
15 | 15 | :metric => MetricFixtures.amloc_hash, |
16 | 16 | :base_tool_name => "Analizo", |
... | ... | @@ -43,7 +43,7 @@ class MetricConfigurationSnapshotFixtures |
43 | 43 | def self.compound_metric_configuration_snapshot_hash |
44 | 44 | { |
45 | 45 | :code => "code", |
46 | - :weight => "1", | |
46 | + :weight => "1.0", | |
47 | 47 | :aggregation_form => 'AVERAGE', |
48 | 48 | :metric => MetricFixtures.compound_metric, |
49 | 49 | :base_tool_name => "Analizo", | ... | ... |
plugins/mezuro/test/fixtures/range_snapshot_fixtures.rb
... | ... | @@ -4,8 +4,16 @@ class RangeSnapshotFixtures |
4 | 4 | Kalibro::RangeSnapshot.new range_snapshot_hash |
5 | 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 | 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 | 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 | 19 | end | ... | ... |
plugins/mezuro/test/unit/kalibro/date_metric_result_test.rb
... | ... | @@ -10,7 +10,7 @@ class DateMetricResultTest < ActiveSupport::TestCase |
10 | 10 | end |
11 | 11 | |
12 | 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 | 14 | end |
15 | 15 | |
16 | 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 < ActiveSupport::TestCase |
10 | 10 | end |
11 | 11 | |
12 | 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 | 14 | end |
15 | 15 | |
16 | 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 < ActiveSupport::TestCase |
13 | 13 | |
14 | 14 | should 'create and convert metric configuration snapshot from hash' do |
15 | 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 | 17 | end |
18 | 18 | |
19 | 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 < ActiveSupport::TestCase |
12 | 12 | end |
13 | 13 | |
14 | 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 | 19 | end |
17 | 20 | |
18 | 21 | should 'convert metric result to hash' do |
... | ... | @@ -28,13 +31,13 @@ class MetricResultTest < ActiveSupport::TestCase |
28 | 31 | should 'return metric results of a module result' do |
29 | 32 | id = 31 |
30 | 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 | 35 | end |
33 | 36 | |
34 | 37 | should 'return history of a metric with a module result id' do |
35 | 38 | module_result_id = 31 |
36 | 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 | 41 | end |
39 | 42 | |
40 | 43 | end | ... | ... |
plugins/mezuro/test/unit/kalibro/module_result_test.rb
... | ... | @@ -11,7 +11,10 @@ class ModuleResultTest < ActiveSupport::TestCase |
11 | 11 | end |
12 | 12 | |
13 | 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 | 18 | end |
16 | 19 | |
17 | 20 | should 'convert module result to hash' do |
... | ... | @@ -41,7 +44,7 @@ class ModuleResultTest < ActiveSupport::TestCase |
41 | 44 | |
42 | 45 | should 'return history of a module result' do |
43 | 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 | 48 | end |
46 | 49 | |
47 | 50 | end | ... | ... |
plugins/mezuro/test/unit/kalibro/process_time_test.rb
... | ... | @@ -11,6 +11,7 @@ class ProcessTimeTest < ActiveSupport::TestCase |
11 | 11 | |
12 | 12 | should 'create process time from hash' do |
13 | 13 | assert_equal @hash[:state], Kalibro::ProcessTime.new(@hash).state |
14 | + assert_equal @hash[:time].to_i, Kalibro::ProcessTime.new(@hash).time | |
14 | 15 | end |
15 | 16 | |
16 | 17 | should 'convert process time to hash' do | ... | ... |
plugins/mezuro/test/unit/kalibro/processing_test.rb
... | ... | @@ -11,8 +11,10 @@ class ProcessingTest < ActiveSupport::TestCase |
11 | 11 | end |
12 | 12 | |
13 | 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 | 18 | end |
17 | 19 | |
18 | 20 | should 'convert processing to hash' do | ... | ... |
plugins/mezuro/test/unit/kalibro/project_test.rb
... | ... | @@ -13,6 +13,7 @@ class ProjectTest < ActiveSupport::TestCase |
13 | 13 | should 'initialize new project from hash' do |
14 | 14 | project = Kalibro::Project.new @hash |
15 | 15 | assert_equal @hash[:name], project.name |
16 | + assert_equal @hash[:id].to_i, project.id | |
16 | 17 | end |
17 | 18 | |
18 | 19 | should 'convert project to hash' do | ... | ... |
plugins/mezuro/test/unit/kalibro/range_snapshot_test.rb
... | ... | @@ -6,11 +6,23 @@ class RangeSnapshotTest < ActiveSupport::TestCase |
6 | 6 | |
7 | 7 | def setup |
8 | 8 | @hash = RangeSnapshotFixtures.range_snapshot_hash |
9 | + @range_snapshot_with_infinite_range_hash = RangeSnapshotFixtures.range_snapshot_with_infinite_range_hash | |
9 | 10 | @range_snapshot = RangeSnapshotFixtures.range_snapshot |
11 | + @range_snapshot_with_infinite_range = RangeSnapshotFixtures.range_snapshot_with_infinite_range | |
10 | 12 | end |
11 | 13 | |
12 | 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 | 26 | end |
15 | 27 | |
16 | 28 | should 'convert range_snapshot to hash' do | ... | ... |
plugins/mezuro/test/unit/kalibro/repository_test.rb
... | ... | @@ -11,7 +11,11 @@ class RepositoryTest < ActiveSupport::TestCase |
11 | 11 | end |
12 | 12 | |
13 | 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 | 19 | end |
16 | 20 | |
17 | 21 | should 'convert repository to hash' do | ... | ... |