2013-11-20 20:10:08 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
require_dependency 'url_helper'
|
|
|
|
|
|
|
|
describe UrlHelper do
|
|
|
|
|
|
|
|
describe "#is_local" do
|
|
|
|
|
|
|
|
it "is true when the file has been uploaded" do
|
|
|
|
store = stub
|
|
|
|
store.expects(:has_been_uploaded?).returns(true)
|
|
|
|
Discourse.stubs(:store).returns(store)
|
2015-06-12 18:02:36 +08:00
|
|
|
expect(UrlHelper.is_local("http://discuss.site.com/path/to/file.png")).to eq(true)
|
2013-11-20 20:10:08 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "is true for relative assets" do
|
|
|
|
store = stub
|
|
|
|
store.expects(:has_been_uploaded?).returns(false)
|
|
|
|
Discourse.stubs(:store).returns(store)
|
2015-06-12 18:02:36 +08:00
|
|
|
expect(UrlHelper.is_local("/assets/javascripts/all.js")).to eq(true)
|
2013-11-20 20:10:08 +08:00
|
|
|
end
|
|
|
|
|
2014-01-15 06:51:36 +08:00
|
|
|
it "is true for plugin assets" do
|
|
|
|
store = stub
|
|
|
|
store.expects(:has_been_uploaded?).returns(false)
|
|
|
|
Discourse.stubs(:store).returns(store)
|
2015-06-12 18:02:36 +08:00
|
|
|
expect(UrlHelper.is_local("/plugins/all.js")).to eq(true)
|
2014-01-15 06:51:36 +08:00
|
|
|
end
|
|
|
|
|
2013-11-20 20:10:08 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#absolute" do
|
|
|
|
|
|
|
|
it "does not change non-relative url" do
|
2015-06-12 18:02:36 +08:00
|
|
|
expect(UrlHelper.absolute("http://www.discourse.org")).to eq("http://www.discourse.org")
|
2013-11-20 20:10:08 +08:00
|
|
|
end
|
|
|
|
|
2013-12-17 07:35:34 +08:00
|
|
|
it "changes a relative url to an absolute one using base url by default" do
|
2015-06-12 18:02:36 +08:00
|
|
|
expect(UrlHelper.absolute("/path/to/file")).to eq("http://test.localhost/path/to/file")
|
2013-11-20 20:10:08 +08:00
|
|
|
end
|
|
|
|
|
2013-12-17 07:35:34 +08:00
|
|
|
it "changes a relative url to an absolute one using the cdn when enabled" do
|
|
|
|
Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com")
|
2015-06-12 18:02:36 +08:00
|
|
|
expect(UrlHelper.absolute("/path/to/file")).to eq("http://my.cdn.com/path/to/file")
|
2013-12-17 07:35:34 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#absolute_without_cdn" do
|
|
|
|
|
|
|
|
it "changes a relative url to an absolute one using base url even when cdn is enabled" do
|
|
|
|
Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com")
|
2015-06-12 18:02:36 +08:00
|
|
|
expect(UrlHelper.absolute_without_cdn("/path/to/file")).to eq("http://test.localhost/path/to/file")
|
2013-12-17 07:35:34 +08:00
|
|
|
end
|
|
|
|
|
2013-11-20 20:10:08 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#schemaless" do
|
|
|
|
|
|
|
|
it "removes http or https schemas only" do
|
2015-06-12 18:02:36 +08:00
|
|
|
expect(UrlHelper.schemaless("http://www.discourse.org")).to eq("//www.discourse.org")
|
|
|
|
expect(UrlHelper.schemaless("https://secure.discourse.org")).to eq("//secure.discourse.org")
|
|
|
|
expect(UrlHelper.schemaless("ftp://ftp.discourse.org")).to eq("ftp://ftp.discourse.org")
|
2013-11-20 20:10:08 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|