link_thumbnailer 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,205 +1,205 @@
1
- require 'spec_helper'
2
-
3
- describe LinkThumbnailer do
4
-
5
- let(:og_example) { File.open(File.dirname(__FILE__) + '/examples/og_example.html').read() }
6
- let(:example) { File.open(File.dirname(__FILE__) + '/examples/example.html').read() }
7
- let(:empty_example) { File.open(File.dirname(__FILE__) + '/examples/empty_example.html').read() }
8
-
9
- it { should respond_to :configuration }
10
- it { should respond_to :configure }
11
- it { should respond_to :config }
12
- it { should respond_to :generate }
13
-
14
- describe ".configure" do
15
-
16
- it "should yields self" do
17
- LinkThumbnailer.should_receive(:configure).and_yield(LinkThumbnailer)
18
- LinkThumbnailer.configure {|config|}
19
- end
20
-
21
- before do
22
- LinkThumbnailer.configure {|config|
23
- config.mandatory_attributes = %w(foo bar)
24
- config.strict = false
25
- config.redirect_limit = 5
26
- config.blacklist_urls = []
27
- config.image_attributes = []
28
- config.limit = 5
29
- config.top = 10
30
- config.user_agent = 'linkthumbnailer'
31
- config.verify_ssl = true
32
- config.http_timeout = 5
33
- }
34
- end
35
-
36
- after do
37
- LinkThumbnailer.configuration = nil
38
- end
39
-
40
- specify { LinkThumbnailer.configuration.mandatory_attributes.should eq(%w(foo bar)) }
41
- specify { LinkThumbnailer.configuration.strict.should be_false }
42
- specify { LinkThumbnailer.configuration.redirect_limit.should eq(5) }
43
- specify { LinkThumbnailer.configuration.blacklist_urls.should eq([]) }
44
- specify { LinkThumbnailer.configuration.image_attributes.should eq([]) }
45
- specify { LinkThumbnailer.configuration.limit.should eq(5) }
46
- specify { LinkThumbnailer.configuration.top.should eq(10) }
47
- specify { LinkThumbnailer.configuration.user_agent.should eq('linkthumbnailer') }
48
- specify { LinkThumbnailer.configuration.verify_ssl.should be_true }
49
- specify { LinkThumbnailer.configuration.http_timeout.should eq(5) }
50
-
51
- end
52
-
53
- context "default values" do
54
-
55
- before do
56
- LinkThumbnailer.configure {|config| }
57
- end
58
-
59
- specify { LinkThumbnailer.configuration.mandatory_attributes.should eq(%w(url title images)) }
60
- specify { LinkThumbnailer.configuration.strict.should be_true }
61
- specify { LinkThumbnailer.configuration.redirect_limit.should eq(3) }
62
- specify { LinkThumbnailer.configuration.blacklist_urls.should eq([
63
- %r{^http://ad\.doubleclick\.net/},
64
- %r{^http://b\.scorecardresearch\.com/},
65
- %r{^http://pixel\.quantserve\.com/},
66
- %r{^http://s7\.addthis\.com/}
67
- ]) }
68
- specify { LinkThumbnailer.configuration.image_attributes.should eq(%w(source_url size type)) }
69
- specify { LinkThumbnailer.configuration.limit.should eq(10) }
70
- specify { LinkThumbnailer.configuration.top.should eq(5) }
71
- specify { LinkThumbnailer.configuration.user_agent.should eq('linkthumbnailer') }
72
- specify { LinkThumbnailer.configuration.verify_ssl.should be_true }
73
- specify { LinkThumbnailer.configuration.http_timeout.should eq(5) }
74
-
75
- end
76
-
77
- describe ".generate" do
78
-
79
- it "should set default options" do
80
- LinkThumbnailer.should_receive(:config)
81
- LinkThumbnailer.generate('foo')
82
- end
83
-
84
- context "with valid arguments" do
85
-
86
- context "and options" do
87
-
88
- it "should set top option" do
89
- expect { LinkThumbnailer.generate('foo', top: 20).to change(LinkThumbnailer.configuration.top).from(5).to(20) }
90
- end
91
-
92
- it "should set limit option" do
93
- expect { LinkThumbnailer.generate('foo', limit: 20).to change(LinkThumbnailer.configuration.limit).from(10).to(20) }
94
- end
95
-
96
- it "should set mandatory_attributes option" do
97
- expect { LinkThumbnailer.generate('foo', mandatory_attributes: %w(one two)).to change(LinkThumbnailer.configuration.mandatory_attributes).from(%w(url title images)).to(%w(one two)) }
98
- end
99
-
100
- it "should set strict option" do
101
- expect { LinkThumbnailer.generate('foo', strict: false).to change(LinkThumbnailer.configuration.strict).from(true).to(false) }
102
- end
103
-
104
- it "should set redirect_limit option" do
105
- expect { LinkThumbnailer.generate('foo', redirect_limit: 5).to change(LinkThumbnailer.configuration.redirect_limit).from(3).to(5) }
106
- end
107
-
108
- it "should set blacklist_urls option" do
109
- expect { LinkThumbnailer.generate('foo', blacklist_urls: [%r{^http://foo\.bar\.com/}]).to change(LinkThumbnailer.configuration.blacklist_urls).to([%r{^http://foo\.bar\.com/}]) }
110
- end
111
-
112
- it "should set image_attributes option" do
113
- expect { LinkThumbnailer.generate('foo', image_attributes: %w(one two)).to change(LinkThumbnailer.configuration.image_attributes).to(%w(one two)) }
114
- end
115
-
116
- it "should set user_agent option" do
117
- expect { LinkThumbnailer.generate('foo', user_agent: 'Mac Safari').to change(LinkThumbnailer.configuration.mandatory_attributes).from('linkthumbnailer').to('Mac Safari') }
118
- end
119
-
120
- it "should set verify_ssl option" do
121
- expect { LinkThumbnailer.generate('foo', verify_ssl: false).to change(LinkThumbnailer.configuration.verify_ssl).from(true).to(false) }
122
- end
123
-
124
- it "should set http_timeout option" do
125
- expect { LinkThumbnailer.generate('foo', http_timeout: 2).to change(LinkThumbnailer.configuration.http_timeout).from(5).to(2) }
126
- end
127
-
128
- end
129
-
130
- context "when strict" do
131
-
132
- context "and not valid" do
133
-
134
- subject { LinkThumbnailer.generate('foo') }
135
-
136
- it { expect(LinkThumbnailer.generate('foo')).to be_nil }
137
-
138
- end
139
-
140
- context "and valid" do
141
-
142
- before do
143
- stub_request(:get, 'http://foo.com/').to_return(status: 200, body: og_example, headers: {})
144
- end
145
-
146
- it { expect(LinkThumbnailer.generate('http://foo.com')).to_not be_nil }
147
- it { expect(LinkThumbnailer.generate('http://foo.com')).to be_valid }
148
-
149
- end
150
-
151
- context "and empty" do
152
-
153
- before do
154
- stub_request(:get, 'http://foo.com/').to_return(status: 200, body: empty_example, headers: {})
155
- end
156
-
157
- it { expect(LinkThumbnailer.generate('http://foo.com/')).to be_nil }
158
- it { expect { LinkThumbnailer.generate('http://foo.com/') }.to_not raise_exception }
159
-
160
- end
161
-
162
- end
163
-
164
- context "when not strict" do
165
-
166
- before do
167
- LinkThumbnailer.configure {|config| config.strict = false }
168
- end
169
-
170
- context "and not valid" do
171
-
172
- it { expect(LinkThumbnailer.generate('foo')).to_not be_nil }
173
- it { expect(LinkThumbnailer.generate('foo')).to be_valid }
174
-
175
- end
176
-
177
- context "and valid" do
178
-
179
- before do
180
- stub_request(:get, 'http://foo.com/').to_return(status: 200, body: og_example, headers: {})
181
- end
182
-
183
- it { expect(LinkThumbnailer.generate('http://foo.com')).to_not be_nil }
184
- it { expect(LinkThumbnailer.generate('http://foo.com')).to be_valid }
185
-
186
- end
187
-
188
- context "and empty" do
189
-
190
- before do
191
- stub_request(:get, 'http://foo.com/').to_return(status: 200, body: empty_example, headers: {})
192
- end
193
-
194
- it { expect(LinkThumbnailer.generate('http://foo.com/')).to_not be_nil }
195
- it { expect { LinkThumbnailer.generate('http://foo.com/') }.to_not raise_exception }
196
-
197
- end
198
-
199
- end
200
-
201
- end
202
-
203
- end
204
-
205
- end
1
+ require 'spec_helper'
2
+
3
+ describe LinkThumbnailer do
4
+
5
+ let(:og_example) { File.open(File.dirname(__FILE__) + '/examples/og_example.html').read() }
6
+ let(:example) { File.open(File.dirname(__FILE__) + '/examples/example.html').read() }
7
+ let(:empty_example) { File.open(File.dirname(__FILE__) + '/examples/empty_example.html').read() }
8
+
9
+ it { should respond_to :configuration }
10
+ it { should respond_to :configure }
11
+ it { should respond_to :config }
12
+ it { should respond_to :generate }
13
+
14
+ describe ".configure" do
15
+
16
+ it "should yields self" do
17
+ LinkThumbnailer.should_receive(:configure).and_yield(LinkThumbnailer)
18
+ LinkThumbnailer.configure {|config|}
19
+ end
20
+
21
+ before do
22
+ LinkThumbnailer.configure {|config|
23
+ config.mandatory_attributes = %w(foo bar)
24
+ config.strict = false
25
+ config.redirect_limit = 5
26
+ config.blacklist_urls = []
27
+ config.image_attributes = []
28
+ config.limit = 5
29
+ config.top = 10
30
+ config.user_agent = 'linkthumbnailer'
31
+ config.verify_ssl = true
32
+ config.http_timeout = 5
33
+ }
34
+ end
35
+
36
+ after do
37
+ LinkThumbnailer.configuration = nil
38
+ end
39
+
40
+ specify { LinkThumbnailer.configuration.mandatory_attributes.should eq(%w(foo bar)) }
41
+ specify { LinkThumbnailer.configuration.strict.should be_false }
42
+ specify { LinkThumbnailer.configuration.redirect_limit.should eq(5) }
43
+ specify { LinkThumbnailer.configuration.blacklist_urls.should eq([]) }
44
+ specify { LinkThumbnailer.configuration.image_attributes.should eq([]) }
45
+ specify { LinkThumbnailer.configuration.limit.should eq(5) }
46
+ specify { LinkThumbnailer.configuration.top.should eq(10) }
47
+ specify { LinkThumbnailer.configuration.user_agent.should eq('linkthumbnailer') }
48
+ specify { LinkThumbnailer.configuration.verify_ssl.should be_true }
49
+ specify { LinkThumbnailer.configuration.http_timeout.should eq(5) }
50
+
51
+ end
52
+
53
+ context "default values" do
54
+
55
+ before do
56
+ LinkThumbnailer.configure {|config| }
57
+ end
58
+
59
+ specify { LinkThumbnailer.configuration.mandatory_attributes.should eq(%w(url title images)) }
60
+ specify { LinkThumbnailer.configuration.strict.should be_true }
61
+ specify { LinkThumbnailer.configuration.redirect_limit.should eq(3) }
62
+ specify { LinkThumbnailer.configuration.blacklist_urls.should eq([
63
+ %r{^http://ad\.doubleclick\.net/},
64
+ %r{^http://b\.scorecardresearch\.com/},
65
+ %r{^http://pixel\.quantserve\.com/},
66
+ %r{^http://s7\.addthis\.com/}
67
+ ]) }
68
+ specify { LinkThumbnailer.configuration.image_attributes.should eq(%w(source_url size type)) }
69
+ specify { LinkThumbnailer.configuration.limit.should eq(10) }
70
+ specify { LinkThumbnailer.configuration.top.should eq(5) }
71
+ specify { LinkThumbnailer.configuration.user_agent.should eq('linkthumbnailer') }
72
+ specify { LinkThumbnailer.configuration.verify_ssl.should be_true }
73
+ specify { LinkThumbnailer.configuration.http_timeout.should eq(5) }
74
+
75
+ end
76
+
77
+ describe ".generate" do
78
+
79
+ it "should set default options" do
80
+ LinkThumbnailer.should_receive(:config)
81
+ LinkThumbnailer.generate('foo')
82
+ end
83
+
84
+ context "with valid arguments" do
85
+
86
+ context "and options" do
87
+
88
+ it "should set top option" do
89
+ expect { LinkThumbnailer.generate('foo', top: 20).to change(LinkThumbnailer.configuration.top).from(5).to(20) }
90
+ end
91
+
92
+ it "should set limit option" do
93
+ expect { LinkThumbnailer.generate('foo', limit: 20).to change(LinkThumbnailer.configuration.limit).from(10).to(20) }
94
+ end
95
+
96
+ it "should set mandatory_attributes option" do
97
+ expect { LinkThumbnailer.generate('foo', mandatory_attributes: %w(one two)).to change(LinkThumbnailer.configuration.mandatory_attributes).from(%w(url title images)).to(%w(one two)) }
98
+ end
99
+
100
+ it "should set strict option" do
101
+ expect { LinkThumbnailer.generate('foo', strict: false).to change(LinkThumbnailer.configuration.strict).from(true).to(false) }
102
+ end
103
+
104
+ it "should set redirect_limit option" do
105
+ expect { LinkThumbnailer.generate('foo', redirect_limit: 5).to change(LinkThumbnailer.configuration.redirect_limit).from(3).to(5) }
106
+ end
107
+
108
+ it "should set blacklist_urls option" do
109
+ expect { LinkThumbnailer.generate('foo', blacklist_urls: [%r{^http://foo\.bar\.com/}]).to change(LinkThumbnailer.configuration.blacklist_urls).to([%r{^http://foo\.bar\.com/}]) }
110
+ end
111
+
112
+ it "should set image_attributes option" do
113
+ expect { LinkThumbnailer.generate('foo', image_attributes: %w(one two)).to change(LinkThumbnailer.configuration.image_attributes).to(%w(one two)) }
114
+ end
115
+
116
+ it "should set user_agent option" do
117
+ expect { LinkThumbnailer.generate('foo', user_agent: 'Mac Safari').to change(LinkThumbnailer.configuration.mandatory_attributes).from('linkthumbnailer').to('Mac Safari') }
118
+ end
119
+
120
+ it "should set verify_ssl option" do
121
+ expect { LinkThumbnailer.generate('foo', verify_ssl: false).to change(LinkThumbnailer.configuration.verify_ssl).from(true).to(false) }
122
+ end
123
+
124
+ it "should set http_timeout option" do
125
+ expect { LinkThumbnailer.generate('foo', http_timeout: 2).to change(LinkThumbnailer.configuration.http_timeout).from(5).to(2) }
126
+ end
127
+
128
+ end
129
+
130
+ context "when strict" do
131
+
132
+ context "and not valid" do
133
+
134
+ subject { LinkThumbnailer.generate('foo') }
135
+
136
+ it { expect(LinkThumbnailer.generate('foo')).to be_nil }
137
+
138
+ end
139
+
140
+ context "and valid" do
141
+
142
+ before do
143
+ stub_request(:get, 'http://foo.com/').to_return(status: 200, body: og_example, headers: {})
144
+ end
145
+
146
+ it { expect(LinkThumbnailer.generate('http://foo.com')).to_not be_nil }
147
+ it { expect(LinkThumbnailer.generate('http://foo.com')).to be_valid }
148
+
149
+ end
150
+
151
+ context "and empty" do
152
+
153
+ before do
154
+ stub_request(:get, 'http://foo.com/').to_return(status: 200, body: empty_example, headers: {})
155
+ end
156
+
157
+ it { expect(LinkThumbnailer.generate('http://foo.com/')).to be_nil }
158
+ it { expect { LinkThumbnailer.generate('http://foo.com/') }.to_not raise_exception }
159
+
160
+ end
161
+
162
+ end
163
+
164
+ context "when not strict" do
165
+
166
+ before do
167
+ LinkThumbnailer.configure {|config| config.strict = false }
168
+ end
169
+
170
+ context "and not valid" do
171
+
172
+ it { expect(LinkThumbnailer.generate('foo')).to_not be_nil }
173
+ it { expect(LinkThumbnailer.generate('foo')).to be_valid }
174
+
175
+ end
176
+
177
+ context "and valid" do
178
+
179
+ before do
180
+ stub_request(:get, 'http://foo.com/').to_return(status: 200, body: og_example, headers: {})
181
+ end
182
+
183
+ it { expect(LinkThumbnailer.generate('http://foo.com')).to_not be_nil }
184
+ it { expect(LinkThumbnailer.generate('http://foo.com')).to be_valid }
185
+
186
+ end
187
+
188
+ context "and empty" do
189
+
190
+ before do
191
+ stub_request(:get, 'http://foo.com/').to_return(status: 200, body: empty_example, headers: {})
192
+ end
193
+
194
+ it { expect(LinkThumbnailer.generate('http://foo.com/')).to_not be_nil }
195
+ it { expect { LinkThumbnailer.generate('http://foo.com/') }.to_not raise_exception }
196
+
197
+ end
198
+
199
+ end
200
+
201
+ end
202
+
203
+ end
204
+
205
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,13 @@
1
- require 'simplecov'
2
- require 'coveralls'
3
- Coveralls.wear!
4
-
5
- require 'link_thumbnailer'
6
- require 'rspec'
7
- require 'webmock/rspec'
8
- require 'json'
9
-
10
- SimpleCov.formatter = Coveralls::SimpleCov::Formatter
11
-
12
- RSpec.configure do |config|
13
- end
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+
5
+ require 'link_thumbnailer'
6
+ require 'rspec'
7
+ require 'webmock/rspec'
8
+ require 'json'
9
+
10
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
11
+
12
+ RSpec.configure do |config|
13
+ end
@@ -1,57 +1,57 @@
1
- require 'spec_helper'
2
-
3
- describe LinkThumbnailer::WebImage do
4
-
5
- class Foo
6
- end
7
-
8
- let(:foo) { Foo.new }
9
-
10
- before do
11
- foo.extend LinkThumbnailer::WebImage
12
- end
13
-
14
- subject { foo }
15
-
16
- it { should respond_to :to_hash }
17
- it { should respond_to :source_url }
18
- it { should respond_to :doc }
19
-
20
- describe ".to_hash" do
21
-
22
- context "with default attributes" do
23
-
24
- let(:attributes) { [:source_url] }
25
-
26
- before do
27
- LinkThumbnailer.config
28
- end
29
-
30
- subject { foo.to_hash }
31
-
32
- it { subject.keys.should eq(attributes.map(&:to_sym)) }
33
-
34
- end
35
-
36
- context "with all attributes" do
37
-
38
- let(:attributes) { LinkThumbnailer.configuration.image_attributes }
39
-
40
- before do
41
- attributes.each {|a| foo.class.send(:define_method, a.to_sym) { 'foo' } }
42
- end
43
-
44
- after do
45
- attributes.each {|a| foo.class.send(:undef_method, a.to_sym) }
46
- end
47
-
48
- subject { foo.to_hash }
49
-
50
- it { subject.keys.should eq(attributes.map(&:to_sym)) }
51
- it { subject.values.should include('foo') }
52
-
53
- end
54
-
55
- end
56
-
57
- end
1
+ require 'spec_helper'
2
+
3
+ describe LinkThumbnailer::WebImage do
4
+
5
+ class Foo
6
+ end
7
+
8
+ let(:foo) { Foo.new }
9
+
10
+ before do
11
+ foo.extend LinkThumbnailer::WebImage
12
+ end
13
+
14
+ subject { foo }
15
+
16
+ it { should respond_to :to_hash }
17
+ it { should respond_to :source_url }
18
+ it { should respond_to :doc }
19
+
20
+ describe ".to_hash" do
21
+
22
+ context "with default attributes" do
23
+
24
+ let(:attributes) { [:source_url] }
25
+
26
+ before do
27
+ LinkThumbnailer.config
28
+ end
29
+
30
+ subject { foo.to_hash }
31
+
32
+ it { subject.keys.should eq(attributes.map(&:to_sym)) }
33
+
34
+ end
35
+
36
+ context "with all attributes" do
37
+
38
+ let(:attributes) { LinkThumbnailer.configuration.image_attributes }
39
+
40
+ before do
41
+ attributes.each {|a| foo.class.send(:define_method, a.to_sym) { 'foo' } }
42
+ end
43
+
44
+ after do
45
+ attributes.each {|a| foo.class.send(:undef_method, a.to_sym) }
46
+ end
47
+
48
+ subject { foo.to_hash }
49
+
50
+ it { subject.keys.should eq(attributes.map(&:to_sym)) }
51
+ it { subject.values.should include('foo') }
52
+
53
+ end
54
+
55
+ end
56
+
57
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: link_thumbnailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre-Louis Gottfrois
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-25 00:00:00.000000000 Z
11
+ date: 2014-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake