wovnrb 0.2.04 → 0.2.05

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b14f7b1db39f462612fbfb5437c8b9a57ab0545
4
- data.tar.gz: 216b7d095a9ab39fe039ecd7a86cb421f93edbba
3
+ metadata.gz: 7f44db81ea6171f81032cd739b569bbb251ea71d
4
+ data.tar.gz: 0904bb2bfb09ccc05f6ffdecbdaa0a3de9405b53
5
5
  SHA512:
6
- metadata.gz: 03c36df5a7edb5fc443124eafdf338d272d009b7c612188512cf24ec272f68538808b4c7dd312fa37822b96cf25200afde4185a6c8c6593d9939f00a1f0e5015
7
- data.tar.gz: 79114a464d34be6fb01dd0091bec13f58823d14f61f6308a964cff85cf24d69f43b35838e4bde1ab80eddc49aede2fe984a82a5057276bedce15d98e5d7d4ac8
6
+ metadata.gz: 7781e8dc905ae4c07b7467d59d00c85c4085af2df65d6759355ab0dafdfa863b6c902f92871e02a5435464a4c5011dc70a8c6d214a88584a77d479197881b67e
7
+ data.tar.gz: 2201ca3f501a761c41a7ac1c2afd4b572183b06051f5ef3e17cf7e3a69a7c3a17d13a5bfe06d818a508405a82f0221ad94080826f63feb2b413e7c8d66f1cbdb
@@ -179,7 +179,18 @@ module Wovnrb
179
179
  @env
180
180
  end
181
181
 
182
+ # Remove language code from the URI.
183
+ #
184
+ # @param uri [String] original URI
185
+ # @param lang [String] language code
186
+ # @return [String] removed URI
182
187
  def remove_lang(uri, lang=self.path_lang)
188
+
189
+ # Do nothing if lang is empty.
190
+ if lang.nil? || lang.empty?
191
+ return uri
192
+ end
193
+
183
194
  case @settings['url_pattern']
184
195
  when 'query'
185
196
  return uri.sub(/(^|\?|&)wovn=#{lang}(&|$)/, '\1').gsub(/(\?|&)$/, '')
@@ -1,3 +1,3 @@
1
1
  module Wovnrb
2
- VERSION = "0.2.04"
2
+ VERSION = "0.2.05"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require 'test_helper'
2
2
  require 'wovnrb/headers'
3
+ require 'wovnrb/lang'
3
4
  require 'minitest/autorun'
4
5
  require 'pry'
5
6
 
@@ -5911,4 +5912,109 @@ class HeadersTest < Minitest::Test
5911
5912
  h = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://wovn.io:1234/zh-cht'), Wovnrb.get_settings)
5912
5913
  assert_equal('zh-CHT', h.path_lang)
5913
5914
  end
5915
+
5916
+ def test_remove_lang_path
5917
+ h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings)
5918
+
5919
+ keys = Wovnrb::Lang::LANG.keys
5920
+ assert_equal(28, keys.size)
5921
+
5922
+ for key in keys
5923
+ uri_without_scheme = h.remove_lang("wovn.io/#{key}", key)
5924
+ assert_equal('wovn.io/', uri_without_scheme)
5925
+
5926
+ uri_with_scheme = h.remove_lang("https://wovn.io/#{key}/", key)
5927
+ assert_equal('https://wovn.io/', uri_with_scheme)
5928
+ end
5929
+ end
5930
+
5931
+ def test_remove_lang_path_with_nil_lang
5932
+ h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings)
5933
+
5934
+ uri_without_scheme = h.remove_lang('wovn.io', nil)
5935
+ assert_equal('wovn.io', uri_without_scheme)
5936
+
5937
+ uri_with_scheme = h.remove_lang('https://wovn.io/', nil)
5938
+ assert_equal('https://wovn.io/', uri_with_scheme)
5939
+ end
5940
+
5941
+ def test_remove_lang_path_with_empty_lang
5942
+ h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings)
5943
+
5944
+ uri_without_scheme = h.remove_lang('wovn.io', '')
5945
+ assert_equal('wovn.io', uri_without_scheme)
5946
+
5947
+ uri_with_scheme = h.remove_lang('https://wovn.io/', '')
5948
+ assert_equal('https://wovn.io/', uri_with_scheme)
5949
+ end
5950
+
5951
+ def test_remove_lang_query
5952
+ h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings('url_pattern' => 'query'))
5953
+
5954
+ keys = Wovnrb::Lang::LANG.keys
5955
+ assert_equal(28, keys.size)
5956
+
5957
+ for key in keys
5958
+ uri_without_scheme = h.remove_lang("wovn.io/?wovn=#{key}", key)
5959
+ assert_equal('wovn.io/', uri_without_scheme)
5960
+
5961
+ uri_with_scheme = h.remove_lang("https://wovn.io?wovn=#{key}", key)
5962
+ assert_equal('https://wovn.io', uri_with_scheme)
5963
+ end
5964
+ end
5965
+
5966
+ def test_remove_lang_query_with_nil_lang
5967
+ h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings('url_pattern' => 'query'))
5968
+
5969
+ uri_without_scheme = h.remove_lang('wovn.io', nil)
5970
+ assert_equal('wovn.io', uri_without_scheme)
5971
+
5972
+ uri_with_scheme = h.remove_lang('https://wovn.io/', nil)
5973
+ assert_equal('https://wovn.io/', uri_with_scheme)
5974
+ end
5975
+
5976
+ def test_remove_lang_query_with_empty_lang
5977
+ h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings('url_pattern' => 'query'))
5978
+
5979
+ uri_without_scheme = h.remove_lang('wovn.io', '')
5980
+ assert_equal('wovn.io', uri_without_scheme)
5981
+
5982
+ uri_with_scheme = h.remove_lang('https://wovn.io/', '')
5983
+ assert_equal('https://wovn.io/', uri_with_scheme)
5984
+ end
5985
+
5986
+ def test_remove_lang_subdomain
5987
+ h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings('url_pattern' => 'subdomain'))
5988
+
5989
+ keys = Wovnrb::Lang::LANG.keys
5990
+ assert_equal(28, keys.size)
5991
+
5992
+ for key in keys
5993
+ uri_without_scheme = h.remove_lang("#{key.downcase}.wovn.io/", key)
5994
+ assert_equal('wovn.io/', uri_without_scheme)
5995
+
5996
+ uri_with_scheme = h.remove_lang("https://#{key.downcase}.wovn.io", key)
5997
+ assert_equal('https://wovn.io', uri_with_scheme)
5998
+ end
5999
+ end
6000
+
6001
+ def test_remove_lang_subdomain_with_nil_lang
6002
+ h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings('url_pattern' => 'subdomain'))
6003
+
6004
+ uri_without_scheme = h.remove_lang('wovn.io', nil)
6005
+ assert_equal('wovn.io', uri_without_scheme)
6006
+
6007
+ uri_with_scheme = h.remove_lang('https://wovn.io/', nil)
6008
+ assert_equal('https://wovn.io/', uri_with_scheme)
6009
+ end
6010
+
6011
+ def test_remove_lang_subdomain_with_empty_lang
6012
+ h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings('url_pattern' => 'subdomain'))
6013
+
6014
+ uri_without_scheme = h.remove_lang('wovn.io', '')
6015
+ assert_equal('wovn.io', uri_without_scheme)
6016
+
6017
+ uri_with_scheme = h.remove_lang('https://wovn.io/', '')
6018
+ assert_equal('https://wovn.io/', uri_with_scheme)
6019
+ end
5914
6020
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wovnrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.04
4
+ version: 0.2.05
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Sandford
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-31 00:00:00.000000000 Z
12
+ date: 2016-06-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogumbo