diff --git a/plugins/mezuro/controllers/profile/mezuro_plugin_project_controller.rb b/plugins/mezuro/controllers/profile/mezuro_plugin_project_controller.rb new file mode 100644 index 0000000..22c705e --- /dev/null +++ b/plugins/mezuro/controllers/profile/mezuro_plugin_project_controller.rb @@ -0,0 +1,54 @@ +class MezuroPluginProjectController < ProfileController + append_view_path File.join(File.dirname(__FILE__) + '/../../views/project') + + def project_state + @content = profile.articles.find(params[:id]) + project = @content.project + if project_content_has_errors? + redirect_to_error_page(@content.errors[:base]) + else + state = project.kalibro_error.nil? ? project.state : "ERROR" + render :text => state + end + end + + def project_error + @content = profile.articles.find(params[:id]) + @project = @content.project + if project_content_has_errors? + redirect_to_error_page(@content.errors[:base]) + else + render :partial => 'content_viewer/project_error' + end + end + + def project_result + @content = profile.articles.find(params[:id]) + date = params[:date] + @project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date) + if project_content_has_errors? + redirect_to_error_page(@content.errors[:base]) + else + render :partial => 'content_viewer/project_result' + end + end + + def project_tree + @content = profile.articles.find(params[:id]) + date = params[:date] + project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date) + @project_name = @content.project.name if not @content.project.nil? + if project_content_has_errors? + redirect_to_error_page(@content.errors[:base]) + else + @source_tree = project_result.node(params[:module_name]) + render :partial =>'content_viewer/source_tree' + end + end + + private + + def project_content_has_errors? + not @content.errors[:base].nil? + end +end diff --git a/plugins/mezuro/test/functional/mezuro_plugin_project_controller_test.rb b/plugins/mezuro/test/functional/mezuro_plugin_project_controller_test.rb new file mode 100644 index 0000000..cecc2e2 --- /dev/null +++ b/plugins/mezuro/test/functional/mezuro_plugin_project_controller_test.rb @@ -0,0 +1,92 @@ +require 'test_helper' + +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/error_fixtures" +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/repository_fixtures" + +class MezuroPluginProjectControllerTest < ActionController::TestCase + def setup + @controller = MezuroPluginProjectController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @profile = fast_create(Community) + + @project_result = ProjectResultFixtures.project_result + @repository_url = RepositoryFixtures.repository.address + @project = @project_result.project + @date = "2012-04-13T20:39:41+04:00" + + Kalibro::Project.expects(:all_names).returns([]) + @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => @project.name, :repository_url => @repository_url) + @content.expects(:send_project_to_service).returns(nil) + @content.save + 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 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 + 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 => ErrorFixtures.error_hash})}) + get :project_error, :profile => @profile.identifier, :id => @content.id + assert_response 200 + assert_select('h3', 'ERROR') + assert_equal @content, assigns(:content) + assert_equal @project.name, assigns(:project).name + end + + should 'test project result without date' do + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :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 + 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::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true}) + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :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 + assert_response 200 + assert_select('h4', 'Last Result') + end + + should 'test project tree without date' do + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :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}) + get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => nil + assert_equal @content, assigns(:content) + assert_equal @project.name, assigns(:project_name) + assert_equal @project_result.source_tree.module.name, assigns(:source_tree).module.name + assert_response 200 + assert_select('h2', /Qt-Calculator/) + end + + should 'test project tree with a specific date' do + request_body = {:project_name => @project.name, :date => @project_result.date} + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true}) + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash}) + get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => @project_result.date + assert_equal @content, assigns(:content) + assert_equal @project.name, assigns(:project_name) + assert_equal @project_result.source_tree.module.name, assigns(:source_tree).module.name + assert_response 200 + end + +end diff --git a/plugins/mezuro/views/project/_project_error.rhtml b/plugins/mezuro/views/project/_project_error.rhtml new file mode 100644 index 0000000..5df49c5 --- /dev/null +++ b/plugins/mezuro/views/project/_project_error.rhtml @@ -0,0 +1,12 @@ +

<%= _('ERROR') %>

+

+ <%= "State when error ocurred: #{@project.state}" %> +
+ <% error = @project.kalibro_error %> + <%= error.message %> +

+

diff --git a/plugins/mezuro/views/project/_project_result.rhtml b/plugins/mezuro/views/project/_project_result.rhtml new file mode 100644 index 0000000..126c7b7 --- /dev/null +++ b/plugins/mezuro/views/project/_project_result.rhtml @@ -0,0 +1,51 @@ +<% unless @content.errors[:base].nil? %> + <%= @content.errors[:base] %> +<% else %> + <% form_for :project_date, :html=>{:id=>"project_history_date"} do |f| %> + <%= f.label :day, "Choose project date:" %> + + + + + + + + + + + + +
+ Day + + Month + + Year +
+ <%= f.text_field :day, :size => 1, :maxlength => 2, :placeholder =>"dd" %> + + <%= f.text_field :month, :size => 1, :maxlength => 2, :placeholder =>"mm" %> + + <%= f.text_field :year, :size => 1, :maxlength => 4, :placeholder =>"yyyy" %> +
+ <%= f.submit "Refresh" %> + <% end %> + + +

<%= _('Last Result') %>

+ + + + + + + + + + + + + + +
<%= _('Date') %><%= @project_result.date %>
<%= _('Load time') %><%= @project_result.formatted_load_time %>
<%= _('Analysis time') %><%= @project_result.formatted_analysis_time %>
+<% end %> diff --git a/plugins/mezuro/views/project/_source_tree.rhtml b/plugins/mezuro/views/project/_source_tree.rhtml new file mode 100644 index 0000000..8c7b315 --- /dev/null +++ b/plugins/mezuro/views/project/_source_tree.rhtml @@ -0,0 +1,45 @@ +<% 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' %> + + + + + <% else %> + + + + + <% end %> + <% end %> +
<%= image_tag('/plugins/mezuro/images/folder.png')%><%= child.module.name %>
<%= image_tag('/plugins/mezuro/images/file.png') %> + + <%= child.module.name %> + +
+ <% end %> +<% end %> diff --git a/plugins/mezuro/views/project/content_viewer/_project_error.rhtml b/plugins/mezuro/views/project/content_viewer/_project_error.rhtml new file mode 100644 index 0000000..5df49c5 --- /dev/null +++ b/plugins/mezuro/views/project/content_viewer/_project_error.rhtml @@ -0,0 +1,12 @@ +

<%= _('ERROR') %>

+

+ <%= "State when error ocurred: #{@project.state}" %> +
+ <% error = @project.kalibro_error %> + <%= error.message %> +

+

diff --git a/plugins/mezuro/views/project/content_viewer/_project_result.rhtml b/plugins/mezuro/views/project/content_viewer/_project_result.rhtml new file mode 100644 index 0000000..126c7b7 --- /dev/null +++ b/plugins/mezuro/views/project/content_viewer/_project_result.rhtml @@ -0,0 +1,51 @@ +<% unless @content.errors[:base].nil? %> + <%= @content.errors[:base] %> +<% else %> + <% form_for :project_date, :html=>{:id=>"project_history_date"} do |f| %> + <%= f.label :day, "Choose project date:" %> + + + + + + + + + + + + +
+ Day + + Month + + Year +
+ <%= f.text_field :day, :size => 1, :maxlength => 2, :placeholder =>"dd" %> + + <%= f.text_field :month, :size => 1, :maxlength => 2, :placeholder =>"mm" %> + + <%= f.text_field :year, :size => 1, :maxlength => 4, :placeholder =>"yyyy" %> +
+ <%= f.submit "Refresh" %> + <% end %> + + +

<%= _('Last Result') %>

+ + + + + + + + + + + + + + +
<%= _('Date') %><%= @project_result.date %>
<%= _('Load time') %><%= @project_result.formatted_load_time %>
<%= _('Analysis time') %><%= @project_result.formatted_analysis_time %>
+<% end %> diff --git a/plugins/mezuro/views/project/content_viewer/_source_tree.rhtml b/plugins/mezuro/views/project/content_viewer/_source_tree.rhtml new file mode 100644 index 0000000..8c7b315 --- /dev/null +++ b/plugins/mezuro/views/project/content_viewer/_source_tree.rhtml @@ -0,0 +1,45 @@ +<% 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' %> + + + + + <% else %> + + + + + <% end %> + <% end %> +
<%= image_tag('/plugins/mezuro/images/folder.png')%><%= child.module.name %>
<%= image_tag('/plugins/mezuro/images/file.png') %> + + <%= child.module.name %> + +
+ <% end %> +<% end %> diff --git a/plugins/mezuro/views/project/content_viewer/show_project.rhtml b/plugins/mezuro/views/project/content_viewer/show_project.rhtml new file mode 100644 index 0000000..563cc06 --- /dev/null +++ b/plugins/mezuro/views/project/content_viewer/show_project.rhtml @@ -0,0 +1,59 @@ + + +<% @project = @page.project %> +<% unless @page.errors[:base].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 %>
+
+
+ +
+ +
+
+
+
+
+<% end %> diff --git a/plugins/mezuro/views/project/show_project.rhtml b/plugins/mezuro/views/project/show_project.rhtml new file mode 100644 index 0000000..563cc06 --- /dev/null +++ b/plugins/mezuro/views/project/show_project.rhtml @@ -0,0 +1,59 @@ + + +<% @project = @page.project %> +<% unless @page.errors[:base].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 %>
+
+
+ +
+ +
+
+
+
+
+<% end %> diff --git a/test/test_helper.rb b/test/test_helper.rb index 36935d4..f671797 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,11 +1,11 @@ ENV["RAILS_ENV"] = "test" # Start/stop Solr -if not $test_helper_loaded - abort unless system 'rake -s solr:start' - at_exit { system 'rake -s solr:stop' } - $test_helper_loaded = true -end +#if not $test_helper_loaded +# abort unless system 'rake -s solr:start' +# at_exit { system 'rake -s solr:stop' } +# $test_helper_loaded = true +#end require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' -- libgit2 0.21.2