2012-06-16 20:48:41 -04:00
|
|
|
Feature: link_to helper
|
2012-05-24 19:14:17 -04:00
|
|
|
|
2013-06-12 14:19:02 -04:00
|
|
|
Scenario: link_to works with blocks (erb)
|
|
|
|
Given the Server is running at "link-to-app"
|
|
|
|
When I go to "/link_to_erb.html"
|
|
|
|
Then I should see "erb <s>with html tags</s>"
|
|
|
|
|
2015-03-03 16:09:46 -05:00
|
|
|
Scenario: link_to works with absolute URLs (where the relative part matches a local path)
|
|
|
|
Given a fixture app "link-to-app"
|
|
|
|
And a file named "config.rb" with:
|
|
|
|
"""
|
|
|
|
set :relative_links, true
|
|
|
|
"""
|
|
|
|
And a file named "source/test.html.erb" with:
|
|
|
|
"""
|
|
|
|
Hello
|
|
|
|
"""
|
|
|
|
And a file named "source/link_to_absolute.html.erb" with:
|
|
|
|
"""
|
|
|
|
<%= link_to "test", "http://google.com/test.html" %>
|
|
|
|
"""
|
|
|
|
And the Server is running at "link-to-app"
|
|
|
|
When I go to "/link_to_absolute.html"
|
|
|
|
Then I should see '<a href="http://google.com/test.html">test</a>'
|
|
|
|
|
2013-06-12 14:19:02 -04:00
|
|
|
Scenario: link_to works with blocks (slim)
|
|
|
|
Given the Server is running at "link-to-app"
|
|
|
|
When I go to "/link_to_slim.html"
|
|
|
|
Then I should see "<s>slim with html tags</s>"
|
|
|
|
|
|
|
|
Scenario: link_to works with blocks (haml)
|
|
|
|
Given the Server is running at "link-to-app"
|
|
|
|
When I go to "/link_to_haml.html"
|
|
|
|
Then I should see "<s>haml with html tags</s>"
|
|
|
|
|
2012-06-16 20:48:41 -04:00
|
|
|
Scenario: link_to produces relative links
|
2012-05-24 19:31:21 -04:00
|
|
|
Given a fixture app "indexable-app"
|
|
|
|
And an empty file named "config.rb"
|
|
|
|
And a file named "source/link_to.html.erb" with:
|
|
|
|
"""
|
|
|
|
absolute: <%= link_to "Needs Index", "/needs_index.html", :relative => true %>
|
|
|
|
relative: <%= link_to "Relative", "needs_index.html", :relative => true %>
|
|
|
|
"""
|
|
|
|
And a file named "source/link_to/sub.html.erb" with:
|
|
|
|
"""
|
|
|
|
absolute: <%= link_to "Needs Index", "/needs_index.html", :relative => true %>
|
|
|
|
relative: <%= link_to "Relative", "../needs_index.html", :relative => true %>
|
|
|
|
"""
|
|
|
|
And the Server is running at "indexable-app"
|
|
|
|
When I go to "/link_to.html"
|
|
|
|
Then I should see 'absolute: <a href="needs_index.html">Needs Index</a>'
|
|
|
|
Then I should see 'relative: <a href="needs_index.html">Relative</a>'
|
|
|
|
When I go to "/link_to/sub.html"
|
|
|
|
Then I should see 'absolute: <a href="../needs_index.html">Needs Index</a>'
|
|
|
|
Then I should see 'relative: <a href="../needs_index.html">Relative</a>'
|
|
|
|
|
2013-01-08 02:30:04 -05:00
|
|
|
Scenario: link_to 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='link_to.html')
|
|
|
|
sitemap.find_resource_by_destination_path(path).children
|
|
|
|
end
|
|
|
|
end
|
|
|
|
"""
|
|
|
|
And a file named "source/link_to.html.erb" with:
|
|
|
|
"""
|
|
|
|
<% menu_items.each do |item| %>
|
2013-04-06 15:15:05 -04:00
|
|
|
<%= link_to(item.data['title'], item.url) %>
|
|
|
|
<%= link_to(item.data['title'], item) %>
|
2013-01-08 02:30:04 -05:00
|
|
|
<% end %>
|
|
|
|
"""
|
|
|
|
And a file named "source/link_to/sub.html.erb" with:
|
|
|
|
"""
|
|
|
|
<% menu_items.each do |item| %>
|
2013-04-06 15:15:05 -04:00
|
|
|
<%= link_to(item.data['title'], item.url) %>
|
|
|
|
<%= link_to(item.data['title'], item) %>
|
2013-01-08 02:30:04 -05:00
|
|
|
<% end %>
|
|
|
|
"""
|
|
|
|
And the Server is running at "indexable-app"
|
|
|
|
When I go to "/link_to.html"
|
|
|
|
Then I should see '"link_to/sub.html"'
|
|
|
|
Then I should not see "/link_to/sub.html"
|
|
|
|
When I go to "/link_to/sub.html"
|
|
|
|
Then I should see '"sub.html"'
|
|
|
|
Then I should not see "/link_to/sub.html"
|
|
|
|
|
2012-06-16 20:48:41 -04:00
|
|
|
Scenario: link_to produces relative links when :relative_links is set to true
|
2012-05-24 19:31:21 -04:00
|
|
|
Given a fixture app "indexable-app"
|
|
|
|
And a file named "config.rb" with:
|
|
|
|
"""
|
|
|
|
set :relative_links, true
|
|
|
|
"""
|
|
|
|
And a file named "source/link_to.html.erb" with:
|
|
|
|
"""
|
|
|
|
absolute: <%= link_to "Needs Index", "/needs_index.html" %>
|
|
|
|
relative: <%= link_to "Relative", "needs_index.html", :relative => false %>
|
|
|
|
unknown: <%= link_to "Unknown", "foo.html" %>
|
|
|
|
"""
|
|
|
|
And a file named "source/link_to/sub.html.erb" with:
|
|
|
|
"""
|
|
|
|
absolute: <%= link_to "Needs Index", "/needs_index.html" %>
|
|
|
|
relative: <%= link_to "Relative", "../needs_index.html" %>
|
|
|
|
"""
|
|
|
|
And the Server is running at "indexable-app"
|
|
|
|
When I go to "/link_to.html"
|
|
|
|
Then I should see 'absolute: <a href="needs_index.html">Needs Index</a>'
|
|
|
|
Then I should see 'relative: <a href="/needs_index.html">Relative</a>'
|
|
|
|
Then I should see 'unknown: <a href="foo.html">Unknown</a>'
|
|
|
|
When I go to "/link_to/sub.html"
|
|
|
|
Then I should see 'absolute: <a href="../needs_index.html">Needs Index</a>'
|
|
|
|
Then I should see 'relative: <a href="../needs_index.html">Relative</a>'
|
|
|
|
|
2012-06-16 20:48:41 -04:00
|
|
|
Scenario: link_to knows about directory indexes
|
2012-05-24 19:14:17 -04:00
|
|
|
Given a fixture app "indexable-app"
|
|
|
|
And a file named "source/link_to.html.erb" with:
|
|
|
|
"""
|
|
|
|
absolute: <%= link_to "Needs Index", "/needs_index.html", :relative => true %>
|
|
|
|
relative: <%= link_to "Relative", "needs_index.html", :relative => true %>
|
|
|
|
"""
|
|
|
|
And a file named "source/link_to/sub.html.erb" with:
|
|
|
|
"""
|
|
|
|
absolute: <%= link_to "Needs Index", "/needs_index.html", :relative => true %>
|
|
|
|
relative: <%= link_to "Relative", "../needs_index.html", :relative => true %>
|
|
|
|
"""
|
|
|
|
And the Server is running at "indexable-app"
|
|
|
|
When I go to "/link_to/"
|
|
|
|
Then I should see 'absolute: <a href="../needs_index/">Needs Index</a>'
|
2012-06-16 20:48:41 -04:00
|
|
|
Then I should see 'relative: <a href="../needs_index/">Relative</a>'
|
2012-07-01 01:02:23 -04:00
|
|
|
When I go to "/link_to/sub/"
|
|
|
|
Then I should see 'absolute: <a href="../../needs_index/">Needs Index</a>'
|
|
|
|
Then I should see 'relative: <a href="../../needs_index/">Relative</a>'
|
2012-06-16 20:48:41 -04:00
|
|
|
|
|
|
|
Scenario: link_to can take a Resource
|
|
|
|
Given a fixture app "indexable-app"
|
|
|
|
And a file named "source/link_to.html.erb" with:
|
|
|
|
"""
|
|
|
|
<%= link_to "Needs Index", sitemap.find_resource_by_path("/needs_index.html") %>
|
|
|
|
"""
|
|
|
|
And the Server is running at "indexable-app"
|
|
|
|
When I go to "/link_to/"
|
|
|
|
Then I should see '<a href="/needs_index/">Needs Index</a>'
|
2012-06-23 20:19:24 -04:00
|
|
|
|
|
|
|
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/link_to.html.erb" with:
|
|
|
|
"""
|
|
|
|
<%= link_to "Needs Index", "/needs_index.html" %>
|
|
|
|
"""
|
|
|
|
And the Server is running at "indexable-app"
|
|
|
|
When I go to "/link_to.html"
|
|
|
|
Then I should see '<a href="/foo/needs_index.html">Needs Index</a>'
|
|
|
|
|
2012-12-21 21:25:49 -05:00
|
|
|
Scenario: link_to preserves query string and anchor and isn't messed up by them
|
|
|
|
Given a fixture app "indexable-app"
|
|
|
|
And a file named "source/link_to.html.erb" with:
|
|
|
|
"""
|
|
|
|
<%= link_to "Needs Index Anchor", "/needs_index.html#foo" %>
|
|
|
|
<%= link_to "Needs Index Query", "/needs_index.html?foo" %>
|
|
|
|
<%= link_to "Needs Index Query and Anchor", "/needs_index.html?foo#foo" %>
|
|
|
|
"""
|
|
|
|
And the Server is running at "indexable-app"
|
|
|
|
When I go to "/link_to/"
|
|
|
|
Then I should see '<a href="/needs_index/#foo">Needs Index Anchor</a>'
|
|
|
|
Then I should see '<a href="/needs_index/?foo">Needs Index Query</a>'
|
|
|
|
Then I should see '<a href="/needs_index/?foo#foo">Needs Index Query and Anchor</a>'
|
2012-12-30 19:27:33 -05:00
|
|
|
|
|
|
|
Scenario: link_to accepts a :query option that appends a query string
|
|
|
|
Given a fixture app "indexable-app"
|
|
|
|
And a file named "source/link_to.html.erb" with:
|
|
|
|
"""
|
|
|
|
<%= link_to "Needs Index String", "/needs_index.html", :query => "foo" %>
|
|
|
|
<%= link_to "Needs Index Hash", "/needs_index.html", :query => { :foo => :bar } %>
|
|
|
|
"""
|
|
|
|
And the Server is running at "indexable-app"
|
|
|
|
When I go to "/link_to/"
|
|
|
|
Then I should see '<a href="/needs_index/?foo">Needs Index String</a>'
|
|
|
|
Then I should see '<a href="/needs_index/?foo=bar">Needs Index Hash</a>'
|