Commit f5f28ddcee1e483a7d343a87f8cbba99d4378583

Authored by Rafael Manzo
Committed by Paulo Meireles
1 parent abab0c3e

[Mezuro] New controller Project

plugins/mezuro/controllers/profile/mezuro_plugin_project_controller.rb 0 → 100644
... ... @@ -0,0 +1,54 @@
  1 +class MezuroPluginProjectController < ProfileController
  2 + append_view_path File.join(File.dirname(__FILE__) + '/../../views/project')
  3 +
  4 + def project_state
  5 + @content = profile.articles.find(params[:id])
  6 + project = @content.project
  7 + if project_content_has_errors?
  8 + redirect_to_error_page(@content.errors[:base])
  9 + else
  10 + state = project.kalibro_error.nil? ? project.state : "ERROR"
  11 + render :text => state
  12 + end
  13 + end
  14 +
  15 + def project_error
  16 + @content = profile.articles.find(params[:id])
  17 + @project = @content.project
  18 + if project_content_has_errors?
  19 + redirect_to_error_page(@content.errors[:base])
  20 + else
  21 + render :partial => 'content_viewer/project_error'
  22 + end
  23 + end
  24 +
  25 + def project_result
  26 + @content = profile.articles.find(params[:id])
  27 + date = params[:date]
  28 + @project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date)
  29 + if project_content_has_errors?
  30 + redirect_to_error_page(@content.errors[:base])
  31 + else
  32 + render :partial => 'content_viewer/project_result'
  33 + end
  34 + end
  35 +
  36 + def project_tree
  37 + @content = profile.articles.find(params[:id])
  38 + date = params[:date]
  39 + project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date)
  40 + @project_name = @content.project.name if not @content.project.nil?
  41 + if project_content_has_errors?
  42 + redirect_to_error_page(@content.errors[:base])
  43 + else
  44 + @source_tree = project_result.node(params[:module_name])
  45 + render :partial =>'content_viewer/source_tree'
  46 + end
  47 + end
  48 +
  49 + private
  50 +
  51 + def project_content_has_errors?
  52 + not @content.errors[:base].nil?
  53 + end
  54 +end
... ...
plugins/mezuro/test/functional/mezuro_plugin_project_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,92 @@
  1 +require 'test_helper'
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures"
  4 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/error_fixtures"
  5 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/repository_fixtures"
  6 +
  7 +class MezuroPluginProjectControllerTest < ActionController::TestCase
  8 + def setup
  9 + @controller = MezuroPluginProjectController.new
  10 + @request = ActionController::TestRequest.new
  11 + @response = ActionController::TestResponse.new
  12 + @profile = fast_create(Community)
  13 +
  14 + @project_result = ProjectResultFixtures.project_result
  15 + @repository_url = RepositoryFixtures.repository.address
  16 + @project = @project_result.project
  17 + @date = "2012-04-13T20:39:41+04:00"
  18 +
  19 + Kalibro::Project.expects(:all_names).returns([])
  20 + @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => @project.name, :repository_url => @repository_url)
  21 + @content.expects(:send_project_to_service).returns(nil)
  22 + @content.save
  23 + end
  24 +
  25 + should 'test project state without kalibro_error' do
  26 + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash})
  27 + get :project_state, :profile => @profile.identifier, :id => @content.id
  28 + assert_response 200
  29 + assert_equal @content, assigns(:content)
  30 + end
  31 +
  32 + should 'test project state with kalibro_error' do
  33 + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash.merge({:error => ErrorFixtures.error_hash})})
  34 + get :project_state, :profile => @profile.identifier, :id => @content.id
  35 + assert_response 200
  36 + assert_equal "ERROR", @response.body
  37 + assert_equal @content, assigns(:content)
  38 + end
  39 +
  40 + should 'test project error' do
  41 + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash.merge({:error => ErrorFixtures.error_hash})})
  42 + get :project_error, :profile => @profile.identifier, :id => @content.id
  43 + assert_response 200
  44 + assert_select('h3', 'ERROR')
  45 + assert_equal @content, assigns(:content)
  46 + assert_equal @project.name, assigns(:project).name
  47 + end
  48 +
  49 + should 'test project result without date' do
  50 + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash})
  51 + get :project_result, :profile => @profile.identifier, :id => @content.id, :date => nil
  52 + assert_equal @content, assigns(:content)
  53 + assert_equal @project_result.project.name, assigns(:project_result).project.name
  54 + assert_response 200
  55 + assert_select('h4', 'Last Result')
  56 + end
  57 +
  58 + should 'test project results from a specific date' do
  59 + request_body = {:project_name => @project.name, :date => @date}
  60 + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true})
  61 + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash})
  62 + get :project_result, :profile => @profile.identifier, :id => @content.id, :date => @date
  63 + assert_equal @content, assigns(:content)
  64 + assert_equal @project_result.project.name, assigns(:project_result).project.name
  65 + assert_response 200
  66 + assert_select('h4', 'Last Result')
  67 + end
  68 +
  69 + should 'test project tree without date' do
  70 + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash})
  71 + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash})
  72 + get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => nil
  73 + assert_equal @content, assigns(:content)
  74 + assert_equal @project.name, assigns(:project_name)
  75 + assert_equal @project_result.source_tree.module.name, assigns(:source_tree).module.name
  76 + assert_response 200
  77 + assert_select('h2', /Qt-Calculator/)
  78 + end
  79 +
  80 + should 'test project tree with a specific date' do
  81 + request_body = {:project_name => @project.name, :date => @project_result.date}
  82 + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash})
  83 + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true})
  84 + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash})
  85 + get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => @project_result.date
  86 + assert_equal @content, assigns(:content)
  87 + assert_equal @project.name, assigns(:project_name)
  88 + assert_equal @project_result.source_tree.module.name, assigns(:source_tree).module.name
  89 + assert_response 200
  90 + end
  91 +
  92 +end
... ...
plugins/mezuro/views/project/_project_error.rhtml 0 → 100644
... ... @@ -0,0 +1,12 @@
  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/project/_project_result.rhtml 0 → 100644
... ... @@ -0,0 +1,51 @@
  1 +<% unless @content.errors[:base].nil? %>
  2 + <%= @content.errors[:base] %>
  3 +<% else %>
  4 + <% form_for :project_date, :html=>{:id=>"project_history_date"} do |f| %>
  5 + <%= f.label :day, "Choose project date:" %>
  6 +
  7 + <table>
  8 + <tr>
  9 + <td>
  10 + Day
  11 + </td>
  12 + <td>
  13 + Month
  14 + </td>
  15 + <td>
  16 + Year
  17 + </td>
  18 + </tr>
  19 + <tr>
  20 + <td>
  21 + <%= f.text_field :day, :size => 1, :maxlength => 2, :placeholder =>"dd" %>
  22 + </td>
  23 + <td>
  24 + <%= f.text_field :month, :size => 1, :maxlength => 2, :placeholder =>"mm" %>
  25 + </td>
  26 + <td>
  27 + <%= f.text_field :year, :size => 1, :maxlength => 4, :placeholder =>"yyyy" %>
  28 + </td>
  29 + </tr>
  30 + </table>
  31 + <%= f.submit "Refresh" %>
  32 + <% end %>
  33 +
  34 +
  35 + <h4><%= _('Last Result') %></h4>
  36 +
  37 + <table>
  38 + <tr>
  39 + <td><%= _('Date') %></td>
  40 + <td><%= @project_result.date %></td>
  41 + </tr>
  42 + <tr>
  43 + <td><%= _('Load time') %></td>
  44 + <td><%= @project_result.formatted_load_time %></td>
  45 + </tr>
  46 + <tr>
  47 + <td><%= _('Analysis time') %></td>
  48 + <td><%= @project_result.formatted_analysis_time %></td>
  49 + </tr>
  50 + </table>
  51 +<% end %>
... ...
plugins/mezuro/views/project/_source_tree.rhtml 0 → 100644
... ... @@ -0,0 +1,45 @@
  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 %>
... ...
plugins/mezuro/views/project/content_viewer/_project_error.rhtml 0 → 100644
... ... @@ -0,0 +1,12 @@
  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/project/content_viewer/_project_result.rhtml 0 → 100644
... ... @@ -0,0 +1,51 @@
  1 +<% unless @content.errors[:base].nil? %>
  2 + <%= @content.errors[:base] %>
  3 +<% else %>
  4 + <% form_for :project_date, :html=>{:id=>"project_history_date"} do |f| %>
  5 + <%= f.label :day, "Choose project date:" %>
  6 +
  7 + <table>
  8 + <tr>
  9 + <td>
  10 + Day
  11 + </td>
  12 + <td>
  13 + Month
  14 + </td>
  15 + <td>
  16 + Year
  17 + </td>
  18 + </tr>
  19 + <tr>
  20 + <td>
  21 + <%= f.text_field :day, :size => 1, :maxlength => 2, :placeholder =>"dd" %>
  22 + </td>
  23 + <td>
  24 + <%= f.text_field :month, :size => 1, :maxlength => 2, :placeholder =>"mm" %>
  25 + </td>
  26 + <td>
  27 + <%= f.text_field :year, :size => 1, :maxlength => 4, :placeholder =>"yyyy" %>
  28 + </td>
  29 + </tr>
  30 + </table>
  31 + <%= f.submit "Refresh" %>
  32 + <% end %>
  33 +
  34 +
  35 + <h4><%= _('Last Result') %></h4>
  36 +
  37 + <table>
  38 + <tr>
  39 + <td><%= _('Date') %></td>
  40 + <td><%= @project_result.date %></td>
  41 + </tr>
  42 + <tr>
  43 + <td><%= _('Load time') %></td>
  44 + <td><%= @project_result.formatted_load_time %></td>
  45 + </tr>
  46 + <tr>
  47 + <td><%= _('Analysis time') %></td>
  48 + <td><%= @project_result.formatted_analysis_time %></td>
  49 + </tr>
  50 + </table>
  51 +<% end %>
... ...
plugins/mezuro/views/project/content_viewer/_source_tree.rhtml 0 → 100644
... ... @@ -0,0 +1,45 @@
  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 %>
... ...
plugins/mezuro/views/project/content_viewer/show_project.rhtml 0 → 100644
... ... @@ -0,0 +1,59 @@
  1 +<script src="/plugins/mezuro/javascripts/project_content.js" type="text/javascript"></script>
  2 +
  3 +<% @project = @page.project %>
  4 +<% unless @page.errors[:base].nil? %>
  5 + <% if @page.errors[:base] =~ /There is no project named/ %>
  6 + <h3>Warning:</h3>
  7 + <p>This project doesn't exist on the Web Service. Do you want to <a href="/myprofile/<%= @page.profile.name %>/cms/destroy/<%= @page.id%>">delete</a> or <a href="/myprofile/<%= @page.profile.name %>/cms/edit/<%= @page.id%>">save it again</a>?</p>
  8 + <% else %>
  9 + <%= @page.errors[:base] %>
  10 + <% end %>
  11 +<% else %>
  12 +
  13 + <table>
  14 + <tr>
  15 + <td><%= _('Name') %></td>
  16 + <td><%= @project.name %></td>
  17 + </tr>
  18 + <tr>
  19 + <td><%= _('License') %></td>
  20 + <td><%= @project.license %></td>
  21 + </tr>
  22 + <tr>
  23 + <td><%= _('Description') %></td>
  24 + <td><%= @project.description %></td>
  25 + </tr>
  26 + <tr>
  27 + <td><%= _('Repository type') %></td>
  28 + <td><%= @project.repository.type %></td>
  29 + </tr>
  30 + <tr>
  31 + <td><%= _('Repository address') %></td>
  32 + <td><%= @project.repository.address %></td>
  33 + </tr>
  34 + <tr>
  35 + <td><%= _('Configuration') %></td>
  36 + <td><%= @project.configuration_name %></td>
  37 + </tr>
  38 + <tr>
  39 + <td><%= _('Periodicity') %></td>
  40 + <td><%= MezuroPlugin::Helpers::ContentViewerHelper.get_periodicity_option(@page.periodicity_in_days) %></td>
  41 + </tr>
  42 + <tr>
  43 + <td><%= _('Status')%></td>
  44 + <td>
  45 + <div id="project-state"><%= @project.state %></div>
  46 + <div id="msg-time"></div>
  47 + </td>
  48 + </tr>
  49 + </table>
  50 +
  51 + <br />
  52 +
  53 + <div id="project-result" data-profile="<%= @page.profile.identifier %>" data-content="<%= @page.id %>"
  54 + data-project-name="<%= @project.name %>">
  55 + </div>
  56 + <div id="project-tree"></div>
  57 + <div id="module-result">
  58 + </div>
  59 +<% end %>
... ...
plugins/mezuro/views/project/show_project.rhtml 0 → 100644
... ... @@ -0,0 +1,59 @@
  1 +<script src="/plugins/mezuro/javascripts/project_content.js" type="text/javascript"></script>
  2 +
  3 +<% @project = @page.project %>
  4 +<% unless @page.errors[:base].nil? %>
  5 + <% if @page.errors[:base] =~ /There is no project named/ %>
  6 + <h3>Warning:</h3>
  7 + <p>This project doesn't exist on the Web Service. Do you want to <a href="/myprofile/<%= @page.profile.name %>/cms/destroy/<%= @page.id%>">delete</a> or <a href="/myprofile/<%= @page.profile.name %>/cms/edit/<%= @page.id%>">save it again</a>?</p>
  8 + <% else %>
  9 + <%= @page.errors[:base] %>
  10 + <% end %>
  11 +<% else %>
  12 +
  13 + <table>
  14 + <tr>
  15 + <td><%= _('Name') %></td>
  16 + <td><%= @project.name %></td>
  17 + </tr>
  18 + <tr>
  19 + <td><%= _('License') %></td>
  20 + <td><%= @project.license %></td>
  21 + </tr>
  22 + <tr>
  23 + <td><%= _('Description') %></td>
  24 + <td><%= @project.description %></td>
  25 + </tr>
  26 + <tr>
  27 + <td><%= _('Repository type') %></td>
  28 + <td><%= @project.repository.type %></td>
  29 + </tr>
  30 + <tr>
  31 + <td><%= _('Repository address') %></td>
  32 + <td><%= @project.repository.address %></td>
  33 + </tr>
  34 + <tr>
  35 + <td><%= _('Configuration') %></td>
  36 + <td><%= @project.configuration_name %></td>
  37 + </tr>
  38 + <tr>
  39 + <td><%= _('Periodicity') %></td>
  40 + <td><%= MezuroPlugin::Helpers::ContentViewerHelper.get_periodicity_option(@page.periodicity_in_days) %></td>
  41 + </tr>
  42 + <tr>
  43 + <td><%= _('Status')%></td>
  44 + <td>
  45 + <div id="project-state"><%= @project.state %></div>
  46 + <div id="msg-time"></div>
  47 + </td>
  48 + </tr>
  49 + </table>
  50 +
  51 + <br />
  52 +
  53 + <div id="project-result" data-profile="<%= @page.profile.identifier %>" data-content="<%= @page.id %>"
  54 + data-project-name="<%= @project.name %>">
  55 + </div>
  56 + <div id="project-tree"></div>
  57 + <div id="module-result">
  58 + </div>
  59 +<% end %>
... ...
test/test_helper.rb
1 1 ENV["RAILS_ENV"] = "test"
2 2  
3 3 # Start/stop Solr
4   -if not $test_helper_loaded
5   - abort unless system 'rake -s solr:start'
6   - at_exit { system 'rake -s solr:stop' }
7   - $test_helper_loaded = true
8   -end
  4 +#if not $test_helper_loaded
  5 +# abort unless system 'rake -s solr:start'
  6 +# at_exit { system 'rake -s solr:stop' }
  7 +# $test_helper_loaded = true
  8 +#end
9 9  
10 10 require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
11 11 require 'test_help'
... ...