Commit 25ebd3b10093fa96800ae2712872cc1467f85138
Committed by
João M. M. da Silva
1 parent
55a9a0db
Exists in
master
and in
29 other branches
[Mezuro] processing action in processing controller
Showing
11 changed files
with
91 additions
and
147 deletions
Show diff stats
plugins/mezuro/controllers/profile/mezuro_plugin_processing_controller.rb
| ... | ... | @@ -8,22 +8,13 @@ class MezuroPluginProcessingController < MezuroPluginProfileController |
| 8 | 8 | render :text => last_state |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | - def processing_error | |
| 12 | - @content = profile.articles.find(params[:id]) | |
| 13 | - @processing = @content.processing | |
| 14 | - if project_content_has_errors? | |
| 15 | - redirect_to_error_page(@content.errors[:base]) | |
| 16 | - else | |
| 17 | - render :partial => 'processing_error' | |
| 18 | - end | |
| 19 | - end | |
| 20 | - | |
| 21 | 11 | def processing |
| 22 | - @content = profile.articles.find(params[:id]) | |
| 23 | 12 | date = params[:date] |
| 24 | - @processing = date.nil? ? @content.processing : @content.processing_with_date(date) | |
| 25 | - if project_content_has_errors? | |
| 26 | - redirect_to_error_page(@content.errors[:base]) | |
| 13 | + repository_id = params[:repository_id].to_i | |
| 14 | + processing_class = Kalibro::Processing | |
| 15 | + @processing = date.nil? ? processing_class.processing_of(repository_id) : processing_class.processing_with_date_of(repository_id, date) | |
| 16 | + if @processing.state == 'ERROR' | |
| 17 | + render :partial => 'processing_error' | |
| 27 | 18 | else |
| 28 | 19 | render :partial => 'processing' |
| 29 | 20 | end | ... | ... |
plugins/mezuro/lib/kalibro/processing.rb
| ... | ... | @@ -6,7 +6,7 @@ class Kalibro::Processing < Kalibro::Model |
| 6 | 6 | def self.processing_of(repository_id) |
| 7 | 7 | if has_ready_processing(repository_id) |
| 8 | 8 | last_ready_processing_of(repository_id) |
| 9 | - else | |
| 9 | + else #always exists a processing, we send a requisition to kalibro to process repository | |
| 10 | 10 | last_processing_of(repository_id) |
| 11 | 11 | end |
| 12 | 12 | end |
| ... | ... | @@ -37,6 +37,10 @@ class Kalibro::Processing < Kalibro::Model |
| 37 | 37 | process_time |
| 38 | 38 | end |
| 39 | 39 | |
| 40 | + def error=(value) | |
| 41 | + @error = Kalibro::Throwable.to_object value | |
| 42 | + end | |
| 43 | + | |
| 40 | 44 | private |
| 41 | 45 | |
| 42 | 46 | def self.has_processing(repository_id) | ... | ... |
plugins/mezuro/test/fixtures/processing_fixtures.rb
| 1 | 1 | require File.dirname(__FILE__) + '/process_time_fixtures' |
| 2 | +require File.dirname(__FILE__) + '/throwable_fixtures' | |
| 2 | 3 | |
| 3 | 4 | class ProcessingFixtures |
| 4 | 5 | |
| 5 | 6 | def self.processing |
| 6 | 7 | Kalibro::Processing.new processing_hash |
| 7 | 8 | end |
| 8 | - | |
| 9 | + | |
| 9 | 10 | def self.processing_hash |
| 10 | 11 | { |
| 11 | 12 | :id => 31, |
| 12 | 13 | :date => '2011-10-20T18:26:43.151+00:00', |
| 13 | 14 | :state => 'READY', |
| 14 | 15 | :process_time => [ProcessTimeFixtures.process_time_hash], |
| 15 | - :results_root_id => 13 | |
| 16 | + :results_root_id => 13 | |
| 16 | 17 | } |
| 17 | 18 | end |
| 18 | - | |
| 19 | + | |
| 20 | + def self.processing_with_error_hash | |
| 21 | + { | |
| 22 | + :id => 31, | |
| 23 | + :date => '2011-10-20T18:26:43.151+00:00', | |
| 24 | + :state => 'ERROR', | |
| 25 | + :process_time => [ProcessTimeFixtures.process_time_hash], | |
| 26 | + :error => ThrowableFixtures.throwable_hash | |
| 27 | + } | |
| 28 | + end | |
| 29 | + | |
| 19 | 30 | end | ... | ... |
plugins/mezuro/test/functional/profile/mezuro_plugin_processing_controller_test.rb
| ... | ... | @@ -12,9 +12,10 @@ class MezuroPluginProcessingControllerTest < ActionController::TestCase |
| 12 | 12 | @response = ActionController::TestResponse.new |
| 13 | 13 | @profile = fast_create(Community) |
| 14 | 14 | |
| 15 | - @repository = RepositoryFixtures.repository | |
| 15 | + @repository_id = RepositoryFixtures.repository.id | |
| 16 | 16 | @processing = ProcessingFixtures.processing |
| 17 | - | |
| 17 | + @processing_hash = ProcessingFixtures.processing_hash | |
| 18 | + @processing_with_error_hash = ProcessingFixtures.processing_with_error_hash | |
| 18 | 19 | =begin |
| 19 | 20 | @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => @project.name, :repository_url => @repository_url) |
| 20 | 21 | @content.expects(:send_project_to_service).returns(nil) |
| ... | ... | @@ -26,51 +27,40 @@ class MezuroPluginProcessingControllerTest < ActionController::TestCase |
| 26 | 27 | end |
| 27 | 28 | |
| 28 | 29 | should 'render last processing state' do |
| 29 | - Kalibro::Processing.expects(:request).with(:last_processing_state, :repository_id => @repository.id).returns({:process_state => @processing.state}) | |
| 30 | - get :render_last_state, :profile => @profile.identifier, :repository_id => @repository.id | |
| 30 | + Kalibro::Processing.expects(:request).with(:last_processing_state, :repository_id => @repository_id).returns({:process_state => @processing.state}) | |
| 31 | + get :render_last_state, :profile => @profile.identifier, :repository_id => @repository_id | |
| 31 | 32 | assert_response 200 |
| 32 | 33 | assert_equal @processing.state, @response.body |
| 33 | 34 | end |
| 34 | 35 | |
| 35 | -#TODO refatorar todos os testes | |
| 36 | -=begin | |
| 37 | - should 'test project state with kalibro_error' do | |
| 38 | - Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash.merge({:error => ThrowableFixtures.throwable_hash})}) | |
| 39 | - get :project_state, :profile => @profile.identifier, :id => @content.id | |
| 40 | - assert_response 200 | |
| 41 | - assert_equal "ERROR", @response.body | |
| 42 | - assert_equal @content, assigns(:content) | |
| 43 | - end | |
| 44 | 36 | |
| 45 | - should 'test project error' do | |
| 46 | - Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash.merge({:error => ThrowableFixtures.throwable_hash})}) | |
| 47 | - get :project_error, :profile => @profile.identifier, :id => @content.id | |
| 37 | + should 'render processing with error' do | |
| 38 | + Kalibro::Processing.expects(:request).with(:has_ready_processing, {:repository_id => @repository_id}).returns({:exists => false}) | |
| 39 | + Kalibro::Processing.expects(:request).with(:last_processing, :repository_id => @repository_id).returns({:processing => @processing_with_error_hash}) | |
| 40 | + get :processing, :profile => @profile.identifier, :repository_id => @repository_id | |
| 48 | 41 | assert_response 200 |
| 49 | - assert_select('h3', 'ERROR') | |
| 50 | - assert_equal @content, assigns(:content) | |
| 51 | - assert_equal @project.name, assigns(:project).name | |
| 42 | + assert_equal @processing_with_error_hash[:state], assigns(:processing).state | |
| 43 | + #TODO How to assert from view? assert_select('h3', 'ERROR') | |
| 52 | 44 | end |
| 53 | 45 | |
| 54 | 46 | should 'test project result without date' do |
| 55 | - Kalibro::Processing.expects(:request).with("Processing", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash}) | |
| 56 | - get :project_result, :profile => @profile.identifier, :id => @content.id, :date => nil | |
| 57 | - assert_equal @content, assigns(:content) | |
| 58 | - assert_equal @project_result.project.name, assigns(:project_result).project.name | |
| 47 | + Kalibro::Processing.expects(:request).with(:has_ready_processing, {:repository_id => @repository_id}).returns({:exists => true}) | |
| 48 | + Kalibro::Processing.expects(:request).with(:last_ready_processing, {:repository_id => @repository_id}).returns({:processing => @processing_hash}) | |
| 49 | + get :processing, :profile => @profile.identifier, :repository_id => @repository_id | |
| 59 | 50 | assert_response 200 |
| 60 | 51 | assert_select('h4', 'Last Result') |
| 61 | 52 | end |
| 62 | 53 | |
| 63 | 54 | should 'test project results from a specific date' do |
| 64 | - request_body = {:project_name => @project.name, :date => @date} | |
| 65 | - Kalibro::Processing.expects(:request).with("Processing", :has_results_before, request_body).returns({:has_results => true}) | |
| 66 | - Kalibro::Processing.expects(:request).with("Processing", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash}) | |
| 67 | - get :project_result, :profile => @profile.identifier, :id => @content.id, :date => @date | |
| 68 | - assert_equal @content, assigns(:content) | |
| 69 | - assert_equal @project_result.project.name, assigns(:project_result).project.name | |
| 55 | + Kalibro::Processing.expects(:request).with(:has_processing_after, {:repository_id => @repository_id, :date => @processing.date}).returns({:exists => true}) | |
| 56 | + Kalibro::Processing.expects(:request).with(:first_processing_after, :repository_id => @repository_id, :date => @processing.date).returns({:processing => @processing_hash}) | |
| 57 | + get :processing, :profile => @profile.identifier, :repository_id => @repository_id, :date => @processing.date | |
| 70 | 58 | assert_response 200 |
| 71 | 59 | assert_select('h4', 'Last Result') |
| 72 | 60 | end |
| 73 | 61 | |
| 62 | +#TODO refatorar todos os testes | |
| 63 | +=begin | |
| 74 | 64 | should 'test project tree without date' do |
| 75 | 65 | Kalibro::Processing.expects(:request).with("Processing", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash}) |
| 76 | 66 | Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) | ... | ... |
plugins/mezuro/views/mezuro_plugin_processing/_error_page.html.erb
0 → 100644
plugins/mezuro/views/mezuro_plugin_processing/_processing.rhtml
0 → 100644
| ... | ... | @@ -0,0 +1,34 @@ |
| 1 | +<div id="current_processing_date" data-date="<%= @processing.date %>"/> | |
| 2 | + | |
| 3 | +<h4><%= _('Last Result') %></h4> | |
| 4 | + | |
| 5 | +<table> | |
| 6 | + <tr> | |
| 7 | + <td><%= _('Date') %></td> | |
| 8 | + <td><%= @processing.date %></td> | |
| 9 | + </tr> | |
| 10 | + <% @processing.process_time.each do |process_time| %> | |
| 11 | + <tr> | |
| 12 | + <td><%= _(process_time.state + ' time') %></td> | |
| 13 | + <td><%= process_time.time %></td> | |
| 14 | + </tr> | |
| 15 | + <% end %> | |
| 16 | + <tr> | |
| 17 | + <td>Click to choose specific date:</td> | |
| 18 | + <td><%= link_to(image_tag('/images/calendar_date_select/calendar.png', :width => 20, :height => 20, :onClick => "$( 'datepicker' ).toggle();"), "javascript:void(0)") %></td> | |
| 19 | + </tr> | |
| 20 | +</table> | |
| 21 | + | |
| 22 | +<div id="datepicker"></div> | |
| 23 | + | |
| 24 | +<script> | |
| 25 | + jQuery(document).ready(function($) { | |
| 26 | + $("#datepicker").datepicker({ | |
| 27 | + onSelect: function(dateText, inst) { | |
| 28 | + reloadProjectWithDate(dateText) } }); | |
| 29 | + $("#datepicker").toggle(); | |
| 30 | + var date = jQuery("#current_processing_date").attr('data-date').substr(0,10); | |
| 31 | + $("#datepicker").datepicker( "setDate" , date ); | |
| 32 | + | |
| 33 | + }); | |
| 34 | +</script> | ... | ... |
plugins/mezuro/views/mezuro_plugin_processing/_processing_error.rhtml
0 → 100644
| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | +<h3><%= _('ERROR') %></h3> | |
| 2 | +<p> | |
| 3 | + <%= "State when error ocurred: #{@processing.state}" %> | |
| 4 | + <br/> | |
| 5 | + <% error = @processing.error %> | |
| 6 | + <%= error.message %> | |
| 7 | +<ul> | |
| 8 | + <% error.stack_trace.each do |trace| %> | |
| 9 | + <li><%= "#{trace.declaring_class}.#{trace.method_name}(#{trace.file_name}:#{trace.line_number})" %></li> | |
| 10 | + <% end %> | |
| 11 | +</ul> | |
| 12 | +</p> | ... | ... |
plugins/mezuro/views/mezuro_plugin_project/_error_page.html.erb
plugins/mezuro/views/mezuro_plugin_project/_project_error.rhtml
| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | -<h3><%= _('ERROR') %></h3> | |
| 2 | -<p> | |
| 3 | - <%= "State when error ocurred: #{@project.state}" %> | |
| 4 | - <br/> | |
| 5 | - <% error = @project.kalibro_error %> | |
| 6 | - <%= error.message %> | |
| 7 | -<ul> | |
| 8 | - <% error.stack_trace.each do |trace| %> | |
| 9 | - <li><%= "#{trace.declaring_class}.#{trace.method_name}(#{trace.file_name}:#{trace.line_number})" %></li> | |
| 10 | - <% end %> | |
| 11 | -</ul> | |
| 12 | -</p> |
plugins/mezuro/views/mezuro_plugin_project/_project_result.rhtml
| ... | ... | @@ -1,41 +0,0 @@ |
| 1 | -<% unless @content.errors[:base].nil? %> | |
| 2 | - <%= @content.errors[:base] %> | |
| 3 | -<% else %> | |
| 4 | - <div id="current_project_date" data-date="<%= @project_result.date %>"/> | |
| 5 | - | |
| 6 | - <h4><%= _('Last Result') %></h4> | |
| 7 | - | |
| 8 | - <table> | |
| 9 | - <tr> | |
| 10 | - <td><%= _('Date') %></td> | |
| 11 | - <td><%= @project_result.date %></td> | |
| 12 | - </tr> | |
| 13 | - <tr> | |
| 14 | - <td><%= _('Load time') %></td> | |
| 15 | - <td><%= @project_result.formatted_load_time %></td> | |
| 16 | - </tr> | |
| 17 | - <tr> | |
| 18 | - <td><%= _('Analysis time') %></td> | |
| 19 | - <td><%= @project_result.formatted_analysis_time %></td> | |
| 20 | - </tr> | |
| 21 | - <tr> | |
| 22 | - <td>Click to choose specific date:</td> | |
| 23 | - <td><%= link_to(image_tag('/images/calendar_date_select/calendar.png', :width => 20, :height => 20, :onClick => "$( 'datepicker' ).toggle();"), "javascript:void(0)") %></td> | |
| 24 | - </tr> | |
| 25 | - </table> | |
| 26 | - | |
| 27 | - <div id="datepicker"></div> | |
| 28 | - | |
| 29 | - <script> | |
| 30 | - jQuery(document).ready(function($) { | |
| 31 | - $("#datepicker").datepicker({ | |
| 32 | - onSelect: function(dateText, inst) { | |
| 33 | - reloadProjectWithDate(dateText) } }); | |
| 34 | - $("#datepicker").toggle(); | |
| 35 | - var date = jQuery("#current_project_date").attr('data-date').substr(0,10); | |
| 36 | - $("#datepicker").datepicker( "setDate" , date ); | |
| 37 | - | |
| 38 | - }); | |
| 39 | - </script> | |
| 40 | - | |
| 41 | -<% end %> |
plugins/mezuro/views/mezuro_plugin_project/_source_tree.rhtml
| ... | ... | @@ -1,45 +0,0 @@ |
| 1 | -<% unless @content.errors[:base].nil? %> | |
| 2 | - <%= @content.errors[:base] %> | |
| 3 | -<% else %> | |
| 4 | - <h4><%= _('Source tree') %></h4> | |
| 5 | - <% module_name = @source_tree.module.name %> | |
| 6 | - <% module_label = "#{module_name} (#{@source_tree.module.granularity})" %> | |
| 7 | - | |
| 8 | - <p><h2 class="path"> | |
| 9 | - <% if module_name != @project_name %> | |
| 10 | - <a href="#" class="source-tree-link" data-module-name="<%= @project_name %>"> | |
| 11 | - <%= @project_name %> | |
| 12 | - </a> | |
| 13 | - <% end %> | |
| 14 | - | |
| 15 | - | |
| 16 | - <% split_link = @source_tree.module.ancestor_names %> | |
| 17 | - <% split_link.each do |link| %> | |
| 18 | - /<a href="#" class="source-tree-link" data-module-name="<%= link %>"> | |
| 19 | - <%= link.split(".").last %> | |
| 20 | - </a> | |
| 21 | - <% end %> | |
| 22 | - </h2></p> | |
| 23 | - | |
| 24 | - <% if @source_tree.children %> | |
| 25 | - <table border="0" class="source-tree"> | |
| 26 | - <% @source_tree.children.each do |child| %> | |
| 27 | - <% if child.module.granularity=='PACKAGE' %> | |
| 28 | - <tr> | |
| 29 | - <td class="icon"><%= image_tag('/plugins/mezuro/images/folder.png')%></td> | |
| 30 | - <td class="source-tree-text"><a href='#' class="source-tree-link" data-module-name="<%= child.module.name %>"><%= child.module.name %></a></td> | |
| 31 | - </tr> | |
| 32 | - <% else %> | |
| 33 | - <tr> | |
| 34 | - <td class="icon"><%= image_tag('/plugins/mezuro/images/file.png') %></td> | |
| 35 | - <td class="source-tree-text"> | |
| 36 | - <a href='#' class="source-tree-link" data-module-name="<%= child.module.name %>"> | |
| 37 | - <%= child.module.name %> | |
| 38 | - </a> | |
| 39 | - </td> | |
| 40 | - </tr> | |
| 41 | - <% end %> | |
| 42 | - <% end %> | |
| 43 | - </table> | |
| 44 | - <% end %> | |
| 45 | -<% end %> |