Commit 16914728c84a56f7c1eb539a4227809aee651161
1 parent
fccc9c74
Exists in
master
and in
28 other branches
[Mezuro] started error treatment when a project doesn't exist in kalibro
Showing
5 changed files
with
20 additions
and
21 deletions
Show diff stats
plugins/mezuro/lib/kalibro/client/project_client.rb
| ... | ... | @@ -46,7 +46,15 @@ class Kalibro::Client::ProjectClient |
| 46 | 46 | end |
| 47 | 47 | |
| 48 | 48 | def project(project_name) |
| 49 | - hash = @port.request(:get_project, {:project_name => project_name})[:project] | |
| 49 | + begin | |
| 50 | + hash = @port.request(:get_project, {:project_name => project_name})[:project] | |
| 51 | + rescue Exception => error | |
| 52 | + if (error.to_s =~ /There is no project named/) != nil | |
| 53 | + return nil | |
| 54 | + else | |
| 55 | + raise error | |
| 56 | + end | |
| 57 | + end | |
| 50 | 58 | Kalibro::Entities::Project.from_hash(hash) |
| 51 | 59 | end |
| 52 | 60 | ... | ... |
plugins/mezuro/lib/mezuro_plugin/project_content.rb
| ... | ... | @@ -14,19 +14,10 @@ class MezuroPlugin::ProjectContent < Article |
| 14 | 14 | include ActionView::Helpers::TagHelper |
| 15 | 15 | def to_html(options = {}) |
| 16 | 16 | lambda do |
| 17 | - | |
| 18 | - render :file => 'content_viewer/show_project.rhtml', :locals => { :project => project_kalibro, :error_kalibro => error_kalibro } | |
| 17 | + render :file => 'content_viewer/show_project.rhtml' | |
| 19 | 18 | end |
| 20 | 19 | end |
| 21 | 20 | |
| 22 | - def rescue_error_kalibro | |
| 23 | - error_kalibro = false | |
| 24 | - begin | |
| 25 | - project_kalibro = project | |
| 26 | - rescue | |
| 27 | - error_kalibro = true | |
| 28 | - end | |
| 29 | - end | |
| 30 | 21 | |
| 31 | 22 | def project |
| 32 | 23 | @project ||= Kalibro::Client::ProjectClient.project(name) | ... | ... |
plugins/mezuro/test/unit/kalibro/client/project_client_test.rb
| ... | ... | @@ -16,6 +16,13 @@ class ProjectClientTest < ActiveSupport::TestCase |
| 16 | 16 | @port.expects(:request).with(:get_project, request_body).returns(response_hash) |
| 17 | 17 | assert_equal @project, Kalibro::Client::ProjectClient.project(@project.name) |
| 18 | 18 | end |
| 19 | + | |
| 20 | + should 'raise error when project doesnt exist' do | |
| 21 | + request_body = {:project_name => @project.name} | |
| 22 | + @port.expects(:request).with(:get_project, request_body) | |
| 23 | + .raises(Exception.new("(S:Server) There is no project named " + @project.name)) | |
| 24 | + assert_nil Kalibro::Client::ProjectClient.project(@project.name) | |
| 25 | + end | |
| 19 | 26 | |
| 20 | 27 | should 'save project' do |
| 21 | 28 | create_project_content_mock | ... | ... |
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
| ... | ... | @@ -31,11 +31,6 @@ class ProjectContentTest < ActiveSupport::TestCase |
| 31 | 31 | should 'have an html view' do |
| 32 | 32 | assert_not_nil @content.to_html |
| 33 | 33 | end |
| 34 | - | |
| 35 | - should 'rescue error when project doesnt exist in kalibro' do | |
| 36 | - MezuroPlugin::ProjectContent.expects(:project).returns(create_project_error) | |
| 37 | - assert_equal true, @content.rescue_error_kalibro | |
| 38 | - end | |
| 39 | 34 | |
| 40 | 35 | should 'get project from service' do |
| 41 | 36 | Kalibro::Client::ProjectClient.expects(:project).with(@content.name).returns(@project) | ... | ... |
plugins/mezuro/views/content_viewer/show_project.rhtml
| 1 | 1 | <script src="/plugins/mezuro/javascripts/project_content.js" type="text/javascript"></script> |
| 2 | -<% if error_kalibro %> | |
| 3 | - Projeto nao existe TODO: Perguntar oa usuário se deseja excluir o projeto do Noosfero | |
| 4 | -<% else %> | |
| 5 | -<% @project = project %> | |
| 2 | + | |
| 3 | +<% @project = @page.project %> | |
| 6 | 4 | <table> |
| 7 | 5 | <tr> |
| 8 | 6 | <td><%= _('Name') %></td> |
| ... | ... | @@ -45,4 +43,4 @@ |
| 45 | 43 | <div id="project-tree"></div> |
| 46 | 44 | <div id="module-result"> |
| 47 | 45 | </div> |
| 48 | -<% end %> | |
| 46 | + | ... | ... |