bluebird 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +7 -0
- data/bluebird.gemspec +26 -0
- data/lib/bluebird.rb +56 -0
- data/lib/bluebird/config.rb +21 -0
- data/lib/bluebird/partial.rb +70 -0
- data/lib/bluebird/strategies/base.rb +13 -0
- data/lib/bluebird/strategies/squeeze.rb +1 -0
- data/lib/bluebird/strategies/squeeze/strategy.rb +29 -0
- data/lib/bluebird/strategies/strip.rb +1 -0
- data/lib/bluebird/strategies/strip/strategy.rb +31 -0
- data/lib/bluebird/strategies/truncate_text.rb +4 -0
- data/lib/bluebird/strategies/truncate_text/config.rb +15 -0
- data/lib/bluebird/strategies/truncate_text/strategy.rb +147 -0
- data/lib/bluebird/tweet.rb +115 -0
- data/lib/bluebird/version.rb +3 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/strategies/squeeze/strategy_spec.rb +444 -0
- data/spec/strategies/strip/strategy_spec.rb +228 -0
- data/spec/strategies/truncate_text/strategy_spec.rb +188 -0
- data/spec/tweet_spec.rb +209 -0
- metadata +129 -0
@@ -0,0 +1,228 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bluebird::Strategies::Strip::Strategy do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
Bluebird.configure do |config|
|
7
|
+
config.max_length = 20
|
8
|
+
config.characters_reserved_per_media = 5
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
let!(:strategy) { Bluebird::Strategies::Strip::Strategy }
|
13
|
+
let(:config) { Bluebird::Config }
|
14
|
+
|
15
|
+
context 'When tweet is shorter than max' do
|
16
|
+
context 'and without leading whitespace' do
|
17
|
+
context 'and without trailing whitespace' do
|
18
|
+
context 'and without media' do
|
19
|
+
it 'does not modify the tweet' do
|
20
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum')
|
21
|
+
strategy.run(tweet, config)
|
22
|
+
expect(tweet.status).to eq 'Lorem ipsum'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
context 'and with media' do
|
26
|
+
it 'does not modify the tweet' do
|
27
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum', media: true)
|
28
|
+
strategy.run(tweet, config)
|
29
|
+
expect(tweet.status).to eq 'Lorem ipsum'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
context 'and with trailing whitespace' do
|
34
|
+
context 'and without media' do
|
35
|
+
it 'does not modify the tweet' do
|
36
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum ')
|
37
|
+
strategy.run(tweet, config)
|
38
|
+
expect(tweet.status).to eq 'Lorem ipsum '
|
39
|
+
end
|
40
|
+
end
|
41
|
+
context 'and with media' do
|
42
|
+
it 'does not modify the tweet' do
|
43
|
+
tweet = Bluebird::Tweet.new('Lorem ', media: true)
|
44
|
+
strategy.run(tweet, config)
|
45
|
+
expect(tweet.status).to eq 'Lorem '
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
context 'and with leading whitespace' do
|
51
|
+
context 'and without trailing whitespace' do
|
52
|
+
context 'and without media' do
|
53
|
+
it 'does not modify the tweet' do
|
54
|
+
tweet = Bluebird::Tweet.new(' Lorem ipsum')
|
55
|
+
strategy.run(tweet, config)
|
56
|
+
expect(tweet.status).to eq ' Lorem ipsum'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
context 'and with media' do
|
60
|
+
it 'does not modify the tweet' do
|
61
|
+
tweet = Bluebird::Tweet.new(' Lorem', media: true)
|
62
|
+
strategy.run(tweet, config)
|
63
|
+
expect(tweet.status).to eq ' Lorem'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
context 'and with trailing whitespace' do
|
68
|
+
context 'and without media' do
|
69
|
+
it 'does not modify the tweet' do
|
70
|
+
tweet = Bluebird::Tweet.new(' Lorem ipsum ')
|
71
|
+
strategy.run(tweet, config)
|
72
|
+
expect(tweet.status).to eq ' Lorem ipsum '
|
73
|
+
end
|
74
|
+
end
|
75
|
+
context 'and with media' do
|
76
|
+
it 'does not modify the tweet' do
|
77
|
+
tweet = Bluebird::Tweet.new(' Lorem ', media: true)
|
78
|
+
strategy.run(tweet, config)
|
79
|
+
expect(tweet.status).to eq ' Lorem '
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'When tweet is longer than max' do
|
87
|
+
context 'and without leading whitespace' do
|
88
|
+
context 'and without trailing whitespace' do
|
89
|
+
context 'and without media' do
|
90
|
+
it 'does not modify the tweet' do
|
91
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum dolor sit amet')
|
92
|
+
strategy.run(tweet, config)
|
93
|
+
expect(tweet.status).to eq 'Lorem ipsum dolor sit amet'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
context 'and with media' do
|
97
|
+
it 'does not modify the tweet' do
|
98
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum dolor sit amet', media: true)
|
99
|
+
strategy.run(tweet, config)
|
100
|
+
expect(tweet.status).to eq 'Lorem ipsum dolor sit amet'
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
context 'and with trailing whitespace' do
|
105
|
+
context 'and without media' do
|
106
|
+
it 'strips the tweet' do
|
107
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum dolor sit amet ')
|
108
|
+
strategy.run(tweet, config)
|
109
|
+
expect(tweet.status).to eq 'Lorem ipsum dolor sit amet'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
context 'and with media' do
|
113
|
+
it 'strips the tweet' do
|
114
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum sit ', media: true)
|
115
|
+
strategy.run(tweet, config)
|
116
|
+
expect(tweet.status).to eq 'Lorem ipsum sit'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
context 'and with leading whitespace' do
|
122
|
+
context 'and without trailing whitespace' do
|
123
|
+
context 'and without media' do
|
124
|
+
it 'strips the tweet' do
|
125
|
+
tweet = Bluebird::Tweet.new(' Lorem ipsum dolor sit amet')
|
126
|
+
strategy.run(tweet, config)
|
127
|
+
expect(tweet.status).to eq 'Lorem ipsum dolor sit amet'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
context 'and without media' do
|
131
|
+
it 'strips the tweet' do
|
132
|
+
tweet = Bluebird::Tweet.new(' Lorem ipsum', media: true)
|
133
|
+
strategy.run(tweet, config)
|
134
|
+
expect(tweet.status).to eq 'Lorem ipsum'
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
context 'and with trailing whitespace' do
|
139
|
+
context 'and without media' do
|
140
|
+
it 'strips the tweet' do
|
141
|
+
tweet = Bluebird::Tweet.new(' Lorem ipsum dolor sit amet ')
|
142
|
+
strategy.run(tweet, config)
|
143
|
+
expect(tweet.status).to eq 'Lorem ipsum dolor sit amet'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
context 'and without media' do
|
147
|
+
it 'strips the tweet' do
|
148
|
+
tweet = Bluebird::Tweet.new(' Lorem ipsum ', media: true)
|
149
|
+
strategy.run(tweet, config)
|
150
|
+
expect(tweet.status).to eq 'Lorem ipsum'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "When tweet's length is equal to max" do
|
158
|
+
context 'and without leading whitespace' do
|
159
|
+
context 'and without trailing whitespace' do
|
160
|
+
context 'and without media' do
|
161
|
+
it 'does not modify the tweet' do
|
162
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum dolor si')
|
163
|
+
strategy.run(tweet, config)
|
164
|
+
expect(tweet.status).to eq 'Lorem ipsum dolor si'
|
165
|
+
end
|
166
|
+
end
|
167
|
+
context 'and with media' do
|
168
|
+
it 'does not modify the tweet' do
|
169
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum dol', media: true)
|
170
|
+
strategy.run(tweet, config)
|
171
|
+
expect(tweet.status).to eq 'Lorem ipsum dol'
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
context 'and with trailing whitespace' do
|
176
|
+
context 'and without media' do
|
177
|
+
it 'does not modify the tweet' do
|
178
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum dolor ')
|
179
|
+
strategy.run(tweet, config)
|
180
|
+
expect(tweet.status).to eq 'Lorem ipsum dolor '
|
181
|
+
end
|
182
|
+
end
|
183
|
+
context 'and with media' do
|
184
|
+
it 'does not modify the tweet' do
|
185
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum ', media: true)
|
186
|
+
strategy.run(tweet, config)
|
187
|
+
expect(tweet.status).to eq 'Lorem ipsum '
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
context 'and with leading whitespace' do
|
193
|
+
context 'and without trailing whitespace' do
|
194
|
+
context 'and without media' do
|
195
|
+
it 'does not modify the tweet' do
|
196
|
+
tweet = Bluebird::Tweet.new(' Lorem ipsum dolor')
|
197
|
+
strategy.run(tweet, config)
|
198
|
+
expect(tweet.status).to eq ' Lorem ipsum dolor'
|
199
|
+
end
|
200
|
+
end
|
201
|
+
context 'and with media' do
|
202
|
+
it 'does not modify the tweet' do
|
203
|
+
tweet = Bluebird::Tweet.new(' Lorem ipsumd', media: true)
|
204
|
+
strategy.run(tweet, config)
|
205
|
+
expect(tweet.status).to eq ' Lorem ipsumd'
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
context 'and with trailing whitespace' do
|
210
|
+
context 'and without media' do
|
211
|
+
it 'does not modify the tweet' do
|
212
|
+
tweet = Bluebird::Tweet.new(' Lorem ipsum dolo ')
|
213
|
+
strategy.run(tweet, config)
|
214
|
+
expect(tweet.status).to eq ' Lorem ipsum dolo '
|
215
|
+
end
|
216
|
+
end
|
217
|
+
context 'and with media' do
|
218
|
+
it 'does not modify the tweet' do
|
219
|
+
tweet = Bluebird::Tweet.new(' Loremi dolo ', media: true)
|
220
|
+
strategy.run(tweet, config)
|
221
|
+
expect(tweet.status).to eq ' Loremi dolo '
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bluebird::Strategies::TruncateText::Strategy do
|
4
|
+
|
5
|
+
let!(:strategy) { Bluebird::Strategies::TruncateText::Strategy }
|
6
|
+
|
7
|
+
describe '#run?' do
|
8
|
+
it 'returns true if tweet is longer than max' do
|
9
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum')
|
10
|
+
expect(strategy.send(:run?, tweet, 10)).to be_true
|
11
|
+
end
|
12
|
+
it 'returns false if tweet is shorter than max' do
|
13
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum')
|
14
|
+
expect(strategy.send(:run?, tweet, 15)).to be_false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#truncate' do
|
19
|
+
|
20
|
+
context 'When tweet is shorter than max' do
|
21
|
+
it 'does not modify the tweet' do
|
22
|
+
tweet = Bluebird::Tweet.new('Lorem #ipsum @dolor')
|
23
|
+
strategy.send(:truncate, tweet, 20)
|
24
|
+
expect(tweet.status).to eq 'Lorem #ipsum @dolor'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "When tweet's length is equal to max" do
|
29
|
+
it 'does not modify the tweet' do
|
30
|
+
tweet = Bluebird::Tweet.new('Lorem #ipsum @dolor ')
|
31
|
+
strategy.send(:truncate, tweet, 20)
|
32
|
+
expect(tweet.status).to eq 'Lorem #ipsum @dolor '
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'When tweet is longer than max' do
|
37
|
+
it 'truncates the text partial which can handle all the truncation' do
|
38
|
+
Bluebird::Config.truncate_text.omission = '...'
|
39
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum #dolor sit #amet')
|
40
|
+
strategy.send(:truncate, tweet, 20)
|
41
|
+
expect(tweet.status).to eq '... #dolor sit #amet'
|
42
|
+
end
|
43
|
+
it 'does nothing if there is no text partial' do
|
44
|
+
tweet = Bluebird::Tweet.new('#Lorem @ipsum dolor.com #amet')
|
45
|
+
strategy.send(:truncate, tweet, 20)
|
46
|
+
expect(tweet.status).to eq '#Lorem @ipsum dolor.com #amet'
|
47
|
+
end
|
48
|
+
it 'truncates all text partials' do
|
49
|
+
tweet = Bluebird::Tweet.new('#Lorem ipsum dolor.com and #amet')
|
50
|
+
strategy.send(:truncate, tweet, 20)
|
51
|
+
expect(tweet.status).to eq '#Lorem dolor.com #amet'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#truncate_partials' do
|
58
|
+
|
59
|
+
before(:all) { Bluebird::Config.truncate_text.omission = '...' }
|
60
|
+
|
61
|
+
it 'truncates the text partials' do
|
62
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum @dolor sit')
|
63
|
+
strategy.send(:truncate_partials, tweet, 9)
|
64
|
+
expect(tweet.status).to eq 'Lor... @dolor'
|
65
|
+
end
|
66
|
+
it 'truncates the text partials' do
|
67
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum @dolor sit #amet')
|
68
|
+
strategy.send(:truncate_partials, tweet, 9)
|
69
|
+
expect(tweet.status).to eq 'Lor... @dolor #amet'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#truncate_partial' do
|
74
|
+
context 'When partial can handle whole truncation' do
|
75
|
+
|
76
|
+
it 'truncates the partial' do
|
77
|
+
partial = Bluebird::Partial.new('Lorem', :text)
|
78
|
+
strategy.send(:truncate_partial, partial, 3)
|
79
|
+
expect(partial.content).to eq 'Lo'
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'and with trailing whitespace' do
|
83
|
+
context 'and without a trailing partial' do
|
84
|
+
it 'truncates the partial' do
|
85
|
+
partial = Bluebird::Partial.new('Lorem ', :text)
|
86
|
+
strategy.send(:truncate_partial, partial, 3)
|
87
|
+
expect(partial.content).to eq 'Lore'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
context 'and with a trailing partial' do
|
91
|
+
it 'truncates the partial and keeps the trailing space' do
|
92
|
+
tweet = Bluebird::Tweet.new('Lorem @ipsum')
|
93
|
+
partial = tweet.partials[0]
|
94
|
+
strategy.send(:truncate_partial, partial, 3)
|
95
|
+
expect(partial.content).to eq 'Lo '
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'and partial is between two entities' do
|
101
|
+
it 'truncates the partial and adds a space' do
|
102
|
+
tweet = Bluebird::Tweet.new('#Lorem ipsum @dolor')
|
103
|
+
partial = tweet.partials[1]
|
104
|
+
strategy.send(:truncate_partial, partial, 6)
|
105
|
+
expect(partial.content).to eq ' '
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'When partial cannot handle whole truncation' do
|
112
|
+
context 'and partial is a reply preventer' do
|
113
|
+
it 'truncates the partial and adds a dot to prevent replying' do
|
114
|
+
tweet = Bluebird::Tweet.new('Lorem @ipsum')
|
115
|
+
partial = tweet.partials[0]
|
116
|
+
strategy.send(:truncate_partial, partial, 6)
|
117
|
+
expect(partial.content).to eq '.'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
context 'and partial is between two entities' do
|
121
|
+
it 'truncates the partial and adds a space' do
|
122
|
+
tweet = Bluebird::Tweet.new('#Lorem ipsum @dolor')
|
123
|
+
partial = tweet.partials[1]
|
124
|
+
strategy.send(:truncate_partial, partial, 8)
|
125
|
+
expect(partial.content).to eq ' '
|
126
|
+
end
|
127
|
+
end
|
128
|
+
context 'and partial can be deleted' do
|
129
|
+
it "deletes the partial's content" do
|
130
|
+
tweet = Bluebird::Tweet.new('#Lorem ipsum @dolor sit')
|
131
|
+
partial = tweet.partials[3]
|
132
|
+
strategy.send(:truncate_partial, partial, 5)
|
133
|
+
expect(partial.content).to eq ''
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#add_omission' do
|
140
|
+
context 'When omission is present' do
|
141
|
+
|
142
|
+
before(:all) { Bluebird::Config.truncate_text.omission = '...' }
|
143
|
+
|
144
|
+
context 'and partial can handle the omission' do
|
145
|
+
|
146
|
+
it 'adds the omission' do
|
147
|
+
partial = Bluebird::Partial.new('Lorem ipsum', :text)
|
148
|
+
strategy.send(:add_omission, partial)
|
149
|
+
expect(partial.content).to eq 'Lorem ip...'
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'with trailing entity' do
|
153
|
+
it 'adds the omission before the whitespace' do
|
154
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum http://www.example.com')
|
155
|
+
partial = tweet.partials[0]
|
156
|
+
strategy.send(:add_omission, partial)
|
157
|
+
expect(partial.content).to eq 'Lorem ip... '
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'and partial cannot handle omission' do
|
163
|
+
it 'does not add omission' do
|
164
|
+
partial = Bluebird::Partial.new('Lor', :text)
|
165
|
+
strategy.send(:add_omission, partial)
|
166
|
+
expect(partial.content).to eq 'Lor'
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
context 'When omission is nil' do
|
171
|
+
it 'does not add omission' do
|
172
|
+
Bluebird::Config.truncate_text.omission = nil
|
173
|
+
partial = Bluebird::Partial.new('Lorem ipsum', :text)
|
174
|
+
strategy.send(:add_omission, partial)
|
175
|
+
expect(partial.content).to eq 'Lorem ipsum'
|
176
|
+
end
|
177
|
+
end
|
178
|
+
context 'When omission is false' do
|
179
|
+
it 'does not add omission' do
|
180
|
+
Bluebird::Config.truncate_text.omission = false
|
181
|
+
partial = Bluebird::Partial.new('Lorem ipsum', :text)
|
182
|
+
strategy.send(:add_omission, partial)
|
183
|
+
expect(partial.content).to eq 'Lorem ipsum'
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
data/spec/tweet_spec.rb
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Bluebird::Tweet do
|
6
|
+
|
7
|
+
describe '#initialize' do
|
8
|
+
it 'sets original_status' do
|
9
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum')
|
10
|
+
expect(tweet.original_status).to eq 'Lorem ipsum'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'sets partials' do
|
14
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum')
|
15
|
+
expect(tweet.partials).to be_kind_of Array
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'When media options is present' do
|
19
|
+
it 'sets the media' do
|
20
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum', media: true)
|
21
|
+
expect(tweet.media).to be_true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'When media options is missing' do
|
26
|
+
it 'does not set the media' do
|
27
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum')
|
28
|
+
expect(tweet.media).to be_nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#status' do
|
34
|
+
it 'returns the status of the tweet' do
|
35
|
+
tweet = Bluebird::Tweet.new('Lorem #ipsum @dolor $sit amet')
|
36
|
+
expect(tweet.status).to eq 'Lorem #ipsum @dolor $sit amet'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#length' do
|
41
|
+
context 'When with media' do
|
42
|
+
it 'returns the length' do
|
43
|
+
tweet = Bluebird::Tweet.new('Lorem #ipsum @dolor $sit amet')
|
44
|
+
expect(tweet.length).to be 29
|
45
|
+
end
|
46
|
+
end
|
47
|
+
context 'When without media' do
|
48
|
+
it 'returns the length' do
|
49
|
+
Bluebird::Config.characters_reserved_per_media = 5
|
50
|
+
tweet = Bluebird::Tweet.new('Lorem #ipsum @dolor $sit amet', media: true)
|
51
|
+
expect(tweet.length).to be 34
|
52
|
+
end
|
53
|
+
end
|
54
|
+
context 'When has unicode characters' do
|
55
|
+
it 'returns the length' do
|
56
|
+
tweet = Bluebird::Tweet.new('İşçğdööüqizpqiıı')
|
57
|
+
expect(tweet.length).to be 16
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#extract_partials' do
|
63
|
+
it 'breaks tweet into partials' do
|
64
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum')
|
65
|
+
expect(tweet.partials.length).to eq 1
|
66
|
+
|
67
|
+
partial = tweet.partials[0]
|
68
|
+
expect(partial.content).to eq 'Lorem ipsum'
|
69
|
+
expect(partial.text?).to be_true
|
70
|
+
end
|
71
|
+
it 'breaks tweet into partials' do
|
72
|
+
tweet = Bluebird::Tweet.new('Lorem #ipsum')
|
73
|
+
expect(tweet.partials.length).to eq 2
|
74
|
+
|
75
|
+
partial = tweet.partials[0]
|
76
|
+
expect(partial.content).to eq 'Lorem '
|
77
|
+
expect(partial.text?).to be_true
|
78
|
+
|
79
|
+
partial = tweet.partials[1]
|
80
|
+
expect(partial.content).to eq '#ipsum'
|
81
|
+
expect(partial.hashtag?).to be_true
|
82
|
+
end
|
83
|
+
it 'breaks tweet into partials' do
|
84
|
+
tweet = Bluebird::Tweet.new('#Lorem #ipsum')
|
85
|
+
expect(tweet.partials.length).to eq 3
|
86
|
+
|
87
|
+
partial = tweet.partials[0]
|
88
|
+
expect(partial.content).to eq '#Lorem'
|
89
|
+
expect(partial.hashtag?).to be_true
|
90
|
+
|
91
|
+
partial = tweet.partials[1]
|
92
|
+
expect(partial.content).to eq ' '
|
93
|
+
expect(partial.text?).to be_true
|
94
|
+
|
95
|
+
partial = tweet.partials[2]
|
96
|
+
expect(partial.content).to eq '#ipsum'
|
97
|
+
expect(partial.hashtag?).to be_true
|
98
|
+
end
|
99
|
+
it 'breaks tweet into partials' do
|
100
|
+
tweet = Bluebird::Tweet.new('#Lorem ipsum @dolor')
|
101
|
+
expect(tweet.partials.length).to eq 3
|
102
|
+
|
103
|
+
partial = tweet.partials[0]
|
104
|
+
expect(partial.content).to eq '#Lorem'
|
105
|
+
expect(partial.hashtag?).to be_true
|
106
|
+
|
107
|
+
partial = tweet.partials[1]
|
108
|
+
expect(partial.content).to eq ' ipsum '
|
109
|
+
expect(partial.text?).to be_true
|
110
|
+
|
111
|
+
partial = tweet.partials[2]
|
112
|
+
expect(partial.content).to eq '@dolor'
|
113
|
+
expect(partial.mention?).to be_true
|
114
|
+
end
|
115
|
+
it 'breaks tweet into partials' do
|
116
|
+
tweet = Bluebird::Tweet.new(' #Lorem ipsum @dolor ')
|
117
|
+
expect(tweet.partials.length).to eq 5
|
118
|
+
|
119
|
+
partial = tweet.partials[0]
|
120
|
+
expect(partial.content).to eq ' '
|
121
|
+
expect(partial.text?).to be_true
|
122
|
+
|
123
|
+
partial = tweet.partials[1]
|
124
|
+
expect(partial.content).to eq '#Lorem'
|
125
|
+
expect(partial.hashtag?).to be_true
|
126
|
+
|
127
|
+
partial = tweet.partials[2]
|
128
|
+
expect(partial.content).to eq ' ipsum '
|
129
|
+
expect(partial.text?).to be_true
|
130
|
+
|
131
|
+
partial = tweet.partials[3]
|
132
|
+
expect(partial.content).to eq '@dolor'
|
133
|
+
expect(partial.mention?).to be_true
|
134
|
+
|
135
|
+
partial = tweet.partials[4]
|
136
|
+
expect(partial.content).to eq ' '
|
137
|
+
expect(partial.text?).to be_true
|
138
|
+
end
|
139
|
+
it 'breaks tweet into partials' do
|
140
|
+
tweet = Bluebird::Tweet.new('http://example.com example.com.')
|
141
|
+
expect(tweet.partials.length).to eq 4
|
142
|
+
|
143
|
+
partial = tweet.partials[0]
|
144
|
+
expect(partial.content).to eq 'http://example.com'
|
145
|
+
expect(partial.url?).to be_true
|
146
|
+
|
147
|
+
partial = tweet.partials[1]
|
148
|
+
expect(partial.content).to eq ' '
|
149
|
+
expect(partial.text?).to be_true
|
150
|
+
|
151
|
+
partial = tweet.partials[2]
|
152
|
+
expect(partial.content).to eq 'example.com'
|
153
|
+
expect(partial.url?).to be_true
|
154
|
+
|
155
|
+
partial = tweet.partials[3]
|
156
|
+
expect(partial.content).to eq '.'
|
157
|
+
expect(partial.text?).to be_true
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'breaks tweet into partials' do
|
161
|
+
tweet = Bluebird::Tweet.new('#abc.#def')
|
162
|
+
expect(tweet.partials.length).to eq 3
|
163
|
+
|
164
|
+
partial = tweet.partials[0]
|
165
|
+
expect(partial.content).to eq '#abc'
|
166
|
+
expect(partial.hashtag?).to be_true
|
167
|
+
|
168
|
+
partial = tweet.partials[1]
|
169
|
+
expect(partial.content).to eq '.'
|
170
|
+
expect(partial.text?).to be_true
|
171
|
+
|
172
|
+
partial = tweet.partials[2]
|
173
|
+
expect(partial.content).to eq '#def'
|
174
|
+
expect(partial.hashtag?).to be_true
|
175
|
+
end
|
176
|
+
it 'breaks tweet into partials' do
|
177
|
+
tweet = Bluebird::Tweet.new('Lorem ipsum @abc/def')
|
178
|
+
expect(tweet.partials.length).to eq 2
|
179
|
+
|
180
|
+
partial = tweet.partials[0]
|
181
|
+
expect(partial.content).to eq 'Lorem ipsum '
|
182
|
+
expect(partial.text?).to be_true
|
183
|
+
|
184
|
+
partial = tweet.partials[1]
|
185
|
+
expect(partial.content).to eq '@abc/def'
|
186
|
+
expect(partial.list?).to be_true
|
187
|
+
end
|
188
|
+
it 'breaks tweet into partials' do
|
189
|
+
tweet = Bluebird::Tweet.new('Lorem #ipsum @dolor')
|
190
|
+
expect(tweet.partials.length).to eq 4
|
191
|
+
|
192
|
+
partial = tweet.partials[0]
|
193
|
+
expect(partial.content).to eq 'Lorem '
|
194
|
+
expect(partial.text?).to be_true
|
195
|
+
|
196
|
+
partial = tweet.partials[1]
|
197
|
+
expect(partial.content).to eq '#ipsum'
|
198
|
+
expect(partial.hashtag?).to be_true
|
199
|
+
|
200
|
+
partial = tweet.partials[2]
|
201
|
+
expect(partial.content).to eq ' '
|
202
|
+
expect(partial.text?).to be_true
|
203
|
+
|
204
|
+
partial = tweet.partials[3]
|
205
|
+
expect(partial.content).to eq '@dolor'
|
206
|
+
expect(partial.mention?).to be_true
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|