From 25ebd3b10093fa96800ae2712872cc1467f85138 Mon Sep 17 00:00:00 2001
From: João M. M. da Silva + Alessandro Palmeira
Date: Tue, 11 Dec 2012 12:22:50 -0200
Subject: [PATCH] [Mezuro] processing action in processing controller
---
plugins/mezuro/controllers/profile/mezuro_plugin_processing_controller.rb | 19 +++++--------------
plugins/mezuro/lib/kalibro/processing.rb | 6 +++++-
plugins/mezuro/test/fixtures/processing_fixtures.rb | 17 ++++++++++++++---
plugins/mezuro/test/functional/profile/mezuro_plugin_processing_controller_test.rb | 48 +++++++++++++++++++-----------------------------
plugins/mezuro/views/mezuro_plugin_processing/_error_page.html.erb | 2 ++
plugins/mezuro/views/mezuro_plugin_processing/_processing.rhtml | 34 ++++++++++++++++++++++++++++++++++
plugins/mezuro/views/mezuro_plugin_processing/_processing_error.rhtml | 12 ++++++++++++
plugins/mezuro/views/mezuro_plugin_project/_error_page.html.erb | 2 --
plugins/mezuro/views/mezuro_plugin_project/_project_error.rhtml | 12 ------------
plugins/mezuro/views/mezuro_plugin_project/_project_result.rhtml | 41 -----------------------------------------
plugins/mezuro/views/mezuro_plugin_project/_source_tree.rhtml | 45 ---------------------------------------------
11 files changed, 91 insertions(+), 147 deletions(-)
create mode 100644 plugins/mezuro/views/mezuro_plugin_processing/_error_page.html.erb
create mode 100644 plugins/mezuro/views/mezuro_plugin_processing/_processing.rhtml
create mode 100644 plugins/mezuro/views/mezuro_plugin_processing/_processing_error.rhtml
delete mode 100644 plugins/mezuro/views/mezuro_plugin_project/_error_page.html.erb
delete mode 100644 plugins/mezuro/views/mezuro_plugin_project/_project_error.rhtml
delete mode 100644 plugins/mezuro/views/mezuro_plugin_project/_project_result.rhtml
delete mode 100644 plugins/mezuro/views/mezuro_plugin_project/_source_tree.rhtml
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 @@
+ An error occured:
+<%= @processing.error.message %>
diff --git a/plugins/mezuro/views/mezuro_plugin_processing/_processing.rhtml b/plugins/mezuro/views/mezuro_plugin_processing/_processing.rhtml
new file mode 100644
index 0000000..69f0d4d
--- /dev/null
+++ b/plugins/mezuro/views/mezuro_plugin_processing/_processing.rhtml
@@ -0,0 +1,34 @@
+
+
+<%= _('Last Result') %>
+
+
+
+ <%= _('Date') %> |
+ <%= @processing.date %> |
+
+ <% @processing.process_time.each do |process_time| %>
+
+ <%= _(process_time.state + ' time') %> |
+ <%= process_time.time %> |
+
+ <% end %>
+
+ 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)") %> |
+
+
+
+
+
+
diff --git a/plugins/mezuro/views/mezuro_plugin_processing/_processing_error.rhtml b/plugins/mezuro/views/mezuro_plugin_processing/_processing_error.rhtml
new file mode 100644
index 0000000..1a4eaca
--- /dev/null
+++ b/plugins/mezuro/views/mezuro_plugin_processing/_processing_error.rhtml
@@ -0,0 +1,12 @@
+<%= _('ERROR') %>
+
+ <%= "State when error ocurred: #{@processing.state}" %>
+
+ <% error = @processing.error %>
+ <%= error.message %>
+
+ <% error.stack_trace.each do |trace| %>
+ - <%= "#{trace.declaring_class}.#{trace.method_name}(#{trace.file_name}:#{trace.line_number})" %>
+ <% end %>
+
+
diff --git a/plugins/mezuro/views/mezuro_plugin_project/_error_page.html.erb b/plugins/mezuro/views/mezuro_plugin_project/_error_page.html.erb
deleted file mode 100644
index 089af13..0000000
--- a/plugins/mezuro/views/mezuro_plugin_project/_error_page.html.erb
+++ /dev/null
@@ -1,2 +0,0 @@
- An error occured:
-<%= @message %>
diff --git a/plugins/mezuro/views/mezuro_plugin_project/_project_error.rhtml b/plugins/mezuro/views/mezuro_plugin_project/_project_error.rhtml
deleted file mode 100644
index 5df49c5..0000000
--- a/plugins/mezuro/views/mezuro_plugin_project/_project_error.rhtml
+++ /dev/null
@@ -1,12 +0,0 @@
-<%= _('ERROR') %>
-
- <%= "State when error ocurred: #{@project.state}" %>
-
- <% error = @project.kalibro_error %>
- <%= error.message %>
-
- <% error.stack_trace.each do |trace| %>
- - <%= "#{trace.declaring_class}.#{trace.method_name}(#{trace.file_name}:#{trace.line_number})" %>
- <% end %>
-
-
diff --git a/plugins/mezuro/views/mezuro_plugin_project/_project_result.rhtml b/plugins/mezuro/views/mezuro_plugin_project/_project_result.rhtml
deleted file mode 100644
index 7313f41..0000000
--- a/plugins/mezuro/views/mezuro_plugin_project/_project_result.rhtml
+++ /dev/null
@@ -1,41 +0,0 @@
-<% unless @content.errors[:base].nil? %>
- <%= @content.errors[:base] %>
-<% else %>
-
-
- <%= _('Last Result') %>
-
-
-
- <%= _('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)") %> |
-
-
-
-
-
-
-
-<% end %>
diff --git a/plugins/mezuro/views/mezuro_plugin_project/_source_tree.rhtml b/plugins/mezuro/views/mezuro_plugin_project/_source_tree.rhtml
deleted file mode 100644
index 8c7b315..0000000
--- a/plugins/mezuro/views/mezuro_plugin_project/_source_tree.rhtml
+++ /dev/null
@@ -1,45 +0,0 @@
-<% unless @content.errors[:base].nil? %>
- <%= @content.errors[:base] %>
-<% else %>
- <%= _('Source tree') %>
- <% module_name = @source_tree.module.name %>
- <% module_label = "#{module_name} (#{@source_tree.module.granularity})" %>
-
-
- <% if module_name != @project_name %>
-
- <%= @project_name %>
-
- <% end %>
-
-
- <% split_link = @source_tree.module.ancestor_names %>
- <% split_link.each do |link| %>
- /
- <%= link.split(".").last %>
-
- <% end %>
-
-
- <% if @source_tree.children %>
-
- <% @source_tree.children.each do |child| %>
- <% if child.module.granularity=='PACKAGE' %>
-
- <%= image_tag('/plugins/mezuro/images/folder.png')%> |
- <%= child.module.name %> |
-
- <% else %>
-
- <%= image_tag('/plugins/mezuro/images/file.png') %> |
-
-
- <%= child.module.name %>
-
- |
-
- <% end %>
- <% end %>
-
- <% end %>
-<% end %>
--
libgit2 0.21.2