Commit f1bbe72d11192726050c96dccfb8925efee6c99b
Committed by
João M. M. da Silva
1 parent
70f57d83
Exists in
master
and in
23 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 | class MezuroPlugin::ConfigurationContent < Article | 1 | class MezuroPlugin::ConfigurationContent < Article |
| 2 | validate_on_create :validate_kalibro_configuration_name | 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 | def self.short_description | 9 | def self.short_description |
| 5 | 'Kalibro configuration' | 10 | 'Kalibro configuration' |
| 6 | end | 11 | end |
| @@ -9,8 +14,6 @@ class MezuroPlugin::ConfigurationContent < Article | @@ -9,8 +14,6 @@ class MezuroPlugin::ConfigurationContent < Article | ||
| 9 | 'Sets of thresholds to interpret metrics' | 14 | 'Sets of thresholds to interpret metrics' |
| 10 | end | 15 | end |
| 11 | 16 | ||
| 12 | - settings_items :description, :clone_configuration_name | ||
| 13 | - | ||
| 14 | include ActionView::Helpers::TagHelper | 17 | include ActionView::Helpers::TagHelper |
| 15 | def to_html(options = {}) | 18 | def to_html(options = {}) |
| 16 | lambda do | 19 | lambda do |
| @@ -34,9 +37,6 @@ class MezuroPlugin::ConfigurationContent < Article | @@ -34,9 +37,6 @@ class MezuroPlugin::ConfigurationContent < Article | ||
| 34 | ["None"] + Kalibro::Configuration.all_names.sort | 37 | ["None"] + Kalibro::Configuration.all_names.sort |
| 35 | end | 38 | end |
| 36 | 39 | ||
| 37 | - after_save :send_configuration_to_service | ||
| 38 | - after_destroy :remove_configuration_from_service | ||
| 39 | - | ||
| 40 | private | 40 | private |
| 41 | 41 | ||
| 42 | def validate_kalibro_configuration_name | 42 | def validate_kalibro_configuration_name |
| @@ -68,15 +68,19 @@ class MezuroPlugin::ConfigurationContent < Article | @@ -68,15 +68,19 @@ class MezuroPlugin::ConfigurationContent < Article | ||
| 68 | end | 68 | end |
| 69 | 69 | ||
| 70 | def editing_configuration? | 70 | def editing_configuration? |
| 71 | - !configuration.nil? | 71 | + configuration.present? |
| 72 | end | 72 | end |
| 73 | 73 | ||
| 74 | def configuration_to_clone | 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 | end | 80 | end |
| 77 | 81 | ||
| 78 | def cloning_configuration? | 82 | def cloning_configuration? |
| 79 | - configuration_to_clone.nil? | 83 | + configuration_to_clone.present? |
| 80 | end | 84 | end |
| 81 | 85 | ||
| 82 | end | 86 | end |
plugins/mezuro/test/fixtures/configuration_fixtures.rb
| @@ -21,7 +21,7 @@ class ConfigurationFixtures | @@ -21,7 +21,7 @@ class ConfigurationFixtures | ||
| 21 | MezuroPlugin::ConfigurationContent.new({ | 21 | MezuroPlugin::ConfigurationContent.new({ |
| 22 | :name => 'Sample Configuration', | 22 | :name => 'Sample Configuration', |
| 23 | :description => 'Kalibro configuration for Java projects.', | 23 | :description => 'Kalibro configuration for Java projects.', |
| 24 | - :clone_configuration_name => clone_configuration | 24 | + :configuration_to_clone_name => clone_configuration |
| 25 | }) | 25 | }) |
| 26 | end | 26 | end |
| 27 | 27 |
plugins/mezuro/test/unit/mezuro_plugin/configuration_content_test.rb
| @@ -44,9 +44,23 @@ class ConfigurationContentTest < ActiveSupport::TestCase | @@ -44,9 +44,23 @@ class ConfigurationContentTest < ActiveSupport::TestCase | ||
| 44 | @content.run_callbacks :after_save | 44 | @content.run_callbacks :after_save |
| 45 | end | 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 | Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) | 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 | @content.send :send_configuration_to_service | 64 | @content.send :send_configuration_to_service |
| 51 | end | 65 | end |
| 52 | 66 |
plugins/mezuro/views/cms/mezuro_plugin/_configuration_content.html.erb
| @@ -15,15 +15,15 @@ | @@ -15,15 +15,15 @@ | ||
| 15 | 15 | ||
| 16 | <% configuration_names = @article.configuration_names %> | 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 | <%= required_fields_message %> | 20 | <%= required_fields_message %> |
| 21 | 21 | ||
| 22 | <%= required labelled_form_field _('Clone Configuration'), | 22 | <%= required labelled_form_field _('Clone Configuration'), |
| 23 | if !configuration.nil? && !@article.id.nil? | 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 | else | 25 | else |
| 26 | - f.select(:clone_configuration_name, configuration_names, {:selected => selected}) | 26 | + f.select(:configuration_to_clone_name, configuration_names, {:selected => selected}) |
| 27 | end %> | 27 | end %> |
| 28 | <br/> | 28 | <br/> |
| 29 | 29 |