absolution 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGVjNzcyODYzNTc5ODk1NWM3ZmE5ZWEyMWI2ZTdlOGUxYTI4YmU0YQ==
4
+ NjEyN2VhZDI3ZGM5OWZiZjMwOWQ3NzhhOWFmM2ViNDZjY2RlM2NlMg==
5
5
  data.tar.gz: !binary |-
6
- MTQyMTZjMWI3ODQ5ZTI1MWJhMjAxYzkxM2EwNTdhMDA0MmNmZDQ5Ng==
6
+ NDE2YzVkMTZkMDI4YmVhMjhkOTUwYjkwOGQ1MWM2ZWYzNjVhYjcxOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- N2Y0NGM0NWZjNGRiZmE0ZGM5Mjg0YWMwNmE4NTkzZWI4YTMyZGI0ZjZjYjMx
10
- YjAxODcyNDM0NTU1ODk2MDc0NTBjNTNjZmNmY2FlZTExNDZkMTUxNzU0OThh
11
- M2U5NTVkOWYzMWFlODU1OThlNGM5Y2Q1NGMxOWVkYTQ4ODA5NGU=
9
+ MWViZDMyMmE5MzU4ZmNiZWJjNTE4OGM2OTY5MjdjZTFlOGM5YzMzNzIxZjdj
10
+ YTY1YzM3NWJiM2U5Yzg3MjU4NzAxYzBjZDYzZDExZTQzMGVkNTAzZWFjYzZh
11
+ Yjc0ZDg2N2QwMjU2M2NiZDViNWNmZTQ5YzE2NmRlMWMwNjE3MjY=
12
12
  data.tar.gz: !binary |-
13
- MmJiNzY2ZTVhMjkyYjVjNTQ5YTU2NmY3MmUyZWEyNTNiMDE1YjVlNzA4YzU5
14
- NDYxZDU0ZmYzZjMxNTdhMmZiMzBlYjMyMmJkOTU0M2YyN2VjZjUxMzk1YjA5
15
- OTZmNGI2N2IyOTU5OGQyY2EyMjc5ODJmZjY0ODM3OTBlZjE0MmI=
13
+ Y2NlMWE5ZTRhZDVmZWIzNjlmYzBkMDBjOWY4OGVjYmM4ZDE4MmI5M2QxM2Zi
14
+ NzU3YzEzNzRlMjRmNWY4YjQ4NmYzMjcyY2FkYTdmYWJmOWQ5ZmQ5M2Q2ODUz
15
+ ZTczOTQ4ZDUxMzE2MTAxMjRmZDE0ZmE1ZWE3OTQwNTgyMGY5YTg=
data/README.md CHANGED
@@ -60,6 +60,7 @@ Do you use git-flow? I sure do. Please base anything you do off of
60
60
 
61
61
  ## History ##
62
62
 
63
+ * 0.0.5 - Better relative path handling
63
64
  * 0.0.4 - Query strings are handled properly
64
65
  * 0.0.2 - Initial release
65
66
 
@@ -1,3 +1,3 @@
1
1
  module Absolution
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
data/lib/absolution.rb CHANGED
@@ -7,12 +7,15 @@ module Absolution
7
7
  end
8
8
 
9
9
  def construct_absolute_url(base_url, path)
10
- u = URI.parse(base_url)
11
- path.split('?').tap do |path_array|
12
- u.path = path_array.first.start_with?('/') ? path_array.first : "/#{path_array.first}"
13
- u.query = path_array.last if path_array.length > 1
10
+ uri = URI.parse(base_url)
11
+
12
+ URI.parse(path.start_with?('/') ? path : "/#{path}").tap do |path_uri|
13
+ uri.path = path_uri.path
14
+ uri.query = path_uri.query
15
+ uri.fragment = path_uri.fragment
14
16
  end
15
- u.to_s
17
+
18
+ uri.to_s
16
19
  end
17
20
 
18
21
  extend self
@@ -34,13 +34,14 @@ describe Absolution do
34
34
  end
35
35
 
36
36
  describe '.construct_absolute_url' do
37
+ let(:base_url) {'http://fake.url'}
38
+
37
39
  it 'combines a base url with a path' do
38
40
  expect(klass.construct_absolute_url('http://fake.url', '/asset.file')).
39
41
  to eql('http://fake.url/asset.file')
40
42
  end
41
43
 
42
44
  it 'separates the base url from the asset with at least 1 /' do
43
- base_url = 'http://fake.url'
44
45
  asset_path = 'asset.file'
45
46
  expected_url = base_url + '/' + asset_path
46
47
  expect(klass.construct_absolute_url(base_url, asset_path)).
@@ -48,20 +49,25 @@ describe Absolution do
48
49
  end
49
50
 
50
51
  it 'removes an extra / when both the base url and the asset path have it' do
51
- base_url = 'http://fake.url/'
52
52
  asset_path = '/asset.file'
53
53
  expected_url = base_url.chomp('/') + asset_path
54
- expect(klass.construct_absolute_url(base_url, asset_path)).
54
+ expect(klass.construct_absolute_url(base_url + '/', asset_path)).
55
55
  to eql(expected_url)
56
56
  end
57
57
 
58
58
  it 'handles query strings appropriately' do
59
- base_url = 'http://fake.url'
60
59
  asset_path = '/asset.file?key=val'
61
60
  expected_url = base_url + asset_path
62
61
  expect(klass.construct_absolute_url(base_url, asset_path)).
63
62
  to eql(expected_url)
64
63
  end
64
+
65
+ it 'handles fragments appropriately' do
66
+ asset_path = '#fortytwo'
67
+ expected_url = base_url + '/' + asset_path
68
+ expect(klass.construct_absolute_url(base_url, asset_path)).
69
+ to eql(expected_url)
70
+ end
65
71
  end
66
72
  end
67
73
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: absolution
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Walters