onebox 1.8.39 → 1.8.40

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.travis.yml +0 -1
  4. data/README.md +1 -1
  5. data/lib/onebox/engine/amazon_onebox.rb +98 -17
  6. data/lib/onebox/version.rb +3 -1
  7. data/onebox.gemspec +5 -5
  8. data/templates/amazon.mustache +7 -1
  9. metadata +7 -177
  10. data/spec/fixtures/amazon-og.response +0 -3675
  11. data/spec/fixtures/amazon.response +0 -3040
  12. data/spec/fixtures/cloudapp-gif.response +0 -66
  13. data/spec/fixtures/cloudapp-jpg.response +0 -66
  14. data/spec/fixtures/cloudapp-mp4.response +0 -65
  15. data/spec/fixtures/cloudapp-others.response +0 -66
  16. data/spec/fixtures/dailymail.response +0 -5914
  17. data/spec/fixtures/discourse_topic.response +0 -344
  18. data/spec/fixtures/discourse_topic_reply.response +0 -345
  19. data/spec/fixtures/douban.response +0 -4399
  20. data/spec/fixtures/etsy.response +0 -5827
  21. data/spec/fixtures/etsy_mobile.response +0 -4230
  22. data/spec/fixtures/gfycat.response +0 -1
  23. data/spec/fixtures/githubblob.response +0 -46
  24. data/spec/fixtures/githubcommit.response +0 -87
  25. data/spec/fixtures/githubgist.response +0 -310
  26. data/spec/fixtures/githubpullrequest.response +0 -216
  27. data/spec/fixtures/googleplayapp.response +0 -138
  28. data/spec/fixtures/image.response +0 -0
  29. data/spec/fixtures/meetup.response.html +0 -4419
  30. data/spec/fixtures/meetup_oembed.response +0 -1
  31. data/spec/fixtures/pubmed-electronic-xml.response +0 -175
  32. data/spec/fixtures/pubmed-electronic.response +0 -307
  33. data/spec/fixtures/pubmed-xml.response +0 -122
  34. data/spec/fixtures/pubmed.response +0 -300
  35. data/spec/fixtures/slides.response +0 -2852
  36. data/spec/fixtures/stackexchange-answer.response +0 -1
  37. data/spec/fixtures/stackexchange-question.response +0 -1
  38. data/spec/fixtures/twitterstatus.response +0 -2814
  39. data/spec/fixtures/video.response +0 -0
  40. data/spec/fixtures/wechat-mp.response +0 -631
  41. data/spec/fixtures/wikimedia.response +0 -1
  42. data/spec/fixtures/wikipedia.response +0 -566
  43. data/spec/fixtures/wikipediaredirected.response +0 -899
  44. data/spec/fixtures/xkcd.response +0 -1
  45. data/spec/fixtures/youku-meta.response +0 -1
  46. data/spec/fixtures/youku.response +0 -1443
  47. data/spec/fixtures/youtube-channel.response +0 -5446
  48. data/spec/fixtures/youtube-json.response +0 -1
  49. data/spec/fixtures/youtube-list-json.response +0 -1
  50. data/spec/fixtures/youtube.response +0 -1625
  51. data/spec/lib/onebox/engine/amazon_onebox_spec.rb +0 -116
  52. data/spec/lib/onebox/engine/audio_onebox_spec.rb +0 -31
  53. data/spec/lib/onebox/engine/cloudapp_onebox_spec.rb +0 -26
  54. data/spec/lib/onebox/engine/douban_onebox_spec.rb +0 -29
  55. data/spec/lib/onebox/engine/gfycat_onebox_spec.rb +0 -34
  56. data/spec/lib/onebox/engine/github_blob_onebox_spec.rb +0 -21
  57. data/spec/lib/onebox/engine/github_commit_onebox_spec.rb +0 -108
  58. data/spec/lib/onebox/engine/github_gist_onebox_spec.rb +0 -67
  59. data/spec/lib/onebox/engine/github_pullrequest_onebox_spec.rb +0 -46
  60. data/spec/lib/onebox/engine/google_docs_onebox_spec.rb +0 -35
  61. data/spec/lib/onebox/engine/google_maps_onebox_spec.rb +0 -72
  62. data/spec/lib/onebox/engine/google_play_app_onebox_spec.rb +0 -28
  63. data/spec/lib/onebox/engine/html_spec.rb +0 -25
  64. data/spec/lib/onebox/engine/image_onebox_spec.rb +0 -39
  65. data/spec/lib/onebox/engine/json_spec.rb +0 -25
  66. data/spec/lib/onebox/engine/pdf_onebox_spec.rb +0 -28
  67. data/spec/lib/onebox/engine/pubmed_onebox_spec.rb +0 -78
  68. data/spec/lib/onebox/engine/slides_onebox_spec.rb +0 -24
  69. data/spec/lib/onebox/engine/stack_exchange_onebox_spec.rb +0 -97
  70. data/spec/lib/onebox/engine/trello_onebox_spec.rb +0 -30
  71. data/spec/lib/onebox/engine/twitch_clips_onebox_spec.rb +0 -10
  72. data/spec/lib/onebox/engine/twitch_stream_onebox_spec.rb +0 -15
  73. data/spec/lib/onebox/engine/twitch_video_onebox_spec.rb +0 -10
  74. data/spec/lib/onebox/engine/twitter_status_onebox_spec.rb +0 -187
  75. data/spec/lib/onebox/engine/video_onebox_spec.rb +0 -31
  76. data/spec/lib/onebox/engine/wechat_mp_onebox_spec.rb +0 -26
  77. data/spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb +0 -179
  78. data/spec/lib/onebox/engine/wikimedia_onebox_spec.rb +0 -23
  79. data/spec/lib/onebox/engine/wikipedia_onebox_spec.rb +0 -21
  80. data/spec/lib/onebox/engine/xkcd_spec.rb +0 -27
  81. data/spec/lib/onebox/engine/youku_onebox_spec.rb +0 -13
  82. data/spec/lib/onebox/engine/youtube_onebox_spec.rb +0 -84
  83. data/spec/lib/onebox/engine_spec.rb +0 -101
  84. data/spec/lib/onebox/helpers_spec.rb +0 -73
  85. data/spec/lib/onebox/layout_spec.rb +0 -79
  86. data/spec/lib/onebox/matcher_spec.rb +0 -74
  87. data/spec/lib/onebox/preview_spec.rb +0 -74
  88. data/spec/lib/onebox/status_check_spec.rb +0 -68
  89. data/spec/lib/onebox_spec.rb +0 -65
  90. data/spec/spec_helper.rb +0 -90
  91. data/spec/support/html_spec_helper.rb +0 -18
  92. data/web/assets/javascripts/jquery.js +0 -4
  93. data/web/assets/javascripts/main.js +0 -23
  94. data/web/assets/stylesheets/normalize.css +0 -427
  95. data/web/assets/stylesheets/style.css +0 -25
  96. data/web/views/index.haml +0 -29
  97. data/web/views/layout.haml +0 -11
@@ -1,23 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Onebox::Engine::WikimediaOnebox do
4
- let(:link) { "https://commons.wikimedia.org/wiki/File:Stones_members_montage2.jpg" }
5
- let(:api_link) { "https://en.wikipedia.org/w/api.php?action=query&titles=File:Stones_members_montage2.jpg&prop=imageinfo&iilimit=50&iiprop=timestamp|user|url&iiurlwidth=500&format=json" }
6
- let(:html) { described_class.new(link).to_html }
7
-
8
- before do
9
- fake(api_link, response("wikimedia"))
10
- end
11
-
12
- it "has the title" do
13
- expect(html).to include("File:Stones members montage2.jpg")
14
- end
15
-
16
- it "has the link" do
17
- expect(html).to include(link)
18
- end
19
-
20
- it "has the image" do
21
- expect(html).to include("https://upload.wikimedia.org/wikipedia/commons/a/af/Stones_members_montage2.jpg")
22
- end
23
- end
@@ -1,21 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Onebox::Engine::WikipediaOnebox do
4
- before(:all) do
5
- @link = "http://en.wikipedia.org/wiki/Billy_Jack"
6
- fake("https://en.wikipedia.org/wiki/Billy_Jack", response(described_class.onebox_name))
7
- end
8
-
9
- include_context "engines"
10
- it_behaves_like "an engine"
11
-
12
- describe "#to_html" do
13
- it "includes article image" do
14
- expect(html).to include("Billy_Jack_poster.jpg")
15
- end
16
-
17
- it "includes summary" do
18
- expect(html).to include("Billy Jack is a 1971 action/drama")
19
- end
20
- end
21
- end
@@ -1,27 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Onebox::Engine::XkcdOnebox do
4
- let(:link) { "https://xkcd.com/327/" }
5
- let(:api_link) { "https://xkcd.com/327/info.0.json" }
6
- let(:html) { described_class.new(link).to_html }
7
-
8
- before do
9
- fake(api_link, response("xkcd"))
10
- end
11
-
12
- it "has the comic's description" do
13
- expect(html).to include("Her daughter is named Help")
14
- end
15
-
16
- it "has the comic's title" do
17
- expect(html).to include("Exploits of a Mom")
18
- end
19
-
20
- it "has the permalink to the comic" do
21
- expect(html).to include(link)
22
- end
23
-
24
- it "has the comic image" do
25
- expect(html).to include("http://imgs.xkcd.com/comics/exploits_of_a_mom.png")
26
- end
27
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Onebox::Engine::YoukuOnebox do
4
- before do
5
- FakeWeb.register_uri(:get, 'http://v.youku.com/v_show/id_XNjM3MzAxNzc2.html', body: response('youku'), content_type: 'text/html')
6
- FakeWeb.register_uri(:get, 'http://v.youku.com/player/getPlayList/VideoIDS/XNjM3MzAxNzc2', body: response('youku-meta'), content_type: 'text/html')
7
- end
8
-
9
- it 'returns embed as the placeholder' do
10
- expect(Onebox.preview('http://v.youku.com/v_show/id_XNjM3MzAxNzc2.html')
11
- .placeholder_html).to match(/embed/)
12
- end
13
- end
@@ -1,84 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Onebox::Engine::YoutubeOnebox do
4
- before do
5
- fake("https://www.youtube.com/watch?feature=player_embedded&v=21Lk4YiASMo", response("youtube"))
6
- fake("https://youtu.be/21Lk4YiASMo", response("youtube"))
7
- fake("https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ", response("youtube-channel"))
8
- fake("http://www.youtube.com/user/googlechrome", response("youtube-channel"))
9
- fake("https://www.youtube.com/playlist?list=PL5308B2E5749D1696", response("youtube-playlist"))
10
- fake("https://www.youtube.com/oembed?format=json&url=https://www.youtube.com/watch?v=21Lk4YiASMo", response("youtube-json"))
11
- fake("https://www.youtube.com/oembed?format=json&url=https://www.youtube.com/playlist?list=PL5308B2E5749D1696", response("youtube-list-json"))
12
- end
13
-
14
- it "adds wmode=opaque" do
15
- expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo').to_s).to match(/wmode=opaque/)
16
- end
17
-
18
- it "rewrites URLs for videos to be HTTPS" do
19
- # match: plain HTTP and protocol agnostic
20
- regex = /(http:|["']\/\/)/
21
-
22
- expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo').to_s).not_to match(regex)
23
- expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo').placeholder_html).not_to match(regex)
24
- expect(Onebox.preview('https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ').to_s).not_to match(regex)
25
- end
26
-
27
- it "can onebox a channel page" do
28
- expect(Onebox.preview('https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ').to_s).to match(/Google Chrome/)
29
- end
30
-
31
- it "can onebox a playlist" do
32
- expect(Onebox.preview('https://www.youtube.com/playlist?list=PL5308B2E5749D1696').to_s).to match(/iframe/)
33
- placeholder_html = Onebox.preview('https://www.youtube.com/playlist?list=PL5308B2E5749D1696').placeholder_html
34
- expect(placeholder_html).to match(/<img/)
35
- expect(placeholder_html).to include("The web is what you make of it")
36
- end
37
-
38
- it "does not make HTTP requests unless necessary" do
39
- # We haven't defined any fixture for requests associated with this ID, so if
40
- # any HTTP requests are made fakeweb will complain and the test will fail.
41
- Onebox.preview('http://www.youtube.com/watch?v=q39Ce3zDScI').to_s
42
- end
43
-
44
- it "does not fail if we cannot get the video ID from the URL" do
45
- expect(Onebox.preview('http://www.youtube.com/watch?feature=player_embedded&v=21Lk4YiASMo').to_s).to match(/embed/)
46
- end
47
-
48
- it "returns an image as the placeholder" do
49
- expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo').placeholder_html).to match(/<img/)
50
- expect(Onebox.preview('https://youtu.be/21Lk4YiASMo').placeholder_html).to match(/<img/)
51
- end
52
-
53
- it "passes the playlist ID through" do
54
- expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo&list=UUQau-O2C0kGJpR3_CHBTGbw&index=1').to_s).to match(/UUQau-O2C0kGJpR3_CHBTGbw/)
55
- end
56
-
57
- it "filters out nonsense parameters" do
58
- expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo&potential[]=exploit&potential[]=fun').to_s).not_to match(/potential|exploit|fun/)
59
- end
60
-
61
- it "converts time strings into a &start= parameter" do
62
- expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo&start=3782').to_s).to match(/start=3782/)
63
- expect(Onebox.preview('https://www.youtube.com/watch?start=1h3m2s&v=21Lk4YiASMo').to_s).to match(/start=3782/)
64
- expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo&t=1h3m2s').to_s).to match(/start=3782/)
65
- expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo&start=1h3m2s').to_s).to match(/start=3782/)
66
- expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo#t=1h3m2s').to_s).to match(/start=3782/)
67
- end
68
-
69
- it "allows both start and end" do
70
- preview = expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo&start=2m&end=3m').to_s)
71
- preview.to match(/start=120/)
72
- preview.to match(/end=180/)
73
- end
74
-
75
- it "permits looping videos" do
76
- preview = expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo&loop').to_s)
77
- preview.to match(/loop=1/)
78
- preview.to match(/playlist=21Lk4YiASMo/)
79
- end
80
-
81
- it "includes title in preview" do
82
- expect(Onebox.preview("https://youtu.be/21Lk4YiASMo").placeholder_html).to include("96neko - orange")
83
- end
84
- end
@@ -1,101 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Onebox::Engine do
4
- class OneboxEngineExample
5
- include Onebox::Engine
6
-
7
- def to_html
8
- "Hello #{link}"
9
- end
10
-
11
- def data
12
- { foo: raw[:key], url: @url }
13
- end
14
-
15
- def raw
16
- { key: "value" }
17
- end
18
- end
19
-
20
- describe "#link" do
21
- before { allow(Onebox::View).to receive(:template) { %|this should be a template| } }
22
-
23
- it "escapes `link`" do
24
- html = OneboxEngineExample.new(%|http://foo.com/'?a=1&b=2|).to_html
25
- expect(html).not_to match(/'/)
26
- end
27
- end
28
-
29
- describe "#record" do
30
- class OneboxEngineRecord
31
- include Onebox::Engine
32
-
33
- def data
34
- "new content"
35
- end
36
- end
37
-
38
- it "returns cached value for given url if its url is already in cache" do
39
- cache = { "http://example.com" => "old content" }
40
- result = OneboxEngineRecord.new("http://example.com", cache).send(:record)
41
- expect(result).to eq("old content")
42
- end
43
-
44
- it "stores cache value for given url if cache key doesn't exist" do
45
- cache = { "http://example.com1" => "old content" }
46
- result = OneboxEngineRecord.new("http://example.com", cache).send(:record)
47
- expect(result).to eq("new content")
48
- end
49
- end
50
-
51
- describe '.placeholder_html' do
52
- let(:onebox) { OneboxEngineExample.new('http://eviltrout.com') }
53
- it "returns `to_html` by default" do
54
- expect(onebox.to_html).to eq(onebox.placeholder_html)
55
- end
56
- end
57
-
58
- describe ".===" do
59
- class OneboxEngineTripleEqual
60
- include Onebox::Engine
61
- @@matcher = /example/
62
- end
63
- it "returns true if argument matches the matcher" do
64
- result = OneboxEngineTripleEqual === URI("http://www.example.com/product/5?var=foo&bar=5")
65
- expect(result).to eq(true)
66
- end
67
- end
68
-
69
- class AlwaysHttpsEngineExample < OneboxEngineExample
70
- always_https
71
- end
72
-
73
- describe "always_https" do
74
- it "never returns a plain http url" do
75
- url = 'http://play.google.com/store/apps/details?id=com.google.android.inputmethod.latin'
76
- onebox = AlwaysHttpsEngineExample.new(url)
77
- result = onebox.to_html
78
- expect(result).to_not match(/http(?!s)/)
79
- expect(result).to_not match(/['"]\/\//)
80
- expect(result).to match(/https/)
81
- end
82
- end
83
- end
84
-
85
- describe ".onebox_name" do
86
- module ScopeForTemplateName
87
- class TemplateNameOnebox
88
- include Onebox::Engine
89
- end
90
- end
91
-
92
- let(:onebox_name) { ScopeForTemplateName::TemplateNameOnebox.onebox_name }
93
-
94
- it "should not include the scope" do
95
- expect(onebox_name).not_to include("ScopeForTemplateName", "scopefortemplatename")
96
- end
97
-
98
- it "should not include the word Onebox" do
99
- expect(onebox_name).not_to include("onebox", "Onebox")
100
- end
101
- end
@@ -1,73 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Onebox::Helpers do
4
- describe '.blank?' do
5
- it { expect(described_class.blank?("")).to be(true) }
6
- it { expect(described_class.blank?(" ")).to be(true) }
7
- it { expect(described_class.blank?("test")).to be(false) }
8
- it { expect(described_class.blank?(["test", "testing"])).to be(false) }
9
- it { expect(described_class.blank?([])).to be(true) }
10
- it { expect(described_class.blank?({})).to be(true) }
11
- it { expect(described_class.blank?(nil)).to be(true) }
12
- it { expect(described_class.blank?(true)).to be(false) }
13
- it { expect(described_class.blank?(false)).to be(true) }
14
- it { expect(described_class.blank?(a: 'test')).to be(false) }
15
- end
16
-
17
- describe ".truncate" do
18
- let(:test_string) { "Chops off on spaces" }
19
- it { expect(described_class.truncate(test_string)).to eq(test_string) }
20
- it { expect(described_class.truncate(test_string, 5)).to eq("Chops...") }
21
- it { expect(described_class.truncate(test_string, 7)).to eq("Chops...") }
22
- it { expect(described_class.truncate(test_string, 9)).to eq("Chops off...") }
23
- it { expect(described_class.truncate(test_string, 10)).to eq("Chops off...") }
24
- it { expect(described_class.truncate(test_string, 100)).to eq("Chops off on spaces") }
25
- it { expect(described_class.truncate(" #{test_string} ", 6)).to eq(" Chops...") }
26
- end
27
-
28
- describe "fetch_response" do
29
- after(:each) do
30
- Onebox.options = Onebox::DEFAULTS
31
- end
32
-
33
- before do
34
- Onebox.options = { max_download_kb: 1 }
35
- fake("http://example.com/large-file", response("slides"))
36
- end
37
-
38
- it "raises an exception when responses are larger than our limit" do
39
- expect {
40
- described_class.fetch_response('http://example.com/large-file')
41
- }.to raise_error(Onebox::Helpers::DownloadTooLarge)
42
- end
43
- end
44
-
45
- describe "user_agent" do
46
- before do
47
- fake("http://example.com/some-resource", body: 'test')
48
- end
49
-
50
- context "default" do
51
- it "has the Ruby user agent" do
52
- described_class.fetch_response('http://example.com/some-resource')
53
- expect(FakeWeb.last_request.to_hash['user-agent'][0]).to eq("Ruby")
54
- end
55
- end
56
-
57
- context "Custom option" do
58
- after(:each) do
59
- Onebox.options = Onebox::DEFAULTS
60
- end
61
-
62
- before do
63
- Onebox.options = { user_agent: "EvilTroutBot v0.1" }
64
- end
65
-
66
- it "has the custom user agent" do
67
- described_class.fetch_response('http://example.com/some-resource')
68
- expect(FakeWeb.last_request.to_hash['user-agent'][0]).to eq("EvilTroutBot v0.1")
69
- end
70
- end
71
- end
72
-
73
- end
@@ -1,79 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Onebox::Layout do
4
- let(:cache) { Moneta.new(:Memory, expires: true, serializer: :json) }
5
- let(:record) { {} }
6
- let(:onebox) { described_class.new("amazon", record, cache) }
7
- let(:html) { onebox.to_html }
8
-
9
- describe ".template_path" do
10
- let(:template_path) { onebox.template_path }
11
-
12
- before(:each) do
13
- Onebox.options.load_paths << "directory_a"
14
- Onebox.options.load_paths << "directory_b"
15
- end
16
-
17
- context "when template exists in directory_b" do
18
- before(:each) do
19
- allow_any_instance_of(described_class).to receive(:template?) { |_, path| path == "directory_b" }
20
- end
21
-
22
- it "returns directory_b" do
23
- expect(template_path).to eq("directory_b")
24
- end
25
- end
26
-
27
- context "when template exists in directory_a" do
28
- before(:each) do
29
- allow_any_instance_of(described_class).to receive(:template?) { |_, path| path == "directory_a" }
30
- end
31
-
32
- it "returns directory_a" do
33
- expect(template_path).to eq("directory_a")
34
- end
35
- end
36
-
37
- context "when template doesn't exist in directory_a or directory_b" do
38
- it "returns default path" do
39
- expect(template_path).to include("template")
40
- end
41
- end
42
-
43
- after(:each) do
44
- Onebox.options.load_paths.pop(2)
45
- end
46
- end
47
-
48
- describe "#to_html" do
49
- class OneboxEngineLayout
50
- include Onebox::Engine
51
-
52
- def data
53
- "new content"
54
- end
55
- end
56
-
57
- it "reads from cache if rendered template is cached" do
58
- described_class.new("amazon", record, cache).to_html
59
- expect(cache).to receive(:fetch)
60
- described_class.new("amazon", record, cache).to_html
61
- end
62
-
63
- it "contains layout template" do
64
- expect(html).to include(%|class="onebox|)
65
- end
66
-
67
- it "contains the view" do
68
- record = { link: "foo" }
69
- html = described_class.new("amazon", record, cache).to_html
70
- expect(html).to include(%|"foo"|)
71
- end
72
-
73
- it "rewrites relative image path" do
74
- record = { image: "/image.png", link: "https://discourse.org" }
75
- klass = described_class.new("whitelistedgeneric", record, cache)
76
- expect(klass.view.record[:image]).to include("https://discourse.org")
77
- end
78
- end
79
- end
@@ -1,74 +0,0 @@
1
- require "spec_helper"
2
-
3
- class TestEngine
4
- def self.===(uri)
5
- true
6
- end
7
- end
8
-
9
- describe Onebox::Matcher do
10
-
11
- describe "oneboxed" do
12
-
13
- describe "with a path" do
14
- let(:url) { "http://party.time.made.up-url.com/beep/boop" }
15
- let(:matcher) { Onebox::Matcher.new(url) }
16
-
17
- it "finds an engine" do
18
- matcher.stubs(:ordered_engines).returns([TestEngine])
19
- expect(matcher.oneboxed).not_to be_nil
20
- end
21
- end
22
-
23
- describe "without a path" do
24
- let(:url) { "http://party.time.made.up-url.com/" }
25
- let(:matcher) { Onebox::Matcher.new(url) }
26
-
27
- it "doesn't find an engine" do
28
- matcher.stubs(:ordered_engines).returns([TestEngine])
29
- expect(matcher.oneboxed).not_to be_nil
30
- end
31
- end
32
-
33
- describe "without a path but has a query string" do
34
- let(:url) { "http://party.time.made.up-url.com/?article_id=1234" }
35
- let(:matcher) { Onebox::Matcher.new(url) }
36
-
37
- it "finds an engine" do
38
- matcher.stubs(:ordered_engines).returns([TestEngine])
39
- expect(matcher.oneboxed).not_to be_nil
40
- end
41
- end
42
-
43
- describe "without a path but has a fragment string" do
44
- let(:url) { "http://party.time.made.up-url.com/#article_id=1234" }
45
- let(:matcher) { Onebox::Matcher.new(url) }
46
-
47
- it "finds an engine" do
48
- matcher.stubs(:ordered_engines).returns([TestEngine])
49
- expect(matcher.oneboxed).not_to be_nil
50
- end
51
- end
52
-
53
- describe "with a whitelisted port/scheme" do
54
- %w{http://example.com https://example.com http://example.com:80 //example.com}.each do |url|
55
- it "finds an engine for '#{url}'" do
56
- matcher = Onebox::Matcher.new(url)
57
- matcher.stubs(:ordered_engines).returns([TestEngine])
58
- expect(matcher.oneboxed).not_to be_nil
59
- end
60
- end
61
- end
62
-
63
- describe "without a whitelisted port/scheme" do
64
- %w{http://example.com:21 ftp://example.com}.each do |url|
65
- it "doesn't find an engine for '#{url}'" do
66
- matcher = Onebox::Matcher.new(url)
67
- matcher.stubs(:ordered_engines).returns([TestEngine])
68
- expect(matcher.oneboxed).to be_nil
69
- end
70
- end
71
- end
72
-
73
- end
74
- end