From fb9b6f815050e4c3993d85250aa7151db3ae0e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Mon, 11 Feb 2013 13:00:45 +0100 Subject: [PATCH 1/2] Fixed configuration overriding The deep merge was made the wrong way around --- lib/octopress/configuration.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/octopress/configuration.rb b/lib/octopress/configuration.rb index db1d7ba..48c0bf5 100644 --- a/lib/octopress/configuration.rb +++ b/lib/octopress/configuration.rb @@ -55,10 +55,10 @@ module Octopress Dir.glob(self.config_dir('*.yml')) do |filename| file_yaml = YAML.load(File.read(filename)) unless file_yaml.nil? - configs = file_yaml.deep_merge(configs) + configs = configs.deep_merge(file_yaml) end end - + configs.to_symbol_keys end From e18fba945689c86d5f17214c5f35ce38b7b42741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Kar=C3=A9kinian?= Date: Tue, 12 Feb 2013 11:31:38 +0100 Subject: [PATCH 2/2] Added initial test coverage --- Rakefile | 5 +++ lib/octopress/configuration.rb | 4 +- .../fixtures/no_override/defaults/classic.yml | 11 +++++ spec/fixtures/override/defaults/classic.yml | 11 +++++ spec/fixtures/override/site.yml | 11 +++++ spec/octopress/configuration_spec.rb | 42 +++++++++++++++++++ 6 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/no_override/defaults/classic.yml create mode 100644 spec/fixtures/override/defaults/classic.yml create mode 100644 spec/fixtures/override/site.yml create mode 100644 spec/octopress/configuration_spec.rb diff --git a/Rakefile b/Rakefile index 07cdfd9..d327fa3 100644 --- a/Rakefile +++ b/Rakefile @@ -9,6 +9,7 @@ require 'rake/minify' require 'time' require 'yaml' require 'octopress' +require 'rake/testtask' ### Configuring Octopress: ### Under _config/ you will find: @@ -525,3 +526,7 @@ task :list do puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:list]]).join(', ')}" puts "(type rake -T for more detail)\n\n" end + +Rake::TestTask.new do |t| + t.pattern = "spec/**/*_spec.rb" +end diff --git a/lib/octopress/configuration.rb b/lib/octopress/configuration.rb index 48c0bf5..0e0034c 100644 --- a/lib/octopress/configuration.rb +++ b/lib/octopress/configuration.rb @@ -2,8 +2,10 @@ require 'yaml' module Octopress module Configuration + CONFIG_DIR = File.join(File.dirname(__FILE__), '../', '../' '_config') + def self.config_dir(*subdirs) - File.absolute_path(File.join(File.dirname(__FILE__), '../', '../' '_config', *subdirs)) + File.absolute_path(File.join(CONFIG_DIR, *subdirs)) end # Static: Reads the configuration of the specified file diff --git a/spec/fixtures/no_override/defaults/classic.yml b/spec/fixtures/no_override/defaults/classic.yml new file mode 100644 index 0000000..1e586e7 --- /dev/null +++ b/spec/fixtures/no_override/defaults/classic.yml @@ -0,0 +1,11 @@ +--- +# ------------------------------- # +# Classic Theme Configuration # +# ------------------------------- # + +url: http://yoursite.com +title: My Octopress Blog +subtitle: A blogging framework for hackers. +author: Your Name +simple_search: http://google.com/search +description: diff --git a/spec/fixtures/override/defaults/classic.yml b/spec/fixtures/override/defaults/classic.yml new file mode 100644 index 0000000..1e586e7 --- /dev/null +++ b/spec/fixtures/override/defaults/classic.yml @@ -0,0 +1,11 @@ +--- +# ------------------------------- # +# Classic Theme Configuration # +# ------------------------------- # + +url: http://yoursite.com +title: My Octopress Blog +subtitle: A blogging framework for hackers. +author: Your Name +simple_search: http://google.com/search +description: diff --git a/spec/fixtures/override/site.yml b/spec/fixtures/override/site.yml new file mode 100644 index 0000000..83b9e6b --- /dev/null +++ b/spec/fixtures/override/site.yml @@ -0,0 +1,11 @@ +--- +# ------------------------------- # +# Classic Theme Configuration # +# ------------------------------- # + +url: http://myownsite.com +title: My Octopress custom Blog +subtitle: "How did this get here? I'm not good with computers" +author: John Doe +simple_search: http://google.com/search +description: diff --git a/spec/octopress/configuration_spec.rb b/spec/octopress/configuration_spec.rb new file mode 100644 index 0000000..59b4b0f --- /dev/null +++ b/spec/octopress/configuration_spec.rb @@ -0,0 +1,42 @@ +require 'minitest/autorun' +require_relative '../../lib/octopress' + +describe Octopress::Configuration do + describe '.read_configuration' do + subject do + Octopress::Configuration.read_configuration + end + + describe "when no override" do + before do + Octopress::Configuration::CONFIG_DIR = File.join(File.dirname(__FILE__), '../', 'fixtures', 'no_override') + end + + it "returns the default config with keys as symbols" do + expected_config = { :url => "http://yoursite.com", + :title => "My Octopress Blog", + :subtitle => "A blogging framework for hackers.", + :author => "Your Name", + :simple_search => "http://google.com/search", + :description => nil } + subject.must_equal expected_config + end + end + + describe "when override" do + before do + Octopress::Configuration::CONFIG_DIR = File.join(File.dirname(__FILE__), '../', 'fixtures', 'override') + end + + it "returns the default config with keys as symbols" do + expected_config = { :url => "http://myownsite.com", + :title => "My Octopress custom Blog", + :subtitle => "How did this get here? I'm not good with computers", + :author => "John Doe", + :simple_search => "http://google.com/search", + :description => nil } + subject.must_equal expected_config + end + end + end +end