1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00
middleman--middleman/middleman-core/features/helpers_url_for.feature
Paul McMahon 4fe0732713
Cleanup of how fixtures customize a fixture (#2342)
* Use "Given" instead of "And" as first scenario step

* Remove unnecessary step

The following step already invokes this step

* Remove setup in feature that doesn't do anything

As this referenced "i18n-test-app", but later we run
"i18n-mixed-sources", these steps weren't doing anything.

* Avoid referencing the same fixture twice

The step "the Server is running at" invokes the "a fixture app" step,
followed by "the Server is running" step.
2020-06-15 11:19:39 -07:00

152 lines
5.3 KiB
Gherkin

Feature: url_for helper
Scenario: url_for produces relative links
Given a fixture app "indexable-app"
And an empty file named "config.rb"
And a file named "source/url_for.html.erb" with:
"""
absolute: <%= url_for "/needs_index.html", relative: true %>
relative: <%= url_for "needs_index.html", relative: true %>
"""
And a file named "source/url_for/sub.html.erb" with:
"""
absolute: <%= url_for "/needs_index.html", relative: true %>
relative: <%= url_for "../needs_index.html", relative: true %>
"""
And the Server is running
When I go to "/url_for.html"
Then I should see 'absolute: needs_index.html'
Then I should see 'relative: needs_index.html'
When I go to "/url_for/sub.html"
Then I should see 'absolute: ../needs_index.html'
Then I should see 'relative: ../needs_index.html'
Scenario: url_for relative works with strip_index_file
Given a fixture app "indexable-app"
And a file named "config.rb" with:
"""
set :relative_links, true
set :strip_index_file, true
helpers do
def menu_items(path='url_for.html')
sitemap.by_destination_path(path).children
end
end
"""
And a file named "source/url_for.html.erb" with:
"""
<% menu_items.each do |item| %>
"<%= url_for(item.url) %>"
"<%= url_for(item) %>"
<% end %>
"""
And a file named "source/url_for/sub.html.erb" with:
"""
<% menu_items.each do |item| %>
"<%= url_for(item.url) %>"
"<%= url_for(item) %>"
<% end %>
"""
And the Server is running
When I go to "/url_for.html"
Then I should see '"url_for/sub.html"'
Then I should not see "/url_for/sub.html"
When I go to "/url_for/sub.html"
Then I should see '"sub.html"'
Then I should not see "/url_for/sub.html"
Scenario: url_for produces relative links when :relative_links is set to true
Given a fixture app "indexable-app"
And a file named "config.rb" with:
"""
set :relative_links, true
"""
And a file named "source/url_for.html.erb" with:
"""
absolute: <%= url_for "/needs_index.html" %>
relative: <%= url_for "needs_index.html", relative: false %>
unknown: <%= url_for "foo.html" %>
"""
And a file named "source/url_for/sub.html.erb" with:
"""
absolute: <%= url_for "/needs_index.html" %>
relative: <%= url_for "../needs_index.html" %>
"""
And the Server is running
When I go to "/url_for.html"
Then I should see 'absolute: needs_index.html'
Then I should see 'relative: /needs_index.html'
Then I should see 'unknown: foo.html'
When I go to "/url_for/sub.html"
Then I should see 'absolute: ../needs_index.html'
Then I should see 'relative: ../needs_index.html'
Scenario: url_for knows about directory indexes
Given a fixture app "indexable-app"
And a file named "source/url_for.html.erb" with:
"""
absolute: <%= url_for "/needs_index.html", relative: true %>
relative: <%= url_for "needs_index.html", relative: true %>
"""
And a file named "source/url_for/sub.html.erb" with:
"""
absolute: <%= url_for "/needs_index.html", relative: true %>
relative: <%= url_for "../needs_index.html", relative: true %>
"""
And the Server is running
When I go to "/url_for/"
Then I should see 'absolute: ../needs_index/'
Then I should see 'relative: ../needs_index/'
When I go to "/url_for/sub/"
Then I should see 'absolute: ../../needs_index/'
Then I should see 'relative: ../../needs_index/'
Scenario: url_for can take a Resource
Given a fixture app "indexable-app"
And a file named "source/url_for.html.erb" with:
"""
"<%= url_for sitemap.by_path("/needs_index.html") %>"
"""
And the Server is running
When I go to "/url_for/"
Then I should see '"/needs_index/"'
Scenario: Setting http_prefix
Given a fixture app "indexable-app"
And a file named "config.rb" with:
"""
set :http_prefix, "/foo"
"""
And a file named "source/url_for.html.erb" with:
"""
<%= url_for "/needs_index.html" %>
"""
And the Server is running
When I go to "/url_for.html"
Then I should see '/foo/needs_index.html'
Scenario: url_for preserves query string and anchor and isn't messed up by them
Given a fixture app "indexable-app"
And a file named "source/url_for.html.erb" with:
"""
Needs Index Anchor <%= url_for "/needs_index.html#foo" %>
Needs Index Query <%= url_for "/needs_index.html?foo" %>
Needs Index Query and Anchor <%= url_for "/needs_index.html?foo#foo" %>
"""
And the Server is running
When I go to "/url_for/"
Then I should see 'Needs Index Anchor /needs_index/#foo'
Then I should see 'Needs Index Query /needs_index/?foo'
Then I should see 'Needs Index Query and Anchor /needs_index/?foo#foo'
Scenario: url_for accepts a :query option that appends a query string
Given a fixture app "indexable-app"
And a file named "source/url_for.html.erb" with:
"""
Needs Index String <%= url_for "/needs_index.html", query: "foo" %>
Needs Index Hash <%= url_for "/needs_index.html", query: { foo: :bar } %>
"""
And the Server is running
When I go to "/url_for/"
Then I should see 'Needs Index String /needs_index/?foo'
Then I should see 'Needs Index Hash /needs_index/?foo=bar'