Commit 3beab8f4035fa0c81b3732400b973cdaa10c462b

Authored by João M. M. da Silva + Diego Araújo
Committed by João M. M. da Silva
1 parent 1be21814

[Mezuro] refactores model on call to "request" method, doesn't need to

pass endpoint anymore.
Showing 31 changed files with 147 additions and 399 deletions   Show diff stats
plugins/mezuro/lib/kalibro/base_tool.rb
... ... @@ -3,11 +3,11 @@ class Kalibro::BaseTool < Kalibro::Model
3 3 attr_accessor :name, :description, :collector_class_name, :supported_metric
4 4  
5 5 def self.all_names
6   - request("BaseTool", :all_base_tool_names)[:base_tool_name].to_a
  6 + request(:all_base_tool_names)[:base_tool_name].to_a
7 7 end
8 8  
9 9 def self.find_by_name(base_tool_name)
10   - new request("BaseTool", :get_base_tool, {:base_tool_name => base_tool_name})[:base_tool]
  10 + new request(:get_base_tool, {:base_tool_name => base_tool_name})[:base_tool]
11 11 end
12 12  
13 13 def self.all
... ...
plugins/mezuro/lib/kalibro/compound_metric_with_error.rb
... ... @@ -1,13 +0,0 @@
1   -class Kalibro::CompoundMetricWithError < Kalibro::Model
2   -
3   - attr_accessor :metric, :error
4   -
5   - def metric=(value)
6   - @metric = Kalibro::CompoundMetric.to_object value
7   - end
8   -
9   - def error=(value)
10   - @error = Kalibro::Error.to_object value
11   - end
12   -
13   -end
plugins/mezuro/lib/kalibro/metric_configuration.rb
... ... @@ -20,7 +20,7 @@ class Kalibro::MetricConfiguration &lt; Kalibro::Model
20 20 end
21 21  
22 22 def self.metric_configurations_of(configuration_id)
23   - hash = request("MetricConfiguration", :metric_configurations_of, {:configuration_id => configuration_id})
  23 + hash = request(:metric_configurations_of, {:configuration_id => configuration_id})
24 24 hash[:metric_configuration].to_a.map { |metric_configuration| new metric_configuration }
25 25 end
26 26  
... ...
plugins/mezuro/lib/kalibro/metric_result.rb
... ... @@ -15,15 +15,15 @@ class Kalibro::MetricResult &lt; Kalibro::Model
15 15 end
16 16  
17 17 def descendant_results
18   - self.class.request("MetricResult", :descendant_results_of, {:metric_result_id => self.id})[:descendant_result].to_a
  18 + self.class.request(:descendant_results_of, {:metric_result_id => self.id})[:descendant_result].to_a
19 19 end
20 20  
21 21 def self.metric_results_of(module_result_id)
22   - request("MetricResult", :metric_results_of, {:module_result_id => module_result_id})[:metric_result].to_a.map {|metric_result| new metric_result}
  22 + request(:metric_results_of, {:module_result_id => module_result_id})[:metric_result].to_a.map {|metric_result| new metric_result}
23 23 end
24 24  
25 25 def history_of(module_id)
26   - self.class.request("MetricResult", :history_of, {:metric_name => self.configuration.metric.name, :module_result_id => module_id})[:date_metric_result].to_a.map {|date_metric_result| Kalibro::DateMetricResult.new date_metric_result}
  26 + self.class.request(:history_of, {:metric_name => self.configuration.metric.name, :module_result_id => module_id})[:date_metric_result].to_a.map {|date_metric_result| Kalibro::DateMetricResult.new date_metric_result}
27 27 end
28 28  
29 29 end
... ...
plugins/mezuro/lib/kalibro/model.rb
... ... @@ -20,7 +20,7 @@ class Kalibro::Model
20 20 hash = {:attributes! => {}}.merge(hash)
21 21 hash[:attributes!][field.to_sym] = {
22 22 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
23   - 'xsi:type' => 'kalibro:' + xml_class_name(field_value) }
  23 + 'xsi:type' => 'kalibro:' + xml_instance_class_name(field_value) }
24 24 end
25 25 end
26 26 end
... ... @@ -28,7 +28,7 @@ class Kalibro::Model
28 28 hash
29 29 end
30 30  
31   - def self.request(endpoint, action, request_body = nil)
  31 + def self.request(action, request_body = nil)
32 32 response = client(endpoint).request(:kalibro, action) { soap.body = request_body }
33 33 response.to_hash["#{action}_response".to_sym] # response is a Savon::SOAP::Response, and to_hash is a Savon::SOAP::Response method
34 34 end
... ... @@ -48,9 +48,17 @@ class Kalibro::Model
48 48 new_model
49 49 end
50 50  
  51 + def self.find(id)
  52 + if(exists?(id))
  53 + new request(find_action, id_params(id))["#{class_name.underscore}".to_sym]
  54 + else
  55 + nil
  56 + end
  57 + end
  58 +
51 59 def save
52 60 begin
53   - self.id = self.class.request(save_endpoint, save_action, save_params)["#{class_name.underscore}_id".to_sym]
  61 + self.id = self.class.request(save_action, save_params)["#{instance_class_name.underscore}_id".to_sym]
54 62 true
55 63 rescue Exception => exception
56 64 add_error exception
... ... @@ -60,14 +68,14 @@ class Kalibro::Model
60 68  
61 69 def destroy
62 70 begin
63   - self.class.request(destroy_endpoint, destroy_action, destroy_params)
  71 + self.class.request(destroy_action, destroy_params)
64 72 rescue Exception => exception
65 73 add_error exception
66 74 end
67 75 end
68 76  
69 77 def self.exists?(id)
70   - request(exists_endpoint, exists_action, exists_params(id))
  78 + request(exists_action, id_params(id))[:exists]
71 79 end
72 80  
73 81 protected
... ... @@ -86,7 +94,7 @@ class Kalibro::Model
86 94 value
87 95 end
88 96  
89   - def xml_class_name(object)
  97 + def xml_instance_class_name(object)
90 98 xml_name = object.class.name
91 99 xml_name["Kalibro::"] = ""
92 100 xml_name[0..0] = xml_name[0..0].downcase
... ... @@ -107,48 +115,44 @@ class Kalibro::Model
107 115 date.to_s[0..18] + milliseconds + date.to_s[19..-1]
108 116 end
109 117  
110   - def class_name
  118 + def instance_class_name
111 119 self.class.name.gsub(/Kalibro::/,"")
112 120 end
113 121  
114   - def save_endpoint
  122 + def self.endpoint
115 123 class_name
116 124 end
117 125  
118 126 def save_action
119   - "save_#{class_name.underscore}".to_sym
  127 + "save_#{instance_class_name.underscore}".to_sym
120 128 end
121 129  
122 130 def save_params
123   - {class_name.underscore.to_sym => self.to_hash}
124   - end
125   -
126   - def destroy_endpoint
127   - class_name
  131 + {instance_class_name.underscore.to_sym => self.to_hash}
128 132 end
129 133  
130 134 def destroy_action
131   - "delete_#{class_name.underscore}".to_sym
  135 + "delete_#{instance_class_name.underscore}".to_sym
132 136 end
133 137  
134 138 def destroy_params
135   - {"#{class_name.underscore}_id".to_sym => self.id}
  139 + {"#{instance_class_name.underscore}_id".to_sym => self.id}
136 140 end
137 141  
138   - def self.exists_class_name
  142 + def self.class_name
139 143 self.name.gsub(/Kalibro::/,"")
140 144 end
141 145  
142   - def self.exists_endpoint
143   - self.exists_class_name
144   - end
145   -
146 146 def self.exists_action
147   - "#{exists_class_name.underscore}_exists".to_sym
  147 + "#{class_name.underscore}_exists".to_sym
148 148 end
149 149  
150   - def self.exists_params(id)
151   - {"#{exists_class_name.underscore}_id".to_sym => id}
  150 + def self.id_params(id)
  151 + {"#{class_name.underscore}_id".to_sym => id}
  152 + end
  153 +
  154 + def self.find_action
  155 + "get_#{class_name.underscore}".to_sym
152 156 end
153 157  
154 158 def add_error(exception)
... ...
plugins/mezuro/lib/kalibro/module.rb
... ... @@ -2,20 +2,4 @@ class Kalibro::Module &lt; Kalibro::Model
2 2  
3 3 attr_accessor :name, :granularity
4 4  
5   -=begin
6   - def self.parent_names(name)
7   - path = []
8   - ancestors = []
9   - name.split(".").each do |token|
10   - path << token
11   - ancestors << path.join(".")
12   - end
13   - ancestors
14   - end
15   -
16   - def ancestor_names
17   - self.class.parent_names(@name)
18   - end
19   -=end
20   -
21 5 end
... ...
plugins/mezuro/lib/kalibro/module_node.rb
... ... @@ -1,21 +0,0 @@
1   -class Kalibro::ModuleNode < Kalibro::Model
2   -
3   - attr_accessor :module, :child
4   -
5   - def module=(value)
6   - @module = Kalibro::Module.to_object value
7   - end
8   -
9   - def child=(value)
10   - @child = Kalibro::ModuleNode.to_objects_array value
11   - end
12   -
13   - def children
14   - @child
15   - end
16   -
17   - def children=(children)
18   - @child = children
19   - end
20   -
21   -end
plugins/mezuro/lib/kalibro/module_result.rb
... ... @@ -3,11 +3,11 @@ class Kalibro::ModuleResult &lt; Kalibro::Model
3 3 attr_accessor :id, :module, :grade, :parent_id
4 4  
5 5 def self.find(id)
6   - new request('ModuleResult', :get_module_result, { :module_result_id => id })[:module_result]
  6 + new request(:get_module_result, { :module_result_id => id })[:module_result]
7 7 end
8 8  
9 9 def children
10   - hash_array = self.class.request('ModuleResult',:children_of, {:module_result_id => self.id})[:module_result].to_a
  10 + hash_array = self.class.request(:children_of, {:module_result_id => self.id})[:module_result].to_a
11 11 hash_array.map { |module_result| self.class.new module_result }
12 12 end
13 13  
... ...
plugins/mezuro/lib/kalibro/processing.rb
1 1 class Kalibro::Processing < Kalibro::Model
2 2  
3   - attr_accessor :id, :date, :state, :error, :process_times, :results_root_id
  3 + attr_accessor :id, :date, :state, :error, :process_time, :results_root_id
4 4  
5 5 def self.has_processing(repository_id)
6   - request('Processing', :has_processing, {:repository_id => repository_id})[:exists]
  6 + request(:has_processing, {:repository_id => repository_id})[:exists]
7 7 end
8 8  
9 9 def self.has_ready_processing(repository_id)
10   - request('Processing', :has_ready_processing, {:repository_id => repository_id})[:exists]
  10 + request(:has_ready_processing, {:repository_id => repository_id})[:exists]
11 11 end
12 12  
13 13 def self.has_processing_after(repository_id, date)
14   - request('Processing', :has_processing_after, {:repository_id => repository_id, :date => date})[:exists]
  14 + request(:has_processing_after, {:repository_id => repository_id, :date => date})[:exists]
15 15 end
16 16  
17 17 def self.has_processing_before(repository_id, date)
18   - request('Processing', :has_processing_before, {:repository_id => repository_id, :date => date})[:exists]
  18 + request(:has_processing_before, {:repository_id => repository_id, :date => date})[:exists]
19 19 end
20 20  
21 21 def self.last_processing_state_of(repository_id)
22   - request('Processing', :last_processing_state, {:repository_id => repository_id})[:process_state]
  22 + request(:last_processing_state, {:repository_id => repository_id})[:process_state]
23 23 end
24 24  
25 25 def self.last_ready_processing_of(repository_id)
26   - new request('Processing', :last_ready_processing, {:repository_id => repository_id})[:processing]
  26 + new request(:last_ready_processing, {:repository_id => repository_id})[:processing]
27 27 end
28 28  
29 29 def self.first_processing_of(repository_id)
30   - new request('Processing', :first_processing, {:repository_id => repository_id})[:processing]
  30 + new request(:first_processing, {:repository_id => repository_id})[:processing]
31 31 end
32 32  
33 33 def self.last_processing_of(repository_id)
34   - new request('Processing', :last_processing, {:repository_id => repository_id})[:processing]
  34 + new request(:last_processing, {:repository_id => repository_id})[:processing]
35 35 end
36 36  
37 37 def self.first_processing_after(repository_id, date)
38   - new request('Processing', :first_processing_after, {:repository_id => repository_id, :date => date})[:processing]
  38 + new request(:first_processing_after, {:repository_id => repository_id, :date => date})[:processing]
39 39 end
40 40  
41 41 def self.last_processing_before(repository_id, date)
42   - new request('Processing', :last_processing_before, {:repository_id => repository_id, :date => date})[:processing]
  42 + new request(:last_processing_before, {:repository_id => repository_id, :date => date})[:processing]
43 43 end
44 44  
45 45 def date=(value)
46 46 @date = value.is_a?(String) ? DateTime.parse(value) : value
47 47 end
48 48  
  49 + def process_times=(value)
  50 + process_time=value
  51 + end
  52 +
  53 + def process_time=(value)
  54 + @process_time = Kalibro::ProcessTime.to_objects_array value
  55 + end
  56 +
  57 + def process_times
  58 + process_time
  59 + end
  60 +
49 61 end
... ...
plugins/mezuro/lib/kalibro/project.rb
... ... @@ -3,50 +3,13 @@ class Kalibro::Project &lt; Kalibro::Model
3 3 attr_accessor :id, :name, :description
4 4  
5 5 def self.all
6   - response = request("Project", :all_projects)[:project].to_a
  6 + response = request(:all_projects)[:project].to_a
7 7 response = [] if response.nil?
8 8 response.map {|project| new project}
9 9 end
10 10  
11   - def self.find(project_id)
12   - new request("Project", :get_project, :project_id => project_id)[:project]
13   - end
14   -
15 11 def self.project_of(repository_id)
16   - new request("Project", :project_of, :repository_id => repository_id)[:project]
17   - end
18   -=begin
19   - def error=(value)
20   - @kalibro_error = Kalibro::Error.to_object value
21   - end
22   -
23   - def process_project(days = '0')
24   - begin
25   - if days.to_i.zero?
26   - self.class.request("Kalibro", :process_project, {:project_name => name})
27   - else
28   - self.class.request("Kalibro", :process_periodically, {:project_name => name, :period_in_days => days})
29   - end
30   - rescue Exception => exception
31   - add_error exception
32   - end
33   - end
34   -
35   - def process_period
36   - begin
37   - self.class.request("Kalibro", :get_process_period, {:project_name => name})[:period]
38   - rescue Exception => exception
39   - add_error exception
40   - end
41   - end
42   -
43   - def cancel_periodic_process
44   - begin
45   - self.class.request("Kalibro", :cancel_periodic_process, {:project_name => name})
46   - rescue Exception => exception
47   - add_error exception
48   - end
  12 + new request(:project_of, :repository_id => repository_id)[:project]
49 13 end
50   -=end
51 14  
52 15 end
... ...
plugins/mezuro/lib/kalibro/range.rb
... ... @@ -39,12 +39,12 @@ class Kalibro::Range &lt; Kalibro::Model
39 39 end
40 40  
41 41 def self.ranges_of( metric_configuration_id )
42   - request("Range", :ranges_of, {:metric_configuration_id => metric_configuration_id} )[:range].to_a.map { |range| new range }
  42 + request(:ranges_of, {:metric_configuration_id => metric_configuration_id} )[:range].to_a.map { |range| new range }
43 43 end
44 44  
45 45 def save( metric_configuration_id )
46 46 begin
47   - self.id = self.class.request("Range", :save_range, {:range => self.to_hash, :metric_configuration_id => metric_configuration_id})[:range_id]
  47 + self.id = self.class.request(:save_range, {:range => self.to_hash, :metric_configuration_id => metric_configuration_id})[:range_id]
48 48 true
49 49 rescue Exception => exception
50 50 add_error exception
... ...
plugins/mezuro/lib/kalibro/reading.rb
... ... @@ -3,15 +3,15 @@ class Kalibro::Reading &lt; Kalibro::Model
3 3 attr_accessor :id, :label, :grade, :color
4 4  
5 5 def self.find(id)
6   - new request("Reading", :get_reading, {:reading_id => id})[:reading]
  6 + new request(:get_reading, {:reading_id => id})[:reading]
7 7 end
8 8  
9 9 def self.readings_of( group_id )
10   - request("Reading", :readings_of, {:group_id => group_id})[:reading].to_a.map { |reading| new reading }
  10 + request(:readings_of, {:group_id => group_id})[:reading].to_a.map { |reading| new reading }
11 11 end
12 12  
13 13 def self.reading_of( range_id )
14   - new request("Reading", :reading_of, {:range_id => range_id} )[:reading]
  14 + new request(:reading_of, {:range_id => range_id} )[:reading]
15 15 end
16 16  
17 17 end
... ...
plugins/mezuro/lib/kalibro/reading_group.rb
... ... @@ -2,21 +2,17 @@ class Kalibro::ReadingGroup &lt; Kalibro::Model
2 2  
3 3 attr_accessor :id, :name, :description
4 4  
5   - def self.find(id)
6   - new request("ReadingGroup", :get_reading_group, {:group_id => id})[:reading_group]
7   - end
8   -
9 5 def self.all
10   - request("ReadingGroup", :all_reading_groups)[:reading_group].to_a.map { |reading_group| new reading_group }
  6 + request(:all_reading_groups)[:reading_group].to_a.map { |reading_group| new reading_group }
11 7 end
12 8  
13 9 def self.reading_group_of( metric_configuration_id )
14   - new request("ReadingGroup", :reading_group_of, {:metric_configuration_id => metric_configuration_id} )[:reading_group]
  10 + new request(:reading_group_of, {:metric_configuration_id => metric_configuration_id} )[:reading_group]
15 11 end
16 12  
17 13 private
18 14  
19   - def self.exists_params(id)
  15 + def self.id_params(id)
20 16 {:group_id => id}
21 17 end
22 18  
... ...
plugins/mezuro/lib/kalibro/repository.rb
... ... @@ -3,23 +3,23 @@ class Kalibro::Repository &lt; Kalibro::Model
3 3 attr_accessor :id, :name, :description, :license, :process_period, :type, :address, :configuration_id
4 4  
5 5 def self.repository_types
6   - request("Repository", :supported_repository_types)[:repository_type].to_a
  6 + request(:supported_repository_types)[:repository_type].to_a
7 7 end
8 8  
9 9 def self.repository_of(processing_id)
10   - new request("Repository", :repository_of, {:processing_id => processing_id})[:repository]
  10 + new request(:repository_of, {:processing_id => processing_id})[:repository]
11 11 end
12 12  
13 13 def self.repositories_of(project_id)
14   - request("Repository", :repositories_of, {:project_id => project_id})[:repository].to_a.map { |repository| new repository }
  14 + request(:repositories_of, {:project_id => project_id})[:repository].to_a.map { |repository| new repository }
15 15 end
16 16  
17 17 def process_repository
18   - self.class.request("Repository", :process_repository, {:repository_id => self.id});
  18 + self.class.request(:process_repository, {:repository_id => self.id});
19 19 end
20 20  
21 21 def cancel_processing_of_repository
22   - self.class.request("Repository", :cancel_processing_of_repository, {:repository_id => self.id});
  22 + self.class.request(:cancel_processing_of_repository, {:repository_id => self.id});
23 23 end
24 24  
25 25 end
... ...
plugins/mezuro/test/fixtures/compound_metric_with_error_fixtures.rb
... ... @@ -1,20 +0,0 @@
1   -require File.dirname(__FILE__) + '/error_fixtures'
2   -require File.dirname(__FILE__) + '/compound_metric_fixtures'
3   -
4   -class CompoundMetricWithErrorFixtures
5   -
6   - def self.compound_metric_with_error
7   - Kalibro::CompoundMetricWithError.new compound_metric_with_error_hash
8   - end
9   -
10   - def self.compound_metric_with_error_hash
11   - {:metric => CompoundMetricFixtures.compound_metric_hash, :error => ErrorFixtures.error_hash,
12   - :attributes! => {:metric => {
13   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
14   - 'xsi:type' => 'kalibro:compoundMetricXml' },
15   - :error => {
16   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
17   - 'xsi:type' => 'kalibro:errorXml' }}}
18   - end
19   -
20   -end
plugins/mezuro/test/fixtures/module_node_fixtures.rb
... ... @@ -1,47 +0,0 @@
1   -require File.dirname(__FILE__) + '/module_fixtures'
2   -
3   -class ModuleNodeFixtures
4   -
5   - def self.module_node
6   - Kalibro::ModuleNode.new module_node_hash
7   - end
8   -
9   - def self.module_node_hash
10   - {
11   - :module => ModuleFixtures.module_hash,:attributes! => {:module => {
12   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
13   - 'xsi:type' => 'kalibro:moduleXml' }},
14   - :child => [{
15   - :module => {
16   - :name => 'org',
17   - :granularity => 'PACKAGE'
18   - },:attributes! => {:module => {
19   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
20   - 'xsi:type' => 'kalibro:moduleXml' }},
21   - :child => [{
22   - :module => {
23   - :name => 'org.Window',
24   - :granularity => 'CLASS'
25   - },:attributes! => {:module => {
26   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
27   - 'xsi:type' => 'kalibro:moduleXml' }}
28   - }]
29   - },{
30   - :module => {
31   - :name => 'Dialog',
32   - :granularity => 'CLASS'
33   - },:attributes! => {:module => {
34   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
35   - 'xsi:type' => 'kalibro:moduleXml' }}
36   - },{
37   - :module => {
38   - :name => 'main',
39   - :granularity => 'CLASS'
40   - },:attributes! => {:module => {
41   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
42   - 'xsi:type' => 'kalibro:moduleXml' }}
43   - }]
44   - }
45   - end
46   -
47   -end
plugins/mezuro/test/fixtures/processing_fixtures.rb
... ... @@ -11,7 +11,7 @@ class ProcessingFixtures
11 11 :id => 31,
12 12 :date => '2011-10-20T18:26:43.151+00:00',
13 13 :state => 'READY',
14   - :process_times => [ProcessTimeFixtures.process_time_hash],
  14 + :process_time => [ProcessTimeFixtures.process_time_hash],
15 15 :results_root_id => 13
16 16 }
17 17 end
... ...
plugins/mezuro/test/unit/kalibro/base_tool_test.rb
... ... @@ -12,21 +12,15 @@ class BaseToolTest &lt; ActiveSupport::TestCase
12 12 assert_equal @hash[:name], Kalibro::BaseTool.new(@hash).name
13 13 end
14 14  
15   -# Mezuro will not send a base_tool hash back to Kalibro
16   -#
17   -# should 'convert base tool to hash' do
18   -# assert_equal @hash, @base_tool.to_hash
19   -# end
20   -
21 15 should 'get base tool names' do
22 16 names = ['Analizo', 'Checkstyle']
23   - Kalibro::BaseTool.expects(:request).with("BaseTool", :all_base_tool_names).returns({:base_tool_name => names})
  17 + Kalibro::BaseTool.expects(:request).with(:all_base_tool_names).returns({:base_tool_name => names})
24 18 assert_equal names, Kalibro::BaseTool.all_names
25 19 end
26 20  
27 21 should 'get base tool by name' do
28 22 request_body = {:base_tool_name => @base_tool.name}
29   - Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool, request_body).returns({:base_tool => @hash})
  23 + Kalibro::BaseTool.expects(:request).with(:get_base_tool, request_body).returns({:base_tool => @hash})
30 24 assert_equal @base_tool.name, Kalibro::BaseTool.find_by_name(@base_tool.name).name
31 25 end
32 26  
... ...
plugins/mezuro/test/unit/kalibro/compound_metric_with_error_test.rb
... ... @@ -1,20 +0,0 @@
1   -require "test_helper"
2   -
3   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/compound_metric_with_error_fixtures"
4   -
5   -class CompoundMetricWithErrorTest < ActiveSupport::TestCase
6   -
7   - def setup
8   - @hash = CompoundMetricWithErrorFixtures.compound_metric_with_error_hash
9   - @compound_metric_with_error = CompoundMetricWithErrorFixtures.compound_metric_with_error
10   - end
11   -
12   - should 'create error from hash' do
13   - assert_equal @hash[:error][:message], Kalibro::CompoundMetricWithError.new(@hash).error.message
14   - end
15   -
16   - should 'convert error to hash' do
17   - assert_equal @hash, @compound_metric_with_error.to_hash
18   - end
19   -
20   -end
plugins/mezuro/test/unit/kalibro/metric_configuration_test.rb
... ... @@ -22,27 +22,27 @@ class MetricConfigurationTest &lt; ActiveSupport::TestCase
22 22 configuration_id = 13
23 23 request_body = { :configuration_id => configuration_id }
24 24 response_hash = {:metric_configuration => [@native_metric_configuration_hash]}
25   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :metric_configurations_of, request_body).returns(response_hash)
  25 + Kalibro::MetricConfiguration.expects(:request).with(:metric_configurations_of, request_body).returns(response_hash)
26 26 assert_equal @native_metric_configuration.code, Kalibro::MetricConfiguration.metric_configurations_of(configuration_id).first.code
27 27 end
28 28  
29 29 should 'return true when metric configuration is saved successfully' do
30 30 id_from_kalibro = 1
31 31 configuration_id = @created_metric_configuration.configuration_id
32   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, {:metric_configuration => @created_metric_configuration.to_hash, :configuration_id => configuration_id}).returns(:metric_configuration_id => id_from_kalibro)
  32 + Kalibro::MetricConfiguration.expects(:request).with(:save_metric_configuration, {:metric_configuration => @created_metric_configuration.to_hash, :configuration_id => configuration_id}).returns(:metric_configuration_id => id_from_kalibro)
33 33 assert @created_metric_configuration.save
34 34 assert_equal id_from_kalibro, @created_metric_configuration.id
35 35 end
36 36  
37 37 should 'return false when metric configuration is not saved successfully' do
38 38 configuration_id = @created_metric_configuration.configuration_id
39   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, {:metric_configuration => @created_metric_configuration.to_hash, :configuration_id => configuration_id}).raises(Exception.new)
  39 + Kalibro::MetricConfiguration.expects(:request).with(:save_metric_configuration, {:metric_configuration => @created_metric_configuration.to_hash, :configuration_id => configuration_id}).raises(Exception.new)
40 40 assert !(@created_metric_configuration.save)
41 41 assert_nil @created_metric_configuration.id
42 42 end
43 43  
44 44 should 'destroy metric configuration' do
45   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :delete_metric_configuration, :metric_configuration_id => @native_metric_configuration.id)
  45 + Kalibro::MetricConfiguration.expects(:request).with(:delete_metric_configuration, :metric_configuration_id => @native_metric_configuration.id)
46 46 @native_metric_configuration.destroy
47 47 end
48 48  
... ...
plugins/mezuro/test/unit/kalibro/metric_result_test.rb
... ... @@ -21,19 +21,19 @@ class MetricResultTest &lt; ActiveSupport::TestCase
21 21  
22 22 should 'return descendant results of a metric result' do
23 23 descendant = [31, 13]
24   - Kalibro::MetricResult.expects(:request).with("MetricResult", :descendant_results_of, {:metric_result_id => @result.id}).returns({:descendant_result => descendant})
  24 + Kalibro::MetricResult.expects(:request).with(:descendant_results_of, {:metric_result_id => @result.id}).returns({:descendant_result => descendant})
25 25 assert_equal descendant, @result.descendant_results
26 26 end
27 27  
28 28 should 'return metric results of a module result' do
29 29 id = 31
30   - Kalibro::MetricResult.expects(:request).with("MetricResult", :metric_results_of, {:module_result_id => id}).returns(:metric_result => [@native_hash, @compound_hash])
  30 + Kalibro::MetricResult.expects(:request).with(:metric_results_of, {:module_result_id => id}).returns(:metric_result => [@native_hash, @compound_hash])
31 31 assert_equal @native_hash[:id], Kalibro::MetricResult.metric_results_of(id).first.id
32 32 end
33 33  
34 34 should 'return history of a metric with a module result id' do
35 35 module_id = 31
36   - Kalibro::MetricResult.expects(:request).with("MetricResult", :history_of, {:metric_name => @result.configuration.metric.name, :module_result_id => module_id}).returns({:date_metric_result => [DateMetricResultFixtures.date_metric_result_hash]})
  36 + Kalibro::MetricResult.expects(:request).with(:history_of, {:metric_name => @result.configuration.metric.name, :module_result_id => module_id}).returns({:date_metric_result => [DateMetricResultFixtures.date_metric_result_hash]})
37 37 assert_equal DateMetricResultFixtures.date_metric_result_hash[:metric_result][:id], @result.history_of(module_id).first.metric_result.id
38 38 end
39 39  
... ...
plugins/mezuro/test/unit/kalibro/module_node_test.rb
... ... @@ -1,19 +0,0 @@
1   -require "test_helper"
2   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_node_fixtures"
3   -
4   -class ModuleNodeTest < ActiveSupport::TestCase
5   -
6   - def setup
7   - @hash = ModuleNodeFixtures.module_node_hash
8   - @node = ModuleNodeFixtures.module_node
9   - end
10   -
11   - should 'create module node from hash' do
12   - assert_equal( @node.child[0].module.name, Kalibro::ModuleNode.new(@hash).child[0].module.name)
13   - end
14   -
15   - should 'convert children hash to array of ModuleNode' do
16   - assert_equal @hash, @node.to_hash
17   - end
18   -
19   -end
plugins/mezuro/test/unit/kalibro/module_result_test.rb
... ... @@ -8,6 +8,7 @@ class ModuleResultTest &lt; ActiveSupport::TestCase
8 8 @hash = ModuleResultFixtures.module_result_hash
9 9 @module_result = ModuleResultFixtures.module_result
10 10 end
  11 +
11 12 should 'create module result' do
12 13 assert_equal @hash[:id] , Kalibro::ModuleResult.new(@hash).id
13 14 end
... ... @@ -18,13 +19,13 @@ class ModuleResultTest &lt; ActiveSupport::TestCase
18 19  
19 20 should 'find module result' do
20 21 response = {:module_result => @hash}
21   - Kalibro::ModuleResult.expects(:request).with('ModuleResult',:get_module_result, {:module_result_id => @module_result.id}).returns(response)
  22 + Kalibro::ModuleResult.expects(:request).with(:get_module_result, {:module_result_id => @module_result.id}).returns(response)
22 23 assert_equal @module_result.grade, Kalibro::ModuleResult.find(@module_result.id).grade
23 24 end
24 25  
25 26 should 'return children of a module result' do
26 27 response = {:module_result => [@hash]}
27   - Kalibro::ModuleResult.expects(:request).with('ModuleResult',:children_of, {:module_result_id => @module_result.id}).returns(response)
  28 + Kalibro::ModuleResult.expects(:request).with(:children_of, {:module_result_id => @module_result.id}).returns(response)
28 29 assert @hash[:id], @module_result.children.first.id
29 30 end
30 31  
... ...
plugins/mezuro/test/unit/kalibro/module_test.rb
... ... @@ -17,16 +17,4 @@ class ModuleTest &lt; ActiveSupport::TestCase
17 17 assert_equal @hash, @module.to_hash
18 18 end
19 19  
20   -=begin
21   - should 'list ancestor names' do
22   - @module.name = "org.kalibro.core"
23   - assert_equal ["org", "org.kalibro", "org.kalibro.core"], @module.ancestor_names
24   - end
25   -
26   - should 'list ancestor with one name' do
27   - @module.name = "org"
28   - assert_equal ["org"], @module.ancestor_names
29   - end
30   -=end
31   -
32 20 end
... ...
plugins/mezuro/test/unit/kalibro/processing_test.rb
... ... @@ -9,21 +9,11 @@ class ProcessingTest &lt; ActiveSupport::TestCase
9 9 @processing = ProcessingFixtures.processing
10 10  
11 11 @repository_id = 31
12   -
13   -=begin
14   - @project_name = @processing.project.name
15   - @date = @processing.date
16   - @flag = DateTime.now.sec % 2 == 0 #random choose between true or false
17   -
18   - @request = {:project_name => @project_name}
19   - @request_with_date = {:project_name => @project_name, :date => @date}
20   - @flag_response = {:has_results => @flag}
21   - @result_response = {:processing => @processing.to_hash}
22   -=end
23 12 end
24 13  
25 14 should 'create project result from hash' do
26   - assert_equal @processing.results_root_id, Kalibro::Processing.new(@hash).results_root_id
  15 + assert_equal @hash[:results_root_id], Kalibro::Processing.new(@hash).results_root_id
  16 + assert_equal @hash[:process_time].first[:state], Kalibro::Processing.new(@hash).process_times.first.state
27 17 end
28 18  
29 19 should 'convert project result to hash' do
... ... @@ -34,8 +24,8 @@ class ProcessingTest &lt; ActiveSupport::TestCase
34 24 true_repository_id = 31
35 25 false_repository_id = 32
36 26  
37   - Kalibro::Processing.expects(:request).with('Processing',:has_processing, {:repository_id => true_repository_id}).returns({:exists => true})
38   - Kalibro::Processing.expects(:request).with('Processing',:has_processing, {:repository_id => false_repository_id}).returns({:exists => false})
  27 + Kalibro::Processing.expects(:request).with(:has_processing, {:repository_id => true_repository_id}).returns({:exists => true})
  28 + Kalibro::Processing.expects(:request).with(:has_processing, {:repository_id => false_repository_id}).returns({:exists => false})
39 29  
40 30 assert Kalibro::Processing.has_processing(true_repository_id)
41 31 assert !Kalibro::Processing.has_processing(false_repository_id)
... ... @@ -45,8 +35,8 @@ class ProcessingTest &lt; ActiveSupport::TestCase
45 35 true_repository_id = 31
46 36 false_repository_id = 32
47 37  
48   - Kalibro::Processing.expects(:request).with('Processing',:has_ready_processing, {:repository_id => true_repository_id}).returns({:exists => true})
49   - Kalibro::Processing.expects(:request).with('Processing',:has_ready_processing, {:repository_id => false_repository_id}).returns({:exists => false})
  38 + Kalibro::Processing.expects(:request).with(:has_ready_processing, {:repository_id => true_repository_id}).returns({:exists => true})
  39 + Kalibro::Processing.expects(:request).with(:has_ready_processing, {:repository_id => false_repository_id}).returns({:exists => false})
50 40  
51 41 assert Kalibro::Processing.has_ready_processing(true_repository_id)
52 42 assert !Kalibro::Processing.has_ready_processing(false_repository_id)
... ... @@ -56,8 +46,8 @@ class ProcessingTest &lt; ActiveSupport::TestCase
56 46 true_repository_id = 31
57 47 false_repository_id = 32
58 48  
59   - Kalibro::Processing.expects(:request).with('Processing',:has_processing_after, {:repository_id => true_repository_id, :date => @processing.date}).returns({:exists => true})
60   - Kalibro::Processing.expects(:request).with('Processing',:has_processing_after, {:repository_id => false_repository_id, :date => @processing.date}).returns({:exists => false})
  49 + Kalibro::Processing.expects(:request).with(:has_processing_after, {:repository_id => true_repository_id, :date => @processing.date}).returns({:exists => true})
  50 + Kalibro::Processing.expects(:request).with(:has_processing_after, {:repository_id => false_repository_id, :date => @processing.date}).returns({:exists => false})
61 51  
62 52 assert Kalibro::Processing.has_processing_after(true_repository_id, @processing.date)
63 53 assert !Kalibro::Processing.has_processing_after(false_repository_id, @processing.date)
... ... @@ -67,67 +57,41 @@ class ProcessingTest &lt; ActiveSupport::TestCase
67 57 true_repository_id = 31
68 58 false_repository_id = 32
69 59  
70   - Kalibro::Processing.expects(:request).with('Processing',:has_processing_before, {:repository_id => true_repository_id, :date => @processing.date}).returns({:exists => true})
71   - Kalibro::Processing.expects(:request).with('Processing',:has_processing_before, {:repository_id => false_repository_id, :date => @processing.date}).returns({:exists => false})
  60 + Kalibro::Processing.expects(:request).with(:has_processing_before, {:repository_id => true_repository_id, :date => @processing.date}).returns({:exists => true})
  61 + Kalibro::Processing.expects(:request).with(:has_processing_before, {:repository_id => false_repository_id, :date => @processing.date}).returns({:exists => false})
72 62  
73 63 assert Kalibro::Processing.has_processing_before(true_repository_id, @processing.date)
74 64 assert !Kalibro::Processing.has_processing_before(false_repository_id, @processing.date)
75 65 end
76 66  
77 67 should 'get last processing state of a repository' do
78   - Kalibro::Processing.expects(:request).with('Processing',:last_processing_state, {:repository_id => @repository_id}).returns({:process_state => @processing.state})
  68 + Kalibro::Processing.expects(:request).with(:last_processing_state, {:repository_id => @repository_id}).returns({:process_state => @processing.state})
79 69 assert_equal @processing.state, Kalibro::Processing.last_processing_state_of(@repository_id)
80 70 end
81 71  
82 72 should 'get last ready processing of a repository' do
83   - Kalibro::Processing.expects(:request).with('Processing', :last_ready_processing, {:repository_id => @repository_id}).returns({:processing => @hash})
  73 + Kalibro::Processing.expects(:request).with(:last_ready_processing, {:repository_id => @repository_id}).returns({:processing => @hash})
84 74 assert_equal @processing.id, Kalibro::Processing.last_ready_processing_of(@repository_id).id
85 75 end
86 76  
87 77 should 'get first processing of a repository' do
88   - Kalibro::Processing.expects(:request).with('Processing', :first_processing, {:repository_id => @repository_id}).returns({:processing => @hash})
  78 + Kalibro::Processing.expects(:request).with(:first_processing, {:repository_id => @repository_id}).returns({:processing => @hash})
89 79 assert_equal @processing.id, Kalibro::Processing.first_processing_of(@repository_id).id
90 80 end
91 81  
92 82 should 'get last processing of a repository' do
93   - Kalibro::Processing.expects(:request).with('Processing', :last_processing, {:repository_id => @repository_id}).returns({:processing => @hash})
  83 + Kalibro::Processing.expects(:request).with(:last_processing, {:repository_id => @repository_id}).returns({:processing => @hash})
94 84 assert_equal @processing.id, Kalibro::Processing.last_processing_of(@repository_id).id
95 85 end
96 86  
97 87 should 'get first processing after a date of a repository' do
98   - Kalibro::Processing.expects(:request).with('Processing', :first_processing_after, {:repository_id => @repository_id, :date => @processing.date}).returns({:processing => @hash})
  88 + Kalibro::Processing.expects(:request).with(:first_processing_after, {:repository_id => @repository_id, :date => @processing.date}).returns({:processing => @hash})
99 89 assert_equal @processing.id, Kalibro::Processing.first_processing_after(@repository_id, @processing.date).id
100 90 end
101 91  
102 92 should 'get last processing before a date of a repository' do
103   - Kalibro::Processing.expects(:request).with('Processing', :last_processing_before, {:repository_id => @repository_id, :date => @processing.date}).returns({:processing => @hash})
  93 + Kalibro::Processing.expects(:request).with(:last_processing_before, {:repository_id => @repository_id, :date => @processing.date}).returns({:processing => @hash})
104 94 assert_equal @processing.id, Kalibro::Processing.last_processing_before(@repository_id, @processing.date).id
105 95 end
106   -
107   -=begin
108   -
109   - should 'retrieve formatted load time' do
110   - assert_equal '00:00:14', @processing.formatted_load_time
111   - end
112   -
113   - should 'retrieve formatted analysis time' do
114   - assert_equal '00:00:01', @processing.formatted_analysis_time
115   - end
116 96  
117   - should 'retrive complex module' do
118   - assert_equal @hash[:source_tree][:child][0][:child].first, @processing.node("org.Window").to_hash
119   - end
120   -
121   - should 'return source tree node when nil is given' do
122   - assert_equal @hash[:source_tree], @processing.node(nil).to_hash
123   - end
124   -
125   - should 'return source tree node when project name is given' do
126   - assert_equal @hash[:source_tree], @processing.node(@processing.project.name).to_hash
127   - end
128   -
129   - should 'return correct node when module name is given' do
130   - assert_equal @hash[:source_tree][:child][2], @processing.node("main").to_hash
131   - end
132   -=end
133 97 end
... ...
plugins/mezuro/test/unit/kalibro/project_test.rb
... ... @@ -8,7 +8,6 @@ class ProjectTest &lt; ActiveSupport::TestCase
8 8 @hash = ProjectFixtures.project_hash
9 9 @project = ProjectFixtures.project
10 10 @created_project = ProjectFixtures.created_project
11   - @project_content = ProjectFixtures.project_content
12 11 end
13 12  
14 13 should 'initialize new project from hash' do
... ... @@ -22,75 +21,53 @@ class ProjectTest &lt; ActiveSupport::TestCase
22 21 end
23 22  
24 23 should 'answer if project exists in kalibro' do
25   - Kalibro::Project.expects(:request).with("Project", :project_exists, {:project_id => @project.id}).returns({:exists => true})
  24 + Kalibro::Project.expects(:request).with(:project_exists, {:project_id => @project.id}).returns({:exists => true})
26 25 assert Kalibro::Project.exists?(@project.id)
27 26 end
28 27  
29 28 should 'find project' do
30   - Kalibro::Project.expects(:request).with("Project", :get_project, {:project_id => @project.id}).returns(:project => @hash)
  29 + Kalibro::Project.expects(:request).with(:project_exists, {:project_id => @project.id}).returns({:exists => true})
  30 + Kalibro::Project.expects(:request).with(:get_project, {:project_id => @project.id}).returns(:project => @hash)
31 31 assert_equal @hash[:name], Kalibro::Project.find(@project.id).name
32 32 end
33 33  
34   - should 'raise error when project doesnt exist' do
35   - request_body = {:project_id => @project.id}
36   - Kalibro::Project.expects(:request).with("Project", :get_project, request_body).raises(Exception.new("(S:Server) There is no project with id #{@project.id}"))
37   - assert_raise Exception do Kalibro::Project.find(@project.id) end
  34 + should 'verify when project doesnt exist' do
  35 + Kalibro::Project.expects(:request).with(:project_exists, {:project_id => @project.id}).returns({:exists => false})
  36 + assert_nil Kalibro::Project.find(@project.id)
38 37 end
39 38  
40 39 should 'get project of a repository' do
41 40 repository_id = 31
42   - Kalibro::Project.expects(:request).with("Project", :project_of, {:repository_id => repository_id}).returns({:project => @hash})
  41 + Kalibro::Project.expects(:request).with(:project_of, {:repository_id => repository_id}).returns({:project => @hash})
43 42 assert_equal @hash[:name], Kalibro::Project.project_of(repository_id).name
44 43 end
45 44  
46 45 should 'get all project' do
47   - Kalibro::Project.expects(:request).with("Project", :all_projects).returns({:project => [@hash]})
  46 + Kalibro::Project.expects(:request).with(:all_projects).returns({:project => [@hash]})
48 47 assert_equal @hash[:name], Kalibro::Project.all.first.name
49 48 end
50 49  
51 50 should 'return empty when there are no projects' do
52   - Kalibro::Project.expects(:request).with("Project", :all_projects).returns({:project => nil})
  51 + Kalibro::Project.expects(:request).with(:all_projects).returns({:project => nil})
53 52 assert_equal [], Kalibro::Project.all
54 53 end
55 54  
56 55 should 'return true when project is saved successfully' do
57 56 id_from_kalibro = 1
58   - Kalibro::Project.expects(:request).with("Project", :save_project, {:project => @created_project.to_hash}).returns(:project_id => id_from_kalibro)
  57 + Kalibro::Project.expects(:request).with(:save_project, {:project => @created_project.to_hash}).returns(:project_id => id_from_kalibro)
59 58 assert @created_project.save
60 59 assert_equal id_from_kalibro, @created_project.id
61 60 end
62 61  
63 62 should 'return false when project is not saved successfully' do
64   - Kalibro::Project.expects(:request).with("Project", :save_project, {:project => @project.to_hash}).raises(Exception.new)
65   - assert !(@project.save)
  63 + Kalibro::Project.expects(:request).with(:save_project, {:project => @created_project.to_hash}).raises(Exception.new)
  64 + assert !(@created_project.save)
66 65 assert_nil @created_project.id
67 66 end
68 67  
69 68 should 'remove existent project from service' do
70   - Kalibro::Project.expects(:request).with("Project", :delete_project, {:project_id => @project.id})
  69 + Kalibro::Project.expects(:request).with(:delete_project, {:project_id => @project.id})
71 70 @project.destroy
72 71 end
73 72  
74   -=begin
75   - should 'process project without days' do
76   - Kalibro::Project.expects(:request).with('Kalibro', :process_project, {:project_name => @project.name})
77   - @project.process_project
78   - end
79   -
80   - should 'process project with days' do
81   - Kalibro::Project.expects(:request).with('Kalibro', :process_periodically, {:project_name => @project.name, :period_in_days => "1"})
82   - @project.process_project "1"
83   - end
84   -
85   - should 'process period' do
86   - Kalibro::Project.expects(:request).with('Kalibro', :get_process_period, {:project_name => @project.name}).returns({:period => "1"})
87   - assert_equal "1", @project.process_period
88   - end
89   -
90   - should 'cancel periodic process' do
91   - Kalibro::Project.expects(:request).with("Kalibro", :cancel_periodic_process, {:project_name => @project.name})
92   - @project.cancel_periodic_process
93   - end
94   -=end
95   -
96 73 end
... ...
plugins/mezuro/test/unit/kalibro/range_test.rb
... ... @@ -20,27 +20,27 @@ class RangeTest &lt; ActiveSupport::TestCase
20 20  
21 21 should 'get ranges of a metric configuration' do
22 22 metric_configuration_id = 31
23   - Kalibro::Range.expects(:request).with("Range", :ranges_of, {:metric_configuration_id => metric_configuration_id}).returns({:range => [@hash]})
  23 + Kalibro::Range.expects(:request).with(:ranges_of, {:metric_configuration_id => metric_configuration_id}).returns({:range => [@hash]})
24 24 assert_equal @hash[:comments], Kalibro::Range.ranges_of(metric_configuration_id).first.comments
25 25 end
26 26  
27 27 should 'return true when range is saved successfully' do
28 28 id_from_kalibro = 1
29 29 metric_configuration_id = 2
30   - Kalibro::Range.expects(:request).with("Range", :save_range, {:range => @created_range.to_hash, :metric_configuration_id => metric_configuration_id}).returns(:range_id => id_from_kalibro)
  30 + Kalibro::Range.expects(:request).with(:save_range, {:range => @created_range.to_hash, :metric_configuration_id => metric_configuration_id}).returns(:range_id => id_from_kalibro)
31 31 assert @created_range.save(metric_configuration_id)
32 32 assert_equal id_from_kalibro, @created_range.id
33 33 end
34 34  
35 35 should 'return false when range is not saved successfully' do
36 36 metric_configuration_id = 2
37   - Kalibro::Range.expects(:request).with("Range", :save_range, {:range => @created_range.to_hash, :metric_configuration_id => metric_configuration_id}).raises(Exception.new)
  37 + Kalibro::Range.expects(:request).with(:save_range, {:range => @created_range.to_hash, :metric_configuration_id => metric_configuration_id}).raises(Exception.new)
38 38 assert !(@created_range.save(metric_configuration_id))
39 39 assert_nil @created_range.id
40 40 end
41 41  
42 42 should 'destroy range by id' do
43   - Kalibro::Range.expects(:request).with("Range", :delete_range, {:range_id => @range.id})
  43 + Kalibro::Range.expects(:request).with(:delete_range, {:range_id => @range.id})
44 44 @range.destroy
45 45 end
46 46  
... ...
plugins/mezuro/test/unit/kalibro/reading_group_test.rb
... ... @@ -18,42 +18,48 @@ class ReadingGroupTest &lt; ActiveSupport::TestCase
18 18 end
19 19  
20 20 should 'verify existence of reading group' do
21   - Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :reading_group_exists, {:group_id => @hash[:id]}).returns({:exists => true})
  21 + fake_id = 0
  22 + Kalibro::ReadingGroup.expects(:request).with(:reading_group_exists, {:group_id => fake_id}).returns({:exists => false})
  23 + Kalibro::ReadingGroup.expects(:request).with(:reading_group_exists, {:group_id => @hash[:id]}).returns({:exists => true})
  24 + assert !Kalibro::ReadingGroup.exists?(fake_id)
22 25 assert Kalibro::ReadingGroup.exists?(@hash[:id])
23 26 end
24 27  
25 28 should 'get reading group' do
26   - Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :get_reading_group, {:group_id => @hash[:id]}).
  29 + Kalibro::ReadingGroup.expects(:request).with(:reading_group_exists, {:group_id => @hash[:id]}).returns({:exists => true})
  30 + Kalibro::ReadingGroup.expects(:request).with(:get_reading_group, {:group_id => @hash[:id]}).
27 31 returns({:reading_group => @hash})
28 32 assert_equal @hash[:name], Kalibro::ReadingGroup.find(@hash[:id]).name
29 33 end
30 34  
  35 +
  36 +
31 37 should 'get all reading groups' do
32   - Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :all_reading_groups).returns({:reading_group => [@hash]})
  38 + Kalibro::ReadingGroup.expects(:request).with(:all_reading_groups).returns({:reading_group => [@hash]})
33 39 assert_equal @hash[:name], Kalibro::ReadingGroup.all.first.name
34 40 end
35 41  
36 42 should 'get reading group of a metric configuration' do
37 43 id = 31
38   - Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :reading_group_of, {:metric_configuration_id => id}).returns({:reading_group => @hash})
  44 + Kalibro::ReadingGroup.expects(:request).with(:reading_group_of, {:metric_configuration_id => id}).returns({:reading_group => @hash})
39 45 assert_equal @hash[:name], Kalibro::ReadingGroup.reading_group_of(id).name
40 46 end
41 47  
42 48 should 'return true when reading group is saved successfully' do
43 49 id_from_kalibro = 1
44   - Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :save_reading_group, {:reading_group => @created_reading_group.to_hash}).returns(:reading_group_id => id_from_kalibro)
  50 + Kalibro::ReadingGroup.expects(:request).with(:save_reading_group, {:reading_group => @created_reading_group.to_hash}).returns(:reading_group_id => id_from_kalibro)
45 51 assert @created_reading_group.save
46 52 assert_equal id_from_kalibro, @created_reading_group.id
47 53 end
48 54  
49 55 should 'return false when reading group is not saved successfully' do
50   - Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :save_reading_group, {:reading_group => @created_reading_group.to_hash}).raises(Exception.new)
  56 + Kalibro::ReadingGroup.expects(:request).with(:save_reading_group, {:reading_group => @created_reading_group.to_hash}).raises(Exception.new)
51 57 assert !(@created_reading_group.save)
52 58 assert_nil @created_reading_group.id
53 59 end
54 60  
55 61 should 'destroy reading group by id' do
56   - Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :delete_reading_group, {:group_id => @reading_group.id})
  62 + Kalibro::ReadingGroup.expects(:request).with(:delete_reading_group, {:group_id => @reading_group.id})
57 63 @reading_group.destroy
58 64 end
59 65  
... ...
plugins/mezuro/test/unit/kalibro/reading_test.rb
... ... @@ -18,38 +18,38 @@ class ReadingTest &lt; ActiveSupport::TestCase
18 18 end
19 19  
20 20 should 'get reading' do
21   - Kalibro::Reading.expects(:request).with("Reading", :get_reading, {:reading_id => @hash[:id]}).
  21 + Kalibro::Reading.expects(:request).with(:get_reading, {:reading_id => @hash[:id]}).
22 22 returns({:reading => @hash})
23 23 assert_equal @hash[:label], Kalibro::Reading.find(@hash[:id]).label
24 24 end
25 25  
26 26 should 'get reading of a range' do
27 27 range_id = 31
28   - Kalibro::Reading.expects(:request).with("Reading", :reading_of, {:range_id => range_id}).returns({:reading => @hash})
  28 + Kalibro::Reading.expects(:request).with(:reading_of, {:range_id => range_id}).returns({:reading => @hash})
29 29 assert_equal @hash[:label], Kalibro::Reading.reading_of(range_id).label
30 30 end
31 31  
32 32 should 'get readings of a reading group' do
33 33 reading_group_id = 31
34   - Kalibro::Reading.expects(:request).with("Reading", :readings_of, {:group_id => reading_group_id}).returns({:reading => [@hash]})
  34 + Kalibro::Reading.expects(:request).with(:readings_of, {:group_id => reading_group_id}).returns({:reading => [@hash]})
35 35 assert_equal @hash[:label], Kalibro::Reading.readings_of(reading_group_id).first.label
36 36 end
37 37  
38 38 should 'return true when reading is saved successfully' do
39 39 id_from_kalibro = 1
40   - Kalibro::Reading.expects(:request).with("Reading", :save_reading, {:reading => @created_reading.to_hash}).returns(:reading_id => id_from_kalibro)
  40 + Kalibro::Reading.expects(:request).with(:save_reading, {:reading => @created_reading.to_hash}).returns(:reading_id => id_from_kalibro)
41 41 assert @created_reading.save
42 42 assert_equal id_from_kalibro, @created_reading.id
43 43 end
44 44  
45 45 should 'return false when reading is not saved successfully' do
46   - Kalibro::Reading.expects(:request).with("Reading", :save_reading, {:reading => @created_reading.to_hash}).raises(Exception.new)
  46 + Kalibro::Reading.expects(:request).with(:save_reading, {:reading => @created_reading.to_hash}).raises(Exception.new)
47 47 assert !(@created_reading.save)
48 48 assert_nil @created_reading.id
49 49 end
50 50  
51 51 should 'destroy reading by id' do
52   - Kalibro::Reading.expects(:request).with("Reading", :delete_reading, {:reading_id => @reading.id})
  52 + Kalibro::Reading.expects(:request).with(:delete_reading, {:reading_id => @reading.id})
53 53 @reading.destroy
54 54 end
55 55  
... ...
plugins/mezuro/test/unit/kalibro/repository_test.rb
... ... @@ -20,47 +20,47 @@ class RepositoryTest &lt; ActiveSupport::TestCase
20 20  
21 21 should 'get supported repository types' do
22 22 types = ['BAZAAR', 'GIT', 'SUBVERSION']
23   - Kalibro::Repository.expects(:request).with('Repository', :supported_repository_types).returns({:repository_type => types})
  23 + Kalibro::Repository.expects(:request).with(:supported_repository_types).returns({:repository_type => types})
24 24 assert_equal types, Kalibro::Repository.repository_types
25 25 end
26 26  
27 27 should 'get repository of a precessing' do
28 28 id = 31
29   - Kalibro::Repository.expects(:request).with("Repository", :repository_of, {:processing_id => id}).returns({:repository => @hash})
  29 + Kalibro::Repository.expects(:request).with(:repository_of, {:processing_id => id}).returns({:repository => @hash})
30 30 assert_equal @hash[:name], Kalibro::Repository.repository_of(id).name
31 31 end
32 32  
33 33 should 'get repositories of a project' do
34 34 project_id = 31
35   - Kalibro::Repository.expects(:request).with("Repository", :repositories_of, {:project_id => project_id}).returns({:repository => [@hash]})
  35 + Kalibro::Repository.expects(:request).with(:repositories_of, {:project_id => project_id}).returns({:repository => [@hash]})
36 36 assert_equal @hash[:name], Kalibro::Repository.repositories_of(project_id).first.name
37 37 end
38 38  
39 39 should 'return true when repository is saved successfully' do
40 40 id_from_kalibro = 1
41   - Kalibro::Repository.expects(:request).with("Repository", :save_repository, {:repository => @created_repository.to_hash}).returns(:repository_id => id_from_kalibro)
  41 + Kalibro::Repository.expects(:request).with(:save_repository, {:repository => @created_repository.to_hash}).returns(:repository_id => id_from_kalibro)
42 42 assert @created_repository.save
43 43 assert_equal id_from_kalibro, @created_repository.id
44 44 end
45 45  
46 46 should 'return false when repository is not saved successfully' do
47   - Kalibro::Repository.expects(:request).with("Repository", :save_repository, {:repository => @created_repository.to_hash}).raises(Exception.new)
  47 + Kalibro::Repository.expects(:request).with(:save_repository, {:repository => @created_repository.to_hash}).raises(Exception.new)
48 48 assert !(@created_repository.save)
49 49 assert_nil @created_repository.id
50 50 end
51 51  
52 52 should 'destroy repository by id' do
53   - Kalibro::Repository.expects(:request).with("Repository", :delete_repository, {:repository_id => @repository.id})
  53 + Kalibro::Repository.expects(:request).with(:delete_repository, {:repository_id => @repository.id})
54 54 @repository.destroy
55 55 end
56 56  
57 57 should 'process repository' do
58   - Kalibro::Repository.expects(:request).with("Repository", :process_repository, {:repository_id => @repository.id});
  58 + Kalibro::Repository.expects(:request).with(:process_repository, {:repository_id => @repository.id});
59 59 @repository.process_repository
60 60 end
61 61  
62 62 should 'cancel processing of a repository' do
63   - Kalibro::Repository.expects(:request).with("Repository", :cancel_processing_of_repository, {:repository_id => @repository.id});
  63 + Kalibro::Repository.expects(:request).with(:cancel_processing_of_repository, {:repository_id => @repository.id});
64 64 @repository.cancel_processing_of_repository
65 65 end
66 66  
... ...
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
1 1 require "test_helper"
2 2  
3 3 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures"
4   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures"
5 4 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_fixtures"
6 5 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures"
7 6  
... ...