ayadn 1.0.3 → 1.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbef520e744519eb89d3572d2ed07278e3d7cff7
4
- data.tar.gz: d334761a0eb199dfed6f62ccb9fa67f16dcabee3
3
+ metadata.gz: 00656e4af8c792c9b5230d9da9bb4bc64513da1a
4
+ data.tar.gz: 458d524340d6dbd9fc7fc6f9bf705f32777baa71
5
5
  SHA512:
6
- metadata.gz: d2643e94560b360c577d4f2d08031fd31f561023276a511e12ded496a70cc61a0b91e7306537b53b1360cf747abd342266cd23b9b576b319cfb420a765f4bbad
7
- data.tar.gz: 4ae9761ff188b03063756b75ff0138bbc9b5c51384ec5f6bc634a449d3f317528812a5bffbaaf6faa0e72c43a7e5f2d9803b42a0551f0d27ed472d81232ad142
6
+ metadata.gz: 74744be16e5315052c51407642389e27d045667067270402359d6b081aafd4fd8567ef2f636a17d1b4837d4331181b2c2f4f0b7599179f23b7246e736f160907
7
+ data.tar.gz: ffcc6b1211f8666f99d4b7bd6a911d08909a75ad4bd81a8209817225354251bc897e37d9a146b330fafecc7b8a7c1c35ab2f3acfa3b498363f9d820791b114cd
@@ -1,3 +1,10 @@
1
+ # 1.0.4
2
+
3
+ - Fixed 'reply to an indexed stream' for Ruby < 2.1
4
+ - More tests for Databases
5
+ - Tests for Blacklist
6
+ - Tests for Set
7
+
1
8
  # 1.0.3
2
9
 
3
10
  - Fixed the bug introduced by the last bugfix (yes, I know... sigh...)
@@ -82,7 +82,7 @@ module Ayadn
82
82
 
83
83
  def self.get_post_from_index(number)
84
84
  unless number > @index.length || number <= 0
85
- @index.to_h.each do |id, values|
85
+ @index.each do |id, values|
86
86
  return values if values[:count] == number
87
87
  end
88
88
  else
@@ -31,7 +31,7 @@ module Ayadn
31
31
  private
32
32
 
33
33
  def self.detokenize(string)
34
- string.to_s.gsub!(/token=[a-zA-Z0-9_-]+/, "token=XXX") unless string.nil?
34
+ string.dup.to_s.gsub!(/token=[a-zA-Z0-9_-]+/, "token=XXX") unless string.nil?
35
35
  end
36
36
  end
37
37
  end
@@ -134,8 +134,7 @@ module Ayadn
134
134
  Settings.save_config
135
135
  end
136
136
  def validate(t)
137
- t = t.to_i
138
- t >= 0.7 ? t : 1.5
137
+ Validators.timer(t)
139
138
  end
140
139
  def timer(t)
141
140
  Settings.options[:scroll][:timer] = t
@@ -158,12 +157,7 @@ module Ayadn
158
157
  Settings.save_config
159
158
  end
160
159
  def validate(value)
161
- case value
162
- when "TRUE", "true", "1", "yes"
163
- true
164
- when "FALSE", "false", "0", "no"
165
- false
166
- end
160
+ Validators.boolean(value)
167
161
  end
168
162
  def auto_save_sent_posts(value)
169
163
  Settings.options[:backup][:auto_save_sent_posts] = value
@@ -176,6 +170,38 @@ module Ayadn
176
170
  end
177
171
  end
178
172
 
173
+ class Validators
174
+ def self.boolean(value)
175
+ case value.downcase
176
+ when "true", "1", "yes"
177
+ true
178
+ when "false", "0", "no"
179
+ false
180
+ else
181
+ abort(Status.error_missing_parameters)
182
+ end
183
+ end
184
+ def self.index_range(min, max, value)
185
+ x = value.to_i
186
+ if x >= min && x <= max
187
+ x
188
+ else
189
+ abort(Status.must_be_integer)
190
+ end
191
+ end
192
+ def self.timer(t)
193
+ t = t.to_i
194
+ t >= 1 ? t : 3
195
+ end
196
+ def self.color(color)
197
+ colors_list = %w{red green magenta cyan yellow blue white}
198
+ unless colors_list.include?(color)
199
+ puts Status.error_missing_parameters
200
+ abort(Status.valid_colors(colors_list))
201
+ end
202
+ end
203
+ end
204
+
179
205
  class SetCounts
180
206
  def initialize
181
207
  Settings.load_config
@@ -192,16 +218,7 @@ module Ayadn
192
218
  Settings.save_config
193
219
  end
194
220
  def validate(value)
195
- if value.is_integer?
196
- x = value
197
- else
198
- x = value.to_i
199
- end
200
- if x >= 1 && x <= 200
201
- x
202
- else
203
- abort(Status.must_be_integer)
204
- end
221
+ Validators.index_range(1, 200, value)
205
222
  end
206
223
  def default(value)
207
224
  Settings.options[:counts][:default] = value
@@ -261,12 +278,7 @@ module Ayadn
261
278
  Logs.create_logger
262
279
  end
263
280
  def validate(value)
264
- case value
265
- when "TRUE", "true", "1", "yes"
266
- 1
267
- when "FALSE", "false", "0", "no"
268
- 0
269
- end
281
+ Validators.boolean(value)
270
282
  end
271
283
  def log(args)
272
284
  x = "New value for '#{args[0]}' in 'Timeline' => #{args[1]}"
@@ -313,11 +325,7 @@ module Ayadn
313
325
  end
314
326
 
315
327
  def validate(color)
316
- colors_list = %w{red green magenta cyan yellow blue white}
317
- unless colors_list.include?(color)
318
- puts Status.error_missing_parameters
319
- abort(Status.valid_colors(colors_list))
320
- end
328
+ Validators.color(color)
321
329
  end
322
330
 
323
331
  def log(args)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Ayadn
3
- VERSION = "1.0.3"
3
+ VERSION = "1.0.4"
4
4
  end
@@ -0,0 +1,114 @@
1
+ require 'spec_helper'
2
+ require 'helpers'
3
+
4
+ describe Ayadn::BlacklistWorkers do
5
+ before do
6
+ Ayadn::Settings.stub(:options).and_return({
7
+ colors: {
8
+ hashtags: :cyan,
9
+ mentions: :red,
10
+ username: :green,
11
+ id: :blue,
12
+ name: :yellow,
13
+ source: :blue,
14
+ symbols: :green,
15
+ index: :blue,
16
+ date: :cyan,
17
+ link: :magenta
18
+ },
19
+ timeline: {
20
+ show_real_name: true,
21
+ show_date: true,
22
+ show_symbols: true,
23
+ show_source: true
24
+ },
25
+ formats: {table: {width: 75}},
26
+ counts: {
27
+ default: 33
28
+ }
29
+ })
30
+ Ayadn::Settings.stub(:config).and_return({
31
+ identity: {
32
+ username: 'test',
33
+ handle: '@test'
34
+ },
35
+ post_max_length: 256,
36
+ message_max_length: 2048,
37
+ version: 'wee',
38
+ paths: {
39
+ db: 'spec/mock/',
40
+ pagination: 'spec/mock/',
41
+ log: 'spec/mock'
42
+ }
43
+ })
44
+ Ayadn::Settings.stub(:user_token).and_return('XYZ')
45
+ Ayadn::Settings.stub(:check_for_accounts)
46
+ Ayadn::Settings.stub(:load_config)
47
+ Ayadn::Settings.stub(:get_token)
48
+ Ayadn::Settings.stub(:init_config)
49
+ Dir.stub(:home).and_return('spec/mock/')
50
+ end
51
+
52
+ describe "add" do
53
+ it "adds a client to the blacklist" do
54
+ k = Ayadn::BlacklistWorkers.new
55
+ k.add(['client', 'IFTTT'])
56
+ expect(Ayadn::Databases.blacklist['IFTTT']).to eq :client
57
+ expect(File.read('spec/mock/ayadn.log')).to include "(wee) INFO -- Added 'IFTTT' to blacklist of clients."
58
+ end
59
+ it "adds a client to the blacklist" do
60
+ k = Ayadn::BlacklistWorkers.new
61
+ k.add(['source', 'Zapier'])
62
+ expect(Ayadn::Databases.blacklist['Zapier']).to eq :client
63
+ expect(File.read('spec/mock/ayadn.log')).to include "(wee) INFO -- Added 'Zapier' to blacklist of clients."
64
+ end
65
+ it "adds a hashtag to the blacklist" do
66
+ k = Ayadn::BlacklistWorkers.new
67
+ k.add(['hashtag', 'sports'])
68
+ expect(Ayadn::Databases.blacklist['sports']).to eq :hashtag
69
+ expect(File.read('spec/mock/ayadn.log')).to include "(wee) INFO -- Added 'sports' to blacklist of hashtags."
70
+ end
71
+ it "adds a hashtag to the blacklist" do
72
+ k = Ayadn::BlacklistWorkers.new
73
+ k.add(['tag', 'tv'])
74
+ expect(Ayadn::Databases.blacklist['tv']).to eq :hashtag
75
+ expect(File.read('spec/mock/ayadn.log')).to include "(wee) INFO -- Added 'tv' to blacklist of hashtags."
76
+ end
77
+ it "adds a mention to the blacklist" do
78
+ k = Ayadn::BlacklistWorkers.new
79
+ k.add(['mention', 'mrtest'])
80
+ expect(Ayadn::Databases.blacklist['@mrtest']).to eq :mention
81
+ expect(File.read('spec/mock/ayadn.log')).to include "(wee) INFO -- Added '@mrtest' to blacklist of mentions."
82
+ end
83
+ it "adds a mention to the blacklist" do
84
+ k = Ayadn::BlacklistWorkers.new
85
+ k.add(['mentions', 'yolo'])
86
+ expect(Ayadn::Databases.blacklist['@yolo']).to eq :mention
87
+ expect(File.read('spec/mock/ayadn.log')).to include "(wee) INFO -- Added '@yolo' to blacklist of mentions."
88
+ end
89
+ end
90
+
91
+ describe "remove" do
92
+ it "removes a client from the blacklist" do
93
+ k = Ayadn::BlacklistWorkers.new
94
+ k.add(['client', 'IFTTT'])
95
+ expect(Ayadn::Databases.blacklist['IFTTT']).to eq :client
96
+ expect(File.read('spec/mock/ayadn.log')).to include "(wee) INFO -- Added 'IFTTT' to blacklist of clients."
97
+ k = Ayadn::BlacklistWorkers.new
98
+ k.remove(['client', 'IFTTT'])
99
+ expect(Ayadn::Databases.blacklist['IFTTT']).to eq nil
100
+ expect(File.read('spec/mock/ayadn.log')).to include "(wee) INFO -- Removed 'client:IFTTT' from blacklist."
101
+ end
102
+ end
103
+
104
+ after do
105
+ File.delete('spec/mock/ayadn.log')
106
+ Ayadn::Databases.open_databases
107
+ Ayadn::Databases.blacklist.clear
108
+ Ayadn::Databases.users.clear
109
+ Ayadn::Databases.pagination.clear
110
+ Ayadn::Databases.index.clear
111
+ Ayadn::Databases.aliases.clear
112
+ Ayadn::Databases.close_all
113
+ end
114
+ end
@@ -30,20 +30,56 @@ describe Ayadn::Databases do
30
30
  expect(u['lucy']).to eq 'Lucy Fair'
31
31
  end
32
32
  end
33
- # describe ".save_max_id" do
34
- # it "saves pagination" do
35
-
36
-
37
- # end
38
- # end
39
- # describe ".has_new?" do
40
- # it "check if new posts since last pagination record" do
41
- # stream = {'meta'=>{'max_id'=>33666}}
42
-
43
- # end
44
- # end
33
+ describe ".save_max_id" do
34
+ it "saves pagination" do
35
+ stream = {'meta'=>{'max_id'=>'33666','marker'=>{'name'=>'test_stream'}}}
36
+ Ayadn::Databases.save_max_id(stream)
37
+ expect(Ayadn::Databases.pagination.keys).to eq ['test_stream']
38
+ expect(Ayadn::Databases.pagination['test_stream']).to eq '33666'
39
+ end
40
+ end
41
+ describe ".has_new?" do
42
+ it "check if new posts since last pagination record" do
43
+ stream = {'meta'=>{'max_id'=>'33666','marker'=>{'name'=>'test_stream'}}}
44
+ Ayadn::Databases.save_max_id(stream)
45
+ expect(Ayadn::Databases.has_new?(stream, 'test_stream')).to eq false
46
+ stream = {'meta'=>{'max_id'=>'42000000','marker'=>{'name'=>'test_stream'}}}
47
+ expect(Ayadn::Databases.has_new?(stream, 'test_stream')).to eq true
48
+ end
49
+ end
50
+ describe ".save_indexed_posts" do
51
+ it "saves index" do
52
+ posts = {'33666' =>{:count=>1},'424242' =>{:count=>2}}
53
+ Ayadn::Databases.save_indexed_posts(posts)
54
+ expect(Ayadn::Databases.index['424242'][:count]).to eq 2
55
+ end
56
+ end
57
+ describe ".get_post_from_index" do
58
+ it "gets post id from index" do
59
+ posts = {'33666' =>{:count=>1, :id=>33666},'424242' =>{:count=>2, :id=>424242}}
60
+ Ayadn::Databases.save_indexed_posts(posts)
61
+ r = Ayadn::Databases.get_post_from_index(1)
62
+ expect(r[:count]).to eq 1
63
+ expect(r[:id]).to eq 33666
64
+ end
65
+ end
66
+ describe ".create_alias" do
67
+ it "creates an alias for a channel id" do
68
+ Ayadn::Databases.create_alias('42','everything')
69
+ expect(Ayadn::Databases.aliases['everything']).to eq '42'
70
+ end
71
+ end
72
+ describe ".get_alias_from_id" do
73
+ it "gets an alias from a channel id" do
74
+ Ayadn::Databases.create_alias('42','everything')
75
+ expect(Ayadn::Databases.get_alias_from_id('42')).to eq 'everything'
76
+ end
77
+ end
45
78
  after do
46
79
  Ayadn::Databases.users.clear
80
+ Ayadn::Databases.pagination.clear
81
+ Ayadn::Databases.index.clear
82
+ Ayadn::Databases.aliases.clear
47
83
  Ayadn::Databases.close_all
48
84
  end
49
85
  end
@@ -0,0 +1,176 @@
1
+ require 'spec_helper'
2
+ require 'helpers'
3
+
4
+ def init_stubs
5
+ Ayadn::Settings.stub(:options).and_return({
6
+ colors: {
7
+ hashtags: :cyan,
8
+ mentions: :red,
9
+ username: :green,
10
+ id: :blue,
11
+ name: :yellow,
12
+ source: :blue,
13
+ symbols: :green,
14
+ index: :blue,
15
+ date: :cyan,
16
+ link: :magenta
17
+ },
18
+ timeline: {
19
+ show_real_name: true,
20
+ show_date: true,
21
+ show_symbols: true,
22
+ show_source: true
23
+ },
24
+ formats: {table: {width: 75}},
25
+ counts: {
26
+ default: 33
27
+ },
28
+ scroll: {
29
+ timer: 5
30
+ }
31
+ })
32
+ Ayadn::Settings.stub(:config).and_return({
33
+ identity: {
34
+ username: 'test',
35
+ handle: '@test'
36
+ },
37
+ post_max_length: 256,
38
+ message_max_length: 2048,
39
+ version: 'wee',
40
+ paths: {
41
+ db: 'spec/mock/',
42
+ pagination: 'spec/mock/',
43
+ log: 'spec/mock'
44
+ }
45
+ })
46
+ Ayadn::Settings.stub(:user_token).and_return('XYZ')
47
+ Ayadn::Settings.stub(:load_config)
48
+ Ayadn::Settings.stub(:get_token)
49
+ Ayadn::Settings.stub(:init_config)
50
+ Dir.stub(:home).and_return('spec/mock/')
51
+ end
52
+
53
+ describe Ayadn::SetScroll do
54
+ before do
55
+ init_stubs
56
+ end
57
+ describe "#validate" do
58
+ it "validates a correct timer value" do
59
+ timer = Ayadn::SetScroll.new.validate(3)
60
+ expect(timer).to eq 3
61
+ end
62
+ it "validates a correct timer value" do
63
+ timer = Ayadn::SetScroll.new.validate(1)
64
+ expect(timer).to eq 1
65
+ end
66
+ it "validates a correct timer value" do
67
+ timer = Ayadn::SetScroll.new.validate(2)
68
+ expect(timer).to eq 2
69
+ end
70
+ it "validates a correct timer value" do
71
+ timer = Ayadn::SetScroll.new.validate(10.2)
72
+ expect(timer).to eq 10
73
+ end
74
+ it "validates a correct timer value" do
75
+ timer = Ayadn::SetScroll.new.validate(1.1)
76
+ expect(timer).to eq 1
77
+ end
78
+ it "sets a default if incorrect timer value" do
79
+ timer = Ayadn::SetScroll.new.validate(0)
80
+ expect(timer).to eq 3
81
+ end
82
+ it "sets a default if incorrect timer value" do
83
+ timer = Ayadn::SetScroll.new.validate('johnson')
84
+ expect(timer).to eq 3
85
+ end
86
+ it "sets a default if incorrect timer value" do
87
+ timer = Ayadn::SetScroll.new.validate(-666)
88
+ expect(timer).to eq 3
89
+ end
90
+ it "sets a default if incorrect timer value" do
91
+ timer = Ayadn::SetScroll.new.validate(0.5)
92
+ expect(timer).to eq 3
93
+ end
94
+ end
95
+ after do
96
+ File.delete('spec/mock/ayadn.log')
97
+ end
98
+ end
99
+
100
+ describe Ayadn::SetCounts do
101
+ before do
102
+ init_stubs
103
+ end
104
+ describe "#validate" do
105
+ it "validates a correct count value" do
106
+ count = Ayadn::SetCounts.new.validate('1')
107
+ expect(count).to eq 1
108
+ end
109
+ it "validates a correct count value" do
110
+ count = Ayadn::SetCounts.new.validate('200')
111
+ expect(count).to eq 200
112
+ end
113
+ it "raises error if incorrect count value" do
114
+ printed = capture_stderr do
115
+ lambda {Ayadn::SetCounts.new.validate('201')}.should raise_error(SystemExit)
116
+ end
117
+ expect(printed).to include 'This paramater must be an integer between 1 and 200'
118
+ end
119
+ it "raises error if incorrect count value" do
120
+ printed = capture_stderr do
121
+ lambda {Ayadn::SetCounts.new.validate('0')}.should raise_error(SystemExit)
122
+ end
123
+ expect(printed).to include 'This paramater must be an integer between 1 and 200'
124
+ end
125
+ it "raises error if incorrect count value" do
126
+ printed = capture_stderr do
127
+ lambda {Ayadn::SetCounts.new.validate('yolo')}.should raise_error(SystemExit)
128
+ end
129
+ expect(printed).to include 'This paramater must be an integer between 1 and 200'
130
+ end
131
+ end
132
+ after do
133
+ File.delete('spec/mock/ayadn.log')
134
+ end
135
+ end
136
+
137
+ describe Ayadn::SetBackup do
138
+ before do
139
+ init_stubs
140
+ end
141
+ describe "#validate" do
142
+ it "validates a correct boolean" do
143
+ value = Ayadn::SetBackup.new.validate('1')
144
+ expect(value).to eq true
145
+ end
146
+ it "validates a correct boolean" do
147
+ value = Ayadn::SetBackup.new.validate('true')
148
+ expect(value).to eq true
149
+ end
150
+ it "validates a correct boolean" do
151
+ value = Ayadn::SetBackup.new.validate('TrUe')
152
+ expect(value).to eq true
153
+ end
154
+ it "validates a correct boolean" do
155
+ value = Ayadn::SetBackup.new.validate('false')
156
+ expect(value).to eq false
157
+ end
158
+ it "validates a correct boolean" do
159
+ value = Ayadn::SetBackup.new.validate('fAlsE')
160
+ expect(value).to eq false
161
+ end
162
+ it "validates a correct boolean" do
163
+ value = Ayadn::SetBackup.new.validate('0')
164
+ expect(value).to eq false
165
+ end
166
+ it "raises error if incorrect boolean" do
167
+ printed = capture_stderr do
168
+ lambda {Ayadn::SetBackup.new.validate('yolo')}.should raise_error(SystemExit)
169
+ end
170
+ expect(printed).to include "You have to submit valid items. See 'ayadn -sg' for a list of valid parameters and values"
171
+ end
172
+ end
173
+ after do
174
+ File.delete('spec/mock/ayadn.log')
175
+ end
176
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ayadn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dejonckheere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-05 00:00:00.000000000 Z
11
+ date: 2014-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -238,10 +238,12 @@ files:
238
238
  - spec/mock/users.db
239
239
  - spec/spec_helper.rb
240
240
  - spec/unit/api_spec.rb
241
+ - spec/unit/blacklistworkers_spec.rb
241
242
  - spec/unit/databases_spec.rb
242
243
  - spec/unit/descriptions_spec.rb
243
244
  - spec/unit/endpoints_spec.rb
244
245
  - spec/unit/post_spec.rb
246
+ - spec/unit/set_spec.rb
245
247
  - spec/unit/status_spec.rb
246
248
  - spec/unit/view_spec.rb
247
249
  - spec/unit/workers_spec.rb
@@ -284,10 +286,12 @@ test_files:
284
286
  - spec/mock/users.db
285
287
  - spec/spec_helper.rb
286
288
  - spec/unit/api_spec.rb
289
+ - spec/unit/blacklistworkers_spec.rb
287
290
  - spec/unit/databases_spec.rb
288
291
  - spec/unit/descriptions_spec.rb
289
292
  - spec/unit/endpoints_spec.rb
290
293
  - spec/unit/post_spec.rb
294
+ - spec/unit/set_spec.rb
291
295
  - spec/unit/status_spec.rb
292
296
  - spec/unit/view_spec.rb
293
297
  - spec/unit/workers_spec.rb