Commit 4c408ea484ac7498b6e8a2183d8c24d231a66ecb
Committed by
Paulo Meireles
1 parent
4901ee90
Exists in
master
and in
29 other branches
[Mezuro] Refactored metric_configuration entity and client to metric_configuration model
Showing
9 changed files
with
208 additions
and
139 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb
... | ... | @@ -26,13 +26,13 @@ class MezuroPluginMyprofileController < ProfileController |
26 | 26 | |
27 | 27 | def edit_metric_configuration |
28 | 28 | @configuration_content = profile.articles.find(params[:id]) |
29 | - @metric_configuration = Kalibro::Client::MetricConfigurationClient.metric_configuration(@configuration_content.name, params[:metric_name]) | |
29 | + @metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_name(@configuration_content.name, params[:metric_name]) | |
30 | 30 | @metric = @metric_configuration.metric |
31 | 31 | end |
32 | 32 | |
33 | 33 | def edit_compound_metric_configuration |
34 | 34 | @configuration_content = profile.articles.find(params[:id]) |
35 | - @metric_configuration = Kalibro::Client::MetricConfigurationClient.metric_configuration(@configuration_content.name, params[:metric_name]) | |
35 | + @metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_name(@configuration_content.name, params[:metric_name]) | |
36 | 36 | @metric_configurations = @configuration_content.metric_configurations |
37 | 37 | @metric = @metric_configuration.metric |
38 | 38 | end |
... | ... | @@ -51,13 +51,13 @@ class MezuroPluginMyprofileController < ProfileController |
51 | 51 | |
52 | 52 | def update_metric_configuration |
53 | 53 | @configuration_content = profile.articles.find(params[:id]) |
54 | - auxiliar_update_metric_configuration(Kalibro::Entities::MetricConfiguration::NATIVE_TYPE) | |
54 | + auxiliar_update_metric_configuration(Kalibro::MetricConfiguration::NATIVE_TYPE) | |
55 | 55 | redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" |
56 | 56 | end |
57 | 57 | |
58 | 58 | def update_compound_metric_configuration |
59 | 59 | @configuration_content = profile.articles.find(params[:id]) |
60 | - auxiliar_update_metric_configuration(Kalibro::Entities::MetricConfiguration::COMPOUND_TYPE) | |
60 | + auxiliar_update_metric_configuration(Kalibro::MetricConfiguration::COMPOUND_TYPE) | |
61 | 61 | redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" |
62 | 62 | end |
63 | 63 | |
... | ... | @@ -71,41 +71,39 @@ class MezuroPluginMyprofileController < ProfileController |
71 | 71 | @metric_name = params[:metric_name] |
72 | 72 | @beginning_id = params[:beginning_id] |
73 | 73 | |
74 | - metric_configuration = Kalibro::Client::MetricConfigurationClient.metric_configuration(@configuration_content.name, @metric_name) | |
74 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_name(@configuration_content.name, @metric_name) | |
75 | 75 | @range = metric_configuration.ranges.find{ |range| range.beginning == @beginning_id.to_f } |
76 | 76 | end |
77 | 77 | |
78 | 78 | def create_range |
79 | 79 | @configuration_content = profile.articles.find(params[:id]) |
80 | - @range = new_range_instance | |
80 | + @range = Kalibro::Range.new params[:range] | |
81 | 81 | metric_name = params[:metric_name] |
82 | 82 | beginning_id = params[:beginning_id] |
83 | - | |
84 | - metric_configuration = Kalibro::Client::MetricConfigurationClient.metric_configuration(@configuration_content.name, metric_name) | |
83 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_name(@configuration_content.name, metric_name) | |
85 | 84 | metric_configuration.add_range(@range) |
86 | - Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, @configuration_content.name) | |
85 | + metric_configuration.save | |
87 | 86 | end |
88 | 87 | |
89 | 88 | def update_range |
90 | 89 | configuration_content = profile.articles.find(params[:id]) |
91 | 90 | metric_name = params[:metric_name] |
92 | 91 | beginning_id = params[:beginning_id] |
93 | - metric_configuration = Kalibro::Client::MetricConfigurationClient.metric_configuration(configuration_content.name, metric_name) | |
92 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_name(configuration_content.name, metric_name) | |
94 | 93 | index = metric_configuration.ranges.index{ |range| range.beginning == beginning_id.to_f } |
95 | - metric_configuration.ranges[index] = new_range_instance | |
96 | - Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, configuration_content.name) | |
94 | + metric_configuration.ranges[index] = Kalibro::Range.new params[:range] | |
95 | + metric_configuration.save | |
97 | 96 | end |
98 | 97 | |
99 | 98 | def remove_range |
100 | 99 | configuration_content = profile.articles.find(params[:id]) |
101 | 100 | metric_name = params[:metric_name] |
102 | 101 | beginning_id = params[:range_beginning] |
103 | - | |
104 | - metric_configuration = Kalibro::Client::MetricConfigurationClient.metric_configuration(configuration_content.name, metric_name) | |
102 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_name(configuration_content.name, metric_name) | |
105 | 103 | metric_configuration.ranges.delete_if { |range| range.beginning == beginning_id.to_f }.inspect |
106 | - Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, configuration_name) | |
104 | + metric_configuration.save | |
107 | 105 | formatted_metric_name = metric_name.gsub(/\s/, '+') |
108 | - if metric_configuration.metric.class == Kalibro::Entities::CompoundMetric | |
106 | + if metric_configuration.metric.class == Kalibro::CompoundMetric | |
109 | 107 | redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}" |
110 | 108 | else |
111 | 109 | redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}" |
... | ... | @@ -115,25 +113,26 @@ class MezuroPluginMyprofileController < ProfileController |
115 | 113 | def remove_metric_configuration |
116 | 114 | configuration_content = profile.articles.find(params[:id]) |
117 | 115 | metric_name = params[:metric_name] |
118 | - Kalibro::Client::MetricConfigurationClient.new.remove(configuration_content.name, metric_name) | |
116 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_name(configuration_content.name, metric_name) | |
117 | + metric_configuration.destroy | |
119 | 118 | redirect_to "/#{profile.identifier}/#{configuration_content.slug}" |
120 | 119 | end |
121 | 120 | |
122 | 121 | private |
123 | 122 | |
124 | 123 | def new_metric_configuration_instance |
125 | - metric_configuration = Kalibro::Entities::MetricConfiguration.new | |
124 | + metric_configuration = Kalibro::MetricConfiguration.new | |
126 | 125 | metric_configuration.metric = Kalibro::NativeMetric.new |
127 | - assign_metric_configuration_instance(metric_configuration, Kalibro::Entities::MetricConfiguration::NATIVE_TYPE) | |
126 | + assign_metric_configuration_instance(metric_configuration, Kalibro::MetricConfiguration::NATIVE_TYPE) | |
128 | 127 | end |
129 | 128 | |
130 | 129 | def new_compound_metric_configuration_instance |
131 | - metric_configuration = Kalibro::Entities::MetricConfiguration.new | |
132 | - metric_configuration.metric = Kalibro::Entities::CompoundMetric.new | |
133 | - assign_metric_configuration_instance(metric_configuration, Kalibro::Entities::MetricConfiguration::COMPOUND_TYPE) | |
130 | + metric_configuration = Kalibro::MetricConfiguration.new | |
131 | + metric_configuration.metric = Kalibro::CompoundMetric.new | |
132 | + assign_metric_configuration_instance(metric_configuration, Kalibro::MetricConfiguration::COMPOUND_TYPE) | |
134 | 133 | end |
135 | 134 | |
136 | - def assign_metric_configuration_instance(metric_configuration, type=Kalibro::Entities::MetricConfiguration::NATIVE_TYPE) | |
135 | + def assign_metric_configuration_instance(metric_configuration, type=Kalibro::MetricConfiguration::NATIVE_TYPE) | |
137 | 136 | metric_configuration.metric.name = params[:metric_configuration][:metric][:name] |
138 | 137 | metric_configuration.metric.description = params[:metric_configuration][:metric][:description] |
139 | 138 | metric_configuration.metric.scope = params[:metric_configuration][:metric][:scope] |
... | ... | @@ -141,36 +140,25 @@ class MezuroPluginMyprofileController < ProfileController |
141 | 140 | metric_configuration.weight = params[:metric_configuration][:weight] |
142 | 141 | metric_configuration.aggregation_form = params[:metric_configuration][:aggregation_form] |
143 | 142 | |
144 | - if type == Kalibro::Entities::MetricConfiguration::NATIVE_TYPE | |
143 | + if type == Kalibro::MetricConfiguration::NATIVE_TYPE | |
145 | 144 | metric_configuration.metric.origin = params[:metric_configuration][:metric][:origin] |
146 | 145 | metric_configuration.metric.language = params[:metric_configuration][:metric][:language] |
147 | - elsif type == Kalibro::Entities::MetricConfiguration::COMPOUND_TYPE | |
146 | + elsif type == Kalibro::MetricConfiguration::COMPOUND_TYPE | |
148 | 147 | metric_configuration.metric.script = params[:metric_configuration][:metric][:script] |
149 | 148 | end |
150 | 149 | metric_configuration |
151 | 150 | end |
152 | 151 | |
153 | 152 | def generic_metric_configuration_creation(metric_configuration, configuration_name) |
154 | - Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, configuration_name) | |
153 | + metric_configuration.save | |
155 | 154 | metric_configuration.metric.name |
156 | 155 | end |
157 | 156 | |
158 | 157 | def auxiliar_update_metric_configuration(type) |
159 | 158 | metric_name = params[:metric_configuration][:metric][:name] |
160 | - metric_configuration = Kalibro::Client::MetricConfigurationClient.metric_configuration(@configuration_content.name, metric_name) | |
159 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_name(@configuration_content.name, metric_name) | |
161 | 160 | metric_configuration = assign_metric_configuration_instance(metric_configuration, type) |
162 | - Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, @configuration_content.name) | |
163 | - end | |
164 | - | |
165 | - def new_range_instance | |
166 | - range = Kalibro::Entities::Range.new | |
167 | - range.beginning = params[:range][:beginning] | |
168 | - range.end = params[:range][:end] | |
169 | - range.label = params[:range][:label] | |
170 | - range.grade = params[:range][:grade] | |
171 | - range.color = params[:range][:color] | |
172 | - range.comments = params[:range][:comments] | |
173 | - range | |
161 | + metric_configuration.save | |
174 | 162 | end |
175 | 163 | |
176 | 164 | end | ... | ... |
plugins/mezuro/lib/kalibro/client/metric_configuration_client.rb
... | ... | @@ -1,32 +0,0 @@ |
1 | -class Kalibro::Client::MetricConfigurationClient | |
2 | - | |
3 | - def self.metric_configuration(configuration_name, metric_name) | |
4 | - new.metric_configuration(configuration_name, metric_name) | |
5 | - end | |
6 | - | |
7 | - def initialize | |
8 | - @port = Kalibro::Client::Port.new('MetricConfiguration') | |
9 | - end | |
10 | - | |
11 | - def save(metric_configuration, configuration_name) | |
12 | - @port.request(:save_metric_configuration, { | |
13 | - :metric_configuration => metric_configuration.to_hash, | |
14 | - :configuration_name => configuration_name}) | |
15 | - end | |
16 | - | |
17 | - def metric_configuration(configuration_name, metric_name) | |
18 | - hash = @port.request(:get_metric_configuration, { | |
19 | - :configuration_name => configuration_name, | |
20 | - :metric_name => metric_name | |
21 | - })[:metric_configuration] | |
22 | - Kalibro::Entities::MetricConfiguration.from_hash(hash) | |
23 | - end | |
24 | - | |
25 | - def remove (configuration_name, metric_name) | |
26 | - @port.request(:remove_metric_configuration, { | |
27 | - :configuration_name => configuration_name, | |
28 | - :metric_name=> metric_name | |
29 | - }) | |
30 | - end | |
31 | - | |
32 | -end |
plugins/mezuro/lib/kalibro/entities/metric_configuration.rb
... | ... | @@ -1,38 +0,0 @@ |
1 | -class Kalibro::Entities::MetricConfiguration < Kalibro::Entities::Entity | |
2 | - | |
3 | - NATIVE_TYPE='native' | |
4 | - COMPOUND_TYPE='compound' | |
5 | - | |
6 | - attr_accessor :metric, :code, :weight, :aggregation_form, :range | |
7 | - | |
8 | - def metric=(value) | |
9 | - if value.kind_of?(Hash) | |
10 | - @metric = to_entity(value, Kalibro::Entities::CompoundMetric) if value.has_key?(:script) | |
11 | - @metric = to_entity(value, Kalibro::Entities::NativeMetric) if value.has_key?(:origin) | |
12 | - else | |
13 | - @metric = value | |
14 | - end | |
15 | - end | |
16 | - | |
17 | - def weight=(value) | |
18 | - @weight = value.to_f | |
19 | - end | |
20 | - | |
21 | - def range=(value) | |
22 | - @range = to_entity_array(value, Kalibro::Entities::Range) | |
23 | - end | |
24 | - | |
25 | - def add_range(new_range) | |
26 | - @range = [] if @range.nil? | |
27 | - @range << new_range | |
28 | - end | |
29 | - | |
30 | - def ranges | |
31 | - @range | |
32 | - end | |
33 | - | |
34 | - def ranges=(ranges) | |
35 | - @range = ranges | |
36 | - end | |
37 | - | |
38 | -end |
... | ... | @@ -0,0 +1,82 @@ |
1 | +class Kalibro::MetricConfiguration < Kalibro::Model | |
2 | + | |
3 | + NATIVE_TYPE='native' | |
4 | + COMPOUND_TYPE='compound' | |
5 | + | |
6 | + attr_accessor :metric, :code, :weight, :aggregation_form, :range, :configuration_name | |
7 | + | |
8 | + def metric=(value) | |
9 | + if value.kind_of?(Hash) | |
10 | + @metric = to_object(value, Kalibro::CompoundMetric) if value.has_key?(:script) | |
11 | + @metric = to_object(value, Kalibro::NativeMetric) if value.has_key?(:origin) | |
12 | + else | |
13 | + @metric = value | |
14 | + end | |
15 | + end | |
16 | + | |
17 | + def weight=(value) | |
18 | + @weight = value.to_f | |
19 | + end | |
20 | + | |
21 | + def range=(value) | |
22 | + @range = to_objects_array(value, Kalibro::Range) | |
23 | + end | |
24 | + | |
25 | + def add_range(new_range) | |
26 | + @range = [] if @range.nil? | |
27 | + @range << new_range | |
28 | + end | |
29 | + | |
30 | + def ranges | |
31 | + @range | |
32 | + end | |
33 | + | |
34 | + def ranges=(ranges) | |
35 | + @range = ranges | |
36 | + end | |
37 | + | |
38 | + def self.find_by_configuration_and_metric(configuration_name, metric_name) | |
39 | + metric_configuration = new request("MetricConfiguration", :get_metric_configuration, { | |
40 | + :configuration_name => configuration_name, | |
41 | + :metric_name => metric_name | |
42 | + })[:metric_configuration] | |
43 | + metric_configuration.configuration_name = configuration_name | |
44 | + metric_configuration | |
45 | + end | |
46 | + | |
47 | + def save | |
48 | + begin | |
49 | + self.class.request("MetricConfiguration", :save_metric_configuration, { | |
50 | + :metric_configuration => to_hash, | |
51 | + :configuration_name => configuration_name}) | |
52 | + true | |
53 | + rescue | |
54 | + false | |
55 | + end | |
56 | + end | |
57 | + | |
58 | + def destroy | |
59 | + self.class.request("MetricConfiguration", :remove_metric_configuration, { | |
60 | + :configuration_name => configuration_name, | |
61 | + :metric_name=> metric.name | |
62 | + }) | |
63 | + end | |
64 | + | |
65 | + def to_hash | |
66 | + hash = Hash.new | |
67 | + fields.each do |field| | |
68 | + if !(field == :configuration_name) | |
69 | + field_value = send(field) | |
70 | + hash[field] = convert_to_hash(field_value) | |
71 | + if field_value.is_a?(Kalibro::Model) | |
72 | + hash = {:attributes! => {}}.merge(hash) | |
73 | + hash[:attributes!][field.to_sym] = { | |
74 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
75 | + 'xsi:type' => 'kalibro:' + xml_class_name(field_value) } | |
76 | + end | |
77 | + end | |
78 | + end | |
79 | + hash | |
80 | + end | |
81 | + | |
82 | +end | ... | ... |
plugins/mezuro/lib/kalibro/model.rb
1 | 1 | class Kalibro::Model |
2 | 2 | |
3 | 3 | def initialize(attributes={}) |
4 | - attributes.each { |field, value| send("#{field}=", value) } | |
4 | + attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) } | |
5 | 5 | end |
6 | 6 | |
7 | 7 | def to_hash |
... | ... | @@ -51,6 +51,10 @@ class Kalibro::Model |
51 | 51 | response.to_hash["#{action}_response".to_sym] |
52 | 52 | end |
53 | 53 | |
54 | + def self.is_valid?(field) | |
55 | + field.to_s[0] != '@' and field != :attributes! | |
56 | + end | |
57 | + | |
54 | 58 | def to_objects_array(value, model_class = nil) |
55 | 59 | array = value.kind_of?(Array) ? value : [value] |
56 | 60 | array.each.collect { |element| to_object(element, model_class) } | ... | ... |
plugins/mezuro/lib/kalibro/project.rb
... | ... | @@ -15,10 +15,6 @@ class Kalibro::Project < Kalibro::Model |
15 | 15 | end |
16 | 16 | end |
17 | 17 | |
18 | - def self.destroy(project_name) | |
19 | - request("Project", :remove_project, {:project_name => project_name}) | |
20 | - end | |
21 | - | |
22 | 18 | def self.create (content) |
23 | 19 | new({ |
24 | 20 | :name => content.name, |
... | ... | @@ -32,6 +28,10 @@ class Kalibro::Project < Kalibro::Model |
32 | 28 | }) |
33 | 29 | end |
34 | 30 | |
31 | + def destroy | |
32 | + self.class.request("Project", :remove_project, {:project_name => name}) | |
33 | + end | |
34 | + | |
35 | 35 | def save |
36 | 36 | begin |
37 | 37 | self.class.request("Project", :save_project, {:project => to_hash}) |
... | ... | @@ -46,4 +46,3 @@ class Kalibro::Project < Kalibro::Model |
46 | 46 | end |
47 | 47 | |
48 | 48 | end |
49 | - | ... | ... |
plugins/mezuro/test/fixtures/metric_configuration_fixtures.rb
... | ... | @@ -4,45 +4,41 @@ require File.dirname(__FILE__) + '/range_fixtures' |
4 | 4 | |
5 | 5 | class MetricConfigurationFixtures |
6 | 6 | |
7 | - def self.amloc_configuration | |
8 | - amloc = Kalibro::Entities::MetricConfiguration.new | |
9 | - amloc.metric = NativeMetricFixtures.amloc | |
10 | - amloc.code = 'amloc' | |
11 | - amloc.weight = 1.0 | |
12 | - amloc.aggregation_form = 'AVERAGE' | |
13 | - amloc.ranges = [RangeFixtures.amloc_excellent, RangeFixtures.amloc_bad] | |
7 | + def self.amloc_metric_configuration | |
8 | + amloc = Kalibro::MetricConfiguration.new amloc_metric_configuration_hash | |
9 | + amloc.configuration_name = "Sample Configuration" | |
14 | 10 | amloc |
15 | 11 | end |
16 | 12 | |
17 | 13 | def self.metric_configuration_without_ranges |
18 | - amloc = Kalibro::Entities::MetricConfiguration.new | |
19 | - amloc.metric = NativeMetricFixtures.amloc | |
20 | - amloc.code = 'amloc' | |
21 | - amloc.weight = 1.0 | |
22 | - amloc.aggregation_form = 'AVERAGE' | |
14 | + amloc = Kalibro::MetricConfiguration.new | |
15 | + { | |
16 | + :metric => NativeMetricFixtures.amloc_hash, | |
17 | + :code => 'amloc', | |
18 | + :weight => 1.0, | |
19 | + :aggregation_form => 'AVERAGE' | |
20 | + } | |
21 | + amloc.configuration_name = "Sample Configuration" | |
23 | 22 | amloc |
24 | 23 | end |
25 | 24 | |
26 | - def self.sc_configuration | |
27 | - sc = Kalibro::Entities::MetricConfiguration.new | |
28 | - sc.metric = CompoundMetricFixtures.sc | |
29 | - sc.code = 'sc' | |
30 | - sc.weight = 1.0 | |
31 | - sc.aggregation_form = 'AVERAGE' | |
25 | + def self.sc_metric_configuration | |
26 | + sc = Kalibro::MetricConfiguration.new sc_metric_configuration_hash | |
27 | + sc.configuration_name = "Sample Configuration" | |
32 | 28 | sc |
33 | 29 | end |
34 | 30 | |
35 | - def self.amloc_configuration_hash | |
31 | + def self.amloc_metric_configuration_hash | |
36 | 32 | {:metric => NativeMetricFixtures.amloc_hash, :code => 'amloc', :weight => 1.0, |
37 | 33 | :aggregation_form => 'AVERAGE', |
38 | - :range => [RangeFixtures.amloc_excellent_hash, RangeFixtures.amloc_bad_hash], | |
34 | + :range => [RangeFixtures.range_excellent_hash, RangeFixtures.range_bad_hash], | |
39 | 35 | :attributes! => {:metric => { |
40 | 36 | 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', |
41 | 37 | 'xsi:type' => 'kalibro:nativeMetricXml' }}} |
42 | 38 | end |
43 | 39 | |
44 | - def self.sc_configuration_hash | |
45 | - {:metric => CompoundMetricFixtures.sc_hash, :code => 'sc', :weight => 1.0, :aggregation_form => 'AVERAGE', | |
40 | + def self.sc_metric_configuration_hash | |
41 | + {:metric => CompoundMetricFixtures.compound_metric_hash, :code => 'sc', :weight => 1.0, :aggregation_form => 'AVERAGE', | |
46 | 42 | :attributes! => {:metric => { |
47 | 43 | 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', |
48 | 44 | 'xsi:type' => 'kalibro:compoundMetricXml' }}} | ... | ... |
plugins/mezuro/test/unit/kalibro/metric_configuration_test.rb
0 → 100644
... | ... | @@ -0,0 +1,70 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures" | |
4 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures" | |
5 | + | |
6 | +class MetricConfigurationTest < ActiveSupport::TestCase | |
7 | + | |
8 | + def setup | |
9 | + @hash = MetricConfigurationFixtures.amloc_metric_configuration_hash | |
10 | + @metric_configuration1 = MetricConfigurationFixtures.amloc_metric_configuration | |
11 | + @metric_configuration2 = MetricConfigurationFixtures.sc_metric_configuration | |
12 | + @metric_configuration_without_ranges = MetricConfigurationFixtures.metric_configuration_without_ranges | |
13 | + @range1 = RangeFixtures.range_excellent | |
14 | + @range2 = RangeFixtures.range_bad | |
15 | + end | |
16 | + | |
17 | + should 'create metric configuration from hash' do | |
18 | + assert_equal @hash[:code], Kalibro::MetricConfiguration.new(@hash).code | |
19 | + end | |
20 | + | |
21 | + should 'convert metric configuration to hash' do | |
22 | + assert_equal @hash, @metric_configuration1.to_hash | |
23 | + end | |
24 | + | |
25 | + should 'create appropriate metric type' do | |
26 | + assert @metric_configuration1.metric.instance_of?(Kalibro::NativeMetric) | |
27 | + assert @metric_configuration2.metric.instance_of?(Kalibro::CompoundMetric) | |
28 | + end | |
29 | + | |
30 | + should 'add a range to an empty range list' do | |
31 | + @metric_configuration_without_ranges.add_range @range1 | |
32 | + assert_equal @metric_configuration_without_ranges.ranges, [@range1] | |
33 | + end | |
34 | + | |
35 | + should 'add a range to an non-empty range list' do | |
36 | + @metric_configuration_without_ranges.ranges = [@range1] | |
37 | + @metric_configuration_without_ranges.add_range @range2 | |
38 | + assert_equal @metric_configuration_without_ranges.ranges, [@range1, @range2] | |
39 | + end | |
40 | + | |
41 | + should 'save metric configuration' do | |
42 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
43 | + :metric_configuration => @metric_configuration1.to_hash, | |
44 | + :configuration_name => @metric_configuration1.configuration_name | |
45 | + }) | |
46 | + @metric_configuration1.save | |
47 | + end | |
48 | + | |
49 | + should 'get metric configuration by name and configuration name' do | |
50 | + request_body = { | |
51 | + :configuration_name => @metric_configuration1.configuration_name, | |
52 | + :metric_name => @metric_configuration1.metric.name | |
53 | + } | |
54 | + response_hash = {:metric_configuration => @metric_configuration1.to_hash} | |
55 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, request_body).returns(response_hash) | |
56 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_metric(@metric_configuration1.configuration_name, | |
57 | + @metric_configuration1.metric.name) | |
58 | + assert_equal @metric_configuration1.code, metric_configuration.code | |
59 | + end | |
60 | + | |
61 | + should 'destroy metric configuration by name' do | |
62 | + request_body = { | |
63 | + :configuration_name => @metric_configuration1.configuration_name, | |
64 | + :metric_name => @metric_configuration1.metric.name | |
65 | + } | |
66 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :remove_metric_configuration, request_body) | |
67 | + @metric_configuration1.destroy | |
68 | + end | |
69 | + | |
70 | +end | ... | ... |
plugins/mezuro/test/unit/kalibro/project_test.rb
... | ... | @@ -42,12 +42,12 @@ class ProjectTest < ActiveSupport::TestCase |
42 | 42 | |
43 | 43 | should 'remove existent project from service' do |
44 | 44 | Kalibro::Project.expects(:request).with("Project", :remove_project, {:project_name => @project.name}) |
45 | - Kalibro::Project.destroy(@project.name) | |
45 | + @project.destroy | |
46 | 46 | end |
47 | 47 | |
48 | 48 | should 'raise error when try to remove inexistent project from service' do |
49 | 49 | Kalibro::Project.expects(:request).with("Project", :remove_project, {:project_name => @project.name}).raises(Exception.new) |
50 | - assert_raise Exception do Kalibro::Project.destroy(@project.name) end | |
50 | + assert_raise Exception do @project.destroy end | |
51 | 51 | end |
52 | 52 | |
53 | 53 | should 'initialize new project from hash' do | ... | ... |