shrinker 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4720887620ed4865e0db88f090a986a8c7765986
4
+ data.tar.gz: da07d703c35ec3fbce6e7df05745fae92aa96f7b
5
+ SHA512:
6
+ metadata.gz: 9e6d0cb30cdfb02dff5edc695286942068c124702aabfaa4d63dd7bf03890075e3f5c40955d2ad1e1299c6e1ef2a5bdb33171a5bc0d264d5e0a1185b935671c3
7
+ data.tar.gz: baef8736cc4853e4990f296338f28c1778e48ca3117d8e4ebd081de7ba4a63aacc7a60d3d63bbd7fb422e588cbb0e58e14719a1fa1561121fd1dec51ce3d7b6a
data/.rspec CHANGED
@@ -1,2 +1 @@
1
1
  --color
2
- --debugger
@@ -0,0 +1 @@
1
+ shrinker
@@ -0,0 +1 @@
1
+ 2.1.5
data/Gemfile CHANGED
@@ -4,6 +4,6 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'rspec'
7
- gem 'debugger'
7
+ gem 'byebug'
8
8
  gem 'redis'
9
- gem 'mail'
9
+ gem 'mail'
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
  ```ruby
23
23
  Shrinker.configure do
24
24
  backend 'Redis'
25
- backend_options client: {port: 6388, host: '192.168.12.22'}
25
+ backend_options client: {port: 6388, host: '192.168.12.22'} # or connection: Redis.current
26
26
  expanded_domain /(www.)?google.com/ # this also works with protocol
27
27
  exclude_path /assets|images/
28
28
  anchors\_only\_in_html true # With the mime only replace the links inside an anchor
@@ -37,8 +37,8 @@ Usage on a text:
37
37
  ```ruby
38
38
 
39
39
  text = <<-EV
40
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
41
- Nunc quis rutrum http://www.google.com?something=true&else=false dolor.
40
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
41
+ Nunc quis rutrum http://www.google.com?something=true&else=false dolor.
42
42
  Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
43
43
  Curabitur ullamcorper nisl non dolor http://google.fr?something=true venenatis consequat.
44
44
  Morbi odio libero, tincidunt quis tempus a, fringilla vitae augue.
@@ -49,9 +49,9 @@ EV
49
49
 
50
50
  new_text = Shrinker::Parser::Text.replace(text, {:user_id => 123})
51
51
 
52
- new_text # =>
53
- # Lorem ipsum dolor sit amet, consectetur adipiscing elit.
54
- # Nunc quis rutrum http://go.com/token1 dolor.
52
+ new_text # =>
53
+ # Lorem ipsum dolor sit amet, consectetur adipiscing elit.
54
+ # Nunc quis rutrum http://go.com/token1 dolor.
55
55
  # Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
56
56
  # Curabitur ullamcorper nisl non dolor http://google.fr?something=true venenatis consequat.
57
57
  # Morbi odio libero, tincidunt quis tempus a, fringilla vitae augue.
@@ -6,6 +6,7 @@ module Shrinker
6
6
  def initialize(options = {})
7
7
  super
8
8
  @client_options = options[:client] || {}
9
+ @client = options[:connection]
9
10
  @namespace = options[:namespace] || '_shrinker'
10
11
  end
11
12
 
@@ -36,7 +37,7 @@ module Shrinker
36
37
  @client ||= begin
37
38
  ::Redis.new(@client_options)
38
39
  end
39
- end
40
+ end
40
41
 
41
42
  def delete(token)
42
43
  client.del(key(token))
@@ -53,4 +54,4 @@ module Shrinker
53
54
  end
54
55
  end
55
56
  end
56
- end
57
+ end
@@ -15,12 +15,12 @@ module Shrinker
15
15
 
16
16
  class_eval <<-EV, __FILE__, __LINE__ + 1
17
17
  attr_reader :#{name}
18
-
18
+
19
19
  def #{name}(value = nil)
20
20
  return @#{name} if value.nil?
21
21
  @#{name} = value
22
22
  value
23
- end
23
+ end
24
24
  EV
25
25
  end
26
26
 
@@ -44,15 +44,17 @@ module Shrinker
44
44
 
45
45
  # setting boolean to replace links only in anchor tags href inside html
46
46
  config_setting :anchors_only_in_html
47
-
47
+
48
48
  # how long should url tokens be, default 6
49
49
  config_setting :token_length_target
50
-
50
+
51
51
  # how should it generate new tokens: longer (default), random
52
52
  config_setting :token_length_strategy
53
53
 
54
54
  def ==(config)
55
- self.class.settings.each { |setting| send(setting) == config.send(setting) }
55
+ self.class.settings.each { |setting| return false unless send(setting) == config.send(setting) }
56
+
57
+ true
56
58
  end
57
59
 
58
60
  def reset!
@@ -18,4 +18,4 @@ module Shrinker
18
18
  end
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -3,7 +3,7 @@ module Shrinker
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- PATCH = 1
6
+ PATCH = 2
7
7
  PRE = nil
8
8
 
9
9
  def self.to_s
@@ -18,36 +18,46 @@ describe Shrinker::Backend::Redis do
18
18
  subject { Shrinker::Backend::Redis.new(options) }
19
19
 
20
20
  it "uses the options" do
21
- Redis.should_receive(:new).with(options[:client])
21
+ expect(Redis).to receive(:new).with(options[:client])
22
22
 
23
23
  subject.send(:client)
24
24
  end
25
+
26
+ it "does not instantiate a redis if we pass it " do
27
+ redis_connection = double
28
+
29
+ subject = Shrinker::Backend::Redis.new(options.merge(connection: redis_connection))
30
+
31
+ expect(Redis).to receive(:new).with(options[:client]).never
32
+
33
+ expect(subject.send(:client)).to eql(redis_connection)
34
+ end
25
35
  end
26
36
 
27
37
  context "with a default client setup" do
28
38
  let(:client) { Redis.new }
29
- before { subject.stub(:client) { client} }
39
+ before { allow(subject).to receive(:client) { client} }
30
40
 
31
41
  describe "#store" do
32
42
  it "stores the raw_url with the token key" do
33
- Shrinker::Serializer.should_receive(:to_json).with('someurl', {}).and_return("tobestored")
43
+ expect(Shrinker::Serializer).to receive(:to_json).with('someurl', {}).and_return("tobestored")
34
44
 
35
45
  subject.store('someurl', 'token')
36
46
 
37
- client.get("_shrinker::token").should == 'tobestored'
47
+ expect(client.get("_shrinker::token")).to eql 'tobestored'
38
48
  end
39
49
 
40
50
  it "stores the raw_url with the attributes" do
41
- Shrinker::Serializer.should_receive(:to_json).with('someurl', {:user_id => 123}).and_return("tobestored")
51
+ expect(Shrinker::Serializer).to receive(:to_json).with('someurl', {:user_id => 123}).and_return("tobestored")
42
52
 
43
53
  subject.store('someurl', 'token', :user_id => 123)
44
- client.get("_shrinker::token").should == 'tobestored'
54
+ expect(client.get("_shrinker::token")).to eql 'tobestored'
45
55
  end
46
56
 
47
57
  it "sets the ttl when present" do
48
- Shrinker::Serializer.should_receive(:to_json).with('someurl', {}).and_return("tobestored")
49
- subject.stub(:ttl) { 32 }
50
- client.should_receive(:setex).with("_shrinker::token", 32, "tobestored")
58
+ expect(Shrinker::Serializer).to receive(:to_json).with('someurl', {}).and_return("tobestored")
59
+ allow(subject).to receive(:ttl) { 32 }
60
+ expect(client).to receive(:setex).with("_shrinker::token", 32, "tobestored")
51
61
 
52
62
  subject.store('someurl', 'token')
53
63
  end
@@ -56,7 +66,7 @@ describe Shrinker::Backend::Redis do
56
66
  describe "#fetch" do
57
67
  it "fetches using the token key" do
58
68
  client.set("_shrinker::token", '{"url": "someurl", "attributes": {}}')
59
- subject.fetch("token").should == {'url' => "someurl", 'attributes' => {}}
69
+ expect(subject.fetch("token")).to eql({'url' => "someurl", 'attributes' => {}})
60
70
  end
61
71
  end
62
72
 
@@ -66,12 +76,12 @@ describe Shrinker::Backend::Redis do
66
76
  it "returns true when the token is used" do
67
77
  client.set("_shrinker::token", '{"url": "someurl", "attributes": {}}')
68
78
 
69
- subject.used_token?('token').should be_true
79
+ expect(subject.used_token?('token')).to eql(true)
70
80
  end
71
81
 
72
82
  it "returns false" do
73
- subject.used_token?('token').should be_false
83
+ expect(subject.used_token?('token')).to eql(false)
74
84
  end
75
85
  end
76
86
  end
77
- end
87
+ end
@@ -21,16 +21,16 @@ describe Shrinker::Config do
21
21
  end
22
22
 
23
23
  it 'should return the config object for manipulation' do
24
- config.is_a?(Shrinker::Config).should be_true
25
- Shrinker.configure.is_a?(Shrinker::Config).should be_true
24
+ expect(config.is_a?(Shrinker::Config)).to eql(true)
25
+ expect(Shrinker.configure.is_a?(Shrinker::Config)).to eql(true)
26
26
  end
27
27
 
28
28
  it 'should yield to the config if a block is present' do
29
- lambda{
29
+ expect {
30
30
  Shrinker.configure do
31
31
  raise self.class.name
32
32
  end
33
- }.should raise_error('Shrinker::Config')
33
+ }.to raise_error('Shrinker::Config')
34
34
  end
35
35
 
36
36
  it 'allows passing the backend' do
@@ -39,14 +39,14 @@ describe Shrinker::Config do
39
39
  backend_options({:key => 'value'})
40
40
  end
41
41
 
42
- Shrinker::Backend::FakeBackend.should_receive(:new).with({:key => 'value'})
42
+ allow(Shrinker::Backend::FakeBackend).to receive(:new).with({:key => 'value'})
43
43
  Shrinker.send(:backend)
44
44
  end
45
45
 
46
46
  describe "#merge!" do
47
47
  it "merges a hash" do
48
48
  config.merge!(backend_options: {something: true})
49
- config.backend_options.should == {something: true}
49
+ expect(config.backend_options).to eql({something: true})
50
50
  end
51
51
 
52
52
  it "merges an instance of Config" do
@@ -59,8 +59,8 @@ describe Shrinker::Config do
59
59
  expanded_pattern 'second_pattern'
60
60
  end
61
61
  config.merge!(other_config)
62
- config.expanded_pattern.should == 'second_pattern'
63
- config.shrinked_pattern.should == 'shrinked_pattern'
62
+ expect(config.expanded_pattern).to eql('second_pattern')
63
+ expect(config.shrinked_pattern).to eql('shrinked_pattern')
64
64
  end
65
65
  end
66
- end
66
+ end
@@ -3,24 +3,24 @@ require 'spec_helper'
3
3
  describe Shrinker::EasyUrl do
4
4
  describe "#to_s" do
5
5
  it "returns itself with no params" do
6
- Shrinker::EasyUrl.new("test").to_s.should == 'test'
6
+ expect(Shrinker::EasyUrl.new("test").to_s).to eql('test')
7
7
  end
8
8
 
9
9
  it "returns itself with params" do
10
- Shrinker::EasyUrl.new("test?something=2").to_s.should == 'test?something=2'
10
+ expect(Shrinker::EasyUrl.new("test?something=2").to_s).to eql('test?something=2')
11
11
  end
12
12
 
13
13
  it "returns itself without the params when deleting it" do
14
14
  easy_url = Shrinker::EasyUrl.new("test?something=2")
15
15
  easy_url.params.delete(:something)
16
- easy_url.to_s.should == 'test'
16
+ expect(easy_url.to_s).to eql('test')
17
17
  end
18
18
 
19
19
  it "keeps the other params when deleting some" do
20
20
  easy_url = Shrinker::EasyUrl.new("test?something=2&else=3")
21
21
  easy_url.params.delete(:something)
22
- easy_url.params[:else].should == '3'
23
- easy_url.to_s.should == 'test?else=3'
22
+ expect(easy_url.params[:else]).to eql('3')
23
+ expect(easy_url.to_s).to eql('test?else=3')
24
24
  end
25
25
  end
26
- end
26
+ end
@@ -17,9 +17,9 @@ describe Shrinker::Extractor do
17
17
 
18
18
  it "returns an EasyUrl instance" do
19
19
  easy_url = Shrinker::Extractor.unshrink("token", config)
20
- easy_url.should be_instance_of(Shrinker::EasyUrl)
21
- easy_url.to_s.should == "someurl"
22
- easy_url.attributes.should == {"test" => 'ab'}
20
+ expect(easy_url).to be_instance_of(Shrinker::EasyUrl)
21
+ expect(easy_url.to_s).to eql("someurl")
22
+ expect(easy_url.attributes).to eql({"test" => 'ab'})
23
23
  end
24
24
 
25
25
  it "raise UrlNotFound when not existing" do
@@ -31,7 +31,7 @@ describe Shrinker::Extractor do
31
31
 
32
32
  describe "#config" do
33
33
  it "returns the default config by default" do
34
- Shrinker::Extractor.new.send(:config).should == Shrinker.config
34
+ expect(Shrinker::Extractor.new.send(:config)).to eql Shrinker.config
35
35
  end
36
36
  end
37
- end
37
+ end
@@ -13,7 +13,7 @@ describe Shrinker::Parser::Mime do
13
13
 
14
14
  Plain text message goes in this part. Notice that it
15
15
  has a blank line before it starts, meaning that this
16
- part has no additional headers.
16
+ part has no additional headers.
17
17
  Here is a link to http://my-example.com/test?params=1
18
18
 
19
19
  --theBoundaryString
@@ -22,7 +22,7 @@ describe Shrinker::Parser::Mime do
22
22
  Content-Disposition: inline
23
23
  Content-Base: "http://somewebsite.com/"
24
24
 
25
- <body><font size=4>This</font> is a
25
+ <body><font size=4>This</font> is a
26
26
  <i>test</i>.
27
27
  --theBoundaryString--
28
28
  MYMIME
@@ -39,11 +39,11 @@ describe Shrinker::Parser::Mime do
39
39
  end
40
40
 
41
41
  it "replace the content in the mime" do
42
- Shrinker::Parser::Url.should_receive(:replace).with('my-example.com/test?params=1', {}, config).and_return("replace1")
43
- Shrinker::Parser::Url.should_receive(:replace).with('somewebsite.com', {}, config).never
42
+ expect(Shrinker::Parser::Url).to receive(:replace).with('my-example.com/test?params=1', {}, config).and_return("replace1")
43
+ expect(Shrinker::Parser::Url).to receive(:replace).with('somewebsite.com', {}, config).never
44
44
 
45
45
  replaced_mime = Shrinker::Parser::Mime::replace(mime, {}, config)
46
- replaced_mime.should include("Here is a link to http://replace1")
46
+ expect(replaced_mime).to include("Here is a link to http://replace1")
47
47
  end
48
48
 
49
49
  context "when mime is multipart" do
@@ -51,22 +51,23 @@ describe Shrinker::Parser::Mime do
51
51
 
52
52
  it "replace only anchor tags when setting anchors_only_in_html to true" do
53
53
  config.anchors_only_in_html true
54
+ config.around_pattern /href="(?:https?:\/\/)?($url)"/
54
55
 
55
- Shrinker::Parser::Url.should_receive(:replace).with("my-example.com/a?something=true", {}, instance_of(Shrinker::Config)).and_return('replace1')
56
- Shrinker::Parser::Url.should_receive(:replace).with("www.my-example.com/donec-lobortis-lacus-vel-urna-variuo--4?clicked=abcdef", {}, instance_of(Shrinker::Config)).and_return('replace2')
57
- Shrinker::Parser::Url.should_receive(:replace).with('www.my-example.com/class-aptent-taciti-sociosqu-ad-litader.jpg', {}, instance_of(Shrinker::Config)).never
58
- Shrinker::Parser::Url.should_receive(:replace).with('www.my-example.com/safe', {}, instance_of(Shrinker::Config)).never
59
- Shrinker::Parser::Url.should_receive(:replace).with('my-example.com/none', {}, instance_of(Shrinker::Config)).never
56
+ expect(Shrinker::Parser::Url).to receive(:replace).with("my-example.com/a?something=true", {}, config).and_return('replace1')
57
+ expect(Shrinker::Parser::Url).to receive(:replace).with("www.my-example.com/donec-lobortis-lacus-vel-urna-variuo--4?clicked=abcdef", {}, config).and_return('replace2')
58
+ expect(Shrinker::Parser::Url).to receive(:replace).with('www.my-example.com/class-aptent-taciti-sociosqu-ad-litader.jpg', {}, config).never
59
+ expect(Shrinker::Parser::Url).to receive(:replace).with('www.my-example.com/safe', {}, config).never
60
+ expect(Shrinker::Parser::Url).to receive(:replace).with('my-example.com/none', {}, config).never
60
61
 
61
62
  replaced_mime = Shrinker::Parser::Mime::replace(mime, {}, config)
62
63
  end
63
64
 
64
65
  it "replace every urls when not setting anchors_only_in_html" do
65
- Shrinker::Parser::Url.should_receive(:replace).with("my-example.com/a?something=true", {}, instance_of(Shrinker::Config)).and_return('replace1')
66
- Shrinker::Parser::Url.should_receive(:replace).with("www.my-example.com/donec-lobortis-lacus-vel-urna-variuo--4?clicked=abcdef", {}, instance_of(Shrinker::Config)).and_return('replace2')
67
- Shrinker::Parser::Url.should_receive(:replace).with('www.my-example.com/class-aptent-taciti-sociosqu-ad-litader.jpg', {}, instance_of(Shrinker::Config)).and_return('replace3')
68
- Shrinker::Parser::Url.should_receive(:replace).with('www.my-example.com/safe', {}, instance_of(Shrinker::Config)).and_return('replace4')
69
- Shrinker::Parser::Url.should_receive(:replace).with('my-example.com/none', {}, instance_of(Shrinker::Config)).and_return('replace5')
66
+ expect(Shrinker::Parser::Url).to receive(:replace).with("my-example.com/a?something=true", {}, config).and_return('replace1')
67
+ expect(Shrinker::Parser::Url).to receive(:replace).with("www.my-example.com/donec-lobortis-lacus-vel-urna-variuo--4?clicked=abcdef", {}, config).and_return('replace2')
68
+ expect(Shrinker::Parser::Url).to receive(:replace).with('www.my-example.com/class-aptent-taciti-sociosqu-ad-litader.jpg', {}, config).and_return('replace3')
69
+ expect(Shrinker::Parser::Url).to receive(:replace).with('www.my-example.com/safe', {}, config).and_return('replace4')
70
+ expect(Shrinker::Parser::Url).to receive(:replace).with('my-example.com/none', {}, config).and_return('replace5')
70
71
 
71
72
  replaced_mime = Shrinker::Parser::Mime::replace(mime, {}, config)
72
73
  end
@@ -90,25 +91,28 @@ describe Shrinker::Parser::Mime do
90
91
  it "replace only anchor tags when setting anchors_only_in_html to true" do
91
92
  config.anchors_only_in_html true
92
93
 
93
- Shrinker::Parser::Url.should_receive(:replace).with("www.somwebsite.com/glencoe-il/t/office-help--0000", {}, instance_of(Shrinker::Config)).and_return('replace1')
94
- Shrinker::Parser::Url.should_receive(:replace).with("www.somwebsite.com/notifications", {}, instance_of(Shrinker::Config)).and_return('replace2')
95
- Shrinker::Parser::Url.should_receive(:replace).with("www.somwebsite.com/go/defdbf1191f17112776a6adb4c201b277af845278971e81b532089d1b96926300347343b15580afba7a7cc41567b9608161d", {}, instance_of(Shrinker::Config)).and_return('replace3')
96
- Shrinker::Parser::Url.should_receive(:replace).with("www.somwebsite.com/go/5f25b2b15ec6b450c3c5af71102616e07413381a718f1b5d21e7ff9e26d6fc216e9c05ab2b8a40195a16c8603be5860170eb", {}, instance_of(Shrinker::Config)).and_return('replace4')
97
- Shrinker::Parser::Url.should_receive(:replace).with('www.somwebsite.com/core/assets/email/somwebsite-sky-header.jpg', {}, instance_of(Shrinker::Config)).never
94
+ config_for_html = config.dup
95
+ config_for_html.around_pattern /href="(?:https?:\/\/)?($url)"/
96
+
97
+ expect(Shrinker::Parser::Url).to receive(:replace).with("www.somwebsite.com/glencoe-il/t/office-help--0000", {}, config).and_return('replace1')
98
+ expect(Shrinker::Parser::Url).to receive(:replace).with("www.somwebsite.com/notifications", {}, config).and_return('replace2')
99
+ expect(Shrinker::Parser::Url).to receive(:replace).with("www.somwebsite.com/go/defdbf1191f17112776a6adb4c201b277af845278971e81b532089d1b96926300347343b15580afba7a7cc41567b9608161d", {}, config_for_html).and_return('replace3')
100
+ expect(Shrinker::Parser::Url).to receive(:replace).with("www.somwebsite.com/go/5f25b2b15ec6b450c3c5af71102616e07413381a718f1b5d21e7ff9e26d6fc216e9c05ab2b8a40195a16c8603be5860170eb", {}, config_for_html).and_return('replace4')
101
+ expect(Shrinker::Parser::Url).to receive(:replace).with('www.somwebsite.com/core/assets/email/somwebsite-sky-header.jpg', {}, config_for_html).never
98
102
 
99
103
  replaced_mime = Shrinker::Parser::Mime::replace(multipart_mime, {}, config)
100
104
  end
101
105
 
102
106
  it "replace every urls when not setting anchors_only_in_html" do
103
- Shrinker::Parser::Url.should_receive(:replace).with("www.somwebsite.com/glencoe-il/t/office-help--0000", {}, instance_of(Shrinker::Config)).and_return('replace1')
104
- Shrinker::Parser::Url.should_receive(:replace).with("www.somwebsite.com/notifications", {}, instance_of(Shrinker::Config)).and_return('replace2')
105
- Shrinker::Parser::Url.should_receive(:replace).with("www.somwebsite.com/go/defdbf1191f17112776a6adb4c201b277af845278971e81b532089d1b96926300347343b15580afba7a7cc41567b9608161d", {}, instance_of(Shrinker::Config)).and_return('replace3')
106
- Shrinker::Parser::Url.should_receive(:replace).with("www.somwebsite.com/go/5f25b2b15ec6b450c3c5af71102616e07413381a718f1b5d21e7ff9e26d6fc216e9c05ab2b8a40195a16c8603be5860170eb", {}, instance_of(Shrinker::Config)).and_return('replace4')
107
- Shrinker::Parser::Url.should_receive(:replace).with('www.somwebsite.com/core/assets/email/somwebsite-sky-header.jpg', {}, instance_of(Shrinker::Config)).never
107
+ expect(Shrinker::Parser::Url).to receive(:replace).with("www.somwebsite.com/glencoe-il/t/office-help--0000", {}, config).and_return('replace1')
108
+ expect(Shrinker::Parser::Url).to receive(:replace).with("www.somwebsite.com/notifications", {}, config).and_return('replace2')
109
+ expect(Shrinker::Parser::Url).to receive(:replace).with("www.somwebsite.com/go/defdbf1191f17112776a6adb4c201b277af845278971e81b532089d1b96926300347343b15580afba7a7cc41567b9608161d", {}, config).and_return('replace3')
110
+ expect(Shrinker::Parser::Url).to receive(:replace).with("www.somwebsite.com/go/5f25b2b15ec6b450c3c5af71102616e07413381a718f1b5d21e7ff9e26d6fc216e9c05ab2b8a40195a16c8603be5860170eb", {}, config).and_return('replace4')
111
+ expect(Shrinker::Parser::Url).to receive(:replace).with('www.somwebsite.com/core/assets/email/somwebsite-sky-header.jpg', {}, config).never
108
112
 
109
113
  replaced_mime = Shrinker::Parser::Mime::replace(multipart_mime, {}, config)
110
114
  end
111
115
 
112
116
  end
113
117
 
114
- end
118
+ end
@@ -16,8 +16,8 @@ describe Shrinker::Parser::Text do
16
16
 
17
17
  it "replaces proper occurences" do
18
18
  content = <<-EV
19
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
20
- Nunc quis rutrum <a href="http://www.google.com?something=true&else=false">dolor</a>.
19
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
20
+ Nunc quis rutrum <a href="http://www.google.com?something=true&else=false">dolor</a>.
21
21
  <a href="www.google.com?params=abcdef" style="text-align:center;">http://google.com/safe</a>
22
22
  Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
23
23
  Curabitur ullamcorper nisl non dolor <a href="http://google.fr?something=true">venenatis</a> consequat.
@@ -26,17 +26,17 @@ describe Shrinker::Parser::Text do
26
26
  Aenean placerat ullamcorper lorem vel feugiat.
27
27
  EV
28
28
 
29
- Shrinker::Parser::Url.should_receive(:replace).with('www.google.com?something=true&else=false', {}, config).and_return("replace1")
30
- Shrinker::Parser::Url.should_receive(:replace).with('www.google.com?params=abcdef', {}, config).and_return("replace2")
31
- Shrinker::Parser::Url.should_receive(:replace).with('google.com/safe', {}, config).never
32
- Shrinker::Parser::Url.should_receive(:replace).with('google.fr?something=true', {}, config).never
33
- Shrinker::Parser::Url.should_receive(:replace).with('google.com/somepath?something=true', {}, config).and_return("replace3")
29
+ allow(Shrinker::Parser::Url).to receive(:replace).with('www.google.com?something=true&else=false', {}, config).and_return("replace1")
30
+ allow(Shrinker::Parser::Url).to receive(:replace).with('www.google.com?params=abcdef', {}, config).and_return("replace2")
31
+ allow(Shrinker::Parser::Url).to receive(:replace).with('google.com/safe', {}, config).never
32
+ allow(Shrinker::Parser::Url).to receive(:replace).with('google.fr?something=true', {}, config).never
33
+ allow(Shrinker::Parser::Url).to receive(:replace).with('google.com/somepath?something=true', {}, config).and_return("replace3")
34
34
 
35
35
  replaced_text = Shrinker::Parser::Text::replace(content, {}, config)
36
36
 
37
37
  expected_replaced_text = <<-EV
38
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
39
- Nunc quis rutrum <a href="http://replace1">dolor</a>.
38
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
39
+ Nunc quis rutrum <a href="http://replace1">dolor</a>.
40
40
  <a href="replace2" style="text-align:center;">http://google.com/safe</a>
41
41
  Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
42
42
  Curabitur ullamcorper nisl non dolor <a href="http://google.fr?something=true">venenatis</a> consequat.
@@ -45,18 +45,18 @@ describe Shrinker::Parser::Text do
45
45
  Aenean placerat ullamcorper lorem vel feugiat.
46
46
  EV
47
47
 
48
- replaced_text.should == expected_replaced_text
48
+ expect(replaced_text).to eql(expected_replaced_text)
49
49
  end
50
50
 
51
51
  it "does not do anything when there is no occurence" do
52
52
  content = <<-EV
53
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
53
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
54
54
  Curabitur ullamcorper nisl non dolor http://google.fr?something=true venenatis consequat.
55
55
  Aenean placerat ullamcorper lorem vel feugiat.
56
56
  EV
57
57
 
58
58
  replaced_text = Shrinker::Parser::Text::replace(content, {}, config)
59
- replaced_text.should == content
59
+ expect(replaced_text).to eql(content)
60
60
  end
61
61
  end
62
62
 
@@ -72,8 +72,8 @@ describe Shrinker::Parser::Text do
72
72
 
73
73
  it "replaces proper occurences" do
74
74
  content = <<-EV
75
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
76
- Nunc quis rutrum http://www.google.com?something=true&else=false dolor.
75
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
76
+ Nunc quis rutrum http://www.google.com?something=true&else=false dolor.
77
77
  Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
78
78
  Curabitur ullamcorper nisl non dolor http://google.fr?something=true venenatis consequat.
79
79
  Morbi odio libero, tincidunt quis tempus a, fringilla vitae augue.
@@ -81,15 +81,15 @@ describe Shrinker::Parser::Text do
81
81
  Aenean placerat ullamcorper lorem vel feugiat.
82
82
  EV
83
83
 
84
- Shrinker::Parser::Url.should_receive(:replace).with('http://www.google.com?something=true&else=false', {}, config).and_return("https://replace1")
85
- Shrinker::Parser::Url.should_receive(:replace).with('google.fr?something=true', {}, config).never
86
- Shrinker::Parser::Url.should_receive(:replace).with('http://google.com/somepath?something=true', {}, config).never
84
+ allow(Shrinker::Parser::Url).to receive(:replace).with('http://www.google.com?something=true&else=false', {}, config).and_return("https://replace1")
85
+ allow(Shrinker::Parser::Url).to receive(:replace).with('google.fr?something=true', {}, config).never
86
+ allow(Shrinker::Parser::Url).to receive(:replace).with('http://google.com/somepath?something=true', {}, config).never
87
87
 
88
88
  replaced_text = Shrinker::Parser::Text::replace(content, {}, config)
89
89
 
90
90
  expected_replaced_text = <<-EV
91
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
92
- Nunc quis rutrum https://replace1 dolor.
91
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
92
+ Nunc quis rutrum https://replace1 dolor.
93
93
  Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
94
94
  Curabitur ullamcorper nisl non dolor http://google.fr?something=true venenatis consequat.
95
95
  Morbi odio libero, tincidunt quis tempus a, fringilla vitae augue.
@@ -97,14 +97,14 @@ describe Shrinker::Parser::Text do
97
97
  Aenean placerat ullamcorper lorem vel feugiat.
98
98
  EV
99
99
 
100
- replaced_text.should == expected_replaced_text
100
+ expect(replaced_text).to eql(expected_replaced_text)
101
101
  end
102
102
  end
103
103
  end
104
104
 
105
105
  describe "#config" do
106
106
  it "returns the default config by default" do
107
- Shrinker::Parser::Text.new.send(:config).should == Shrinker.config
107
+ expect(Shrinker::Parser::Text.new.send(:config) == Shrinker.config).to eql(true)
108
108
  end
109
109
  end
110
- end
110
+ end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Shrinker::Parser::Url do
4
4
  describe "#replace" do
5
- before { Shrinker::Token.stub(:fetch_unique_token).and_return("thetoken") }
5
+ before { allow(Shrinker::Token).to receive(:fetch_unique_token).and_return("thetoken") }
6
6
 
7
7
  context "without protocol" do
8
8
  let(:config) do
@@ -17,38 +17,38 @@ describe Shrinker::Parser::Url do
17
17
  end
18
18
 
19
19
  it "replace the link" do
20
- Shrinker::Parser::Url::replace("www.google.com?something=else", {:user_id => 10}, config).should == "goo.ln/thetoken"
20
+ expect(Shrinker::Parser::Url::replace("www.google.com?something=else", {:user_id => 10}, config)).to eql("goo.ln/thetoken")
21
21
  end
22
22
 
23
23
  it "store the old link" do
24
- Shrinker::Backend::Redis.any_instance.should_receive(:store).with("www.google.com?something=else", 'thetoken', {:user_id => 10})
24
+ expect_any_instance_of(Shrinker::Backend::Redis).to receive(:store).with("www.google.com?something=else", 'thetoken', {:user_id => 10})
25
25
 
26
26
  Shrinker::Parser::Url::replace("www.google.com?something=else", {:user_id => 10}, config)
27
27
  end
28
28
 
29
29
  describe "does not do anything" do
30
30
  before do
31
- Shrinker::Backend::Redis.any_instance.should_receive(:store).never
31
+ expect_any_instance_of(Shrinker::Backend::Redis).to receive(:store).never
32
32
  end
33
33
 
34
34
  it "returns the text if it does not match an url" do
35
- Shrinker::Parser::Url::replace("sometext", {}, config).should == "sometext"
35
+ expect(Shrinker::Parser::Url::replace("sometext", {}, config)).to eql("sometext")
36
36
  end
37
37
 
38
38
  it "returns the text if it does not match the domain" do
39
- Shrinker::Parser::Url::replace("www.google.fr", {}, config).should == "www.google.fr"
39
+ expect(Shrinker::Parser::Url::replace("www.google.fr", {}, config)).to eql("www.google.fr")
40
40
  end
41
41
 
42
42
  it "does not replace the link if there is a shrinker=false" do
43
- Shrinker::Parser::Url::replace("www.google.com?shrinker=false&something=else", {}, config).should == "www.google.com?something=else"
43
+ expect(Shrinker::Parser::Url::replace("www.google.com?shrinker=false&something=else", {}, config)).to eql("www.google.com?something=else")
44
44
  end
45
45
 
46
46
  it "does not replace the link if its excluded" do
47
- Shrinker::Parser::Url::replace("www.google.com/assets/logo.png?something=else", {}, config).should == "www.google.com/assets/logo.png?something=else"
47
+ expect(Shrinker::Parser::Url::replace("www.google.com/assets/logo.png?something=else", {}, config)).to eql("www.google.com/assets/logo.png?something=else")
48
48
  end
49
49
  end
50
50
  end
51
-
51
+
52
52
  context "with full url dynamic pattern" do
53
53
  let(:config) do
54
54
  config = Shrinker::Config.new
@@ -61,16 +61,16 @@ describe Shrinker::Parser::Url do
61
61
  end
62
62
 
63
63
  it "replace the link" do
64
- Shrinker::Parser::Url::replace("www.google.com?something=else", {:user_id => 10}, config).should == "www.google.com/x/thetoken"
64
+ expect(Shrinker::Parser::Url::replace("www.google.com?something=else", {:user_id => 10}, config)).to eql("www.google.com/x/thetoken")
65
65
  end
66
66
 
67
67
  it "store the old link" do
68
- Shrinker::Backend::Redis.any_instance.should_receive(:store).with("www.google.com?something=else", 'thetoken', {:user_id => 10})
68
+ allow_any_instance_of(Shrinker::Backend::Redis).to receive(:store).with("www.google.com?something=else", 'thetoken', {:user_id => 10})
69
69
 
70
70
  Shrinker::Parser::Url::replace("www.google.com?something=else", {:user_id => 10}, config)
71
71
  end
72
72
  end
73
-
73
+
74
74
  context "with partial url dynamic pattern" do
75
75
  let(:config) do
76
76
  config = Shrinker::Config.new
@@ -83,11 +83,11 @@ describe Shrinker::Parser::Url do
83
83
  end
84
84
 
85
85
  it "replace the link" do
86
- Shrinker::Parser::Url::replace("xyz.google.com?something=else", {:user_id => 10}, config).should == "xyz.other.com/thetoken"
86
+ expect(Shrinker::Parser::Url::replace("xyz.google.com?something=else", {:user_id => 10}, config)).to eql("xyz.other.com/thetoken")
87
87
  end
88
88
 
89
89
  it "store the old link" do
90
- Shrinker::Backend::Redis.any_instance.should_receive(:store).with("www.google.com?something=else", 'thetoken', {:user_id => 10})
90
+ allow_any_instance_of(Shrinker::Backend::Redis).to receive(:store).with("www.google.com?something=else", 'thetoken', {:user_id => 10})
91
91
 
92
92
  Shrinker::Parser::Url::replace("www.google.com?something=else", {:user_id => 10}, config)
93
93
  end
@@ -105,14 +105,14 @@ describe Shrinker::Parser::Url do
105
105
  end
106
106
 
107
107
  it "replace the link" do
108
- Shrinker::Parser::Url::replace("http://www.google.com?something=else", {:user_id => 10}, config).should == "https://goo.ln/thetoken"
108
+ expect(Shrinker::Parser::Url::replace("http://www.google.com?something=else", {:user_id => 10}, config)).to eql("https://goo.ln/thetoken")
109
109
  end
110
110
 
111
111
  it "store the old link" do
112
- Shrinker::Backend::Redis.any_instance.should_receive(:store).with("http://www.google.com?something=else", 'thetoken', {:user_id => 10})
112
+ allow_any_instance_of(Shrinker::Backend::Redis).to receive(:store).with("http://www.google.com?something=else", 'thetoken', {:user_id => 10})
113
113
 
114
114
  Shrinker::Parser::Url::replace("http://www.google.com?something=else", {:user_id => 10}, config)
115
115
  end
116
116
  end
117
117
  end
118
- end
118
+ end
@@ -3,21 +3,21 @@ require 'spec_helper'
3
3
  describe Shrinker::Serializer do
4
4
  describe "#hash" do
5
5
  it "returns a hash containing the url" do
6
- Shrinker::Serializer::to_hash('someurl').should == {:url => 'someurl', :attributes => {}}
6
+ expect(Shrinker::Serializer::to_hash('someurl')).to eql({:url => 'someurl', :attributes => {}})
7
7
  end
8
8
 
9
9
  it "returns a hash containing the attributes" do
10
- Shrinker::Serializer::to_hash('someurl', {:user_id => 12}).should == {:url => 'someurl', :attributes => {:user_id => 12}}
10
+ expect(Shrinker::Serializer::to_hash('someurl', {:user_id => 12})).to eql({:url => 'someurl', :attributes => {:user_id => 12}})
11
11
  end
12
12
  end
13
13
 
14
14
  describe "#json" do
15
15
  it "returns a json containing the url" do
16
- Shrinker::Serializer::to_json('someurl').should == {:url => 'someurl', :attributes => {}}.to_json
16
+ expect(Shrinker::Serializer::to_json('someurl')).to eql({:url => 'someurl', :attributes => {}}.to_json)
17
17
  end
18
18
 
19
19
  it "returns a json containing the attributes" do
20
- Shrinker::Serializer::to_json('someurl', {:user_id => 12}).should == {:url => 'someurl', :attributes => {:user_id => 12}}.to_json
20
+ expect(Shrinker::Serializer::to_json('someurl', {:user_id => 12})).to eql({:url => 'someurl', :attributes => {:user_id => 12}}.to_json)
21
21
  end
22
22
  end
23
- end
23
+ end
@@ -3,9 +3,9 @@ require 'spec_helper'
3
3
  describe Shrinker do
4
4
  describe ".unshrink" do
5
5
  it "delegates the method to the Extractor" do
6
- Shrinker::Extractor.should_receive(:unshrink).with('token', Shrinker.config)
6
+ allow(Shrinker::Extractor).to receive(:unshrink).with('token', Shrinker.config)
7
7
 
8
8
  Shrinker.unshrink('token')
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -4,55 +4,55 @@ describe Shrinker::Token do
4
4
  describe "#generate" do
5
5
  before do
6
6
  Shrinker.config.reset!
7
- Shrinker::Token.stub(:rand).and_return('random')
7
+ allow(Shrinker::Token).to receive(:rand).and_return('random')
8
8
  end
9
9
 
10
10
  after do
11
11
  Shrinker.config.reset!
12
12
  end
13
-
14
- it "should use the length config setting" do
13
+
14
+ it "should use the length config setting" do
15
15
  Shrinker.configure do
16
16
  token_length_target 4
17
17
  end
18
-
19
- Digest::MD5.should_receive(:hexdigest).with("something").and_return("abcdefghijklmnopqrstuvwxyz")
20
- Shrinker::Token.generate(0, prefix: 'something').should == "wxyz"
18
+
19
+ allow(Digest::MD5).to receive(:hexdigest).with("something").and_return("abcdefghijklmnopqrstuvwxyz")
20
+ expect(Shrinker::Token.generate(0, prefix: 'something')).to eql("wxyz")
21
21
  end
22
-
22
+
23
23
  it "should use longer than defualt if that is the strategy (default)" do
24
24
  Shrinker.configure do
25
25
  token_length_target 4
26
26
  end
27
-
28
- Digest::MD5.should_receive(:hexdigest).with("something").and_return("abcdefghijklmnopqrstuvwxyz")
29
- Shrinker::Token.generate(1, prefix: 'something').should == "vwxyz"
27
+
28
+ allow(Digest::MD5).to receive(:hexdigest).with("something").and_return("abcdefghijklmnopqrstuvwxyz")
29
+ expect(Shrinker::Token.generate(1, prefix: 'something')).to eql("vwxyz")
30
30
  end
31
-
31
+
32
32
  it "should default to 6 length" do
33
- Digest::MD5.should_receive(:hexdigest).with("something").and_return("abcdefghijklmnopqrstuvwxyz")
33
+ allow(Digest::MD5).to receive(:hexdigest).with("something").and_return("abcdefghijklmnopqrstuvwxyz")
34
34
 
35
- Shrinker::Token.generate(0, prefix: 'something').should == "uvwxyz"
35
+ expect(Shrinker::Token.generate(0, prefix: 'something')).to eql("uvwxyz")
36
36
  end
37
-
37
+
38
38
  it "should use the random strategy if asked" do
39
39
  Shrinker.configure do
40
40
  token_length_strategy :random
41
41
  token_length_target 6
42
42
  end
43
-
44
- Digest::MD5.should_receive(:hexdigest).with("something__random").and_return("abcdefghijklmnopqrstuvwxyz")
45
- Shrinker::Token.generate(0, prefix: 'something').should == "uvwxyz"
43
+
44
+ allow(Digest::MD5).to receive(:hexdigest).with("something__random").and_return("abcdefghijklmnopqrstuvwxyz")
45
+ expect(Shrinker::Token.generate(0, prefix: 'something')).to eql("uvwxyz")
46
46
  end
47
-
47
+
48
48
  it "should not get longer if strategy random" do
49
49
  Shrinker.configure do
50
50
  token_length_strategy :random
51
51
  token_length_target 6
52
52
  end
53
-
54
- Digest::MD5.should_receive(:hexdigest).with("something__random").and_return("abcdefghijklmnopqrstuvwxyz")
55
- Shrinker::Token.generate(1, prefix: 'something').should == "uvwxyz"
53
+
54
+ allow(Digest::MD5).to receive(:hexdigest).with("something__random").and_return("abcdefghijklmnopqrstuvwxyz")
55
+ expect(Shrinker::Token.generate(1, prefix: 'something')).to eql("uvwxyz")
56
56
  end
57
57
  end
58
58
 
@@ -60,11 +60,11 @@ describe Shrinker::Token do
60
60
  let(:backend) { double }
61
61
 
62
62
  it "returns an unique token" do
63
- backend.stub(:used_token?).and_return(true, false)
63
+ allow(backend).to receive(:used_token?).and_return(true, false)
64
64
 
65
- Shrinker::Token.should_receive(:generate).twice.and_return('abcdef')
65
+ allow(Shrinker::Token).to receive(:generate).twice.and_return('abcdef')
66
66
 
67
- Shrinker::Token.fetch_unique_token(backend).should == 'abcdef'
67
+ expect(Shrinker::Token.fetch_unique_token(backend)).to eql('abcdef')
68
68
  end
69
69
  end
70
- end
70
+ end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrinker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - jrichardlai
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-26 00:00:00.000000000 Z
11
+ date: 2014-12-27 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: json
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  description: Find links in a text and shorten them
@@ -34,9 +31,10 @@ executables: []
34
31
  extensions: []
35
32
  extra_rdoc_files: []
36
33
  files:
37
- - .gitignore
38
- - .rspec
39
- - .rvmrc
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".ruby-gemset"
37
+ - ".ruby-version"
40
38
  - Gemfile
41
39
  - LICENSE.txt
42
40
  - README.md
@@ -70,27 +68,26 @@ files:
70
68
  - spec/support/fixtures/multipart_mime.txt
71
69
  homepage: ''
72
70
  licenses: []
71
+ metadata: {}
73
72
  post_install_message:
74
73
  rdoc_options: []
75
74
  require_paths:
76
75
  - lib
77
76
  required_ruby_version: !ruby/object:Gem::Requirement
78
- none: false
79
77
  requirements:
80
- - - ! '>='
78
+ - - ">="
81
79
  - !ruby/object:Gem::Version
82
80
  version: '0'
83
81
  required_rubygems_version: !ruby/object:Gem::Requirement
84
- none: false
85
82
  requirements:
86
- - - ! '>='
83
+ - - ">="
87
84
  - !ruby/object:Gem::Version
88
85
  version: '0'
89
86
  requirements: []
90
87
  rubyforge_project:
91
- rubygems_version: 1.8.23
88
+ rubygems_version: 2.2.2
92
89
  signing_key:
93
- specification_version: 3
90
+ specification_version: 4
94
91
  summary: Find links in a text and shorten them
95
92
  test_files:
96
93
  - spec/lib/backend/redis_spec.rb
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use 1.9.3-p194@shrinker --install --create