Commit b02af6ba5b8b4422b518159d446084ebb30b47b4

Authored by Diego Camarinha
Committed by Paulo Meireles
1 parent 37be7d7c

[Mezuro] Adapting Mezuro to new Kalibro Service.

plugins/mezuro/controllers/myprofile/mezuro_plugin_reading_controller.rb
@@ -10,7 +10,7 @@ class MezuroPluginReadingController < MezuroPluginMyprofileController @@ -10,7 +10,7 @@ class MezuroPluginReadingController < MezuroPluginMyprofileController
10 reading_group_content = profile.articles.find(params[:id]) 10 reading_group_content = profile.articles.find(params[:id])
11 reading = Kalibro::Reading.new params[:reading] 11 reading = Kalibro::Reading.new params[:reading]
12 12
13 - if( reading.save(reading_group_content.reading_group_id) ) 13 + if( reading.save )
14 redirect_to reading_group_content.view_url 14 redirect_to reading_group_content.view_url
15 else 15 else
16 redirect_to_error_page reading.errors[0].message 16 redirect_to_error_page reading.errors[0].message
plugins/mezuro/controllers/profile/mezuro_plugin_repository_controller.rb
@@ -8,16 +8,14 @@ class MezuroPluginRepositoryController < MezuroPluginProfileController @@ -8,16 +8,14 @@ class MezuroPluginRepositoryController < MezuroPluginProfileController
8 8
9 def edit 9 def edit
10 params_repository_form 10 params_repository_form
11 - @repository = @project_content.repositories.select{ |repository| repository.id.to_s == params[:repository_id] }.first 11 + @repository = @project_content.repositories.select{ |repository| repository.id == params[:repository_id].to_i }.first
12 end 12 end
13 13
14 def save 14 def save
15 project_content = profile.articles.find(params[:id]) 15 project_content = profile.articles.find(params[:id])
16 -  
17 repository = Kalibro::Repository.new( params[:repository] ) 16 repository = Kalibro::Repository.new( params[:repository] )
18 - repository.save(project_content.project_id)  
19 17
20 - if( repository.errors.empty? ) 18 + if( repository.save )
21 repository.process 19 repository.process
22 redirect_to(repository_url(project_content, repository.id)) 20 redirect_to(repository_url(project_content, repository.id))
23 else 21 else
@@ -28,7 +26,7 @@ class MezuroPluginRepositoryController < MezuroPluginProfileController @@ -28,7 +26,7 @@ class MezuroPluginRepositoryController < MezuroPluginProfileController
28 def show 26 def show
29 @project_content = profile.articles.find(params[:id]) 27 @project_content = profile.articles.find(params[:id])
30 @repository = @project_content.repositories.select{ |repository| repository.id == params[:repository_id].to_i }.first 28 @repository = @project_content.repositories.select{ |repository| repository.id == params[:repository_id].to_i }.first
31 - @configuration_name = Kalibro::Configuration.configuration_of(@repository.id).name 29 + @configuration_name = Kalibro::Configuration.find(@repository.configuration_id).name
32 end 30 end
33 31
34 def destroy 32 def destroy
plugins/mezuro/lib/kalibro/configuration.rb
@@ -6,10 +6,6 @@ class Kalibro::Configuration < Kalibro::Model @@ -6,10 +6,6 @@ class Kalibro::Configuration < Kalibro::Model
6 @id = value.to_i 6 @id = value.to_i
7 end 7 end
8 8
9 - def self.configuration_of(repository_id)  
10 - new request(:configuration_of, {:repository_id => repository_id})[:configuration]  
11 - end  
12 -  
13 def self.all 9 def self.all
14 response = request(:all_configurations)[:configuration] 10 response = request(:all_configurations)[:configuration]
15 response = [] if response.nil? 11 response = [] if response.nil?
plugins/mezuro/lib/kalibro/module_result.rb
1 class Kalibro::ModuleResult < Kalibro::Model 1 class Kalibro::ModuleResult < Kalibro::Model
2 2
3 - attr_accessor :id, :module, :grade, :parent_id 3 + attr_accessor :id, :module, :grade, :parent_id, :height
4 4
5 def self.find(id) 5 def self.find(id)
6 new request(:get_module_result, { :module_result_id => id })[:module_result] 6 new request(:get_module_result, { :module_result_id => id })[:module_result]
plugins/mezuro/lib/kalibro/project.rb
@@ -12,9 +12,4 @@ class Kalibro::Project &lt; Kalibro::Model @@ -12,9 +12,4 @@ class Kalibro::Project &lt; Kalibro::Model
12 response = [response] if response.is_a?(Hash) 12 response = [response] if response.is_a?(Hash)
13 response.map {|project| new project} 13 response.map {|project| new project}
14 end 14 end
15 -  
16 - def self.project_of(repository_id)  
17 - new request(:project_of, :repository_id => repository_id)[:project]  
18 - end  
19 -  
20 end 15 end
plugins/mezuro/lib/kalibro/reading.rb
1 class Kalibro::Reading < Kalibro::Model 1 class Kalibro::Reading < Kalibro::Model
2 2
3 - attr_accessor :id, :label, :grade, :color 3 + attr_accessor :id, :label, :grade, :color, :group_id
4 4
5 def self.find(id) 5 def self.find(id)
6 new request(:get_reading, {:reading_id => id})[:reading] 6 new request(:get_reading, {:reading_id => id})[:reading]
@@ -25,14 +25,10 @@ class Kalibro::Reading &lt; Kalibro::Model @@ -25,14 +25,10 @@ class Kalibro::Reading &lt; Kalibro::Model
25 @grade = value.to_f 25 @grade = value.to_f
26 end 26 end
27 27
28 - def save(reading_group_id)  
29 - begin  
30 - self.id = self.class.request(:save_reading, {:reading => self.to_hash, :group_id => reading_group_id})[:reading_id]  
31 - true  
32 - rescue Exception => exception  
33 - add_error exception  
34 - false  
35 - end 28 + private
  29 +
  30 + def save_params
  31 + {:reading => self.to_hash, :group_id => group_id}
36 end 32 end
37 33
38 end 34 end
plugins/mezuro/lib/kalibro/repository.rb
1 class Kalibro::Repository < Kalibro::Model 1 class Kalibro::Repository < Kalibro::Model
2 2
3 - attr_accessor :id, :name, :description, :license, :process_period, :type, :address, :configuration_id 3 + attr_accessor :id, :name, :description, :license, :process_period, :type, :address, :configuration_id, :project_id
4 4
5 def self.repository_types 5 def self.repository_types
6 request(:supported_repository_types)[:supported_type].to_a 6 request(:supported_repository_types)[:supported_type].to_a
7 end 7 end
8 -  
9 - def self.repository_of(processing_id)  
10 - new request(:repository_of, {:processing_id => processing_id})[:repository]  
11 - end  
12 8
13 def self.repositories_of(project_id) 9 def self.repositories_of(project_id)
14 response = request(:repositories_of, {:project_id => project_id})[:repository] 10 response = request(:repositories_of, {:project_id => project_id})[:repository]
@@ -37,14 +33,10 @@ class Kalibro::Repository &lt; Kalibro::Model @@ -37,14 +33,10 @@ class Kalibro::Repository &lt; Kalibro::Model
37 self.class.request(:cancel_processing_of_repository, {:repository_id => self.id}) 33 self.class.request(:cancel_processing_of_repository, {:repository_id => self.id})
38 end 34 end
39 35
40 - def save(project_id)  
41 - begin  
42 - self.id = self.class.request(:save_repository, {:repository => self.to_hash, :project_id => project_id})[:repository_id]  
43 - true  
44 - rescue Exception => exception  
45 - add_error exception  
46 - false  
47 - end 36 + private
  37 +
  38 + def save_params
  39 + {:repository => self.to_hash, :project_id => project_id}
48 end 40 end
49 41
50 end 42 end
plugins/mezuro/test/fixtures/reading_fixtures.rb
@@ -5,11 +5,11 @@ class ReadingFixtures @@ -5,11 +5,11 @@ class ReadingFixtures
5 end 5 end
6 6
7 def self.created_reading # A created object has no id before being sent to kalibro 7 def self.created_reading # A created object has no id before being sent to kalibro
8 - Kalibro::Reading.new :label => "Reading Test Label", :grade => "10.5", :color => "AABBCC" 8 + Kalibro::Reading.new :label => "Reading Test Label", :grade => "10.5", :color => "AABBCC", :group_id => "31"
9 end 9 end
10 10
11 def self.reading_hash 11 def self.reading_hash
12 - {:id => "42", :label => "Reading Test Label", :grade => "10.5", :color => "AABBCC" } 12 + {:id => "42", :label => "Reading Test Label", :grade => "10.5", :color => "AABBCC", :group_id => "31"}
13 end 13 end
14 14
15 end 15 end
plugins/mezuro/test/fixtures/repository_fixtures.rb
@@ -12,12 +12,13 @@ class RepositoryFixtures @@ -12,12 +12,13 @@ class RepositoryFixtures
12 :process_period => "1", 12 :process_period => "1",
13 :type => 'SUBVERSION', 13 :type => 'SUBVERSION',
14 :address => 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator', 14 :address => 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator',
15 - :configuration_id => "31" 15 + :configuration_id => "31",
  16 + :project_id => "32"
16 }) 17 })
17 end 18 end
18 19
19 def self.repository_hash 20 def self.repository_hash
20 - {:id => "42", :name => "test repository", :description => "test description", :license => "GPL", :process_period => "1", :type => 'SUBVERSION', :address => "https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator", :configuration_id => "31"} 21 + {:id => "42", :name => "test repository", :description => "test description", :license => "GPL", :process_period => "1", :type => 'SUBVERSION', :address => "https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator", :configuration_id => "31", :project_id => "32"}
21 end 22 end
22 23
23 def self.types 24 def self.types
plugins/mezuro/test/functional/profile/mezuro_plugin_repository_controller_test.rb
@@ -73,7 +73,7 @@ class MezuroPluginRepositoryControllerTest &lt; ActionController::TestCase @@ -73,7 +73,7 @@ class MezuroPluginRepositoryControllerTest &lt; ActionController::TestCase
73 73
74 should 'set variables to show a repository' do 74 should 'set variables to show a repository' do
75 Kalibro::Repository.expects(:repositories_of).with(@content.project_id).returns([@repository]) 75 Kalibro::Repository.expects(:repositories_of).with(@content.project_id).returns([@repository])
76 - Kalibro::Configuration.expects(:configuration_of).with(@repository.id).returns(@configuration) 76 + Kalibro::Configuration.expects(:find).with(@repository.configuration_id).returns(@configuration)
77 77
78 get :show, :profile => @profile.identifier, :id => @content.id, :repository_id => @repository.id 78 get :show, :profile => @profile.identifier, :id => @content.id, :repository_id => @repository.id
79 79
plugins/mezuro/test/unit/kalibro/configuration_test.rb
@@ -23,7 +23,7 @@ class ConfigurationTest &lt; ActiveSupport::TestCase @@ -23,7 +23,7 @@ class ConfigurationTest &lt; ActiveSupport::TestCase
23 assert Kalibro::Configuration.exists?(@configuration.id) 23 assert Kalibro::Configuration.exists?(@configuration.id)
24 end 24 end
25 25
26 - should 'find configuration' do 26 + should 'find a configuration' do
27 Kalibro::Configuration.expects(:request).with(:configuration_exists, {:configuration_id => @configuration.id}).returns({:exists => true}) 27 Kalibro::Configuration.expects(:request).with(:configuration_exists, {:configuration_id => @configuration.id}).returns({:exists => true})
28 Kalibro::Configuration.expects(:request).with(:get_configuration, {:configuration_id => @configuration.id}).returns(:configuration => @hash) 28 Kalibro::Configuration.expects(:request).with(:get_configuration, {:configuration_id => @configuration.id}).returns(:configuration => @hash)
29 assert_equal @hash[:name], Kalibro::Configuration.find(@configuration.id).name 29 assert_equal @hash[:name], Kalibro::Configuration.find(@configuration.id).name
@@ -34,13 +34,7 @@ class ConfigurationTest &lt; ActiveSupport::TestCase @@ -34,13 +34,7 @@ class ConfigurationTest &lt; ActiveSupport::TestCase
34 assert_raise(Kalibro::Errors::RecordNotFound){Kalibro::Configuration.find(@configuration.id)} 34 assert_raise(Kalibro::Errors::RecordNotFound){Kalibro::Configuration.find(@configuration.id)}
35 end 35 end
36 36
37 - should 'get configuration of a repository' do  
38 - repository_id = 31  
39 - Kalibro::Configuration.expects(:request).with(:configuration_of, {:repository_id => repository_id}).returns({:configuration => @hash})  
40 - assert_equal @hash[:name], Kalibro::Configuration.configuration_of(repository_id).name  
41 - end  
42 -  
43 - should 'get all configuration' do 37 + should 'get all configurations' do
44 Kalibro::Configuration.expects(:request).with(:all_configurations).returns({:configuration => [@hash]}) 38 Kalibro::Configuration.expects(:request).with(:all_configurations).returns({:configuration => [@hash]})
45 assert_equal @hash[:name], Kalibro::Configuration.all.first.name 39 assert_equal @hash[:name], Kalibro::Configuration.all.first.name
46 end 40 end
plugins/mezuro/test/unit/kalibro/project_test.rb
@@ -37,12 +37,6 @@ class ProjectTest &lt; ActiveSupport::TestCase @@ -37,12 +37,6 @@ class ProjectTest &lt; ActiveSupport::TestCase
37 assert_raise(Kalibro::Errors::RecordNotFound){Kalibro::Project.find(@project.id)} 37 assert_raise(Kalibro::Errors::RecordNotFound){Kalibro::Project.find(@project.id)}
38 end 38 end
39 39
40 - should 'get project of a repository' do  
41 - repository_id = 31  
42 - Kalibro::Project.expects(:request).with(:project_of, {:repository_id => repository_id}).returns({:project => @hash})  
43 - assert_equal @hash[:name], Kalibro::Project.project_of(repository_id).name  
44 - end  
45 -  
46 should 'get all projects when there is only one project' do 40 should 'get all projects when there is only one project' do
47 Kalibro::Project.expects(:request).with(:all_projects).returns({:project => @hash}) 41 Kalibro::Project.expects(:request).with(:all_projects).returns({:project => @hash})
48 assert_equal @hash[:name], Kalibro::Project.all.first.name 42 assert_equal @hash[:name], Kalibro::Project.all.first.name
plugins/mezuro/test/unit/kalibro/reading_test.rb
@@ -38,17 +38,15 @@ class ReadingTest &lt; ActiveSupport::TestCase @@ -38,17 +38,15 @@ class ReadingTest &lt; ActiveSupport::TestCase
38 end 38 end
39 39
40 should 'return true when reading is saved successfully' do 40 should 'return true when reading is saved successfully' do
41 - reading_group_id = 31  
42 id_from_kalibro = 1 41 id_from_kalibro = 1
43 - Kalibro::Reading.expects(:request).with(:save_reading, {:group_id => reading_group_id, :reading => @created_reading.to_hash}).returns(:reading_id => id_from_kalibro)  
44 - assert @created_reading.save reading_group_id 42 + Kalibro::Reading.expects(:request).with(:save_reading, {:group_id => @created_reading.group_id, :reading => @created_reading.to_hash}).returns(:reading_id => id_from_kalibro)
  43 + assert @created_reading.save
45 assert_equal id_from_kalibro, @created_reading.id 44 assert_equal id_from_kalibro, @created_reading.id
46 end 45 end
47 46
48 should 'return false when reading is not saved successfully' do 47 should 'return false when reading is not saved successfully' do
49 - reading_group_id = 31  
50 - Kalibro::Reading.expects(:request).with(:save_reading, {:group_id => reading_group_id, :reading => @created_reading.to_hash}).raises(Exception.new)  
51 - assert !(@created_reading.save reading_group_id) 48 + Kalibro::Reading.expects(:request).with(:save_reading, {:group_id => @created_reading.group_id, :reading => @created_reading.to_hash}).raises(Exception.new)
  49 + assert !(@created_reading.save)
52 assert_nil @created_reading.id 50 assert_nil @created_reading.id
53 end 51 end
54 52
plugins/mezuro/test/unit/kalibro/repository_test.rb
@@ -28,12 +28,6 @@ class RepositoryTest &lt; ActiveSupport::TestCase @@ -28,12 +28,6 @@ class RepositoryTest &lt; ActiveSupport::TestCase
28 assert_equal types, Kalibro::Repository.repository_types 28 assert_equal types, Kalibro::Repository.repository_types
29 end 29 end
30 30
31 - should 'get repository of a precessing' do  
32 - id = 31  
33 - Kalibro::Repository.expects(:request).with(:repository_of, {:processing_id => id}).returns({:repository => @hash})  
34 - assert_equal @hash[:name], Kalibro::Repository.repository_of(id).name  
35 - end  
36 -  
37 should 'get repositories of a project' do 31 should 'get repositories of a project' do
38 project_id = 31 32 project_id = 31
39 Kalibro::Repository.expects(:request).with(:repositories_of, {:project_id => project_id}).returns({:repository => [@hash]}) 33 Kalibro::Repository.expects(:request).with(:repositories_of, {:project_id => project_id}).returns({:repository => [@hash]})
@@ -42,16 +36,14 @@ class RepositoryTest &lt; ActiveSupport::TestCase @@ -42,16 +36,14 @@ class RepositoryTest &lt; ActiveSupport::TestCase
42 36
43 should 'return true when repository is saved successfully' do 37 should 'return true when repository is saved successfully' do
44 id_from_kalibro = 1 38 id_from_kalibro = 1
45 - project_id = 56  
46 - Kalibro::Repository.expects(:request).with(:save_repository, {:repository => @created_repository.to_hash, :project_id => project_id}).returns(:repository_id => id_from_kalibro)  
47 - assert @created_repository.save(project_id) 39 + Kalibro::Repository.expects(:request).with(:save_repository, {:repository => @created_repository.to_hash, :project_id => @created_repository.project_id}).returns(:repository_id => id_from_kalibro)
  40 + assert @created_repository.save
48 assert_equal id_from_kalibro, @created_repository.id 41 assert_equal id_from_kalibro, @created_repository.id
49 end 42 end
50 43
51 should 'return false when repository is not saved successfully' do 44 should 'return false when repository is not saved successfully' do
52 - project_id = 56  
53 - Kalibro::Repository.expects(:request).with(:save_repository, {:repository => @created_repository.to_hash, :project_id => project_id}).raises(Exception.new)  
54 - assert !(@created_repository.save(project_id)) 45 + Kalibro::Repository.expects(:request).with(:save_repository, {:repository => @created_repository.to_hash, :project_id => @created_repository.project_id}).raises(Exception.new)
  46 + assert !(@created_repository.save)
55 assert_nil @created_repository.id 47 assert_nil @created_repository.id
56 end 48 end
57 49
plugins/mezuro/views/mezuro_plugin_reading/_form.html.erb
1 <%= hidden_field_tag :id, @reading_group_content.id %> 1 <%= hidden_field_tag :id, @reading_group_content.id %>
  2 +<%= f.hidden_field(:group_id, :value => @reading_group_content.reading_group_id) %>
2 3
3 <%= required labelled_form_field _('Label:'), f.text_field(:label) %> 4 <%= required labelled_form_field _('Label:'), f.text_field(:label) %>
4 5
plugins/mezuro/views/mezuro_plugin_reading/new.html.erb
@@ -4,6 +4,6 @@ @@ -4,6 +4,6 @@
4 4
5 <h2><%= link_to("#{@reading_group_content.name} Reading Group", @reading_group_content.view_url) %></h2> 5 <h2><%= link_to("#{@reading_group_content.name} Reading Group", @reading_group_content.view_url) %></h2>
6 6
7 -<% form_for :reading, :url => {:action =>"save", :controller => "mezuro_plugin_reading"}, :method => :get do |f| %> 7 +<% form_for :reading, :url => {:action =>"save", :controller => "mezuro_plugin_reading"}, :method => :get do |f| %>
8 <%= render :partial => "form", :locals => {:f => f} %> 8 <%= render :partial => "form", :locals => {:f => f} %>
9 <% end %> 9 <% end %>
plugins/mezuro/views/mezuro_plugin_repository/_form.html.erb
1 -<h2><%= link_to("#{@project_content.name} Project", @project_content.view_url) %></h2> 1 +<%= hidden_field_tag :id, @project_content.id %>
  2 +<%= f.hidden_field(:project_id, :value => @project_content.project_id) %>
2 3
3 -<% form_for :repository, :url => {:action =>"save", :controller => "mezuro_plugin_repository"}, :method => :get do |f| %>  
4 - <%= f.hidden_field :id %>  
5 - <%= hidden_field_tag :id, @project_content.id %> 4 +<%= required labelled_form_field _('Name'), f.text_field(:name) %>
6 5
7 - <%= required labelled_form_field _('Name'), f.text_field(:name) %> 6 +<%= labelled_form_field _("Description"), f.text_field(:description) %>
8 7
9 - <%= labelled_form_field _("Description"), f.text_field(:description) %> 8 +<%= required labelled_form_field _('License'),
  9 +f.select(:license, MezuroPlugin::Helpers::ContentViewerHelper.license_options) %>
10 10
11 - <%= required labelled_form_field _('License'),  
12 - f.select(:license, MezuroPlugin::Helpers::ContentViewerHelper.license_options) %> 11 +<%= required labelled_form_field _('Process Period'),
  12 +f.select(:process_period, MezuroPlugin::Helpers::ContentViewerHelper.periodicity_options) %>
13 13
14 - <%= required labelled_form_field _('Process Period'),  
15 - f.select(:process_period, MezuroPlugin::Helpers::ContentViewerHelper.periodicity_options) %> 14 +<%= required labelled_form_field _('Type'),
  15 +f.select(:type, @repository_types) %>
16 16
17 - <%= required labelled_form_field _('Type'),  
18 - f.select(:type, @repository_types) %> 17 +<%= required labelled_form_field _('Address'),
  18 +f.text_field(:address) %>
19 19
20 - <%= required labelled_form_field _('Address'),  
21 - f.text_field(:address) %> 20 +<%= required labelled_form_field _('Configuration'),
  21 +f.select(:configuration_id, @configuration_select) %>
22 22
23 - <%= required labelled_form_field _('Configuration'),  
24 - f.select(:configuration_id, @configuration_select) %>  
25 -  
26 - <p> <%= f.submit "Add" %> </p>  
27 -  
28 -<% end %> 23 +<p> <%= f.submit "Add" %> </p>
plugins/mezuro/views/mezuro_plugin_repository/edit.html.erb
1 <script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script> 1 <script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script>
2 2
3 -<%= render :partial => "form" %> 3 +<h2><%= link_to("#{@project_content.name} Project", @project_content.view_url) %></h2>
  4 +<% form_for :repository, :url => {:action =>"save", :controller => "mezuro_plugin_repository"}, :method => :get do |f| %>
  5 + <%= render :partial => "form", :locals => {:f => f} %>
  6 +<% end %>
plugins/mezuro/views/mezuro_plugin_repository/new.html.erb
1 <script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script> 1 <script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script>
2 2
3 -<%= render :partial => "form" %> 3 +<h2><%= link_to("#{@project_content.name} Project", @project_content.view_url) %></h2>
  4 +<% form_for :repository, :url => {:action =>"save", :controller => "mezuro_plugin_repository"}, :method => :get do |f| %>
  5 + <%= render :partial => "form", :locals => {:f => f} %>
  6 +<% end %>