Commit 1be218147b2ca9e9f3d511ceec5e7340b6d3c470
Committed by
João M. M. da Silva
1 parent
66187117
Exists in
master
and in
28 other branches
[Mezuro] Completed configuration model, fixtures and tests.
Showing
3 changed files
with
48 additions
and
63 deletions
Show diff stats
plugins/mezuro/lib/kalibro/configuration.rb
... | ... | @@ -2,40 +2,14 @@ class Kalibro::Configuration < Kalibro::Model |
2 | 2 | |
3 | 3 | attr_accessor :id, :name, :description |
4 | 4 | |
5 | -=begin | |
6 | - def metric_configuration=(value) | |
7 | - @metric_configuration = Kalibro::MetricConfiguration.to_objects_array value | |
8 | - end | |
9 | - | |
10 | - def metric_configurations | |
11 | - @metric_configuration.nil? ? [] : @metric_configuration | |
12 | - end | |
13 | - | |
14 | - def metric_configurations=(metric_configurations) | |
15 | - @metric_configuration = metric_configurations | |
16 | - end | |
17 | -=end | |
18 | - | |
19 | -# Should be on parent class | |
20 | -# | |
21 | -# def self.exists?(id) | |
22 | -# request("Configuration", :configuration_exists, {:configuration_id => id})[:exists] | |
23 | -# end | |
24 | - | |
25 | - def self.find(id) | |
26 | - if(exists?(id)) | |
27 | - new request("Configuration", :get_configuration, {:configuration_name => configuration_name})[:configuration] | |
28 | - else | |
29 | - nil | |
30 | - end | |
31 | - end | |
32 | - | |
33 | 5 | def self.configuration_of(repository_id) |
34 | - new request("Configuration", :configuration_of, {:repository_id => repository_id})[:configuration] | |
6 | + new request(:configuration_of, {:repository_id => repository_id})[:configuration] | |
35 | 7 | end |
36 | 8 | |
37 | 9 | def self.all |
38 | - request("Configuration", :all_configuration)[:configuration] | |
10 | + response = request(:all_configurations)[:configuration].to_a | |
11 | + response = [] if response.nil? | |
12 | + response.map {|configuration| new configuration} | |
39 | 13 | end |
40 | 14 | |
41 | 15 | |
... | ... | @@ -44,7 +18,4 @@ class Kalibro::Configuration < Kalibro::Model |
44 | 18 | save |
45 | 19 | end |
46 | 20 | |
47 | -# def metric_configurations_hash | |
48 | -# self.to_hash[:metric_configuration] | |
49 | -# end | |
50 | 21 | end | ... | ... |
plugins/mezuro/test/fixtures/configuration_fixtures.rb
... | ... | @@ -6,14 +6,18 @@ class ConfigurationFixtures |
6 | 6 | Kalibro::Configuration.new configuration_hash |
7 | 7 | end |
8 | 8 | |
9 | + def self.created_configuration | |
10 | + Kalibro::Configuration.new({ | |
11 | + :name => 'Sample Configuration', | |
12 | + :description => 'Kalibro configuration for Java projects.' | |
13 | + }) | |
14 | + end | |
15 | + | |
9 | 16 | def self.configuration_hash |
10 | 17 | { |
18 | + :id => 42, | |
11 | 19 | :name => 'Sample Configuration', |
12 | - :description => 'Kalibro configuration for Java projects.', | |
13 | - :metric_configuration => [ | |
14 | - MetricConfigurationFixtures.amloc_metric_configuration_hash, | |
15 | - MetricConfigurationFixtures.sc_metric_configuration_hash | |
16 | - ] | |
20 | + :description => 'Kalibro configuration for Java projects.' | |
17 | 21 | } |
18 | 22 | end |
19 | 23 | ... | ... |
plugins/mezuro/test/unit/kalibro/configuration_test.rb
... | ... | @@ -7,7 +7,7 @@ class ConfigurationTest < ActiveSupport::TestCase |
7 | 7 | def setup |
8 | 8 | @hash = ConfigurationFixtures.configuration_hash |
9 | 9 | @configuration = ConfigurationFixtures.configuration |
10 | - @configuration_content = ConfigurationFixtures.configuration_content([]) | |
10 | + @created_configuration = ConfigurationFixtures.created_configuration | |
11 | 11 | end |
12 | 12 | |
13 | 13 | should 'initialize configuration' do |
... | ... | @@ -18,39 +18,49 @@ class ConfigurationTest < ActiveSupport::TestCase |
18 | 18 | assert_equal @hash, @configuration.to_hash |
19 | 19 | end |
20 | 20 | |
21 | - should 'return true when configuration is saved successfully' do | |
22 | - Kalibro::Configuration.expects(:request).with("Configuration", :save_configuration, {:configuration => @configuration.to_hash}) | |
23 | - assert @configuration.save | |
21 | + should 'answer if configuration exists in kalibro' do | |
22 | + Kalibro::Configuration.expects(:request).with(:configuration_exists, {:configuration_id => @configuration.id}).returns({:exists => true}) | |
23 | + assert Kalibro::Configuration.exists?(@configuration.id) | |
24 | 24 | end |
25 | 25 | |
26 | - should 'return false when configuration is not saved successfully' do | |
27 | - Kalibro::Configuration.expects(:request).with("Configuration", :save_configuration, {:configuration => @configuration.to_hash}).raises(Exception.new) | |
28 | - assert !(@configuration.save) | |
26 | + should 'find configuration' do | |
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) | |
29 | + assert_equal @hash[:name], Kalibro::Configuration.find(@configuration.id).name | |
29 | 30 | end |
30 | - | |
31 | - should 'get all configuration names' do | |
32 | - names = ['Kalibro for Java', 'ConfigurationClientTest configuration'] | |
33 | - Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration_names).returns({:configuration_name => names}) | |
34 | - assert_equal names, Kalibro::Configuration.all_names | |
31 | + | |
32 | + should 'return nil when configuration doesnt exist' do | |
33 | + Kalibro::Configuration.expects(:request).with(:configuration_exists, {:configuration_id => @configuration.id}).returns({:exists => false}) | |
34 | + assert_nil Kalibro::Configuration.find(@configuration.id) | |
35 | 35 | end |
36 | 36 | |
37 | - should 'find configuration by name' do | |
38 | - request_body = {:configuration_name => @configuration.name} | |
39 | - response_hash = {:configuration => @configuration.to_hash} | |
40 | - Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, request_body).returns(response_hash) | |
41 | - assert_equal @configuration.name, Kalibro::Configuration.find_by_name(@configuration.name).name | |
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 | |
42 | 41 | end |
43 | 42 | |
44 | - should 'return nil when configuration doesnt exist' do | |
45 | - request_body = {:configuration_name => @configuration.name} | |
46 | - Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, request_body).raises(Exception.new) | |
47 | - assert_raise Exception do | |
48 | - Kalibro::Configuration.find_by_name(@configuration.name) | |
49 | - end | |
43 | + should 'get all configuration' do | |
44 | + Kalibro::Configuration.expects(:request).with(:all_configurations).returns({:configuration => [@hash]}) | |
45 | + assert_equal @hash[:name], Kalibro::Configuration.all.first.name | |
46 | + end | |
47 | + | |
48 | + should 'return true when configuration is saved successfully' do | |
49 | + id_from_kalibro = 1 | |
50 | + Kalibro::Configuration.expects(:request).with(:save_configuration, {:configuration => @created_configuration.to_hash}).returns(:configuration_id => id_from_kalibro) | |
51 | + assert @created_configuration.save | |
52 | + assert_equal id_from_kalibro, @created_configuration.id | |
53 | + end | |
54 | + | |
55 | + should 'return false when configuration is not saved successfully' do | |
56 | + Kalibro::Configuration.expects(:request).with(:save_configuration, {:configuration => @created_configuration.to_hash}).raises(Exception.new) | |
57 | + assert !(@created_configuration.save) | |
58 | + assert_nil @created_configuration.id | |
50 | 59 | end |
51 | 60 | |
52 | - should 'destroy configuration by name' do | |
53 | - Kalibro::Configuration.expects(:request).with("Configuration", :remove_configuration, {:configuration_name => @configuration.name}) | |
61 | + should 'remove existent configuration from service' do | |
62 | + Kalibro::Configuration.expects(:request).with(:delete_configuration, {:configuration_id => @configuration.id}) | |
54 | 63 | @configuration.destroy |
55 | 64 | end |
65 | + | |
56 | 66 | end | ... | ... |