From 0fa1bfe675636330cad372b736ae26bb59c2ec98 Mon Sep 17 00:00:00 2001 From: Tim Bates Date: Fri, 13 Jul 2012 16:00:53 +0930 Subject: [PATCH] Tests and a small bug fix to make them pass --- middleman-core/features/strip_url.feature | 40 +++++++++++++++++++ .../fixtures/strip-url-app/config.rb | 0 .../strip-url-app/source/index.html.erb | 1 + .../strip-url-app/source/other.html.erb | 1 + .../source/subdir/index.html.erb | 1 + .../lib/middleman-core/sitemap/resource.rb | 2 +- 6 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 middleman-core/features/strip_url.feature create mode 100644 middleman-core/fixtures/strip-url-app/config.rb create mode 100755 middleman-core/fixtures/strip-url-app/source/index.html.erb create mode 100755 middleman-core/fixtures/strip-url-app/source/other.html.erb create mode 100755 middleman-core/fixtures/strip-url-app/source/subdir/index.html.erb diff --git a/middleman-core/features/strip_url.feature b/middleman-core/features/strip_url.feature new file mode 100644 index 00000000..8a332d04 --- /dev/null +++ b/middleman-core/features/strip_url.feature @@ -0,0 +1,40 @@ +Feature: Strip the index_file from urls + + Scenario: Default behaviour, strip with trailing slash + Given the Server is running at "strip-url-app" + When I go to "/" + Then I should see "URL: '/'" + When I go to "/index.html" + Then I should see "URL: '/'" + When I go to "/other.html" + Then I should see "URL: '/other.html'" + When I go to "/subdir/index.html" + Then I should see "URL: '/subdir/'" + + Scenario: Trailing slash off + Given a fixture app "strip-url-app" + And a file named "config.rb" with: + """ + set :trailing_slash, false + """ + And the Server is running + When I go to "/" + Then I should see "URL: '/'" + When I go to "/other.html" + Then I should see "URL: '/other.html'" + When I go to "/subdir/index.html" + Then I should see "URL: '/subdir'" + + Scenario: Strip index off + Given a fixture app "strip-url-app" + And a file named "config.rb" with: + """ + set :strip_index_file, false + """ + And the Server is running + When I go to "/" + Then I should see "URL: '/index.html'" + When I go to "/other.html" + Then I should see "URL: '/other.html'" + When I go to "/subdir/index.html" + Then I should see "URL: '/subdir/index.html'" diff --git a/middleman-core/fixtures/strip-url-app/config.rb b/middleman-core/fixtures/strip-url-app/config.rb new file mode 100644 index 00000000..e69de29b diff --git a/middleman-core/fixtures/strip-url-app/source/index.html.erb b/middleman-core/fixtures/strip-url-app/source/index.html.erb new file mode 100755 index 00000000..f0fea13c --- /dev/null +++ b/middleman-core/fixtures/strip-url-app/source/index.html.erb @@ -0,0 +1 @@ +URL: '<%= current_page.url %>' diff --git a/middleman-core/fixtures/strip-url-app/source/other.html.erb b/middleman-core/fixtures/strip-url-app/source/other.html.erb new file mode 100755 index 00000000..f0fea13c --- /dev/null +++ b/middleman-core/fixtures/strip-url-app/source/other.html.erb @@ -0,0 +1 @@ +URL: '<%= current_page.url %>' diff --git a/middleman-core/fixtures/strip-url-app/source/subdir/index.html.erb b/middleman-core/fixtures/strip-url-app/source/subdir/index.html.erb new file mode 100755 index 00000000..f0fea13c --- /dev/null +++ b/middleman-core/fixtures/strip-url-app/source/subdir/index.html.erb @@ -0,0 +1 @@ +URL: '<%= current_page.url %>' diff --git a/middleman-core/lib/middleman-core/sitemap/resource.rb b/middleman-core/lib/middleman-core/sitemap/resource.rb index da8e8f84..28f86e10 100644 --- a/middleman-core/lib/middleman-core/sitemap/resource.rb +++ b/middleman-core/lib/middleman-core/sitemap/resource.rb @@ -143,7 +143,7 @@ module Middleman def url url_path = destination_path if app.strip_index_file - url_path = url_path.sub(/\/#{Regexp.escape(app.index_file)}$/, + url_path = url_path.sub(/(^|\/)#{Regexp.escape(app.index_file)}$/, app.trailing_slash ? '/' : '') end File.join(app.respond_to?(:http_prefix) ? app.http_prefix : '/', url_path)