Commit 189563d8b9ed6a42c619b20f0b4006d34163c1b3

Authored by João M. M. da Silva + Diego Araújo
Committed by Paulo Meireles
1 parent 54bdf4c4

[Mezuro] Refactored project content to new design

plugins/mezuro/lib/mezuro_plugin/project_content.rb
1 -class MezuroPlugin::ProjectContent < Article 1 +class MezuroPlugin::ProjectContent < Article
  2 + include ActionView::Helpers::TagHelper
  3 +
  4 + settings_items :license, :description, :repository_type, :repository_url, :configuration_name, :periodicity_in_days
  5 +
2 validate_on_create :validate_kalibro_project_name 6 validate_on_create :validate_kalibro_project_name
3 validate_on_create :validate_repository_url 7 validate_on_create :validate_repository_url
  8 +
4 def self.short_description 9 def self.short_description
5 'Kalibro project' 10 'Kalibro project'
6 end 11 end
@@ -9,15 +14,11 @@ class MezuroPlugin::ProjectContent &lt; Article @@ -9,15 +14,11 @@ class MezuroPlugin::ProjectContent &lt; Article
9 'Software project tracked by Kalibro' 14 'Software project tracked by Kalibro'
10 end 15 end
11 16
12 - settings_items :license, :description, :repository_type, :repository_url, :configuration_name, :periodicity_in_days  
13 -  
14 - include ActionView::Helpers::TagHelper  
15 def to_html(options = {}) 17 def to_html(options = {})
16 lambda do 18 lambda do
17 render :file => 'content_viewer/show_project.rhtml' 19 render :file => 'content_viewer/show_project.rhtml'
18 end 20 end
19 end 21 end
20 -  
21 22
22 def project 23 def project
23 begin 24 begin
@@ -45,8 +46,8 @@ Kalibro::ProjectResult.first_result_after(name, date) @@ -45,8 +46,8 @@ Kalibro::ProjectResult.first_result_after(name, date)
45 end 46 end
46 47
47 def module_result(module_name) 48 def module_result(module_name)
48 - module_name = project.name if module_name.nil?  
49 - @module_client ||= Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date(project.name, module_name, @project_result.date) 49 + module_name ||= project.name
  50 + @module_result ||= Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date(project.name, module_name, project_result.date)
50 end 51 end
51 52
52 def result_history(module_name) 53 def result_history(module_name)
@@ -88,7 +89,7 @@ Kalibro::ProjectResult.first_result_after(name, date) @@ -88,7 +89,7 @@ Kalibro::ProjectResult.first_result_after(name, date)
88 89
89 def destroy_project_from_service 90 def destroy_project_from_service
90 begin 91 begin
91 - Kalibro::Project.destroy(name) 92 + project.destroy
92 rescue Exception => error 93 rescue Exception => error
93 errors.add_to_base(error.message) 94 errors.add_to_base(error.message)
94 end 95 end
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
@@ -2,16 +2,17 @@ require &quot;test_helper&quot; @@ -2,16 +2,17 @@ require &quot;test_helper&quot;
2 2
3 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" 3 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures"
4 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" 4 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures"
  5 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_fixtures"
  6 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures"
5 7
6 class ProjectContentTest < ActiveSupport::TestCase 8 class ProjectContentTest < ActiveSupport::TestCase
7 9
8 def setup 10 def setup
9 @project = ProjectFixtures.project 11 @project = ProjectFixtures.project
10 @content = ProjectFixtures.project_content 12 @content = ProjectFixtures.project_content
11 - end  
12 -  
13 - should 'be an article' do  
14 - assert_kind_of Article, @content 13 + @project_result = ProjectResultFixtures.project_result
  14 + @module = ModuleFixtures.module
  15 + @module_result = ModuleResultFixtures.module_result
15 end 16 end
16 17
17 should 'provide proper short description' do 18 should 'provide proper short description' do
@@ -27,64 +28,52 @@ class ProjectContentTest &lt; ActiveSupport::TestCase @@ -27,64 +28,52 @@ class ProjectContentTest &lt; ActiveSupport::TestCase
27 end 28 end
28 29
29 should 'get project from service' do 30 should 'get project from service' do
30 - Kalibro::Project.expects(:find_by_name).with(@content.name).returns(@project)  
31 - assert_equal @project, @content.project 31 + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash})
  32 + assert_equal @project.name, @content.project.name
32 end 33 end
33 34
34 should 'get project result from service' do 35 should 'get project result from service' do
35 - project_result = mock  
36 - Kalibro::Client::ProjectResultClient.expects(:last_result).with(@content.name).returns(project_result)  
37 - assert_equal project_result, @content.project_result 36 + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash})
  37 + assert_equal @project_result.load_time, @content.project_result.load_time
38 end 38 end
39 39
40 should 'get date result from service when has_result_before is true' do 40 should 'get date result from service when has_result_before is true' do
41 - client = mock  
42 - project_result = mock  
43 - Kalibro::Client::ProjectResultClient.expects(:new).returns(client)  
44 - client.expects(:has_results_before).with(@project.name, "2012-05-22T22:00:33+04:00").returns(true)  
45 - client.expects(:last_result_before).with(@project.name, "2012-05-22T22:00:33+04:00").returns(project_result)  
46 - assert_equal project_result, @content.get_date_result("2012-05-22T22:00:33+04:00") 41 + request_body = {:project_name => @project.name, :date => @project_result.date}
  42 + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true})
  43 + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash})
  44 + assert_equal @project_result.load_time, @content.project_result_with_date(@project_result.date).load_time
47 end 45 end
48 46
49 should 'get date result from service when has_result_before is false' do 47 should 'get date result from service when has_result_before is false' do
50 - client = mock  
51 - project_result = mock  
52 - Kalibro::Client::ProjectResultClient.expects(:new).returns(client)  
53 - client.expects(:has_results_before).with(@project.name, "2012-05-22T22:00:33+04:00").returns(false)  
54 - client.expects(:first_result_after).with(@project.name, "2012-05-22T22:00:33+04:00").returns(project_result)  
55 - assert_equal project_result, @content.get_date_result("2012-05-22T22:00:33+04:00") 48 + request_body = {:project_name => @project.name, :date => @project_result.date}
  49 + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => false})
  50 + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_first_result_after, request_body).returns({:project_result => @project_result.to_hash})
  51 + assert_equal @project_result.load_time, @content.project_result_with_date(@project_result.date).load_time
56 end 52 end
57 53
58 should 'get module result from service' do 54 should 'get module result from service' do
59 - mock_project_client  
60 - project_result = mock_project_result_client  
61 - module_name = 'My module name'  
62 - module_result_client = mock  
63 - module_result = Kalibro::Entities::ModuleResult.new  
64 - @content.expects(:module_result_client).returns(module_result_client)  
65 - module_result_client.expects(:module_result).with(@project.name, module_name, project_result.date).  
66 -returns(module_result)  
67 - assert_equal module_result, @content.module_result(module_name)  
68 - end  
69 -  
70 - should 'get module result root when nil is given' do  
71 - mock_project_client  
72 - project_result = mock_project_result_client  
73 - module_result_client = mock  
74 - module_result = Kalibro::Entities::ModuleResult.new  
75 - @content.expects(:module_result_client).returns(module_result_client)  
76 - module_result_client.expects(:module_result).with(@project.name, @project.name, project_result.date).  
77 -returns(module_result)  
78 - assert_equal module_result, @content.module_result(nil) 55 + date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date)
  56 + Kalibro::ProjectResult.expects(:request).with('ProjectResult', :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash})
  57 + Kalibro::ModuleResult.expects(:request).with(
  58 + 'ModuleResult',
  59 + :get_module_result,
  60 + {
  61 + :project_name => @project.name,
  62 + :module_name => @module.name,
  63 + :date => date_with_milliseconds
  64 + }).returns({:module_result => @module_result.to_hash})
  65 + assert_equal @module_result.grade, @content.module_result(@module.name).grade
79 end 66 end
80 67
81 should 'get result history' do 68 should 'get result history' do
82 - mock_project_client  
83 - module_name = 'Fake Name'  
84 - module_result_client = mock  
85 - module_result_client.expects(:result_history).with(@project.name, module_name)  
86 - @content.expects(:module_result_client).returns(module_result_client)  
87 - @content.result_history(module_name) 69 + Kalibro::ModuleResult.expects(:request).with(
  70 + 'ModuleResult',
  71 + :get_result_history,
  72 + {
  73 + :project_name => @project.name,
  74 + :module_name => @module.name
  75 + }).returns({:module_result => @module_result.to_hash})
  76 + @content.result_history(@module.name)
88 end 77 end
89 78
90 should 'send project to service after saving' do 79 should 'send project to service after saving' do
@@ -93,15 +82,14 @@ returns(module_result) @@ -93,15 +82,14 @@ returns(module_result)
93 end 82 end
94 83
95 should 'send correct project to service' do 84 should 'send correct project to service' do
96 - project = mock  
97 - Kalibro::Project.expects(:create).with(@content).returns(project)  
98 - project.expects(:save).returns(true) 85 + Kalibro::Project.expects(:create).with(@content).returns(true)
99 Kalibro::Kalibro.expects(:process_project).with(@content.name, @content.periodicity_in_days) 86 Kalibro::Kalibro.expects(:process_project).with(@content.name, @content.periodicity_in_days)
100 @content.send :send_project_to_service 87 @content.send :send_project_to_service
101 end 88 end
102 89
103 should 'destroy project from service' do 90 should 'destroy project from service' do
104 - Kalibro::Project.expects(:destroy).with(@content.name) 91 + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash})
  92 + Kalibro::Project.expects(:request).with("Project", :remove_project, {:project_name => @project.name})
105 @content.send :destroy_project_from_service 93 @content.send :destroy_project_from_service
106 end 94 end
107 95
@@ -111,20 +99,4 @@ returns(module_result) @@ -111,20 +99,4 @@ returns(module_result)
111 assert_equal "Project name already exists in Kalibro", @content.errors.on_base 99 assert_equal "Project name already exists in Kalibro", @content.errors.on_base
112 end 100 end
113 101
114 - private  
115 -  
116 - def mock_project_client  
117 - Kalibro::Project.expects(:find_by_name).with(@content.name).returns(@project)  
118 - end  
119 -  
120 - def mock_project_result_client  
121 - project_result = ProjectResultFixtures.qt_calculator  
122 - Kalibro::Client::ProjectResultClient.expects(:last_result).with(@content.name).returns(project_result)  
123 - project_result  
124 - end  
125 -  
126 - def create_project_error  
127 - raise "Error on Kalibro"  
128 - end  
129 -  
130 end 102 end