Skip to content

Commit dedefb7

Browse files
author
Jerry Cheung
committed
Merge branch 'master' into ci-129
2 parents ba2fee0 + f93b936 commit dedefb7

18 files changed

+105
-75
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ rvm:
1212
- 2.0.0
1313
- 2.1.1
1414
- ree
15+
16+
matrix:
17+
fast_finish: true
18+
allow_failures:
19+
- rvm: ree

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ group :development do
99
end
1010

1111
group :test do
12+
gem "minitest", "~> 5.3"
1213
gem "rinku", "~> 1.7", :require => false
1314
gem "gemoji", "~> 1.0", :require => false
1415
gem "RedCloth", "~> 4.2.9", :require => false
@@ -25,7 +26,12 @@ group :test do
2526

2627
if RUBY_VERSION < "1.9.2"
2728
gem "sanitize", ">= 2", "< 2.0.4", :require => false
29+
gem "nokogiri", ">= 1.4", "< 1.6"
2830
else
2931
gem "sanitize", "~> 2.0", :require => false
3032
end
33+
34+
if RUBY_VERSION < "1.9.3"
35+
gem "activesupport", ">= 2", "< 4"
36+
end
3137
end

html-pipeline.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Gem::Specification.new do |gem|
1515
gem.test_files = gem.files.grep(%r{^test})
1616
gem.require_paths = ["lib"]
1717

18-
gem.add_dependency "nokogiri", RUBY_VERSION < "1.9.2" ? [">= 1.4", "< 1.6"] : "~> 1.4"
19-
gem.add_dependency "activesupport", RUBY_VERSION < "1.9.3" ? [">= 2", "< 4"] : ">= 2"
18+
gem.add_dependency "nokogiri", "~> 1.4"
19+
gem.add_dependency "activesupport", ">= 2"
2020

2121
gem.post_install_message = <<msg
2222
-------------------------------------------------

lib/html/pipeline/https_filter.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
module HTML
22
class Pipeline
3-
# HTML Filter for replacing http github urls with https versions.
3+
# HTML Filter for replacing http references to :base_url with https versions.
4+
# Subdomain references are not rewritten.
5+
#
6+
# Context options:
7+
# :base_url - The url to force https
48
class HttpsFilter < Filter
59
def call
6-
doc.css('a[href^="http://github.com"]').each do |element|
10+
doc.css(%Q(a[href^="#{context[:base_url]}"])).each do |element|
711
element['href'] = element['href'].sub(/^http:/,'https:')
812
end
913
doc
1014
end
15+
16+
# Raise error if :base_url undefined
17+
def validate
18+
needs :base_url
19+
end
1120
end
1221
end
13-
end
22+
end

test/html/pipeline/absolute_source_filter_test.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "test_helper"
22

3-
class HTML::Pipeline::AbsoluteSourceFilterTest < Test::Unit::TestCase
3+
class HTML::Pipeline::AbsoluteSourceFilterTest < Minitest::Test
44
AbsoluteSourceFilter = HTML::Pipeline::AbsoluteSourceFilter
55

66
def setup
@@ -27,26 +27,26 @@ def test_rewrites_relative_urls
2727
def test_does_not_rewrite_absolute_urls
2828
orig = %(<p><img src="http://other.example.com/img.png"></p>)
2929
result = AbsoluteSourceFilter.call(orig, @options).to_s
30-
assert_no_match /@image_base_url/, result
31-
assert_no_match /@image_subpage_url/, result
30+
refute_match /@image_base_url/, result
31+
refute_match /@image_subpage_url/, result
3232
end
3333

3434
def test_fails_when_context_is_missing
35-
assert_raise RuntimeError do
35+
assert_raises RuntimeError do
3636
AbsoluteSourceFilter.call("<img src=\"img.png\">", {})
3737
end
38-
assert_raise RuntimeError do
38+
assert_raises RuntimeError do
3939
AbsoluteSourceFilter.call("<img src=\"/img.png\">", {})
4040
end
4141
end
4242

4343
def test_tells_you_where_context_is_required
44-
exception = assert_raise(RuntimeError) {
44+
exception = assert_raises(RuntimeError) {
4545
AbsoluteSourceFilter.call("<img src=\"img.png\">", {})
4646
}
4747
assert_match 'HTML::Pipeline::AbsoluteSourceFilter', exception.message
4848

49-
exception = assert_raise(RuntimeError) {
49+
exception = assert_raises(RuntimeError) {
5050
AbsoluteSourceFilter.call("<img src=\"/img.png\">", {})
5151
}
5252
assert_match 'HTML::Pipeline::AbsoluteSourceFilter', exception.message

test/html/pipeline/autolink_filter_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
AutolinkFilter = HTML::Pipeline::AutolinkFilter
44

5-
class HTML::Pipeline::AutolinkFilterTest < Test::Unit::TestCase
5+
class HTML::Pipeline::AutolinkFilterTest < Minitest::Test
66
def test_uses_rinku_for_autolinking
77
# just try to parse a complicated piece of HTML
88
# that Rails auto_link cannot handle

test/html/pipeline/camo_filter_test.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "test_helper"
22

3-
class HTML::Pipeline::CamoFilterTest < Test::Unit::TestCase
3+
class HTML::Pipeline::CamoFilterTest < Minitest::Test
44
CamoFilter = HTML::Pipeline::CamoFilter
55

66
def setup
@@ -64,13 +64,11 @@ def test_camouflaging_https_image_urls
6464

6565
def test_handling_images_with_no_src_attribute
6666
orig = %(<p><img></p>)
67-
assert_nothing_raised do
68-
CamoFilter.call(orig, @options).to_s
69-
end
67+
assert_equal orig, CamoFilter.call(orig, @options).to_s
7068
end
7169

7270
def test_required_context_validation
73-
exception = assert_raise(ArgumentError) {
71+
exception = assert_raises(ArgumentError) {
7472
CamoFilter.call("", {})
7573
}
7674
assert_match /:asset_proxy[^_]/, exception.message

test/html/pipeline/emoji_filter_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'test_helper'
22

3-
class HTML::Pipeline::EmojiFilterTest < Test::Unit::TestCase
3+
class HTML::Pipeline::EmojiFilterTest < Minitest::Test
44
EmojiFilter = HTML::Pipeline::EmojiFilter
55

66
def test_emojify
@@ -16,7 +16,7 @@ def test_uri_encoding
1616
end
1717

1818
def test_required_context_validation
19-
exception = assert_raise(ArgumentError) {
19+
exception = assert_raises(ArgumentError) {
2020
EmojiFilter.call("", {})
2121
}
2222
assert_match /:asset_root/, exception.message
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require "test_helper"
2+
3+
HttpsFilter = HTML::Pipeline::HttpsFilter
4+
5+
class HTML::Pipeline::AutolinkFilterTest < Minitest::Test
6+
def filter(html, base_url="http://github.com")
7+
HttpsFilter.to_html(html, :base_url => base_url)
8+
end
9+
10+
def test_http
11+
assert_equal %(<a href="https://github.com">github.com</a>),
12+
filter(%(<a href="http://github.com">github.com</a>))
13+
end
14+
15+
def test_https
16+
assert_equal %(<a href="https://github.com">github.com</a>),
17+
filter(%(<a href="https://github.com">github.com</a>))
18+
end
19+
20+
def test_subdomain
21+
assert_equal %(<a href="http://help.github.com">github.com</a>),
22+
filter(%(<a href="http://help.github.com">github.com</a>))
23+
end
24+
25+
def test_other
26+
assert_equal %(<a href="http://github.io">github.io</a>),
27+
filter(%(<a href="http://github.io">github.io</a>))
28+
end
29+
30+
def test_validation
31+
exception = assert_raises(ArgumentError) { HttpsFilter.call(nil, {}) }
32+
assert_match "HTML::Pipeline::HttpsFilter: :base_url", exception.message
33+
end
34+
end

test/html/pipeline/image_max_width_filter_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "test_helper"
22

3-
class HTML::Pipeline::ImageMaxWidthFilterTest < Test::Unit::TestCase
3+
class HTML::Pipeline::ImageMaxWidthFilterTest < Minitest::Test
44
def filter(html)
55
HTML::Pipeline::ImageMaxWidthFilter.call(html)
66
end

0 commit comments

Comments
 (0)