Tests and a small bug fix to make them pass

i18n_v4
Tim Bates 2012-07-13 16:00:53 +09:30
parent 3cbda0ee36
commit 0fa1bfe675
6 changed files with 44 additions and 1 deletions

View File

@ -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'"

View File

@ -0,0 +1 @@
URL: '<%= current_page.url %>'

View File

@ -0,0 +1 @@
URL: '<%= current_page.url %>'

View File

@ -0,0 +1 @@
URL: '<%= current_page.url %>'

View File

@ -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)