grape-slack-bot 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/slack_bot/dev_console.rb +0 -5
- data/lib/slack_bot/logger.rb +8 -0
- data/lib/slack_bot.rb +2 -1
- data/spec/slack_bot/dev_console_spec.rb +54 -47
- data/spec/slack_bot/logger_spec.rb +13 -0
- data/spec/slack_bot/pager_spec.rb +46 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34be79021e713fec3adb16eaf1006303d01fb3e5da025daba80aa28ee6400bd8
|
4
|
+
data.tar.gz: 7c978813cafc6cb78c97d8db3001e90a9f5961eac73269e0c748e0b4fedcebc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c55b60b6ea73f8528daee36229b9556f8c1fbe885caebd135181d561ed73629e5ebe4784ff2e7cdb9f3d581acc758db493112571f1d0c0eea8824e1613bd6ee
|
7
|
+
data.tar.gz: ed3c34753a2affe1dc01031ebc43af4fd5dea85279cf09cab6272893f81930f5099de57716dbf2cd0f4d5a63166175721bfe657234ead03ba094186f62f8babf
|
data/CHANGELOG.md
CHANGED
data/lib/slack_bot.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'slack_bot/logger'
|
1
2
|
require 'slack_bot/dev_console'
|
2
3
|
|
3
4
|
require 'slack_bot/config'
|
@@ -21,5 +22,5 @@ require 'slack_bot/pager'
|
|
21
22
|
require 'slack_bot/grape_extension'
|
22
23
|
|
23
24
|
module SlackBot
|
24
|
-
VERSION = '1.2.
|
25
|
+
VERSION = '1.2.1'.freeze
|
25
26
|
end
|
@@ -1,50 +1,3 @@
|
|
1
|
-
module SlackBot
|
2
|
-
class Logger
|
3
|
-
def info(*args, **kwargs)
|
4
|
-
puts args, kwargs
|
5
|
-
end
|
6
|
-
end
|
7
|
-
class DevConsole
|
8
|
-
def self.enabled=(value)
|
9
|
-
@enabled = value
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.enabled?
|
13
|
-
@enabled
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.logger=(value)
|
17
|
-
@logger = value
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.logger
|
21
|
-
@logger ||= Logger.new
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.log(message = nil, &block)
|
25
|
-
return unless enabled?
|
26
|
-
|
27
|
-
message = yield if block_given?
|
28
|
-
logger.info(message)
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.log_input(message = nil, &block)
|
32
|
-
message = yield if block_given?
|
33
|
-
log(">>> #{message}")
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.log_output(message = nil, &block)
|
37
|
-
message = yield if block_given?
|
38
|
-
log("<<< #{message}")
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.log_check(message = nil, &block)
|
42
|
-
message = yield if block_given?
|
43
|
-
log("!!! #{message}")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
1
|
require 'spec_helper'
|
49
2
|
|
50
3
|
describe SlackBot::DevConsole do
|
@@ -85,4 +38,58 @@ describe SlackBot::DevConsole do
|
|
85
38
|
end
|
86
39
|
end
|
87
40
|
end
|
41
|
+
|
42
|
+
describe '.log_input' do
|
43
|
+
context 'when enabled' do
|
44
|
+
before { described_class.enabled = true }
|
45
|
+
it 'logs the message' do
|
46
|
+
expect(described_class.logger).to receive(:info).with('>>> test')
|
47
|
+
described_class.log_input('test')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when disabled' do
|
52
|
+
before { described_class.enabled = false }
|
53
|
+
it 'does not log the message' do
|
54
|
+
expect(described_class.logger).not_to receive(:info)
|
55
|
+
described_class.log_input('test')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '.log_output' do
|
61
|
+
context 'when enabled' do
|
62
|
+
before { described_class.enabled = true }
|
63
|
+
it 'logs the message' do
|
64
|
+
expect(described_class.logger).to receive(:info).with('<<< test')
|
65
|
+
described_class.log_output('test')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when disabled' do
|
70
|
+
before { described_class.enabled = false }
|
71
|
+
it 'does not log the message' do
|
72
|
+
expect(described_class.logger).not_to receive(:info)
|
73
|
+
described_class.log_output('test')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '.log_check' do
|
79
|
+
context 'when enabled' do
|
80
|
+
before { described_class.enabled = true }
|
81
|
+
it 'logs the message' do
|
82
|
+
expect(described_class.logger).to receive(:info).with('!!! test')
|
83
|
+
described_class.log_check('test')
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'when disabled' do
|
88
|
+
before { described_class.enabled = false }
|
89
|
+
it 'does not log the message' do
|
90
|
+
expect(described_class.logger).not_to receive(:info)
|
91
|
+
described_class.log_check('test')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
88
95
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SlackBot::Logger do
|
4
|
+
describe '#info' do
|
5
|
+
it 'prints the args' do
|
6
|
+
expect { subject.info('test') }.to output(%(["test"]\n)).to_stdout
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'prints the kwargs' do
|
10
|
+
expect { subject.info(test: 'test') }.to output(%({:test=>"test"}\n)).to_stdout
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,5 +1,51 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SlackBot::Pager do
|
4
|
+
let(:args) do
|
5
|
+
instance_double(SlackBot::Args)
|
6
|
+
end
|
7
|
+
before do
|
8
|
+
allow(args).to receive(:[]).with(:page).and_return(1)
|
9
|
+
allow(args).to receive(:[]).with(:per_page).and_return(10)
|
10
|
+
end
|
4
11
|
|
12
|
+
describe '#total_count' do
|
13
|
+
it 'returns the count of the source cursor' do
|
14
|
+
source_cursor = double(count: 10)
|
15
|
+
pager = described_class.new(source_cursor, args: args)
|
16
|
+
expect(pager.total_count).to eq(10)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#pages_count' do
|
21
|
+
it 'returns the count of the source cursor divided by the limit' do
|
22
|
+
source_cursor = double(count: 10)
|
23
|
+
pager = described_class.new(source_cursor, args: args, limit: 5)
|
24
|
+
expect(pager.pages_count).to eq(2)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns the count of the source cursor divided by the limit' do
|
28
|
+
source_cursor = double(count: 11)
|
29
|
+
pager = described_class.new(source_cursor, args: args, limit: 5)
|
30
|
+
expect(pager.pages_count).to eq(3)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#offset' do
|
35
|
+
it 'returns the offset based on the page and limit' do
|
36
|
+
source_cursor = double(count: 10)
|
37
|
+
pager = described_class.new(source_cursor, args: args, limit: 5, page: 2)
|
38
|
+
expect(pager.offset).to eq(5)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#cursor' do
|
43
|
+
it 'returns the cursor with the limit and offset' do
|
44
|
+
source_cursor = double(count: 10)
|
45
|
+
expect(source_cursor).to receive(:limit).with(5).and_return(source_cursor)
|
46
|
+
expect(source_cursor).to receive(:offset).with(5).and_return(source_cursor)
|
47
|
+
pager = described_class.new(source_cursor, args: args, limit: 5, page: 2)
|
48
|
+
expect(pager.cursor).to eq(source_cursor)
|
49
|
+
end
|
50
|
+
end
|
5
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-slack-bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrei Makarov
|
@@ -174,6 +174,7 @@ files:
|
|
174
174
|
- lib/slack_bot/event.rb
|
175
175
|
- lib/slack_bot/grape_extension.rb
|
176
176
|
- lib/slack_bot/interaction.rb
|
177
|
+
- lib/slack_bot/logger.rb
|
177
178
|
- lib/slack_bot/menu_options.rb
|
178
179
|
- lib/slack_bot/pager.rb
|
179
180
|
- lib/slack_bot/view.rb
|
@@ -186,6 +187,7 @@ files:
|
|
186
187
|
- spec/slack_bot/event_spec.rb
|
187
188
|
- spec/slack_bot/grape_extension_spec.rb
|
188
189
|
- spec/slack_bot/interaction_spec.rb
|
190
|
+
- spec/slack_bot/logger_spec.rb
|
189
191
|
- spec/slack_bot/menu_options_spec.rb
|
190
192
|
- spec/slack_bot/pager_spec.rb
|
191
193
|
- spec/slack_bot/view_spec.rb
|
@@ -228,6 +230,7 @@ test_files:
|
|
228
230
|
- spec/slack_bot/event_spec.rb
|
229
231
|
- spec/slack_bot/grape_extension_spec.rb
|
230
232
|
- spec/slack_bot/interaction_spec.rb
|
233
|
+
- spec/slack_bot/logger_spec.rb
|
231
234
|
- spec/slack_bot/menu_options_spec.rb
|
232
235
|
- spec/slack_bot/pager_spec.rb
|
233
236
|
- spec/slack_bot/view_spec.rb
|