Commit 078f4eec63002348b1944e0b45491e3e02aba9e2
Committed by
Alessandro Palmeira
Exists in
master
and in
28 other branches
Merge branch 'refactoring_project_content' into models_with_ids
Conflicts: plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb plugins/mezuro/lib/kalibro/metric_result.rb plugins/mezuro/lib/kalibro/model.rb plugins/mezuro/lib/kalibro/repository.rb plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
Showing
16 changed files
with
235 additions
and
202 deletions
Show diff stats
plugins/mezuro/controllers/profile/mezuro_plugin_module_controller.rb
@@ -3,10 +3,10 @@ class MezuroPluginModuleController < MezuroPluginProfileController | @@ -3,10 +3,10 @@ class MezuroPluginModuleController < MezuroPluginProfileController | ||
3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') | 3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') |
4 | 4 | ||
5 | def module_result | 5 | def module_result |
6 | - @content = profile.articles.find(params[:id]) | ||
7 | - @module_result = @content.module_result(params) | ||
8 | - @module = @module_result.module | ||
9 | - @module_label = "#{@module.name} (#{@module.granularity})" | 6 | + project_content = profile.articles.find(params[:id]) |
7 | + repositories = project_content.repositories | ||
8 | + @module_result = project_content.module_result(repositories.first.id) | ||
9 | + @metric_results = Kalibro::MetricResult.metric_results_of(@module_result.id) | ||
10 | if project_content_has_errors? | 10 | if project_content_has_errors? |
11 | redirect_to_error_page(@content.errors[:base]) | 11 | redirect_to_error_page(@content.errors[:base]) |
12 | else | 12 | else |
@@ -15,9 +15,9 @@ class MezuroPluginModuleController < MezuroPluginProfileController | @@ -15,9 +15,9 @@ class MezuroPluginModuleController < MezuroPluginProfileController | ||
15 | end | 15 | end |
16 | 16 | ||
17 | def module_metrics_history | 17 | def module_metrics_history |
18 | - metric_name = params[:metric_name] | 18 | + module_result_id = params[:module_result_id] |
19 | @content = profile.articles.find(params[:id]) | 19 | @content = profile.articles.find(params[:id]) |
20 | - module_history = @content.result_history(params[:module_name]) | 20 | + module_history = @content.result_history(params[:module_result_id]) |
21 | if project_content_has_errors? | 21 | if project_content_has_errors? |
22 | redirect_to_error_page(@content.errors[:base]) | 22 | redirect_to_error_page(@content.errors[:base]) |
23 | else | 23 | else |
@@ -28,7 +28,7 @@ class MezuroPluginModuleController < MezuroPluginProfileController | @@ -28,7 +28,7 @@ class MezuroPluginModuleController < MezuroPluginProfileController | ||
28 | 28 | ||
29 | def module_grade_history | 29 | def module_grade_history |
30 | @content = profile.articles.find(params[:id]) | 30 | @content = profile.articles.find(params[:id]) |
31 | - modules_results = @content.result_history(params[:module_name]) | 31 | + modules_results = @content.result_history(params[:module_result_id]) |
32 | if project_content_has_errors? | 32 | if project_content_has_errors? |
33 | redirect_to_error_page(@content.errors[:base]) | 33 | redirect_to_error_page(@content.errors[:base]) |
34 | else | 34 | else |
@@ -42,16 +42,12 @@ class MezuroPluginModuleController < MezuroPluginProfileController | @@ -42,16 +42,12 @@ class MezuroPluginModuleController < MezuroPluginProfileController | ||
42 | private | 42 | private |
43 | 43 | ||
44 | def filtering_metric_history(metric_name, module_history) | 44 | def filtering_metric_history(metric_name, module_history) |
45 | - metrics_history = module_history.map do |module_result| | ||
46 | - [module_result.metric_results, format_date_to_simple_form(module_result.date)] | ||
47 | - end | ||
48 | - metric_history = metrics_history.map do |metric_results_with_date| | ||
49 | - [(metric_results_with_date.first.select do |metric_result| | ||
50 | - metric_result.metric.name.delete("() ") == metric_name | ||
51 | - end).first, metric_results_with_date.last] | 45 | + metrics_history = module_history.select do |m| |
46 | + m.metric_result.configuration.metric.name.delete("() ") == metric_name | ||
52 | end | 47 | end |
53 | - metric_history.map do |metric_result_with_date| | ||
54 | - [metric_result_with_date.first.value, metric_result_with_date.last] | 48 | + |
49 | + metric_history = metrics_history.map do |m| | ||
50 | + [m.metric_result.value, format_date_to_simple_form(m.date)] | ||
55 | end | 51 | end |
56 | end | 52 | end |
57 | 53 |
plugins/mezuro/controllers/profile/mezuro_plugin_project_controller.rb
@@ -2,35 +2,34 @@ class MezuroPluginProjectController < MezuroPluginProfileController | @@ -2,35 +2,34 @@ class MezuroPluginProjectController < MezuroPluginProfileController | ||
2 | 2 | ||
3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') | 3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') |
4 | 4 | ||
5 | - def project_state | 5 | + def processing_state |
6 | @content = profile.articles.find(params[:id]) | 6 | @content = profile.articles.find(params[:id]) |
7 | - project = @content.project | 7 | + processing = @content.processing |
8 | if project_content_has_errors? | 8 | if project_content_has_errors? |
9 | redirect_to_error_page(@content.errors[:base]) | 9 | redirect_to_error_page(@content.errors[:base]) |
10 | else | 10 | else |
11 | - state = project.kalibro_error.nil? ? project.state : "ERROR" | ||
12 | - render :text => state | 11 | + render :text => processing.state |
13 | end | 12 | end |
14 | end | 13 | end |
15 | 14 | ||
16 | - def project_error | 15 | + def processing_error |
17 | @content = profile.articles.find(params[:id]) | 16 | @content = profile.articles.find(params[:id]) |
18 | - @project = @content.project | 17 | + @processing = @content.processing |
19 | if project_content_has_errors? | 18 | if project_content_has_errors? |
20 | redirect_to_error_page(@content.errors[:base]) | 19 | redirect_to_error_page(@content.errors[:base]) |
21 | else | 20 | else |
22 | - render :partial => 'project_error' | 21 | + render :partial => 'processing_error' |
23 | end | 22 | end |
24 | end | 23 | end |
25 | 24 | ||
26 | - def project_result | 25 | + def processing |
27 | @content = profile.articles.find(params[:id]) | 26 | @content = profile.articles.find(params[:id]) |
28 | date = params[:date] | 27 | date = params[:date] |
29 | - @project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date) | 28 | + @processing = date.nil? ? @content.processing : @content.processing_with_date(date) |
30 | if project_content_has_errors? | 29 | if project_content_has_errors? |
31 | redirect_to_error_page(@content.errors[:base]) | 30 | redirect_to_error_page(@content.errors[:base]) |
32 | else | 31 | else |
33 | - render :partial => 'project_result' | 32 | + render :partial => 'processing' |
34 | end | 33 | end |
35 | end | 34 | end |
36 | 35 |
plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb
@@ -11,7 +11,11 @@ class Kalibro::MetricConfigurationSnapshot < Kalibro::Model | @@ -11,7 +11,11 @@ class Kalibro::MetricConfigurationSnapshot < Kalibro::Model | ||
11 | end | 11 | end |
12 | 12 | ||
13 | def range=(value) | 13 | def range=(value) |
14 | - @range = Kalibro::Range.to_object value | 14 | + @range = Kalibro::RangeSnapshot.to_object value |
15 | + end | ||
16 | + | ||
17 | + def range_snapshot | ||
18 | + range | ||
15 | end | 19 | end |
16 | 20 | ||
17 | end | 21 | end |
plugins/mezuro/lib/kalibro/metric_result.rb
@@ -10,6 +10,10 @@ class Kalibro::MetricResult < Kalibro::Model | @@ -10,6 +10,10 @@ class Kalibro::MetricResult < Kalibro::Model | ||
10 | @configuration = Kalibro::MetricConfigurationSnapshot.to_object value | 10 | @configuration = Kalibro::MetricConfigurationSnapshot.to_object value |
11 | end | 11 | end |
12 | 12 | ||
13 | + def metric_configuration_snapshot | ||
14 | + configuration | ||
15 | + end | ||
16 | + | ||
13 | def error=(value) | 17 | def error=(value) |
14 | @error = Kalibro::Throwable.to_object value | 18 | @error = Kalibro::Throwable.to_object value |
15 | end | 19 | end |
@@ -22,8 +26,8 @@ class Kalibro::MetricResult < Kalibro::Model | @@ -22,8 +26,8 @@ class Kalibro::MetricResult < Kalibro::Model | ||
22 | request(:metric_results_of, {:module_result_id => module_result_id})[:metric_result].to_a.map {|metric_result| new metric_result} | 26 | request(:metric_results_of, {:module_result_id => module_result_id})[:metric_result].to_a.map {|metric_result| new metric_result} |
23 | end | 27 | end |
24 | 28 | ||
25 | - def history_of(module_id) | ||
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} | 29 | + def history_of(module_result_id) |
30 | + self.class.request(:history_of, {:metric_name => self.configuration.metric.name, :module_result_id => module_result_id})[:date_metric_result].to_a.map {|date_metric_result| Kalibro::DateMetricResult.new date_metric_result} | ||
27 | end | 31 | end |
28 | 32 | ||
29 | end | 33 | end |
plugins/mezuro/lib/kalibro/model.rb
@@ -40,8 +40,8 @@ class Kalibro::Model | @@ -40,8 +40,8 @@ class Kalibro::Model | ||
40 | 40 | ||
41 | def self.to_object value | 41 | def self.to_object value |
42 | value.kind_of?(Hash) ? new(value) : value | 42 | value.kind_of?(Hash) ? new(value) : value |
43 | - end | ||
44 | - | 43 | + end |
44 | + | ||
45 | def self.create(attributes={}) | 45 | def self.create(attributes={}) |
46 | new_model = new attributes | 46 | new_model = new attributes |
47 | new_model.save | 47 | new_model.save |
@@ -52,7 +52,7 @@ class Kalibro::Model | @@ -52,7 +52,7 @@ class Kalibro::Model | ||
52 | if(exists?(id)) | 52 | if(exists?(id)) |
53 | new request(find_action, id_params(id))["#{class_name.underscore}".to_sym] | 53 | new request(find_action, id_params(id))["#{class_name.underscore}".to_sym] |
54 | else | 54 | else |
55 | - nil | 55 | + raise Errors::RecordNotFound |
56 | end | 56 | end |
57 | end | 57 | end |
58 | 58 | ||
@@ -77,7 +77,7 @@ class Kalibro::Model | @@ -77,7 +77,7 @@ class Kalibro::Model | ||
77 | def self.exists?(id) | 77 | def self.exists?(id) |
78 | request(exists_action, id_params(id))[:exists] | 78 | request(exists_action, id_params(id))[:exists] |
79 | end | 79 | end |
80 | - | 80 | + |
81 | protected | 81 | protected |
82 | 82 | ||
83 | def fields | 83 | def fields |
@@ -88,7 +88,7 @@ class Kalibro::Model | @@ -88,7 +88,7 @@ class Kalibro::Model | ||
88 | return value if value.nil? | 88 | return value if value.nil? |
89 | return value.collect { |element| convert_to_hash(element) } if value.is_a?(Array) | 89 | return value.collect { |element| convert_to_hash(element) } if value.is_a?(Array) |
90 | return value.to_hash if value.is_a?(Kalibro::Model) | 90 | return value.to_hash if value.is_a?(Kalibro::Model) |
91 | - return self.class.date_with_milliseconds(value) if value.is_a?(DateTime) | 91 | + return self.class.date_with_milliseconds(value) if value.is_a?(DateTime) |
92 | return 'INF' if value.is_a?(Float) and value.infinite? == 1 | 92 | return 'INF' if value.is_a?(Float) and value.infinite? == 1 |
93 | return '-INF' if value.is_a?(Float) and value.infinite? == -1 | 93 | return '-INF' if value.is_a?(Float) and value.infinite? == -1 |
94 | value | 94 | value |
@@ -109,32 +109,32 @@ class Kalibro::Model | @@ -109,32 +109,32 @@ class Kalibro::Model | ||
109 | def self.is_valid?(field) | 109 | def self.is_valid?(field) |
110 | field.to_s[0] != '@' and field != :attributes! and (field.to_s =~ /xsi/).nil? | 110 | field.to_s[0] != '@' and field != :attributes! and (field.to_s =~ /xsi/).nil? |
111 | end | 111 | end |
112 | - | 112 | + |
113 | def self.date_with_milliseconds(date) | 113 | def self.date_with_milliseconds(date) |
114 | milliseconds = "." + (date.sec_fraction * 60 * 60 * 24 * 1000).to_s | 114 | milliseconds = "." + (date.sec_fraction * 60 * 60 * 24 * 1000).to_s |
115 | date.to_s[0..18] + milliseconds + date.to_s[19..-1] | 115 | date.to_s[0..18] + milliseconds + date.to_s[19..-1] |
116 | end | 116 | end |
117 | - | 117 | + |
118 | def instance_class_name | 118 | def instance_class_name |
119 | self.class.name.gsub(/Kalibro::/,"") | 119 | self.class.name.gsub(/Kalibro::/,"") |
120 | end | 120 | end |
121 | - | 121 | + |
122 | def self.endpoint | 122 | def self.endpoint |
123 | class_name | 123 | class_name |
124 | end | 124 | end |
125 | - | 125 | + |
126 | def save_action | 126 | def save_action |
127 | "save_#{instance_class_name.underscore}".to_sym | 127 | "save_#{instance_class_name.underscore}".to_sym |
128 | end | 128 | end |
129 | - | 129 | + |
130 | def save_params | 130 | def save_params |
131 | {instance_class_name.underscore.to_sym => self.to_hash} | 131 | {instance_class_name.underscore.to_sym => self.to_hash} |
132 | end | 132 | end |
133 | - | 133 | + |
134 | def destroy_action | 134 | def destroy_action |
135 | "delete_#{instance_class_name.underscore}".to_sym | 135 | "delete_#{instance_class_name.underscore}".to_sym |
136 | end | 136 | end |
137 | - | 137 | + |
138 | def destroy_params | 138 | def destroy_params |
139 | {"#{instance_class_name.underscore}_id".to_sym => self.id} | 139 | {"#{instance_class_name.underscore}_id".to_sym => self.id} |
140 | end | 140 | end |
@@ -142,11 +142,11 @@ class Kalibro::Model | @@ -142,11 +142,11 @@ class Kalibro::Model | ||
142 | def self.class_name | 142 | def self.class_name |
143 | self.name.gsub(/Kalibro::/,"") | 143 | self.name.gsub(/Kalibro::/,"") |
144 | end | 144 | end |
145 | - | 145 | + |
146 | def self.exists_action | 146 | def self.exists_action |
147 | "#{class_name.underscore}_exists".to_sym | 147 | "#{class_name.underscore}_exists".to_sym |
148 | end | 148 | end |
149 | - | 149 | + |
150 | def self.id_params(id) | 150 | def self.id_params(id) |
151 | {"#{class_name.underscore}_id".to_sym => id} | 151 | {"#{class_name.underscore}_id".to_sym => id} |
152 | end | 152 | end |
plugins/mezuro/lib/kalibro/repository.rb
@@ -15,11 +15,15 @@ class Kalibro::Repository < Kalibro::Model | @@ -15,11 +15,15 @@ class Kalibro::Repository < Kalibro::Model | ||
15 | end | 15 | end |
16 | 16 | ||
17 | def process_repository | 17 | def process_repository |
18 | - self.class.request(:process_repository, {:repository_id => self.id}); | 18 | + self.class.request(:process_repository, {:repository_id => self.id}) |
19 | end | 19 | end |
20 | 20 | ||
21 | def cancel_processing_of_repository | 21 | def cancel_processing_of_repository |
22 | - self.class.request(:cancel_processing_of_repository, {:repository_id => self.id}); | 22 | + self.class.request(:cancel_processing_of_repository, {:repository_id => self.id}) |
23 | + end | ||
24 | + | ||
25 | + def save_params | ||
26 | + {:repository => self.to_hash, :project_id => Kalibro::Project.project_of(id).id} | ||
23 | end | 27 | end |
24 | 28 | ||
25 | end | 29 | end |
plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb
@@ -45,8 +45,8 @@ class MezuroPlugin::Helpers::ContentViewerHelper | @@ -45,8 +45,8 @@ class MezuroPlugin::Helpers::ContentViewerHelper | ||
45 | selected_option.first | 45 | selected_option.first |
46 | end | 46 | end |
47 | 47 | ||
48 | - def self.format_name(metric_result) | ||
49 | - metric_result.configuration.metric.name.delete("() ") | 48 | + def self.format_name(metric_configuration_snapshot) |
49 | + metric_configuration_snapshot.metric.name.delete("() ") | ||
50 | end | 50 | end |
51 | 51 | ||
52 | def self.get_license_option(selected) | 52 | def self.get_license_option(selected) |
plugins/mezuro/lib/mezuro_plugin/project_content.rb
1 | class MezuroPlugin::ProjectContent < Article | 1 | class MezuroPlugin::ProjectContent < Article |
2 | include ActionView::Helpers::TagHelper | 2 | include ActionView::Helpers::TagHelper |
3 | 3 | ||
4 | - settings_items :project_license, :description, :repository_type, :repository_url, :configuration_name, :periodicity_in_days | 4 | + settings_items :project_id |
5 | 5 | ||
6 | - validate_on_create :validate_kalibro_project_name | ||
7 | - validate_on_create :validate_repository_url | 6 | + validate_on_create :validate_repository_address |
8 | 7 | ||
9 | def self.short_description | 8 | def self.short_description |
10 | 'Mezuro project' | 9 | 'Mezuro project' |
@@ -22,90 +21,113 @@ class MezuroPlugin::ProjectContent < Article | @@ -22,90 +21,113 @@ class MezuroPlugin::ProjectContent < Article | ||
22 | 21 | ||
23 | def project | 22 | def project |
24 | begin | 23 | begin |
25 | - @project ||= Kalibro::Project.find_by_name(name) | 24 | + @project ||= Kalibro::Project.find(project_id) |
26 | rescue Exception => error | 25 | rescue Exception => error |
27 | errors.add_to_base(error.message) | 26 | errors.add_to_base(error.message) |
28 | end | 27 | end |
29 | @project | 28 | @project |
30 | end | 29 | end |
31 | 30 | ||
32 | - def project_result | 31 | + def repositories |
33 | begin | 32 | begin |
34 | - @project_result ||= Kalibro::ProjectResult.last_result(name) | 33 | + @repositories ||= Kalibro::Repository.repositories_of(project_id) |
35 | rescue Exception => error | 34 | rescue Exception => error |
36 | errors.add_to_base(error.message) | 35 | errors.add_to_base(error.message) |
36 | + @repositories = [] | ||
37 | end | 37 | end |
38 | - @project_result | 38 | + @repositories |
39 | end | 39 | end |
40 | - | ||
41 | - def project_result_with_date(date) | 40 | + |
41 | + def processing(repository_id) | ||
42 | begin | 42 | begin |
43 | - @project_result ||= Kalibro::ProjectResult.has_results_before?(name, date) ? Kalibro::ProjectResult.last_result_before(name, date) : | ||
44 | -Kalibro::ProjectResult.first_result_after(name, date) | 43 | + if Kalibro::Processing.has_ready_processing(repository_id) |
44 | + @processing ||= Kalibro::Processing.last_ready_processing_of(repository_id) | ||
45 | + else | ||
46 | + @processing = Kalibro::Processing.last_processing_of(repository_id) | ||
47 | + end | ||
45 | rescue Exception => error | 48 | rescue Exception => error |
46 | errors.add_to_base(error.message) | 49 | errors.add_to_base(error.message) |
47 | end | 50 | end |
48 | - @project_result | 51 | + @processing |
49 | end | 52 | end |
50 | 53 | ||
51 | - def module_result(attributes) | ||
52 | - module_name = attributes[:module_name].nil? ? project.name : attributes[:module_name] | ||
53 | - date = attributes[:date].nil? ? project_result.date : project_result_with_date(attributes[:date]).date | 54 | + def processing_with_date(repository_id, date) |
54 | begin | 55 | begin |
55 | - @module_result ||= Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date(name, module_name, date) | 56 | + if Kalibro::Processing.has_processing_after(repository_id, date) |
57 | + @processing ||= Kalibro::Processing.first_processing_after(repository_id, date) | ||
58 | + elsif Kalibro::Processing.has_processing_before(repository_id, date) | ||
59 | + @processing ||= Kalibro::Processing.last_processing_before(repository_id, date) | ||
60 | + end | ||
56 | rescue Exception => error | 61 | rescue Exception => error |
57 | errors.add_to_base(error.message) | 62 | errors.add_to_base(error.message) |
58 | end | 63 | end |
59 | - @module_result | 64 | + @processing |
60 | end | 65 | end |
61 | 66 | ||
62 | - def result_history(module_name) | 67 | + def module_result(repository_id, date = nil) |
68 | + @processing ||= date.nil? ? processing(repository_id) : processing_with_date(repository_id, date) | ||
63 | begin | 69 | begin |
64 | - @result_history ||= Kalibro::ModuleResult.all_by_project_name_and_module_name(name, module_name) | 70 | + @module_result ||= Kalibro::ModuleResult.find(@processing.results_root_id) |
65 | rescue Exception => error | 71 | rescue Exception => error |
66 | errors.add_to_base(error.message) | 72 | errors.add_to_base(error.message) |
67 | end | 73 | end |
74 | + @module_result | ||
68 | end | 75 | end |
69 | 76 | ||
70 | - after_save :send_project_to_service | ||
71 | - after_destroy :destroy_project_from_service | ||
72 | - | ||
73 | - private | ||
74 | - | ||
75 | - def validate_kalibro_project_name | 77 | + def result_history(module_result_id) |
76 | begin | 78 | begin |
77 | - existing = Kalibro::Project.all_names | 79 | + @result_history ||= Kalibro::MetricResult.history_of(module_result_id) |
78 | rescue Exception => error | 80 | rescue Exception => error |
79 | errors.add_to_base(error.message) | 81 | errors.add_to_base(error.message) |
80 | - existing = [] | ||
81 | - end | ||
82 | - | ||
83 | - if existing.any?{|existing_name| existing_name.casecmp(name)==0} # existing.include?(name) + case insensitive | ||
84 | - errors.add_to_base("Project name already exists in Kalibro") | ||
85 | end | 82 | end |
86 | end | 83 | end |
84 | + | ||
85 | + def description=(value) | ||
86 | + @description=value | ||
87 | + end | ||
87 | 88 | ||
88 | - def validate_repository_url | ||
89 | - if(repository_url.nil? || repository_url == "") | ||
90 | - errors.add_to_base("Repository URL is mandatory") | ||
91 | - end | 89 | + def description |
90 | + @description | ||
92 | end | 91 | end |
92 | + | ||
93 | + def repositories=(value) | ||
94 | + @repositories = value.kind_of?(Array) ? value : [value] | ||
95 | + @repositories = @repositories.map { |element| to_repository(element) } | ||
96 | + end | ||
97 | + | ||
98 | + after_save :send_project_to_service | ||
99 | + after_destroy :destroy_project_from_service | ||
100 | + | ||
101 | + private | ||
93 | 102 | ||
103 | + def self.to_repository value | ||
104 | + value.kind_of?(Hash) ? Kalibro::Repository.new(value) : value | ||
105 | + end | ||
106 | + | ||
107 | + def validate_repository_address | ||
108 | + repositories.each do |repository| | ||
109 | + if (!repository.nil?) | ||
110 | + address = repository.address | ||
111 | + if(address.nil? || address == "") | ||
112 | + errors.add_to_base("Repository Address is mandatory") | ||
113 | + end | ||
114 | + else | ||
115 | + errors.add_to_base("Repository is mandatory") | ||
116 | + end | ||
117 | + end | ||
118 | + end | ||
119 | + | ||
94 | def send_project_to_service | 120 | def send_project_to_service |
95 | created_project = create_kalibro_project | 121 | created_project = create_kalibro_project |
96 | - created_project.process_project(periodicity_in_days) | 122 | + repositories = Kalibro::Repository.repositories_of(project_id) |
123 | + repositories.each {|repository| repository.process_repository } | ||
97 | end | 124 | end |
98 | 125 | ||
99 | def create_kalibro_project | 126 | def create_kalibro_project |
100 | Kalibro::Project.create( | 127 | Kalibro::Project.create( |
128 | + :id => project_id, | ||
101 | :name => name, | 129 | :name => name, |
102 | - :license => project_license, | ||
103 | - :description => description, | ||
104 | - :repository => { | ||
105 | - :type => repository_type, | ||
106 | - :address => repository_url | ||
107 | - }, | ||
108 | - :configuration_name => configuration_name | 130 | + :description => description |
109 | ) | 131 | ) |
110 | end | 132 | end |
111 | 133 |
plugins/mezuro/public/javascripts/project_content.js
@@ -18,7 +18,7 @@ function display_metric_history() { | @@ -18,7 +18,7 @@ function display_metric_history() { | ||
18 | var metric_name = jQuery(this).attr('show-metric-history'); | 18 | var metric_name = jQuery(this).attr('show-metric-history'); |
19 | toggle_mezuro("." + metric_name); | 19 | toggle_mezuro("." + metric_name); |
20 | metricName = metric_name; | 20 | metricName = metric_name; |
21 | - callAction('module', 'module_metrics_history', {module_name: module_name, metric_name: metric_name}, show_metrics); | 21 | + callAction('module', 'module_metrics_history', {module_id: module_id, module_result_id: module_result_id}, show_metrics); |
22 | return false; | 22 | return false; |
23 | } | 23 | } |
24 | 24 |
plugins/mezuro/test/fixtures/project_content_fixtures.rb
0 → 100644
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +class ProjectContentFixtures | ||
2 | + | ||
3 | + def self.project_content | ||
4 | + content = MezuroPlugin::ProjectContent.new | ||
5 | + content.project_id = 42 | ||
6 | + #content.name = 'Qt-Calculator' | ||
7 | + #content.project_license = 'GPL' | ||
8 | + #content.description = 'Calculator for Qt' | ||
9 | + #content.repository_type = [RepositoryFixtures.repository_hash[:type]] | ||
10 | + #content.repository_url = [RepositoryFixtures.repository_hash[:address]] | ||
11 | + #content.configuration_name = 'Kalibro for Java' | ||
12 | + #content.periodicity_in_days = 1 | ||
13 | + content | ||
14 | + end | ||
15 | + | ||
16 | +end | ||
0 | \ No newline at end of file | 17 | \ No newline at end of file |
plugins/mezuro/test/fixtures/project_fixtures.rb
@@ -17,17 +17,4 @@ class ProjectFixtures | @@ -17,17 +17,4 @@ class ProjectFixtures | ||
17 | :description => 'Calculator for Qt' | 17 | :description => 'Calculator for Qt' |
18 | } | 18 | } |
19 | end | 19 | end |
20 | - | ||
21 | - def self.project_content | ||
22 | - content = MezuroPlugin::ProjectContent.new | ||
23 | - content.name = 'Qt-Calculator' | ||
24 | - content.project_license = 'GPL' | ||
25 | - content.description = 'Calculator for Qt' | ||
26 | - content.repository_type = RepositoryFixtures.repository_hash[:type] | ||
27 | - content.repository_url = RepositoryFixtures.repository_hash[:address] | ||
28 | - content.configuration_name = 'Kalibro for Java' | ||
29 | - content.periodicity_in_days = 1 | ||
30 | - content | ||
31 | - end | ||
32 | - | ||
33 | end | 20 | end |
plugins/mezuro/test/functional/profile/mezuro_plugin_module_controller_test.rb
1 | require 'test_helper' | 1 | require 'test_helper' |
2 | 2 | ||
3 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" | 3 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" |
4 | -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" | ||
5 | -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/error_fixtures" | ||
6 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/repository_fixtures" | 4 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/repository_fixtures" |
5 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" | ||
7 | 6 | ||
8 | class MezuroPluginModuleControllerTest < ActionController::TestCase | 7 | class MezuroPluginModuleControllerTest < ActionController::TestCase |
9 | 8 | ||
@@ -13,19 +12,23 @@ class MezuroPluginModuleControllerTest < ActionController::TestCase | @@ -13,19 +12,23 @@ class MezuroPluginModuleControllerTest < ActionController::TestCase | ||
13 | @response = ActionController::TestResponse.new | 12 | @response = ActionController::TestResponse.new |
14 | @profile = fast_create(Community) | 13 | @profile = fast_create(Community) |
15 | 14 | ||
16 | - @project_result = ProjectResultFixtures.project_result | 15 | + #@project_result = ProjectResultFixtures.project_result |
17 | @module_result = ModuleResultFixtures.module_result | 16 | @module_result = ModuleResultFixtures.module_result |
18 | @repository_url = RepositoryFixtures.repository.address | 17 | @repository_url = RepositoryFixtures.repository.address |
19 | - @project = @project_result.project | 18 | + @project = ProjectFixtures.project |
20 | @date = "2012-04-13T20:39:41+04:00" | 19 | @date = "2012-04-13T20:39:41+04:00" |
21 | 20 | ||
22 | - Kalibro::Project.expects(:all_names).returns([]) | ||
23 | - @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => @project.name, :repository_url => @repository_url) | 21 | + #Kalibro::Project.expects(:all_names).returns([]) |
22 | + @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :project_id => @project.id) | ||
24 | @content.expects(:send_project_to_service).returns(nil) | 23 | @content.expects(:send_project_to_service).returns(nil) |
25 | @content.save | 24 | @content.save |
25 | + | ||
26 | end | 26 | end |
27 | 27 | ||
28 | + should 'get module result' do | ||
29 | + end | ||
28 | 30 | ||
31 | +=begin | ||
29 | should 'get module result without date' do | 32 | should 'get module result without date' do |
30 | date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date) | 33 | date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date) |
31 | Kalibro::ProjectResult.expects(:request). | 34 | Kalibro::ProjectResult.expects(:request). |
@@ -70,5 +73,5 @@ class MezuroPluginModuleControllerTest < ActionController::TestCase | @@ -70,5 +73,5 @@ class MezuroPluginModuleControllerTest < ActionController::TestCase | ||
70 | assert_equal [[@module_result.grade, @module_result.date.to_s[0..9]]], assigns(:score_history) | 73 | assert_equal [[@module_result.grade, @module_result.date.to_s[0..9]]], assigns(:score_history) |
71 | assert_response 200 | 74 | assert_response 200 |
72 | end | 75 | end |
73 | - | 76 | +=end |
74 | end | 77 | end |
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | 2 | ||
3 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" | 3 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" |
4 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_content_fixtures" | ||
5 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/processing_fixtures" | ||
4 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_fixtures" | 6 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_fixtures" |
5 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" | 7 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" |
8 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_metric_result_fixtures" | ||
6 | 9 | ||
7 | class ProjectContentTest < ActiveSupport::TestCase | 10 | class ProjectContentTest < ActiveSupport::TestCase |
8 | 11 | ||
9 | def setup | 12 | def setup |
13 | + @project_content = ProjectContentFixtures.project_content | ||
10 | @project = ProjectFixtures.project | 14 | @project = ProjectFixtures.project |
11 | - @content = ProjectFixtures.project_content | ||
12 | - @project_result = ProjectResultFixtures.project_result | 15 | + @repository = RepositoryFixtures.repository |
16 | + @processing = ProcessingFixtures.processing | ||
17 | + @date = @processing.date | ||
13 | @module = ModuleFixtures.module | 18 | @module = ModuleFixtures.module |
14 | @module_result = ModuleResultFixtures.module_result | 19 | @module_result = ModuleResultFixtures.module_result |
20 | + @date_metric_result = DateMetricResultFixtures.date_metric_result | ||
15 | end | 21 | end |
16 | 22 | ||
17 | should 'provide proper short description' do | 23 | should 'provide proper short description' do |
@@ -23,98 +29,81 @@ class ProjectContentTest < ActiveSupport::TestCase | @@ -23,98 +29,81 @@ class ProjectContentTest < ActiveSupport::TestCase | ||
23 | end | 29 | end |
24 | 30 | ||
25 | should 'have an html view' do | 31 | should 'have an html view' do |
26 | - assert_not_nil @content.to_html | 32 | + assert_not_nil @project_content.to_html |
27 | end | 33 | end |
28 | 34 | ||
29 | should 'get project from service' do | 35 | should 'get project from service' do |
30 | - Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) | ||
31 | - assert_equal @project.name, @content.project.name | 36 | + Kalibro::Project.expects(:find).with(@project.id).returns(@project) |
37 | + assert_equal @project, @project_content.project | ||
32 | end | 38 | end |
33 | 39 | ||
34 | - should 'get project result from service' do | ||
35 | - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash}) | ||
36 | - assert_equal @project_result.load_time, @content.project_result.load_time | 40 | + should 'add error to base when the project does not exist' do |
41 | + Kalibro::Project.expects(:find).with(@project.id).raises(Kalibro::Errors::RecordNotFound) | ||
42 | + assert_nil @project_content.errors[:base] | ||
43 | + @project_content.project | ||
44 | + assert_not_nil @project_content.errors[:base] | ||
45 | + end | ||
46 | + | ||
47 | + should 'get repositories of the project from service' do | ||
48 | + Kalibro::Repository.expects(:repositories_of).with(@project.id).returns([@repository]) | ||
49 | + assert_equal [@repository], @project_content.repositories | ||
37 | end | 50 | end |
38 | 51 | ||
39 | - should 'get date result from service when has_result_before is true' do | ||
40 | - request_body = {:project_name => @project.name, :date => @project_result.date} | ||
41 | - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true}) | ||
42 | - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash}) | ||
43 | - assert_equal @project_result.load_time, @content.project_result_with_date(@project_result.date).load_time | 52 | + should 'add error to base when getting the repositories of a project that does not exist' do |
53 | + Kalibro::Repository.expects(:repositories_of).with(@project.id).raises(Kalibro::Errors::RecordNotFound) | ||
54 | + assert_nil @project_content.errors[:base] | ||
55 | + @project_content.repositories | ||
56 | + assert_not_nil @project_content.errors[:base] | ||
44 | end | 57 | end |
45 | - | ||
46 | - should 'get date result from service when has_result_before is false' do | ||
47 | - request_body = {:project_name => @project.name, :date => @project_result.date} | ||
48 | - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => false}) | ||
49 | - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_first_result_after, request_body).returns({:project_result => @project_result.to_hash}) | ||
50 | - assert_equal @project_result.load_time, @content.project_result_with_date(@project_result.date).load_time | 58 | + |
59 | + should 'get processing of a repository' do | ||
60 | + Kalibro::Processing.expects(:has_ready_processing).with(@repository.id).returns(true) | ||
61 | + Kalibro::Processing.expects(:last_ready_processing_of).with(@repository.id).returns(@processing) | ||
62 | + assert_equal @processing, @project_content.processing(@repository.id) | ||
51 | end | 63 | end |
52 | - | ||
53 | - should 'get module result from service without date' do | ||
54 | - date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date) | ||
55 | - Kalibro::ProjectResult.expects(:request).with('ProjectResult', :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash}) | ||
56 | - Kalibro::ModuleResult.expects(:request).with( | ||
57 | - 'ModuleResult', | ||
58 | - :get_module_result, | ||
59 | - { | ||
60 | - :project_name => @project.name, | ||
61 | - :module_name => @module.name, | ||
62 | - :date => date_with_milliseconds | ||
63 | - }).returns({:module_result => @module_result.to_hash}) | ||
64 | - assert_equal @module_result.grade, @content.module_result({:module_name => @module.name}).grade | 64 | + |
65 | + should 'get not ready processing of a repository' do | ||
66 | + Kalibro::Processing.expects(:has_ready_processing).with(@repository.id).returns(false) | ||
67 | + Kalibro::Processing.expects(:last_processing_of).with(@repository.id).returns(@processing) | ||
68 | + assert_equal @processing, @project_content.processing(@repository.id) | ||
65 | end | 69 | end |
66 | - | ||
67 | - should 'get module result from service with date' do | ||
68 | - date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date) | ||
69 | - request_body = {:project_name => @project.name, :date => @project_result.date} | ||
70 | - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => false}) | ||
71 | - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_first_result_after, request_body).returns({:project_result => @project_result.to_hash}) | ||
72 | - Kalibro::ModuleResult.expects(:request).with( | ||
73 | - 'ModuleResult', | ||
74 | - :get_module_result, | ||
75 | - { | ||
76 | - :project_name => @project.name, | ||
77 | - :module_name => @module.name, | ||
78 | - :date => date_with_milliseconds | ||
79 | - }).returns({:module_result => @module_result.to_hash}) | ||
80 | - assert_equal @module_result.grade, @content.module_result({:module_name => @module.name, :date => @project_result.date}).grade | 70 | + |
71 | + should 'get processing of a repository after date' do | ||
72 | + Kalibro::Processing.expects(:has_processing_after).with(@repository.id, @date).returns(true) | ||
73 | + Kalibro::Processing.expects(:first_processing_after).with(@repository.id, @date).returns(@processing) | ||
74 | + assert_equal @processing, @project_content.processing_with_date(@repository.id, @date) | ||
81 | end | 75 | end |
82 | - | ||
83 | - should 'get result history' do | ||
84 | - Kalibro::ModuleResult.expects(:request).with( | ||
85 | - 'ModuleResult', | ||
86 | - :get_result_history, | ||
87 | - { | ||
88 | - :project_name => @project.name, | ||
89 | - :module_name => @module.name | ||
90 | - }).returns({:module_result => @module_result.to_hash}) | ||
91 | - @content.result_history(@module.name) | 76 | + |
77 | + should 'get processing of a repository before date' do | ||
78 | + Kalibro::Processing.expects(:has_processing_after).with(@repository.id, @date).returns(false) | ||
79 | + Kalibro::Processing.expects(:has_processing_before).with(@repository.id, @date).returns(true) | ||
80 | + Kalibro::Processing.expects(:last_processing_before).with(@repository.id, @date).returns(@processing) | ||
81 | + assert_equal @processing, @project_content.processing_with_date(@repository.id, @date) | ||
92 | end | 82 | end |
93 | 83 | ||
94 | - should 'send project to service after saving' do | ||
95 | - @content.expects :send_project_to_service | ||
96 | - @content.run_callbacks :after_save | 84 | + should 'get module result' do |
85 | + @project_content.expects(:processing).with(@repository.id).returns(@processing) | ||
86 | + Kalibro::ModuleResult.expects(:find).with(@processing.results_root_id).returns(@module_result) | ||
87 | + assert_equal @module_result, @project_content.module_result(@repository.id) | ||
88 | + | ||
89 | + end | ||
90 | + | ||
91 | + should 'get module result with date' do | ||
92 | + @project_content.expects(:processing_with_date).with(@repository.id,@date.to_s).returns(@processing) | ||
93 | + Kalibro::ModuleResult.expects(:find).with(@processing.results_root_id).returns(@module_result) | ||
94 | + assert_equal @module_result, @project_content.module_result(@repository.id, @date.to_s) | ||
97 | end | 95 | end |
98 | 96 | ||
99 | - should 'send correct project to service' do | ||
100 | - hash = ProjectFixtures.project_hash | ||
101 | - hash.delete(:attributes!) | ||
102 | - hash.delete(:state) | ||
103 | - Kalibro::Project.expects(:create).with(hash).returns(@project) | ||
104 | - @project.expects(:process_project).with(@content.periodicity_in_days) | ||
105 | - @content.send :send_project_to_service | 97 | + should 'get result history' do |
98 | + Kalibro::MetricResult.expects(:history_of).with(@module_result.id).returns([@date_metric_result]) | ||
99 | + assert_equal [@date_metric_result], @project_content.result_history(@module_result.id) | ||
106 | end | 100 | end |
107 | 101 | ||
108 | - should 'destroy project from service' do | ||
109 | - Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) | ||
110 | - Kalibro::Project.expects(:request).with("Project", :remove_project, {:project_name => @project.name}) | ||
111 | - @content.send :destroy_project_from_service | 102 | + should 'add error to base when the module_result does not exist' do |
103 | + Kalibro::MetricResult.expects(:history_of).with(@module_result.id).raises(Kalibro::Errors::RecordNotFound) | ||
104 | + assert_nil @project_content.errors[:base] | ||
105 | + @project_content.result_history(@module_result.id) | ||
106 | + assert_not_nil @project_content.errors[:base] | ||
112 | end | 107 | end |
113 | - | ||
114 | - should 'not save a project with an existing project name in kalibro' do | ||
115 | - Kalibro::Project.expects(:all_names).returns([@content.name]) | ||
116 | - @content.send :validate_kalibro_project_name | ||
117 | - assert_equal "Project name already exists in Kalibro", @content.errors.on_base | ||
118 | - end | ||
119 | - | 108 | + |
120 | end | 109 | end |
plugins/mezuro/views/mezuro_plugin_module/_module_result.rhtml
1 | -<h5><%= _('Metric results for: ') + @module_label %> </h5> | 1 | +<% module_name = @module_result.module.name |
2 | +<h5><%= _('Metric results for: #{module_name} (#{@module_result.module.granularity}) ') %> </h5> | ||
2 | 3 | ||
3 | <hr/> | 4 | <hr/> |
4 | <div class="zoomable-image"> | 5 | <div class="zoomable-image"> |
@@ -12,26 +13,28 @@ | @@ -12,26 +13,28 @@ | ||
12 | </tr> | 13 | </tr> |
13 | </thead> | 14 | </thead> |
14 | <tbody> | 15 | <tbody> |
15 | - <% @module_result.metric_results.each do |metric_result| %> | ||
16 | - <% range = metric_result.range %> | ||
17 | - <% if !range.nil? %> | 16 | + <% @metric_results.each do |metric_result| %> |
17 | + <% metric_configuration_snapshot = metric_result.metric_configuration_snapshot%> | ||
18 | + <% range_snapshot = metric_configuration_snapshot.range_snapshot %> | ||
19 | + <% formatted_name = MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_configuration_snapshot) %> | ||
20 | + <% if !range_snapshot.nil? %> | ||
18 | <tr> | 21 | <tr> |
19 | - <td style="width: 74%"><a href="#" show-metric-history="<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>" data-module-name="<%= @module.name %>"><%= metric_result.metric.name %></a></td> | 22 | + <td style="width: 74%"><a href="#" show-metric-history="<%= formatted_name %>" data-module-name="<%= module_name %>"><%= metric_configuration_snapshot.metric.name %></a></td> |
20 | <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %></td> | 23 | <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %></td> |
21 | - <td><%= metric_result.weight %></td> | ||
22 | - <td style="background-color: #<%= range.color[2..-1] %>"> | ||
23 | - <span title="<%= range.comments %>" > | ||
24 | - <%= range.label %> | 24 | + <td><%= metric_configuration_snapshot.weight %></td> |
25 | + <td style="background-color: #<%= range_snapshot.color %>"> | ||
26 | + <span title="<%= range_snapshot.comments %>" > | ||
27 | + <%= range_snapshot.label %> | ||
25 | </span> | 28 | </span> |
26 | </td> | 29 | </td> |
27 | </tr> | 30 | </tr> |
28 | - <tr class="<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>" style="display: none;"> | 31 | + <tr class="<%= formatted_name %>" style="display: none;"> |
29 | <td colspan="3"> | 32 | <td colspan="3"> |
30 | - <div id='historical-<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>'> | 33 | + <div id='historical-<%= formatted_name %>'> |
31 | </div> | 34 | </div> |
32 | </td> | 35 | </td> |
33 | <td align="right"> | 36 | <td align="right"> |
34 | - <%= range.comments.nil? ? '' : range.comments %> | 37 | + <%= range_snapshot.comments.nil? ? '' : range_snapshot.comments %> |
35 | </td> | 38 | </td> |
36 | </tr> | 39 | </tr> |
37 | <% end %> | 40 | <% end %> |
@@ -43,7 +46,7 @@ | @@ -43,7 +46,7 @@ | ||
43 | <div id='historical-grade' style="display: none;"></div> | 46 | <div id='historical-grade' style="display: none;"></div> |
44 | </td> | 47 | </td> |
45 | <td align = "right"> | 48 | <td align = "right"> |
46 | - <a href="#" show-grade-history="<%= @module_result.module.name %>" data-module-name="<%= @module.name%>" > | 49 | + <a href="#" show-grade-history="<%= module_name %>" data-module-name="<%= module_name%>" > |
47 | <strong> | 50 | <strong> |
48 | <%= _('Grade:') %> | 51 | <%= _('Grade:') %> |
49 | <%= "%.02f" % @module_result.grade %> | 52 | <%= "%.02f" % @module_result.grade %> |