grape-slack-bot 1.1.0 → 1.2.1
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +1 -0
- data/lib/slack_bot/dev_console.rb +13 -5
- data/lib/slack_bot/logger.rb +8 -0
- data/lib/slack_bot.rb +2 -1
- data/spec/slack_bot/dev_console_spec.rb +95 -0
- data/spec/slack_bot/logger_spec.rb +13 -0
- data/spec/slack_bot/pager_spec.rb +46 -0
- metadata +6 -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/README.md
CHANGED
@@ -133,6 +133,7 @@ References:
|
|
133
133
|
Create `app/api/slack_bot_api.rb`, it will contain bot configuration and endpoints setup:
|
134
134
|
|
135
135
|
```ruby
|
136
|
+
SlackBot::DevConsole.logger = Rails.logger
|
136
137
|
SlackBot::DevConsole.enabled = Rails.env.development?
|
137
138
|
SlackBot::Config.configure do
|
138
139
|
callback_storage Rails.cache
|
@@ -8,24 +8,32 @@ module SlackBot
|
|
8
8
|
@enabled
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.
|
11
|
+
def self.logger=(value)
|
12
|
+
@logger = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.logger
|
16
|
+
@logger ||= Logger.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.log(message = nil, &block)
|
12
20
|
return unless enabled?
|
13
21
|
|
14
22
|
message = yield if block_given?
|
15
|
-
|
23
|
+
logger.info(message)
|
16
24
|
end
|
17
25
|
|
18
|
-
def self.log_input(message = nil, &)
|
26
|
+
def self.log_input(message = nil, &block)
|
19
27
|
message = yield if block_given?
|
20
28
|
log(">>> #{message}")
|
21
29
|
end
|
22
30
|
|
23
|
-
def self.log_output(message = nil, &)
|
31
|
+
def self.log_output(message = nil, &block)
|
24
32
|
message = yield if block_given?
|
25
33
|
log("<<< #{message}")
|
26
34
|
end
|
27
35
|
|
28
|
-
def self.log_check(message = nil, &)
|
36
|
+
def self.log_check(message = nil, &block)
|
29
37
|
message = yield if block_given?
|
30
38
|
log("!!! #{message}")
|
31
39
|
end
|
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.1
|
25
|
+
VERSION = '1.2.1'.freeze
|
25
26
|
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SlackBot::DevConsole do
|
4
|
+
let(:logger) { instance_double(SlackBot::Logger) }
|
5
|
+
before do
|
6
|
+
described_class.enabled = true
|
7
|
+
described_class.logger = logger
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.enabled=' do
|
11
|
+
it 'sets the enabled value' do
|
12
|
+
expect { described_class.enabled = false }.to change(described_class, :enabled?).from(true).to(false)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.logger=' do
|
17
|
+
let(:new_logger) { instance_double(SlackBot::Logger) }
|
18
|
+
after { described_class.logger = logger }
|
19
|
+
it 'sets the logger' do
|
20
|
+
expect { described_class.logger = new_logger }.to change(described_class, :logger).from(logger).to(new_logger)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '.log' do
|
25
|
+
context 'when enabled' do
|
26
|
+
before { described_class.enabled = true }
|
27
|
+
it 'logs the message' do
|
28
|
+
expect(described_class.logger).to receive(:info).with('test')
|
29
|
+
described_class.log('test')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when disabled' do
|
34
|
+
before { described_class.enabled = false }
|
35
|
+
it 'does not log the message' do
|
36
|
+
expect(described_class.logger).not_to receive(:info)
|
37
|
+
described_class.log('test')
|
38
|
+
end
|
39
|
+
end
|
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
|
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.1
|
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
|
@@ -182,9 +183,11 @@ files:
|
|
182
183
|
- spec/slack_bot/callback_spec.rb
|
183
184
|
- spec/slack_bot/command_spec.rb
|
184
185
|
- spec/slack_bot/config_spec.rb
|
186
|
+
- spec/slack_bot/dev_console_spec.rb
|
185
187
|
- spec/slack_bot/event_spec.rb
|
186
188
|
- spec/slack_bot/grape_extension_spec.rb
|
187
189
|
- spec/slack_bot/interaction_spec.rb
|
190
|
+
- spec/slack_bot/logger_spec.rb
|
188
191
|
- spec/slack_bot/menu_options_spec.rb
|
189
192
|
- spec/slack_bot/pager_spec.rb
|
190
193
|
- spec/slack_bot/view_spec.rb
|
@@ -223,9 +226,11 @@ test_files:
|
|
223
226
|
- spec/slack_bot/callback_spec.rb
|
224
227
|
- spec/slack_bot/command_spec.rb
|
225
228
|
- spec/slack_bot/config_spec.rb
|
229
|
+
- spec/slack_bot/dev_console_spec.rb
|
226
230
|
- spec/slack_bot/event_spec.rb
|
227
231
|
- spec/slack_bot/grape_extension_spec.rb
|
228
232
|
- spec/slack_bot/interaction_spec.rb
|
233
|
+
- spec/slack_bot/logger_spec.rb
|
229
234
|
- spec/slack_bot/menu_options_spec.rb
|
230
235
|
- spec/slack_bot/pager_spec.rb
|
231
236
|
- spec/slack_bot/view_spec.rb
|