diff --git a/plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb b/plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb index b577697..e6087ab 100644 --- a/plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb +++ b/plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb @@ -8,6 +8,7 @@ class MezuroPluginMyprofileController < ProfileController end def error_page + @message = params[:message] end def choose_base_tool diff --git a/plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb b/plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb index 976c081..b23accf 100644 --- a/plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb +++ b/plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb @@ -4,15 +4,17 @@ class MezuroPluginProfileController < ProfileController rescue_from Exception do |exception| message = URI.escape(CGI.escape(exception.message),'.') - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/error_page?message=#{message}" + redirect_to_error_page message end def error_page + @message = params[:message] end def project_state @content = profile.articles.find(params[:id]) project = @content.project + redirect_to_error_page(project.errors[0].message) if not project.errors.empty? state = project.kalibro_error.nil? ? project.state : "ERROR" render :text => state end @@ -75,4 +77,10 @@ class MezuroPluginProfileController < ProfileController metric_result.value end end + + def redirect_to_error_page(message) + redirect_to "/profile/#{profile.identifier}/plugin/mezuro/error_page?message=#{message}" + end + end + diff --git a/plugins/mezuro/lib/kalibro/model.rb b/plugins/mezuro/lib/kalibro/model.rb index 630dabe..38b807a 100644 --- a/plugins/mezuro/lib/kalibro/model.rb +++ b/plugins/mezuro/lib/kalibro/model.rb @@ -55,10 +55,6 @@ class Kalibro::Model false end end - - def add_error(exception) - @errors << exception - end def destroy begin @@ -133,4 +129,9 @@ class Kalibro::Model {"#{class_name.underscore}_name".to_sym => self.name} end + def add_error(exception) + @errors << exception + end + end + diff --git a/plugins/mezuro/lib/mezuro_plugin/project_content.rb b/plugins/mezuro/lib/mezuro_plugin/project_content.rb index 09394a5..78919fb 100644 --- a/plugins/mezuro/lib/mezuro_plugin/project_content.rb +++ b/plugins/mezuro/lib/mezuro_plugin/project_content.rb @@ -25,6 +25,7 @@ class MezuroPlugin::ProjectContent < Article @project ||= Kalibro::Project.find_by_name(name) rescue Exception => error errors.add_to_base(error.message) + @project end end @@ -105,7 +106,7 @@ Kalibro::ProjectResult.first_result_after(name, date) end def destroy_project_from_service - project.destroy + project.destroy unless project.nil? end end diff --git a/plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb b/plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb index 87c6f71..180f1c8 100644 --- a/plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb +++ b/plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb @@ -25,14 +25,21 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase @content.save end - should 'test project state without error' do + should 'show an error page if an exception is raised' do + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns(Exception.new(:message => "Error message")) + get :project_state, :profile => @profile.identifier, :id => @content.id + assert_response 302 + assert_select('h2', 'An error occured: ') + end + + should 'test project state without kalibro_error' do Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) get :project_state, :profile => @profile.identifier, :id => @content.id assert_response 200 assert_equal @content, assigns(:content) end - should 'test project state with error' do + 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 => ErrorFixtures.error_hash})}) get :project_state, :profile => @profile.identifier, :id => @content.id assert_response 200 diff --git a/plugins/mezuro/views/content_viewer/show_configuration.rhtml b/plugins/mezuro/views/content_viewer/show_configuration.rhtml index b2da80e..040a877 100644 --- a/plugins/mezuro/views/content_viewer/show_configuration.rhtml +++ b/plugins/mezuro/views/content_viewer/show_configuration.rhtml @@ -1,50 +1,59 @@ <% @configuration_content = @page @configuration = @page.configuration %> +<% unless @page.errors[:base].nil? %> + <% if @page.errors[:base] =~ /There is no project named/ %> +

Warning:

+

This Configuration doesn't exist on the Web Service. Do you want to delete or save it again?

+ <% else %> + <%= @page.errors[:base] %> + <% end %> +<% else %> - - - - - - - - - -
<%= _('Name') %><%= @configuration.name %>
<%= _('Description') %><%= @configuration.description %>
+ + + + + + + + + +
<%= _('Name') %><%= @configuration.name %>
<%= _('Description') %><%= @configuration.description %>
-
+
-<%= link_to "#{image_tag ('/plugins/mezuro/images/plus.png')}Add Metric", :controller => "mezuro_plugin_myprofile", -:action => "choose_base_tool", :params => { :id => @configuration_content.id } %>
+ <%= link_to "#{image_tag ('/plugins/mezuro/images/plus.png')}Add Metric", :controller => "mezuro_plugin_myprofile", + :action => "choose_base_tool", :params => { :id => @configuration_content.id } %>
- - - - - - - <% @configuration.metric_configurations.each do |metric_configuration| %> - - - <% if metric_configuration.metric.instance_of? Kalibro::NativeMetric %> - - - - <% else %> - - - - <% end %> - - +
Metric Name
Collector Name
Metric Code
-
<%= metric_configuration.metric.name %> - <%= metric_configuration.metric.origin %> - <%= metric_configuration.code %><%= link_to "Edit", :controller => "mezuro_plugin_myprofile", :action => "edit_metric_configuration", :params => - {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %> - Compound Metric - <%= metric_configuration.code %><%= link_to "Edit", :controller => "mezuro_plugin_myprofile", :action => "edit_compound_metric_configuration", :params => - {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %><%= link_to "Remove", :controller => "mezuro_plugin_myprofile", :action => "remove_metric_configuration", :params => - {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %>
+ + + + + - <% end %> -
Metric Name
Collector Name
Metric Code
+ <% @configuration.metric_configurations.each do |metric_configuration| %> + + <%= metric_configuration.metric.name %> + <% if metric_configuration.metric.instance_of? Kalibro::NativeMetric %> + + <%= metric_configuration.metric.origin %> + + <%= metric_configuration.code %> + <%= link_to "Edit", :controller => "mezuro_plugin_myprofile", :action => "edit_metric_configuration", :params => + {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %> + <% else %> + + Compound Metric + + <%= metric_configuration.code %> + <%= link_to "Edit", :controller => "mezuro_plugin_myprofile", :action => "edit_compound_metric_configuration", :params => + {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %> + <% end %> + + <%= link_to "Remove", :controller => "mezuro_plugin_myprofile", :action => "remove_metric_configuration", :params => + {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %> + + <% end %> + +<% end %> diff --git a/plugins/mezuro/views/content_viewer/show_project.rhtml b/plugins/mezuro/views/content_viewer/show_project.rhtml index 1160ea6..563cc06 100644 --- a/plugins/mezuro/views/content_viewer/show_project.rhtml +++ b/plugins/mezuro/views/content_viewer/show_project.rhtml @@ -2,60 +2,58 @@ <% @project = @page.project %> <% unless @page.errors[:base].nil? %> - <%= @page.errors[:base] %> -<% else %> - - <% if (@project==nil) %> + <% if @page.errors[:base] =~ /There is no project named/ %>

Warning:

This project doesn't exist on the Web Service. Do you want to delete or save it again?

<% else %> + <%= @page.errors[:base] %> + <% end %> +<% else %> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
<%= _('Name') %><%= @project.name %>
<%= _('License') %><%= @project.license %>
<%= _('Description') %><%= @project.description %>
<%= _('Repository type') %><%= @project.repository.type %>
<%= _('Repository address') %><%= @project.repository.address %>
<%= _('Configuration') %><%= @project.configuration_name %>
<%= _('Periodicity') %><%= MezuroPlugin::Helpers::ContentViewerHelper.get_periodicity_option(@page.periodicity_in_days) %>
<%= _('Status')%> +
<%= @project.state %>
+
+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
<%= _('Name') %><%= @project.name %>
<%= _('License') %><%= @project.license %>
<%= _('Description') %><%= @project.description %>
<%= _('Repository type') %><%= @project.repository.type %>
<%= _('Repository address') %><%= @project.repository.address %>
<%= _('Configuration') %><%= @project.configuration_name %>
<%= _('Periodicity') %><%= MezuroPlugin::Helpers::ContentViewerHelper.get_periodicity_option(@page.periodicity_in_days) %>
<%= _('Status')%> -
<%= @project.state %>
-
-
- -
+
-
-
-
-
-
- <% end %> +
+
+
+
+
<% end %> diff --git a/plugins/mezuro/views/mezuro_plugin_myprofile/error_page.html.erb b/plugins/mezuro/views/mezuro_plugin_myprofile/error_page.html.erb index 8d9f941..1d3c248 100644 --- a/plugins/mezuro/views/mezuro_plugin_myprofile/error_page.html.erb +++ b/plugins/mezuro/views/mezuro_plugin_myprofile/error_page.html.erb @@ -1,3 +1,3 @@ -

<%= "An error occured: " %>

-<%=h params[:message] %> +

An error occured:

+<%= @message %> diff --git a/plugins/mezuro/views/mezuro_plugin_profile/error_page.html.erb b/plugins/mezuro/views/mezuro_plugin_profile/error_page.html.erb new file mode 100644 index 0000000..1d3c248 --- /dev/null +++ b/plugins/mezuro/views/mezuro_plugin_profile/error_page.html.erb @@ -0,0 +1,3 @@ +

An error occured:

+<%= @message %> + -- libgit2 0.21.2