roadie 3.0.0.pre1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Changelog.md +22 -1
- data/Gemfile +0 -4
- data/Guardfile +3 -2
- data/README.md +6 -4
- data/lib/roadie.rb +3 -1
- data/lib/roadie/filesystem_provider.rb +13 -2
- data/lib/roadie/inliner.rb +10 -8
- data/lib/roadie/markup_improver.rb +1 -1
- data/lib/roadie/provider_list.rb +5 -1
- data/lib/roadie/rspec/asset_provider.rb +9 -9
- data/lib/roadie/selector.rb +1 -0
- data/lib/roadie/style_attribute_builder.rb +25 -0
- data/lib/roadie/style_block.rb +0 -1
- data/lib/roadie/upgrade_guide.rb +36 -0
- data/lib/roadie/version.rb +1 -1
- data/roadie.gemspec +2 -1
- data/spec/integration_spec.rb +15 -15
- data/spec/lib/roadie/asset_scanner_spec.rb +27 -27
- data/spec/lib/roadie/css_not_found_spec.rb +4 -3
- data/spec/lib/roadie/document_spec.rb +19 -19
- data/spec/lib/roadie/filesystem_provider_spec.rb +29 -6
- data/spec/lib/roadie/inliner_spec.rb +18 -18
- data/spec/lib/roadie/markup_improver_spec.rb +17 -17
- data/spec/lib/roadie/null_provider_spec.rb +4 -4
- data/spec/lib/roadie/provider_list_spec.rb +23 -15
- data/spec/lib/roadie/selector_spec.rb +16 -13
- data/spec/lib/roadie/style_attribute_builder_spec.rb +29 -0
- data/spec/lib/roadie/style_block_spec.rb +6 -6
- data/spec/lib/roadie/style_property_spec.rb +22 -22
- data/spec/lib/roadie/stylesheet_spec.rb +8 -8
- data/spec/lib/roadie/test_provider_spec.rb +5 -5
- data/spec/lib/roadie/url_generator_spec.rb +21 -20
- data/spec/lib/roadie/url_rewriter_spec.rb +7 -7
- data/spec/shared_examples/asset_provider.rb +4 -4
- data/spec/shared_examples/url_rewriter.rb +6 -6
- data/spec/spec_helper.rb +2 -1
- data/spec/support/have_attribute_matcher.rb +2 -2
- data/spec/support/have_node_matcher.rb +2 -2
- data/spec/support/have_selector_matcher.rb +2 -2
- data/spec/support/have_styling_matcher.rb +7 -5
- metadata +36 -21
- data/lib/roadie/style_properties.rb +0 -29
- data/spec/lib/roadie/style_properties_spec.rb +0 -61
@@ -7,10 +7,10 @@ module Roadie
|
|
7
7
|
it_behaves_like "asset provider role"
|
8
8
|
|
9
9
|
def expect_empty_stylesheet(stylesheet)
|
10
|
-
stylesheet.
|
11
|
-
stylesheet.name.
|
12
|
-
stylesheet.
|
13
|
-
stylesheet.to_s.
|
10
|
+
expect(stylesheet).not_to be_nil
|
11
|
+
expect(stylesheet.name).to eq("(null)")
|
12
|
+
expect(stylesheet).to have(0).blocks
|
13
|
+
expect(stylesheet.to_s).to be_empty
|
14
14
|
end
|
15
15
|
|
16
16
|
it "finds an empty stylesheet for every name" do
|
@@ -16,19 +16,27 @@ module Roadie
|
|
16
16
|
second = TestProvider.new "bar.css" => "bar { color: green; }"
|
17
17
|
provider = ProviderList.new [first, second]
|
18
18
|
|
19
|
-
provider.find_stylesheet("foo.css").to_s.
|
20
|
-
provider.find_stylesheet("bar.css").to_s.
|
21
|
-
provider.find_stylesheet("baz.css").
|
19
|
+
expect(provider.find_stylesheet("foo.css").to_s).to include "foo"
|
20
|
+
expect(provider.find_stylesheet("bar.css").to_s).to include "bar"
|
21
|
+
expect(provider.find_stylesheet("baz.css")).to be_nil
|
22
22
|
end
|
23
23
|
|
24
24
|
it "is enumerable" do
|
25
|
-
provider.
|
26
|
-
provider.
|
27
|
-
provider.each.to_a.
|
25
|
+
expect(provider).to be_kind_of(Enumerable)
|
26
|
+
expect(provider).to respond_to(:each)
|
27
|
+
expect(provider.each.to_a).to eq([test_provider])
|
28
28
|
end
|
29
29
|
|
30
30
|
it "has a size" do
|
31
|
-
provider.size.
|
31
|
+
expect(provider.size).to eq(1)
|
32
|
+
expect(provider).not_to be_empty
|
33
|
+
end
|
34
|
+
|
35
|
+
it "has a first and a last element" do
|
36
|
+
providers = [double("1"), double("2"), double("3")]
|
37
|
+
list = ProviderList.new(providers)
|
38
|
+
expect(list.first).to eq(providers.first)
|
39
|
+
expect(list.last).to eq(providers.last)
|
32
40
|
end
|
33
41
|
|
34
42
|
it "can have providers pushed and popped" do
|
@@ -40,7 +48,7 @@ module Roadie
|
|
40
48
|
}.to change(provider, :size).by(2)
|
41
49
|
|
42
50
|
expect {
|
43
|
-
provider.pop.
|
51
|
+
expect(provider.pop).to eq(other)
|
44
52
|
}.to change(provider, :size).by(-1)
|
45
53
|
end
|
46
54
|
|
@@ -52,29 +60,29 @@ module Roadie
|
|
52
60
|
}.to change(provider, :size).by(1)
|
53
61
|
|
54
62
|
expect {
|
55
|
-
provider.shift.
|
63
|
+
expect(provider.shift).to eq(other)
|
56
64
|
}.to change(provider, :size).by(-1)
|
57
65
|
end
|
58
66
|
|
59
67
|
describe "wrapping" do
|
60
68
|
it "creates provider lists with the arguments" do
|
61
|
-
ProviderList.wrap(test_provider).
|
62
|
-
ProviderList.wrap(test_provider, test_provider).size.
|
69
|
+
expect(ProviderList.wrap(test_provider)).to be_instance_of(ProviderList)
|
70
|
+
expect(ProviderList.wrap(test_provider, test_provider).size).to eq(2)
|
63
71
|
end
|
64
72
|
|
65
73
|
it "flattens arrays" do
|
66
|
-
ProviderList.wrap([test_provider, test_provider], test_provider).size.
|
67
|
-
ProviderList.wrap([test_provider, test_provider]).size.
|
74
|
+
expect(ProviderList.wrap([test_provider, test_provider], test_provider).size).to eq(3)
|
75
|
+
expect(ProviderList.wrap([test_provider, test_provider]).size).to eq(2)
|
68
76
|
end
|
69
77
|
|
70
78
|
it "combines with providers from other lists" do
|
71
79
|
other_list = ProviderList.new([test_provider, test_provider])
|
72
|
-
ProviderList.wrap(test_provider, other_list).size.
|
80
|
+
expect(ProviderList.wrap(test_provider, other_list).size).to eq(3)
|
73
81
|
end
|
74
82
|
|
75
83
|
it "returns the passed list if only a single ProviderList is passed" do
|
76
84
|
other_list = ProviderList.new([test_provider])
|
77
|
-
ProviderList.wrap(other_list).
|
85
|
+
expect(ProviderList.wrap(other_list)).to eql other_list
|
78
86
|
end
|
79
87
|
end
|
80
88
|
end
|
@@ -4,11 +4,11 @@ require 'spec_helper'
|
|
4
4
|
module Roadie
|
5
5
|
describe Selector do
|
6
6
|
it "can be coerced into String" do
|
7
|
-
("I love " + Selector.new("html")).
|
7
|
+
expect("I love " + Selector.new("html")).to eq("I love html")
|
8
8
|
end
|
9
9
|
|
10
10
|
it "can be inlined when simple" do
|
11
|
-
Selector.new("html body #main p.class").
|
11
|
+
expect(Selector.new("html body #main p.class")).to be_inlinable
|
12
12
|
end
|
13
13
|
|
14
14
|
it "cannot be inlined when containing pseudo functions" do
|
@@ -19,42 +19,45 @@ module Roadie
|
|
19
19
|
p:link
|
20
20
|
p:target
|
21
21
|
p:visited
|
22
|
-
p:before
|
23
|
-
p:after
|
24
22
|
p:-ms-input-placeholder
|
25
23
|
p:-moz-placeholder
|
24
|
+
p:before
|
25
|
+
p:after
|
26
|
+
p:enabled
|
27
|
+
p:disabled
|
28
|
+
p:checked
|
26
29
|
].each do |bad_selector|
|
27
|
-
Selector.new(bad_selector).
|
30
|
+
expect(Selector.new(bad_selector)).not_to be_inlinable
|
28
31
|
end
|
29
32
|
|
30
|
-
Selector.new('p.active').
|
33
|
+
expect(Selector.new('p.active')).to be_inlinable
|
31
34
|
end
|
32
35
|
|
33
36
|
it "cannot be inlined when containing pseudo elements" do
|
34
|
-
Selector.new('p::some-element').
|
37
|
+
expect(Selector.new('p::some-element')).not_to be_inlinable
|
35
38
|
end
|
36
39
|
|
37
40
|
it "cannot be inlined when selector is an at-rule" do
|
38
|
-
Selector.new('@keyframes progress-bar-stripes').
|
41
|
+
expect(Selector.new('@keyframes progress-bar-stripes')).not_to be_inlinable
|
39
42
|
end
|
40
43
|
|
41
44
|
it "has a calculated specificity" do
|
42
45
|
selector = "html p.active.nice #main.deep-selector"
|
43
|
-
Selector.new(selector).specificity.
|
46
|
+
expect(Selector.new(selector).specificity).to eq(CssParser.calculate_specificity(selector))
|
44
47
|
end
|
45
48
|
|
46
49
|
it "can be told about the specificity at initialization" do
|
47
50
|
selector = "html p.active.nice #main.deep-selector"
|
48
|
-
Selector.new(selector, 1337).specificity.
|
51
|
+
expect(Selector.new(selector, 1337).specificity).to eq(1337)
|
49
52
|
end
|
50
53
|
|
51
54
|
it "is equal to other selectors when they match the same things" do
|
52
|
-
Selector.new("foo").
|
53
|
-
Selector.new("foo").
|
55
|
+
expect(Selector.new("foo")).to eq(Selector.new("foo "))
|
56
|
+
expect(Selector.new("foo")).not_to eq("foo")
|
54
57
|
end
|
55
58
|
|
56
59
|
it "strips the given selector" do
|
57
|
-
Selector.new(" foo \n").to_s.
|
60
|
+
expect(Selector.new(" foo \n").to_s).to eq(Selector.new("foo").to_s)
|
58
61
|
end
|
59
62
|
end
|
60
63
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Roadie
|
4
|
+
describe StyleAttributeBuilder do
|
5
|
+
it "sorts the added properties" do
|
6
|
+
builder = StyleAttributeBuilder.new
|
7
|
+
|
8
|
+
builder << StyleProperty.new("color", "green", true, 1)
|
9
|
+
builder << StyleProperty.new("font-size", "110%", false, 15)
|
10
|
+
builder << StyleProperty.new("color", "red", false, 15)
|
11
|
+
|
12
|
+
expect(builder.attribute_string).to eq "font-size:110%;color:red;color:green !important"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "preserves the order of added attributes with the same specificity" do
|
16
|
+
builder = StyleAttributeBuilder.new
|
17
|
+
|
18
|
+
builder << StyleProperty.new("color", "pink", false, 50)
|
19
|
+
builder << StyleProperty.new("color", "red", false, 50)
|
20
|
+
builder << StyleProperty.new("color", "green", false, 50)
|
21
|
+
|
22
|
+
# We need one different element to trigger the problem with Ruby's
|
23
|
+
# unstable sort
|
24
|
+
builder << StyleProperty.new("background", "white", false, 1)
|
25
|
+
|
26
|
+
expect(builder.attribute_string).to eq "background:white;color:pink;color:red;color:green"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -8,28 +8,28 @@ module Roadie
|
|
8
8
|
selector = double "Selector"
|
9
9
|
|
10
10
|
block = StyleBlock.new(selector, properties)
|
11
|
-
block.selector.
|
12
|
-
block.properties.
|
11
|
+
expect(block.selector).to eq(selector)
|
12
|
+
expect(block.properties).to eq(properties)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "delegates #specificity to the selector" do
|
16
16
|
selector = double "Selector", specificity: 45
|
17
|
-
StyleBlock.new(selector, []).specificity.
|
17
|
+
expect(StyleBlock.new(selector, []).specificity).to eq(45)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "delegates #inlinable? to the selector" do
|
21
21
|
selector = double "Selector", inlinable?: "maybe"
|
22
|
-
StyleBlock.new(selector, []).inlinable
|
22
|
+
expect(StyleBlock.new(selector, []).inlinable?).to eq("maybe")
|
23
23
|
end
|
24
24
|
|
25
25
|
it "delegates #selector_string to selector#to_s" do
|
26
26
|
selector = double "Selector", to_s: "yey"
|
27
|
-
StyleBlock.new(selector, []).selector_string.
|
27
|
+
expect(StyleBlock.new(selector, []).selector_string).to eq("yey")
|
28
28
|
end
|
29
29
|
|
30
30
|
it "has a string representation" do
|
31
31
|
properties = [double(to_s: "bar"), double(to_s: "baz")]
|
32
|
-
StyleBlock.new(double(to_s: "foo"), properties).to_s.
|
32
|
+
expect(StyleBlock.new(double(to_s: "foo"), properties).to_s).to eq("foo{bar;baz}")
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -4,21 +4,21 @@ module Roadie
|
|
4
4
|
describe StyleProperty do
|
5
5
|
it "is initialized with a property, value, if it is marked as important, and the specificity" do
|
6
6
|
StyleProperty.new('color', 'green', true, 45).tap do |declaration|
|
7
|
-
declaration.property.
|
8
|
-
declaration.value.
|
9
|
-
declaration.
|
10
|
-
declaration.specificity.
|
7
|
+
expect(declaration.property).to eq('color')
|
8
|
+
expect(declaration.value).to eq('green')
|
9
|
+
expect(declaration).to be_important
|
10
|
+
expect(declaration.specificity).to eq(45)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "string representation" do
|
15
15
|
it "is the property and the value joined with a colon" do
|
16
|
-
StyleProperty.new('color', 'green', false, 1).to_s.
|
17
|
-
StyleProperty.new('font-size', '1.1em', false, 1).to_s.
|
16
|
+
expect(StyleProperty.new('color', 'green', false, 1).to_s).to eq('color:green')
|
17
|
+
expect(StyleProperty.new('font-size', '1.1em', false, 1).to_s).to eq('font-size:1.1em')
|
18
18
|
end
|
19
19
|
|
20
20
|
it "contains the !important flag when set" do
|
21
|
-
StyleProperty.new('color', 'green', true, 1).to_s.
|
21
|
+
expect(StyleProperty.new('color', 'green', true, 1).to_s).to eq('color:green !important')
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -28,20 +28,20 @@ module Roadie
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "compares on specificity" do
|
31
|
-
declaration(5).
|
32
|
-
declaration(4).
|
33
|
-
declaration(6).
|
31
|
+
expect(declaration(5)).to eq(declaration(5))
|
32
|
+
expect(declaration(4)).to be < declaration(5)
|
33
|
+
expect(declaration(6)).to be > declaration(5)
|
34
34
|
end
|
35
35
|
|
36
36
|
context "with an important declaration" do
|
37
37
|
it "is less than the important declaration regardless of the specificity" do
|
38
|
-
declaration(99, false).
|
38
|
+
expect(declaration(99, false)).to be < declaration(1, true)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "compares like normal when both declarations are important" do
|
42
|
-
declaration(5, true).
|
43
|
-
declaration(4, true).
|
44
|
-
declaration(6, true).
|
42
|
+
expect(declaration(5, true)).to eq(declaration(5, true))
|
43
|
+
expect(declaration(4, true)).to be < declaration(5, true)
|
44
|
+
expect(declaration(6, true)).to be > declaration(5, true)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -53,23 +53,23 @@ module Roadie
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it "understands simple declarations" do
|
56
|
-
parsing("color: green", 1).
|
57
|
-
parsing(" color:green; ", 1).
|
58
|
-
parsing("color: green ", 1).
|
59
|
-
parsing("color: green ; ", 1).
|
56
|
+
expect(parsing("color: green", 1)).to eq(["color", "green", false, 1])
|
57
|
+
expect(parsing(" color:green; ", 1)).to eq(["color", "green", false, 1])
|
58
|
+
expect(parsing("color: green ", 1)).to eq(["color", "green", false, 1])
|
59
|
+
expect(parsing("color: green ; ", 1)).to eq(["color", "green", false, 1])
|
60
60
|
end
|
61
61
|
|
62
62
|
it "understands more complex values" do
|
63
|
-
parsing("padding:0 1px 5rem 9%;", 89).
|
63
|
+
expect(parsing("padding:0 1px 5rem 9%;", 89)).to eq(["padding", "0 1px 5rem 9%", false, 89])
|
64
64
|
end
|
65
65
|
|
66
66
|
it "understands more complex names" do
|
67
|
-
parsing("font-size: 50%", 10).
|
67
|
+
expect(parsing("font-size: 50%", 10)).to eq(["font-size", "50%", false, 10])
|
68
68
|
end
|
69
69
|
|
70
70
|
it "correctly reads !important declarations" do
|
71
|
-
parsing("color: green !important", 1).
|
72
|
-
parsing("color: green !important;", 1).
|
71
|
+
expect(parsing("color: green !important", 1)).to eq(["color", "green", true, 1])
|
72
|
+
expect(parsing("color: green !important;", 1)).to eq(["color", "green", true, 1])
|
73
73
|
end
|
74
74
|
|
75
75
|
it "raises an error on unparseable declarations" do
|
@@ -5,7 +5,7 @@ module Roadie
|
|
5
5
|
describe Stylesheet do
|
6
6
|
it "is initialized with a name and CSS" do
|
7
7
|
stylesheet = Stylesheet.new("foo.css", "body { color: green; }")
|
8
|
-
stylesheet.name.
|
8
|
+
expect(stylesheet.name).to eq("foo.css")
|
9
9
|
end
|
10
10
|
|
11
11
|
it "has a list of blocks" do
|
@@ -13,12 +13,12 @@ module Roadie
|
|
13
13
|
body { color: green !important; font-size: 200%; }
|
14
14
|
a, i { color: red; }
|
15
15
|
CSS
|
16
|
-
stylesheet.
|
17
|
-
stylesheet.blocks.map(&:to_s).
|
16
|
+
expect(stylesheet).to have(3).blocks
|
17
|
+
expect(stylesheet.blocks.map(&:to_s)).to eq([
|
18
18
|
"body{color:green !important;font-size:200%}",
|
19
19
|
"a{color:red}",
|
20
20
|
"i{color:red}",
|
21
|
-
]
|
21
|
+
])
|
22
22
|
end
|
23
23
|
|
24
24
|
it "can iterate all inlinable blocks" do
|
@@ -26,16 +26,16 @@ module Roadie
|
|
26
26
|
bad = double(inlinable?: false, selector: "bad", properties: "props")
|
27
27
|
|
28
28
|
stylesheet = Stylesheet.new("example.css", "")
|
29
|
-
stylesheet.
|
29
|
+
allow(stylesheet).to receive_messages blocks: [bad, inlinable, bad]
|
30
30
|
|
31
|
-
stylesheet.each_inlinable_block.to_a.
|
31
|
+
expect(stylesheet.each_inlinable_block.to_a).to eq([
|
32
32
|
["good", "props"],
|
33
|
-
]
|
33
|
+
])
|
34
34
|
end
|
35
35
|
|
36
36
|
it "has a string representation of the contents" do
|
37
37
|
stylesheet = Stylesheet.new("example.css", "body { color: green;}a{ color: red; font-size: small }")
|
38
|
-
stylesheet.to_s.
|
38
|
+
expect(stylesheet.to_s).to eq("body{color:green}\na{color:red;font-size:small}")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -13,9 +13,9 @@ describe TestProvider do
|
|
13
13
|
"foo.css" => "a { color: red; }",
|
14
14
|
"bar.css" => "body { color: green; }",
|
15
15
|
})
|
16
|
-
provider.find_stylesheet("foo.css").to_s.
|
17
|
-
provider.find_stylesheet("bar.css").to_s.
|
18
|
-
provider.find_stylesheet("baz.css").
|
16
|
+
expect(provider.find_stylesheet("foo.css").to_s).not_to include("body")
|
17
|
+
expect(provider.find_stylesheet("bar.css").to_s).to include("body")
|
18
|
+
expect(provider.find_stylesheet("baz.css")).to be_nil
|
19
19
|
end
|
20
20
|
|
21
21
|
it "can have a default for missing entries" do
|
@@ -23,7 +23,7 @@ describe TestProvider do
|
|
23
23
|
"foo.css" => "a { color: red; }",
|
24
24
|
:default => "body { color: green; }",
|
25
25
|
})
|
26
|
-
provider.find_stylesheet("foo.css").to_s.
|
27
|
-
provider.find_stylesheet("bar.css").to_s.
|
26
|
+
expect(provider.find_stylesheet("foo.css").to_s).not_to include("body")
|
27
|
+
expect(provider.find_stylesheet("bar.css").to_s).to include("body")
|
28
28
|
end
|
29
29
|
end
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
module Roadie
|
5
5
|
describe UrlGenerator do
|
6
6
|
it "is initialized with URL options" do
|
7
|
-
UrlGenerator.new(host: "foo.com").url_options.
|
7
|
+
expect(UrlGenerator.new(host: "foo.com").url_options).to eq({host: "foo.com"})
|
8
8
|
end
|
9
9
|
|
10
10
|
it "raises an argument error if no URL options are specified" do
|
@@ -31,37 +31,38 @@ module Roadie
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "uses the given host" do
|
34
|
-
url("/hello.jpg", host: "goats.com").
|
34
|
+
expect(url("/hello.jpg", host: "goats.com")).to eq("http://goats.com/hello.jpg")
|
35
35
|
end
|
36
36
|
|
37
37
|
it "uses the given port" do
|
38
|
-
url("/", host: "example.com", port: 1337).
|
38
|
+
expect(url("/", host: "example.com", port: 1337)).to eq("http://example.com:1337/")
|
39
39
|
end
|
40
40
|
|
41
41
|
it "uses the given scheme" do
|
42
|
-
url("/", host: "example.com", scheme: "https").
|
42
|
+
expect(url("/", host: "example.com", scheme: "https")).to eq("https://example.com/")
|
43
43
|
end
|
44
44
|
|
45
45
|
it "regards :protocol as an alias for scheme" do
|
46
|
-
url("/", host: "example.com", protocol: "https").
|
46
|
+
expect(url("/", host: "example.com", protocol: "https")).to eq("https://example.com/")
|
47
47
|
end
|
48
48
|
|
49
49
|
it "strips extra characters from the scheme" do
|
50
|
-
url("/", host: "example.com", scheme: "https://").
|
50
|
+
expect(url("/", host: "example.com", scheme: "https://")).to eq("https://example.com/")
|
51
51
|
end
|
52
52
|
|
53
53
|
it "uses the given path as a prefix" do
|
54
|
-
url("/my_file", host: "example.com", path: "/my_app").
|
54
|
+
expect(url("/my_file", host: "example.com", path: "/my_app")).to eq(
|
55
55
|
"http://example.com/my_app/my_file"
|
56
|
+
)
|
56
57
|
end
|
57
58
|
|
58
59
|
it "returns the original URL if it is absolute" do
|
59
|
-
url("http://foo.com/", host: "bar.com").
|
60
|
+
expect(url("http://foo.com/", host: "bar.com")).to eq("http://foo.com/")
|
60
61
|
end
|
61
62
|
|
62
63
|
it "returns the base URL for blank paths" do
|
63
|
-
url("", host: "foo.com").
|
64
|
-
url(nil, host: "foo.com").
|
64
|
+
expect(url("", host: "foo.com")).to eq("http://foo.com")
|
65
|
+
expect(url(nil, host: "foo.com")).to eq("http://foo.com")
|
65
66
|
end
|
66
67
|
|
67
68
|
it "raises an error on invalid path" do
|
@@ -71,17 +72,17 @@ module Roadie
|
|
71
72
|
end
|
72
73
|
|
73
74
|
it "accepts base paths without a slash in the beginning" do
|
74
|
-
url("/bar", host: "example.com", path: "foo").
|
75
|
-
url("/bar/", host: "example.com", path: "foo/").
|
75
|
+
expect(url("/bar", host: "example.com", path: "foo")).to eq("http://example.com/foo/bar")
|
76
|
+
expect(url("/bar/", host: "example.com", path: "foo/")).to eq("http://example.com/foo/bar/")
|
76
77
|
end
|
77
78
|
|
78
79
|
it "accepts input paths without a slash in the beginning" do
|
79
|
-
url("bar", host: "example.com", path: "/foo").
|
80
|
-
url("bar", host: "example.com", path: "/foo/").
|
80
|
+
expect(url("bar", host: "example.com", path: "/foo")).to eq("http://example.com/foo/bar")
|
81
|
+
expect(url("bar", host: "example.com", path: "/foo/")).to eq("http://example.com/foo/bar")
|
81
82
|
end
|
82
83
|
|
83
84
|
it "does not touch data: URIs" do
|
84
|
-
url("data:deadbeef", host: "example.com").
|
85
|
+
expect(url("data:deadbeef", host: "example.com")).to eq("data:deadbeef")
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
@@ -105,15 +106,15 @@ module Roadie
|
|
105
106
|
describe "generating URLs with custom base" do
|
106
107
|
it "resolves relative paths" do
|
107
108
|
generator = UrlGenerator.new(host: "foo.com")
|
108
|
-
generator.generate_url("../images/bg.png", "/stylesheets").
|
109
|
-
generator.generate_url("../images/bg.png", "email/stylesheets").
|
110
|
-
generator.generate_url("images/bg.png", "email/").
|
109
|
+
expect(generator.generate_url("../images/bg.png", "/stylesheets")).to eq("http://foo.com/images/bg.png")
|
110
|
+
expect(generator.generate_url("../images/bg.png", "email/stylesheets")).to eq("http://foo.com/email/images/bg.png")
|
111
|
+
expect(generator.generate_url("images/bg.png", "email/")).to eq("http://foo.com/email/images/bg.png")
|
111
112
|
end
|
112
113
|
|
113
114
|
it "does not use the base when presented with a root-based path" do
|
114
115
|
generator = UrlGenerator.new(host: "foo.com")
|
115
|
-
generator.generate_url("/images/bg.png", "/stylesheets").
|
116
|
-
generator.generate_url("/images/bg.png", "email/stylesheets").
|
116
|
+
expect(generator.generate_url("/images/bg.png", "/stylesheets")).to eq("http://foo.com/images/bg.png")
|
117
|
+
expect(generator.generate_url("/images/bg.png", "email/stylesheets")).to eq("http://foo.com/images/bg.png")
|
117
118
|
end
|
118
119
|
end
|
119
120
|
end
|