diff --git a/plugins/mezuro/controllers/profile/mezuro_plugin_processing_controller.rb b/plugins/mezuro/controllers/profile/mezuro_plugin_processing_controller.rb index 378e337..8b56d5d 100644 --- a/plugins/mezuro/controllers/profile/mezuro_plugin_processing_controller.rb +++ b/plugins/mezuro/controllers/profile/mezuro_plugin_processing_controller.rb @@ -8,22 +8,13 @@ class MezuroPluginProcessingController < MezuroPluginProfileController render :text => last_state end - def processing_error - @content = profile.articles.find(params[:id]) - @processing = @content.processing - if project_content_has_errors? - redirect_to_error_page(@content.errors[:base]) - else - render :partial => 'processing_error' - end - end - def processing - @content = profile.articles.find(params[:id]) date = params[:date] - @processing = date.nil? ? @content.processing : @content.processing_with_date(date) - if project_content_has_errors? - redirect_to_error_page(@content.errors[:base]) + repository_id = params[:repository_id].to_i + processing_class = Kalibro::Processing + @processing = date.nil? ? processing_class.processing_of(repository_id) : processing_class.processing_with_date_of(repository_id, date) + if @processing.state == 'ERROR' + render :partial => 'processing_error' else render :partial => 'processing' end diff --git a/plugins/mezuro/lib/kalibro/processing.rb b/plugins/mezuro/lib/kalibro/processing.rb index ea5c1a8..7adba10 100644 --- a/plugins/mezuro/lib/kalibro/processing.rb +++ b/plugins/mezuro/lib/kalibro/processing.rb @@ -6,7 +6,7 @@ class Kalibro::Processing < Kalibro::Model def self.processing_of(repository_id) if has_ready_processing(repository_id) last_ready_processing_of(repository_id) - else + else #always exists a processing, we send a requisition to kalibro to process repository last_processing_of(repository_id) end end @@ -37,6 +37,10 @@ class Kalibro::Processing < Kalibro::Model process_time end + def error=(value) + @error = Kalibro::Throwable.to_object value + end + private def self.has_processing(repository_id) diff --git a/plugins/mezuro/test/fixtures/processing_fixtures.rb b/plugins/mezuro/test/fixtures/processing_fixtures.rb index bddb81a..735f4c5 100644 --- a/plugins/mezuro/test/fixtures/processing_fixtures.rb +++ b/plugins/mezuro/test/fixtures/processing_fixtures.rb @@ -1,19 +1,30 @@ require File.dirname(__FILE__) + '/process_time_fixtures' +require File.dirname(__FILE__) + '/throwable_fixtures' class ProcessingFixtures def self.processing Kalibro::Processing.new processing_hash end - + def self.processing_hash { :id => 31, :date => '2011-10-20T18:26:43.151+00:00', :state => 'READY', :process_time => [ProcessTimeFixtures.process_time_hash], - :results_root_id => 13 + :results_root_id => 13 } end - + + def self.processing_with_error_hash + { + :id => 31, + :date => '2011-10-20T18:26:43.151+00:00', + :state => 'ERROR', + :process_time => [ProcessTimeFixtures.process_time_hash], + :error => ThrowableFixtures.throwable_hash + } + end + end diff --git a/plugins/mezuro/test/functional/profile/mezuro_plugin_processing_controller_test.rb b/plugins/mezuro/test/functional/profile/mezuro_plugin_processing_controller_test.rb index fef8c5e..77b8b55 100644 --- a/plugins/mezuro/test/functional/profile/mezuro_plugin_processing_controller_test.rb +++ b/plugins/mezuro/test/functional/profile/mezuro_plugin_processing_controller_test.rb @@ -12,9 +12,10 @@ class MezuroPluginProcessingControllerTest < ActionController::TestCase @response = ActionController::TestResponse.new @profile = fast_create(Community) - @repository = RepositoryFixtures.repository + @repository_id = RepositoryFixtures.repository.id @processing = ProcessingFixtures.processing - + @processing_hash = ProcessingFixtures.processing_hash + @processing_with_error_hash = ProcessingFixtures.processing_with_error_hash =begin @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => @project.name, :repository_url => @repository_url) @content.expects(:send_project_to_service).returns(nil) @@ -26,51 +27,40 @@ class MezuroPluginProcessingControllerTest < ActionController::TestCase end should 'render last processing state' do - Kalibro::Processing.expects(:request).with(:last_processing_state, :repository_id => @repository.id).returns({:process_state => @processing.state}) - get :render_last_state, :profile => @profile.identifier, :repository_id => @repository.id + Kalibro::Processing.expects(:request).with(:last_processing_state, :repository_id => @repository_id).returns({:process_state => @processing.state}) + get :render_last_state, :profile => @profile.identifier, :repository_id => @repository_id assert_response 200 assert_equal @processing.state, @response.body end -#TODO refatorar todos os testes -=begin - should 'test project state with kalibro_error' do - Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash.merge({:error => ThrowableFixtures.throwable_hash})}) - get :project_state, :profile => @profile.identifier, :id => @content.id - assert_response 200 - assert_equal "ERROR", @response.body - assert_equal @content, assigns(:content) - end - should 'test project error' do - Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash.merge({:error => ThrowableFixtures.throwable_hash})}) - get :project_error, :profile => @profile.identifier, :id => @content.id + should 'render processing with error' do + Kalibro::Processing.expects(:request).with(:has_ready_processing, {:repository_id => @repository_id}).returns({:exists => false}) + Kalibro::Processing.expects(:request).with(:last_processing, :repository_id => @repository_id).returns({:processing => @processing_with_error_hash}) + get :processing, :profile => @profile.identifier, :repository_id => @repository_id assert_response 200 - assert_select('h3', 'ERROR') - assert_equal @content, assigns(:content) - assert_equal @project.name, assigns(:project).name + assert_equal @processing_with_error_hash[:state], assigns(:processing).state + #TODO How to assert from view? assert_select('h3', 'ERROR') end should 'test project result without date' do - Kalibro::Processing.expects(:request).with("Processing", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash}) - get :project_result, :profile => @profile.identifier, :id => @content.id, :date => nil - assert_equal @content, assigns(:content) - assert_equal @project_result.project.name, assigns(:project_result).project.name + Kalibro::Processing.expects(:request).with(:has_ready_processing, {:repository_id => @repository_id}).returns({:exists => true}) + Kalibro::Processing.expects(:request).with(:last_ready_processing, {:repository_id => @repository_id}).returns({:processing => @processing_hash}) + get :processing, :profile => @profile.identifier, :repository_id => @repository_id assert_response 200 assert_select('h4', 'Last Result') end should 'test project results from a specific date' do - request_body = {:project_name => @project.name, :date => @date} - Kalibro::Processing.expects(:request).with("Processing", :has_results_before, request_body).returns({:has_results => true}) - Kalibro::Processing.expects(:request).with("Processing", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash}) - get :project_result, :profile => @profile.identifier, :id => @content.id, :date => @date - assert_equal @content, assigns(:content) - assert_equal @project_result.project.name, assigns(:project_result).project.name + Kalibro::Processing.expects(:request).with(:has_processing_after, {:repository_id => @repository_id, :date => @processing.date}).returns({:exists => true}) + Kalibro::Processing.expects(:request).with(:first_processing_after, :repository_id => @repository_id, :date => @processing.date).returns({:processing => @processing_hash}) + get :processing, :profile => @profile.identifier, :repository_id => @repository_id, :date => @processing.date assert_response 200 assert_select('h4', 'Last Result') end +#TODO refatorar todos os testes +=begin should 'test project tree without date' do Kalibro::Processing.expects(:request).with("Processing", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash}) Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) diff --git a/plugins/mezuro/views/mezuro_plugin_processing/_error_page.html.erb b/plugins/mezuro/views/mezuro_plugin_processing/_error_page.html.erb new file mode 100644 index 0000000..55bdf75 --- /dev/null +++ b/plugins/mezuro/views/mezuro_plugin_processing/_error_page.html.erb @@ -0,0 +1,2 @@ +
<%= _('Date') %> | +<%= @processing.date %> | +
<%= _(process_time.state + ' time') %> | +<%= process_time.time %> | +
Click to choose specific date: | +<%= link_to(image_tag('/images/calendar_date_select/calendar.png', :width => 20, :height => 20, :onClick => "$( 'datepicker' ).toggle();"), "javascript:void(0)") %> | +
+ <%= "State when error ocurred: #{@processing.state}" %>
+
+ <% error = @processing.error %>
+ <%= error.message %>
+
- <%= "State when error ocurred: #{@project.state}" %>
-
- <% error = @project.kalibro_error %>
- <%= error.message %>
-
<%= _('Date') %> | -<%= @project_result.date %> | -
<%= _('Load time') %> | -<%= @project_result.formatted_load_time %> | -
<%= _('Analysis time') %> | -<%= @project_result.formatted_analysis_time %> | -
Click to choose specific date: | -<%= link_to(image_tag('/images/calendar_date_select/calendar.png', :width => 20, :height => 20, :onClick => "$( 'datepicker' ).toggle();"), "javascript:void(0)") %> | -
<%= image_tag('/plugins/mezuro/images/folder.png')%> | -<%= child.module.name %> | -
<%= image_tag('/plugins/mezuro/images/file.png') %> | -- - <%= child.module.name %> - - | -