-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests #3
Tests #3
Changes from 6 commits
3f1deac
f9a6072
cdbab00
f6bd680
39c6dca
13411ef
d230e8b
d2bbab6
a01ac74
19d28c6
0225448
6d210a9
dfe29e1
0e8a3cd
826da7d
e276dd4
36ded27
0e0137e
077cc17
3682905
72d0521
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
language: ruby | ||
|
||
rvm: | ||
- 2.0.0 | ||
|
||
cache: bundler | ||
|
||
notifications: | ||
email: false | ||
hipchat: | ||
rooms: 0715dd54b78b69f7dc310969a35036@208408 | ||
on_success: never | ||
on_failure: change | ||
template: '%{repository}#%{build_number} (%{branch} - %{commit} : %{author}): %{message}' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org/' | ||
|
||
gemspec |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
twingly-url-normalizer (0.0.1) | ||
domainatrix | ||
postrank-uri | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
activesupport (4.0.3) | ||
i18n (~> 0.6, >= 0.6.4) | ||
minitest (~> 4.2) | ||
multi_json (~> 1.3) | ||
thread_safe (~> 0.1) | ||
tzinfo (~> 0.3.37) | ||
addressable (2.3.5) | ||
ansi (1.4.3) | ||
atomic (1.1.14) | ||
domainatrix (0.0.11) | ||
addressable | ||
i18n (0.6.9) | ||
minitest (4.7.5) | ||
multi_json (1.8.4) | ||
nokogiri (1.5.11) | ||
postrank-uri (1.0.17) | ||
addressable (~> 2.3.0) | ||
nokogiri (~> 1.5.5) | ||
public_suffix (~> 1.1.3) | ||
public_suffix (1.1.3) | ||
rake (10.1.1) | ||
shoulda (3.5.0) | ||
shoulda-context (~> 1.0, >= 1.0.1) | ||
shoulda-matchers (>= 1.4.1, < 3.0) | ||
shoulda-context (1.1.6) | ||
shoulda-matchers (2.5.0) | ||
activesupport (>= 3.0.0) | ||
thread_safe (0.1.3) | ||
atomic | ||
turn (0.9.6) | ||
ansi | ||
tzinfo (0.3.38) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
rake | ||
shoulda | ||
turn | ||
twingly-url-normalizer! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'bundler/setup' | ||
|
||
task default: 'test:unit' | ||
task test: 'test:unit' | ||
|
||
require 'rake/testtask' | ||
namespace :test do | ||
Rake::TestTask.new(:unit) do |test| | ||
test.pattern = "test/unit/*_test.rb" | ||
test.libs << 'lib' | ||
test.libs << 'test' | ||
end | ||
|
||
Rake::TestTask.new(:profile) do |test| | ||
test.pattern = "test/profile/*_test.rb" | ||
test.libs << 'lib' | ||
test.libs << 'test' | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'bundler/setup' | ||
require 'turn/autorun' | ||
require 'shoulda' | ||
|
||
require 'twingly-url-normalizer' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
require 'test_helper' | ||
|
||
class NormalizerTest < Test::Unit::TestCase | ||
context ".normalize" do | ||
setup do | ||
@normalizer = Twingly::URL::Normalizer | ||
end | ||
|
||
should "accept a String" do | ||
assert @normalizer.normalize("") | ||
end | ||
|
||
should "accept an Array" do | ||
assert @normalizer.normalize([]) | ||
end | ||
|
||
should "handle URL with ] in it" do | ||
url = "http://www.iwaseki.co.jp/cgi/yybbs/yybbs.cgi/%DEuropean]buy" | ||
assert @normalizer.normalize(url) | ||
end | ||
|
||
should "handle URL with reference to another URL in it" do | ||
url = "http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNGc4A_sfGS6fMMqggiK_8h6yk2miw&url=http:%20%20%20//fansided.com/2013/08/02/nike-decides-to-drop-milwaukee-brewers-ryan-braun" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this URL be supported? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, why not? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cause some library didn't like it (it's now working). I agree this should be supported, if Chrome supports it it should work (we should snatch their tests!) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works in curl too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hmm, is the "another URL" valid? $ curl -v http:%20%20%20//fansided.com/2013/08/02/nike-decides-to-drop-milwaukee-brewers-ryan-braun
* Adding handle: conn: 0x7fbd82007a00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fbd82007a00) send_pipe: 1, recv_pipe: 0
* Could not resolve host: http
* Closing connection 0
curl: (6) Could not resolve host: http There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I don't think it matters that it's a URL with another URL in it, parameters can contain whatever, don't they? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably. I think the original site changed the "internal URL", replaced some stuff. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I'm not sure the test name is that could, but I couldn't figure out a better one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Or not, Google says "The previous page is sending you to an invalid url". |
||
assert @normalizer.normalize(url) | ||
end | ||
end | ||
|
||
context ".extract_urls" do | ||
setup do | ||
@normalizer = Twingly::URL::Normalizer | ||
end | ||
|
||
should "detect two urls in a String" do | ||
urls = "http://blog.twingly.com/ http://twingly.com/" | ||
response = @normalizer.extract_urls(urls) | ||
|
||
response.size.must_equal 2 | ||
end | ||
|
||
should "detect two urls in an Array" do | ||
urls = %w(http://blog.twingly.com/ http://twingly.com/) | ||
response = @normalizer.extract_urls(urls) | ||
|
||
response.size.must_equal 2 | ||
end | ||
|
||
should "return an Array" do | ||
response = @normalizer.extract_urls(nil) | ||
|
||
response.must_be_instance_of Array | ||
end | ||
end | ||
|
||
context ".normalize_url" do | ||
setup do | ||
@normalizer = Twingly::URL::Normalizer | ||
end | ||
|
||
should "add www if host is missing a subdomain" do | ||
url = "http://twingly.com/" | ||
result = @normalizer.normalize_url(url) | ||
|
||
assert_equal "http://www.twingly.com/", result | ||
end | ||
|
||
should "not add www if the host has a subdomain" do | ||
url = "http://blog.twingly.com/" | ||
result = @normalizer.normalize_url(url) | ||
|
||
assert_equal "http://blog.twingly.com/", result | ||
end | ||
|
||
should "keep www if the host already has it" do | ||
url = "http://www.twingly.com/" | ||
result = @normalizer.normalize_url(url) | ||
|
||
assert_equal "http://www.twingly.com/", result | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix this one with Addressable::URI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in d230e8b