Commit f1bbe72d11192726050c96dccfb8925efee6c99b
Committed by
João M. M. da Silva
1 parent
70f57d83
Exists in
master
and in
29 other branches
[Mezuro] tests for clone configuration feature
Showing
4 changed files
with
32 additions
and
14 deletions
Show diff stats
plugins/mezuro/lib/mezuro_plugin/configuration_content.rb
1 | 1 | class MezuroPlugin::ConfigurationContent < Article |
2 | 2 | validate_on_create :validate_kalibro_configuration_name |
3 | 3 | |
4 | + settings_items :description, :configuration_to_clone_name | |
5 | + | |
6 | + after_save :send_configuration_to_service | |
7 | + after_destroy :remove_configuration_from_service | |
8 | + | |
4 | 9 | def self.short_description |
5 | 10 | 'Kalibro configuration' |
6 | 11 | end |
... | ... | @@ -9,8 +14,6 @@ class MezuroPlugin::ConfigurationContent < Article |
9 | 14 | 'Sets of thresholds to interpret metrics' |
10 | 15 | end |
11 | 16 | |
12 | - settings_items :description, :clone_configuration_name | |
13 | - | |
14 | 17 | include ActionView::Helpers::TagHelper |
15 | 18 | def to_html(options = {}) |
16 | 19 | lambda do |
... | ... | @@ -34,9 +37,6 @@ class MezuroPlugin::ConfigurationContent < Article |
34 | 37 | ["None"] + Kalibro::Configuration.all_names.sort |
35 | 38 | end |
36 | 39 | |
37 | - after_save :send_configuration_to_service | |
38 | - after_destroy :remove_configuration_from_service | |
39 | - | |
40 | 40 | private |
41 | 41 | |
42 | 42 | def validate_kalibro_configuration_name |
... | ... | @@ -68,15 +68,19 @@ class MezuroPlugin::ConfigurationContent < Article |
68 | 68 | end |
69 | 69 | |
70 | 70 | def editing_configuration? |
71 | - !configuration.nil? | |
71 | + configuration.present? | |
72 | 72 | end |
73 | 73 | |
74 | 74 | def configuration_to_clone |
75 | - @configuration_to_clone ||= Kalibro::Configuration.find_by_name(self.clone_configuration_name) | |
75 | + @configuration_to_clone ||= find_configuration_to_clone | |
76 | + end | |
77 | + | |
78 | + def find_configuration_to_clone | |
79 | + configuration_to_clone_name.nil? ? nil : Kalibro::Configuration.find_by_name(configuration_to_clone_name) | |
76 | 80 | end |
77 | 81 | |
78 | 82 | def cloning_configuration? |
79 | - configuration_to_clone.nil? | |
83 | + configuration_to_clone.present? | |
80 | 84 | end |
81 | 85 | |
82 | 86 | end | ... | ... |
plugins/mezuro/test/fixtures/configuration_fixtures.rb
... | ... | @@ -21,7 +21,7 @@ class ConfigurationFixtures |
21 | 21 | MezuroPlugin::ConfigurationContent.new({ |
22 | 22 | :name => 'Sample Configuration', |
23 | 23 | :description => 'Kalibro configuration for Java projects.', |
24 | - :clone_configuration_name => clone_configuration | |
24 | + :configuration_to_clone_name => clone_configuration | |
25 | 25 | }) |
26 | 26 | end |
27 | 27 | ... | ... |
plugins/mezuro/test/unit/mezuro_plugin/configuration_content_test.rb
... | ... | @@ -44,9 +44,23 @@ class ConfigurationContentTest < ActiveSupport::TestCase |
44 | 44 | @content.run_callbacks :after_save |
45 | 45 | end |
46 | 46 | |
47 | - should 'send correct configuration to service' do | |
47 | + should 'create new configuration' do | |
48 | + Kalibro::Configuration.expects(:create).with(:name => @content.name, :description => @content.description) | |
49 | + Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(nil) | |
50 | + @content.send :send_configuration_to_service | |
51 | + end | |
52 | + | |
53 | + should 'clone configuration' do | |
54 | + @content.configuration_to_clone_name = 'clone name' | |
55 | + Kalibro::Configuration.expects(:create).with(:name => @content.name, :description => @content.description, :metric_configuration => @configuration.metric_configurations_hash) | |
56 | + Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(nil) | |
57 | + Kalibro::Configuration.expects(:find_by_name).with('clone name').returns(@configuration) | |
58 | + @content.send :send_configuration_to_service | |
59 | + end | |
60 | + | |
61 | + should 'edit configuration' do | |
48 | 62 | Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) |
49 | - @configuration.expects(:save).returns(true) | |
63 | + @configuration.expects(:update_attributes).with(:description => @content.description) | |
50 | 64 | @content.send :send_configuration_to_service |
51 | 65 | end |
52 | 66 | ... | ... |
plugins/mezuro/views/cms/mezuro_plugin/_configuration_content.html.erb
... | ... | @@ -15,15 +15,15 @@ |
15 | 15 | |
16 | 16 | <% configuration_names = @article.configuration_names %> |
17 | 17 | |
18 | -<% selected = (configuration.nil? ? "None" : @article.clone_configuration_name) %> | |
18 | +<% selected = (configuration.nil? ? "None" : @article.configuration_to_clone_name) %> | |
19 | 19 | |
20 | 20 | <%= required_fields_message %> |
21 | 21 | |
22 | 22 | <%= required labelled_form_field _('Clone Configuration'), |
23 | 23 | if !configuration.nil? && !@article.id.nil? |
24 | - f.select(:clone_configuration_name, configuration_names, {:selected => selected}, :disabled => 'true') | |
24 | + f.select(:configuration_to_clone_name, configuration_names, {:selected => selected}, :disabled => 'true') | |
25 | 25 | else |
26 | - f.select(:clone_configuration_name, configuration_names, {:selected => selected}) | |
26 | + f.select(:configuration_to_clone_name, configuration_names, {:selected => selected}) | |
27 | 27 | end %> |
28 | 28 | <br/> |
29 | 29 | ... | ... |