onebox 1.8.9 → 1.8.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,90 +1,117 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Onebox::Engine::AmazonOnebox do
4
- before(:all) do
5
- @link = "https://www.amazon.com/Knit-Noro-Accessories-Colorful-Little/dp/193609620X"
6
- @uri = "https://www.amazon.com/gp/aw/d/193609620X"
7
- end
8
-
9
- include_context "engines"
10
- it_behaves_like "an engine"
11
4
 
12
- describe "works with international domains" do
13
5
 
14
- def check_link(tdl, link)
15
- onebox_cls = Onebox::Matcher.new(link).oneboxed
16
- expect(onebox_cls).to_not be(nil)
17
- expect(onebox_cls.new(link).url).to include("https://www.amazon.#{tdl}")
6
+ context "regular amazon page" do
7
+ before do
8
+ @link = "https://www.amazon.com/Knit-Noro-Accessories-Colorful-Little/dp/193609620X"
9
+ @uri = "https://www.amazon.com/gp/aw/d/193609620X"
18
10
  end
11
+ include_context "engines"
12
+ it_behaves_like "an engine"
19
13
 
20
- it "matches canadian domains" do
21
- check_link("ca", "https://www.amazon.ca/Too-Much-Happiness-Alice-Munro-ebook/dp/B0031TZ98K/")
22
- end
14
+ describe "works with international domains" do
23
15
 
24
- it "matches german domains" do
25
- check_link("de", "https://www.amazon.de/Buddenbrooks-Verfall-einer-Familie-Roman/dp/3596294312/")
26
- end
16
+ def check_link(tdl, link)
17
+ onebox_cls = Onebox::Matcher.new(link).oneboxed
18
+ expect(onebox_cls).to_not be(nil)
19
+ expect(onebox_cls.new(link).url).to include("https://www.amazon.#{tdl}")
20
+ end
27
21
 
28
- it "matches uk domains" do
29
- check_link("co.uk", "https://www.amazon.co.uk/Pygmalion-George-Bernard-Shaw/dp/1420925237/")
30
- end
22
+ it "matches canadian domains" do
23
+ check_link("ca", "https://www.amazon.ca/Too-Much-Happiness-Alice-Munro-ebook/dp/B0031TZ98K/")
24
+ end
31
25
 
32
- it "matches japanese domains" do
33
- check_link("co.jp", "https://www.amazon.co.jp/%E9%9B%AA%E5%9B%BD-%E6%96%B0%E6%BD%AE%E6%96%87%E5%BA%AB-%E3%81%8B-1-1-%E5%B7%9D%E7%AB%AF-%E5%BA%B7%E6%88%90/dp/4101001014/")
34
- end
26
+ it "matches german domains" do
27
+ check_link("de", "https://www.amazon.de/Buddenbrooks-Verfall-einer-Familie-Roman/dp/3596294312/")
28
+ end
35
29
 
36
- it "matches chinese domains" do
37
- check_link("cn", "https://www.amazon.cn/%E5%AD%99%E5%AD%90%E5%85%B5%E6%B3%95-%E5%AD%99%E8%86%91%E5%85%B5%E6%B3%95-%E5%AD%99%E6%AD%A6/dp/B0011C40FC/")
38
- end
30
+ it "matches uk domains" do
31
+ check_link("co.uk", "https://www.amazon.co.uk/Pygmalion-George-Bernard-Shaw/dp/1420925237/")
32
+ end
39
33
 
40
- it "matches french domains" do
41
- check_link("fr", "https://www.amazon.fr/Les-Mots-autres-%C3%A9crits-autobiographiques/dp/2070114147/")
42
- end
34
+ it "matches japanese domains" do
35
+ check_link("co.jp", "https://www.amazon.co.jp/%E9%9B%AA%E5%9B%BD-%E6%96%B0%E6%BD%AE%E6%96%87%E5%BA%AB-%E3%81%8B-1-1-%E5%B7%9D%E7%AB%AF-%E5%BA%B7%E6%88%90/dp/4101001014/")
36
+ end
43
37
 
44
- it "matches italian domains" do
45
- check_link("it", "https://www.amazon.it/Tutte-poesie-Salvatore-Quasimodo/dp/8804520477/")
46
- end
38
+ it "matches chinese domains" do
39
+ check_link("cn", "https://www.amazon.cn/%E5%AD%99%E5%AD%90%E5%85%B5%E6%B3%95-%E5%AD%99%E8%86%91%E5%85%B5%E6%B3%95-%E5%AD%99%E6%AD%A6/dp/B0011C40FC/")
40
+ end
47
41
 
48
- it "matches spanish domains" do
49
- check_link("es", "https://www.amazon.es/familia-Pascual-Duarte-Camilo-Jos%C3%A9-ebook/dp/B00EJRTKTW/")
50
- end
42
+ it "matches french domains" do
43
+ check_link("fr", "https://www.amazon.fr/Les-Mots-autres-%C3%A9crits-autobiographiques/dp/2070114147/")
44
+ end
45
+
46
+ it "matches italian domains" do
47
+ check_link("it", "https://www.amazon.it/Tutte-poesie-Salvatore-Quasimodo/dp/8804520477/")
48
+ end
49
+
50
+ it "matches spanish domains" do
51
+ check_link("es", "https://www.amazon.es/familia-Pascual-Duarte-Camilo-Jos%C3%A9-ebook/dp/B00EJRTKTW/")
52
+ end
53
+
54
+ it "matches brasilian domains" do
55
+ check_link("com.br", "https://www.amazon.com.br/A-p%C3%A1tria-chuteiras-Nelson-Rodrigues-ebook/dp/B00J2B414Y/")
56
+ end
57
+
58
+ it "matches indian domains" do
59
+ check_link("in", "https://www.amazon.in/Fireflies-Rabindranath-Tagore/dp/9381523169/")
60
+ end
51
61
 
52
- it "matches brasilian domains" do
53
- check_link("com.br", "https://www.amazon.com.br/A-p%C3%A1tria-chuteiras-Nelson-Rodrigues-ebook/dp/B00J2B414Y/")
54
62
  end
55
63
 
56
- it "matches indian domains" do
57
- check_link("in", "https://www.amazon.in/Fireflies-Rabindranath-Tagore/dp/9381523169/")
64
+ describe "#url" do
65
+ it "maintains the same http/https scheme as the requested URL" do
66
+ expect(described_class.new("https://www.amazon.fr/gp/product/B01BYD0TZM").url)
67
+ .to eq("https://www.amazon.fr/gp/aw/d/B01BYD0TZM")
68
+
69
+ expect(described_class.new("http://www.amazon.fr/gp/product/B01BYD0TZM").url)
70
+ .to eq("https://www.amazon.fr/gp/aw/d/B01BYD0TZM")
71
+ end
58
72
  end
59
73
 
60
- end
74
+ describe "#to_html" do
75
+ it "includes image" do
76
+ expect(html).to include("http://ecx.images-amazon.com/images/I/51opYcR6kVL._SY400_.jpg")
77
+ end
61
78
 
62
- describe "#url" do
63
- it "maintains the same http/https scheme as the requested URL" do
64
- expect(described_class.new("https://www.amazon.fr/gp/product/B01BYD0TZM").url)
65
- .to eq("https://www.amazon.fr/gp/aw/d/B01BYD0TZM")
79
+ it "includes description" do
80
+ expect(html).to include("I have been programming for 25 years in a variety of hardware and software languages.")
81
+ end
66
82
 
67
- expect(described_class.new("http://www.amazon.fr/gp/product/B01BYD0TZM").url)
68
- .to eq("https://www.amazon.fr/gp/aw/d/B01BYD0TZM")
83
+ it "includes price" do
84
+ expect(html).to include("$25.34")
85
+ end
86
+
87
+ it "includes title" do
88
+ expect(html).to include("Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages (Pragmatic Programmers)")
89
+ end
69
90
  end
70
91
  end
71
92
 
72
- describe "#to_html" do
73
- it "includes image" do
74
- expect(html).to include("http://ecx.images-amazon.com/images/I/51opYcR6kVL._SY400_.jpg")
75
- end
93
+ context "amazon with opengraph" do
94
+ let(:link) { "https://www.amazon.com/dp/B01MFXN4Y2" }
95
+ let(:html) { described_class.new(link).to_html }
76
96
 
77
- it "includes description" do
78
- expect(html).to include("I have been programming for 25 years in a variety of hardware and software languages.")
97
+ before do
98
+ fake("https://www.amazon.com/gp/aw/d/B01MFXN4Y2", response("amazon-og"))
79
99
  end
80
100
 
81
- it "includes price" do
82
- expect(html).to include("$25.34")
83
- end
101
+ describe "#to_html" do
102
+ it "includes image" do
103
+ expect(html).to include("https://images-na.ssl-images-amazon.com/images/I/51nOF2iBa6L._SX940_.jpg")
104
+ end
84
105
 
85
- it "includes title" do
86
- expect(html).to include("Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages (Pragmatic Programmers)")
106
+ it "includes description" do
107
+ expect(html).to include("CHRISTINE is the story of an aspiring newswoman caught in the midst of a personal and professional life crisis. Between unrequited love, frustration at work, a tumultuous home, and self-doubt; she begins to spiral down a dark path.")
108
+ end
109
+
110
+ it "includes title" do
111
+ expect(html).to include("Watch Christine online - Amazon Video")
112
+ end
87
113
  end
114
+
88
115
  end
89
116
 
90
117
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.9
4
+ version: 1.8.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joanna Zeta
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-06-01 00:00:00.000000000 Z
13
+ date: 2017-06-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json
@@ -393,6 +393,7 @@ files:
393
393
  - lib/onebox/web.rb
394
394
  - lib/onebox/web_helpers.rb
395
395
  - onebox.gemspec
396
+ - spec/fixtures/amazon-og.response
396
397
  - spec/fixtures/amazon.response
397
398
  - spec/fixtures/dailymail.response
398
399
  - spec/fixtures/douban.response
@@ -512,6 +513,7 @@ signing_key:
512
513
  specification_version: 4
513
514
  summary: A gem for turning URLs into previews.
514
515
  test_files:
516
+ - spec/fixtures/amazon-og.response
515
517
  - spec/fixtures/amazon.response
516
518
  - spec/fixtures/dailymail.response
517
519
  - spec/fixtures/douban.response