Commit 64b24c2299b82b476bae845f9ea0eb64b9e6b430
Committed by
João M. M. da Silva
1 parent
e50674fe
Exists in
master
and in
29 other branches
[Mezuro] completed repository model refactoring.
Showing
3 changed files
with
73 additions
and
4 deletions
Show diff stats
plugins/mezuro/lib/kalibro/repository.rb
1 | 1 | class Kalibro::Repository < Kalibro::Model |
2 | 2 | |
3 | - attr_accessor :type, :address, :username, :password | |
3 | + attr_accessor :id, :name, :description, :license, :process_period, :type, :address, :configuration_id | |
4 | 4 | |
5 | 5 | def self.repository_types |
6 | - request("Kalibro", :get_supported_repository_types)[:repository_type].to_a | |
6 | + request("Repository", :supported_repository_types)[:repository_type].to_a | |
7 | + end | |
8 | + | |
9 | + def self.repository_of(processing_id) | |
10 | + new request("Repository", :repository_of, {:processing_id => processing_id})[:repository] | |
11 | + end | |
12 | + | |
13 | + def self.repositories_of(project_id) | |
14 | + request("Repository", :repositories_of, {:project_id => project_id})[:repository].to_a.map { |repository| new repository } | |
15 | + end | |
16 | + | |
17 | + def process_repository | |
18 | + self.class.request("Repository", :process_repository, {:repository_id => self.id}); | |
19 | + end | |
20 | + | |
21 | + def cancel_processing_of_repository | |
22 | + self.class.request("Repository", :cancel_processing_of_repository, {:repository_id => self.id}); | |
7 | 23 | end |
8 | 24 | |
9 | 25 | end | ... | ... |
plugins/mezuro/test/fixtures/repository_fixtures.rb
... | ... | @@ -4,8 +4,20 @@ class RepositoryFixtures |
4 | 4 | Kalibro::Repository.new repository_hash |
5 | 5 | end |
6 | 6 | |
7 | + def self.created_repository | |
8 | + Kalibro::Repository.new({ | |
9 | + :name => "test created repository", | |
10 | + :description => "test description", | |
11 | + :license => "GPL", | |
12 | + :process_period => "1", | |
13 | + :type => 'SUBVERSION', | |
14 | + :address => 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator', | |
15 | + :configuration_id => 31 | |
16 | + }) | |
17 | + end | |
18 | + | |
7 | 19 | def self.repository_hash |
8 | - {:type => 'SUBVERSION', :address => 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator'} | |
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} | |
9 | 21 | end |
10 | 22 | |
11 | 23 | end | ... | ... |
plugins/mezuro/test/unit/kalibro/repository_test.rb
... | ... | @@ -7,6 +7,7 @@ class RepositoryTest < ActiveSupport::TestCase |
7 | 7 | def setup |
8 | 8 | @hash = RepositoryFixtures.repository_hash |
9 | 9 | @repository = RepositoryFixtures.repository |
10 | + @created_repository = RepositoryFixtures.created_repository | |
10 | 11 | end |
11 | 12 | |
12 | 13 | should 'new repository from hash' do |
... | ... | @@ -19,8 +20,48 @@ class RepositoryTest < ActiveSupport::TestCase |
19 | 20 | |
20 | 21 | should 'get supported repository types' do |
21 | 22 | types = ['BAZAAR', 'GIT', 'SUBVERSION'] |
22 | - Kalibro::Repository.expects(:request).with('Kalibro', :get_supported_repository_types).returns({:repository_type => types}) | |
23 | + Kalibro::Repository.expects(:request).with('Repository', :supported_repository_types).returns({:repository_type => types}) | |
23 | 24 | assert_equal types, Kalibro::Repository.repository_types |
24 | 25 | end |
25 | 26 | |
27 | + should 'get repository of a precessing' do | |
28 | + id = 31 | |
29 | + Kalibro::Repository.expects(:request).with("Repository", :repository_of, {:processing_id => id}).returns({:repository => @hash}) | |
30 | + assert_equal @hash[:name], Kalibro::Repository.repository_of(id).name | |
31 | + end | |
32 | + | |
33 | + should 'get repositories of a project' do | |
34 | + project_id = 31 | |
35 | + Kalibro::Repository.expects(:request).with("Repository", :repositories_of, {:project_id => project_id}).returns({:repository => [@hash]}) | |
36 | + assert_equal @hash[:name], Kalibro::Repository.repositories_of(project_id).first.name | |
37 | + end | |
38 | + | |
39 | + should 'return true when repository is saved successfully' do | |
40 | + id_from_kalibro = 1 | |
41 | + Kalibro::Repository.expects(:request).with("Repository", :save_repository, {:repository => @created_repository.to_hash}).returns(id_from_kalibro) | |
42 | + assert @created_repository.save | |
43 | + assert_equal id_from_kalibro, @created_repository.id | |
44 | + end | |
45 | + | |
46 | + should 'return false when repository is not saved successfully' do | |
47 | + Kalibro::Repository.expects(:request).with("Repository", :save_repository, {:repository => @created_repository.to_hash}).raises(Exception.new) | |
48 | + assert !(@created_repository.save) | |
49 | + assert_nil @created_repository.id | |
50 | + end | |
51 | + | |
52 | + should 'destroy repository by id' do | |
53 | + Kalibro::Repository.expects(:request).with("Repository", :delete_repository, {:repository_id => @repository.id}) | |
54 | + @repository.destroy | |
55 | + end | |
56 | + | |
57 | + should 'process repository' do | |
58 | + Kalibro::Repository.expects(:request).with("Repository", :process_repository, {:repository_id => @repository.id}); | |
59 | + @repository.process_repository | |
60 | + end | |
61 | + | |
62 | + should 'cancel processing of a repository' do | |
63 | + Kalibro::Repository.expects(:request).with("Repository", :cancel_processing_of_repository, {:repository_id => @repository.id}); | |
64 | + @repository.cancel_processing_of_repository | |
65 | + end | |
66 | + | |
26 | 67 | end | ... | ... |