daily_run_history_length should always be >= 1, so we raise an
ArgumentException if this is not the case.

Paired-with: Nick Lewis <n...@puppetlabs.com>
Signed-off-by: Jacob Helwig <ja...@puppetlabs.com>
---

Local-branch: tickets/next/4403-fix-dst-handling

 lib/settings_reader.rb           |    6 ++++++
 spec/lib/settings_reader_spec.rb |   33 +++++++++++++++++++++++++++++----
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/lib/settings_reader.rb b/lib/settings_reader.rb
index c3521d6..8e4ad08 100644
--- a/lib/settings_reader.rb
+++ b/lib/settings_reader.rb
@@ -42,6 +42,8 @@ class SettingsReader
 
     RAILS_DEFAULT_LOGGER.info(message) rescue nil
 
+    validate(settings)
+
     return OpenStruct.new(settings)
   end
 
@@ -54,4 +56,8 @@ class SettingsReader
   def self.filename_to_hash(filename)
     return YAML.load(ERB.new(File.read(filename)).result) rescue {}
   end
+
+  def self.validate(settings)
+    raise ArgumentError.new("'daily_run_history_length' must be >= 1") unless 
settings['daily_run_history_length'].to_i >= 1
+  end
 end
diff --git a/spec/lib/settings_reader_spec.rb b/spec/lib/settings_reader_spec.rb
index 6d2a627..54f80ce 100644
--- a/spec/lib/settings_reader_spec.rb
+++ b/spec/lib/settings_reader_spec.rb
@@ -9,11 +9,17 @@ FILE
     @sample_file = <<FILE
 foo: bob
 bat: baz
+daily_run_history_length: 1
 FILE
 
     @settings_file_all = <<FILE
 foo: bar
 bat: man
+daily_run_history_length: 1
+FILE
+
+    @settings_file_invalid_daily_run = <<FILE
+daily_run_history_length: 0
 FILE
   end
 
@@ -22,14 +28,22 @@ FILE
     File.stubs(:read).with {|filename| File.basename(filename) == 
"settings.yml.example"}.returns(@sample_file)
     RAILS_DEFAULT_LOGGER.expects(:info).with {|msg| msg =~ /Using default 
values for unspecified settings "bat"/}
 
-    SettingsReader.read.should == OpenStruct.new("foo" => "bar", "bat" => 
"baz")
+    SettingsReader.read.should == OpenStruct.new(
+      "foo"                      => "bar",
+      "bat"                      => "baz",
+      "daily_run_history_length" => 1
+    )
   end
 
   it "should use values from settings.yml.example if settings.yml does not 
exist" do
     File.stubs(:read).with {|filename| File.basename(filename) == 
"settings.yml.example"}.returns(@sample_file)
-    RAILS_DEFAULT_LOGGER.expects(:info).with {|msg| msg =~ /Using default 
values for unspecified settings "bat" and "foo"/}
+    RAILS_DEFAULT_LOGGER.expects(:info).with {|msg| msg =~ /Using default 
values for unspecified settings "bat", "daily_run_history_length", and "foo"/}
 
-    SettingsReader.read.should == OpenStruct.new("foo" => "bob", "bat" => 
"baz")
+    SettingsReader.read.should == OpenStruct.new(
+      "foo"                      => "bob",
+      "bat"                      => "baz",
+      "daily_run_history_length" => 1
+    )
   end
 
   it "should not output a warning if settings.yml defines all settings" do
@@ -37,6 +51,17 @@ FILE
     File.stubs(:read).with {|filename| File.basename(filename) == 
"settings.yml.example"}.returns(@sample_file)
     RAILS_DEFAULT_LOGGER.expects(:info).with {|msg| msg !~ /Using default 
values/}
 
-    SettingsReader.read.should == OpenStruct.new("foo" => "bar", "bat" => 
"man")
+    SettingsReader.read.should == OpenStruct.new(
+      "foo"                      => "bar",
+      "bat"                      => "man",
+      "daily_run_history_length" => 1
+    )
+  end
+
+  it "should validate that 'daily_run_history_length' is >= 1" do
+    File.stubs(:read).with {|filename| File.basename(filename) == 
"settings.yml"}.returns(@settings_file_invalid_daily_run)
+    File.stubs(:read).with {|filename| File.basename(filename) == 
"settings.yml.example"}.returns(@sample_file)
+
+    lambda { SettingsReader.read }.should raise_error(ArgumentError, 
"'daily_run_history_length' must be >= 1")
   end
 end
-- 
1.7.4.1

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to puppet-dev@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to