qiita_team_services 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d4c5b560eeb0143ee323479dd0ca493af868401
4
- data.tar.gz: 76b0e85c196621822b0450b9a60f35cdeb54a84f
3
+ metadata.gz: 4da9ccfe481121e812f461f312a74732edfeb956
4
+ data.tar.gz: 16dcd0bf7ab843d2ab25cf2fcef6a0a3f9bb47eb
5
5
  SHA512:
6
- metadata.gz: dec92fbde534b8681234212e2166d45ac262c6e1610ddd701113c3b46e7261e9060f037a4c33a7a8a5c20ef4ed6f0a0261385cf4ad7f8564da91da6358770d01
7
- data.tar.gz: 658d390c292f958e6ea41ca29eb69262db05e3de447fa965150570cb586f5928bb02864f189596ae012369dd0d3b97938737d459e8b15a295f87af9d8f5aac87
6
+ metadata.gz: cead78f4002f9b6e63aa33528d1e32fb80da1cc2050a594023c74b3da4439c8c00503dea184e85bb10bac0f57d9ecb4bd5c0737e64e2ae4b12e52283c3fb9d36
7
+ data.tar.gz: 77802d7473b8dd267a16af6caa0bc6397ea6c824af27f7e4a867715924b754850cfb039178cf82a45c16d0187dfb1ccf74653c7918171f997eb8c8a18be06c97
@@ -35,8 +35,7 @@ module Qiita::Team::Services
35
35
 
36
36
  # @return [void]
37
37
  def ping
38
- fallback = "Test message sent from Qiita:Team"
39
- send_message(attachments: [fallback: fallback, pretext: fallback])
38
+ send_message(text: "Test message sent from Qiita:Team")
40
39
  rescue DeliveryError
41
40
  nil
42
41
  end
@@ -65,12 +64,8 @@ module Qiita::Team::Services
65
64
  # @return [void]
66
65
  # @raise [Qiita::Team::Services::DeliveryError]
67
66
  def item_updated(event)
68
- fallback = "#{user_link(event.user)} updated #{item_link(event.item)}"
69
67
  send_message(
70
- attachments: [
71
- fallback: fallback,
72
- pretext: fallback,
73
- ],
68
+ text: "#{user_link(event.user)} updated #{item_link(event.item)}",
74
69
  )
75
70
  end
76
71
 
@@ -78,12 +73,8 @@ module Qiita::Team::Services
78
73
  # @return [void]
79
74
  # @raise [Qiita::Team::Services::DeliveryError]
80
75
  def item_became_coediting(event)
81
- fallback = "#{user_link(event.user)} changed #{item_link(event.item)} to coedit mode"
82
76
  send_message(
83
- attachments: [
84
- fallback: fallback,
85
- pretext: fallback,
86
- ],
77
+ text: "#{user_link(event.user)} changed #{item_link(event.item)} to coedit mode",
87
78
  )
88
79
  end
89
80
 
@@ -91,12 +82,8 @@ module Qiita::Team::Services
91
82
  # @return [void]
92
83
  # @raise [Qiita::Team::Services::DeliveryError]
93
84
  def item_destroyed(event)
94
- fallback = "#{user_link(event.user)} deleted #{event.item.title}"
95
85
  send_message(
96
- attachments: [
97
- fallback: fallback,
98
- pretext: fallback,
99
- ],
86
+ text: "#{user_link(event.user)} deleted #{event.item.title}",
100
87
  )
101
88
  end
102
89
 
@@ -127,26 +114,17 @@ module Qiita::Team::Services
127
114
  # @return [void]
128
115
  # @raise [Qiita::Team::Services::DeliveryError]
129
116
  def item_comment_updated(event)
130
- fallback = "#{user_link(event.user)} updated a #{comment_link(event.comment)}"
131
- fallback << " on #{item_link(event.item)}"
132
- send_message(
133
- attachments: [
134
- fallback: fallback,
135
- pretext: fallback,
136
- ],
137
- )
117
+ text = "#{user_link(event.user)} updated a #{comment_link(event.comment)}"
118
+ text << " on #{item_link(event.item)}"
119
+ send_message(text: text)
138
120
  end
139
121
 
140
122
  # @param event [Qiita::Team::Services::Events::ItemCommentDestroyed]
141
123
  # @return [void]
142
124
  # @raise [Qiita::Team::Services::DeliveryError]
143
125
  def item_comment_destroyed(event)
144
- fallback = "#{user_link(event.user)} deleted a comemnt on #{item_link(event.item)}"
145
126
  send_message(
146
- attachments: [
147
- fallback: fallback,
148
- pretext: fallback,
149
- ],
127
+ text: "#{user_link(event.user)} deleted a comemnt on #{item_link(event.item)}",
150
128
  )
151
129
  end
152
130
 
@@ -172,26 +150,17 @@ module Qiita::Team::Services
172
150
  # @return [void]
173
151
  # @raise [Qiita::Team::Services::DeliveryError]
174
152
  def project_comment_updated(event)
175
- fallback = "#{user_link(event.user)} updated a #{comment_link(event.comment)}"
176
- fallback << " on #{project_link(event.project)}"
177
- send_message(
178
- attachments: [
179
- fallback: fallback,
180
- pretext: fallback,
181
- ],
182
- )
153
+ text = "#{user_link(event.user)} updated a #{comment_link(event.comment)}"
154
+ text << " on #{project_link(event.project)}"
155
+ send_message(text: text)
183
156
  end
184
157
 
185
158
  # @param event [Qiita::Team::Services::Events::ProjectCommentDestroyed]
186
159
  # @return [void]
187
160
  # @raise [Qiita::Team::Services::DeliveryError]
188
161
  def project_comment_destroyed(event)
189
- fallback = "#{user_link(event.user)} deleted a comemnt on #{project_link(event.project)}"
190
162
  send_message(
191
- attachments: [
192
- fallback: fallback,
193
- pretext: fallback,
194
- ],
163
+ text: "#{user_link(event.user)} deleted a comemnt on #{project_link(event.project)}",
195
164
  )
196
165
  end
197
166
 
@@ -199,12 +168,8 @@ module Qiita::Team::Services
199
168
  # @return [void]
200
169
  # @raise [Qiita::Team::Services::DeliveryError]
201
170
  def team_member_added(event)
202
- fallback = "#{user_link(event.member)} was added to the #{team_link(event.team)} team"
203
171
  send_message(
204
- attachments: [
205
- fallback: fallback,
206
- pretext: fallback,
207
- ],
172
+ text: "#{user_link(event.member)} was added to the #{team_link(event.team)} team",
208
173
  )
209
174
  end
210
175
 
@@ -212,12 +177,8 @@ module Qiita::Team::Services
212
177
  # @return [void]
213
178
  # @raise [Qiita::Team::Services::DeliveryError]
214
179
  def team_member_removed(event)
215
- fallback = "#{event.member.name} was removed from the #{team_link(event.team)} team"
216
180
  send_message(
217
- attachments: [
218
- fallback: fallback,
219
- pretext: fallback,
220
- ],
181
+ text: "#{event.member.name} was removed from the #{team_link(event.team)} team",
221
182
  )
222
183
  end
223
184
 
@@ -225,12 +186,8 @@ module Qiita::Team::Services
225
186
  # @return [void]
226
187
  # @raise [Qiita::Team::Services::DeliveryError]
227
188
  def project_created(event)
228
- fallback = "#{user_link(event.user)} created #{project_link(event.project)} project"
229
189
  send_message(
230
- attachments: [
231
- fallback: fallback,
232
- pretext: fallback,
233
- ],
190
+ text: "#{user_link(event.user)} created #{project_link(event.project)} project",
234
191
  )
235
192
  end
236
193
 
@@ -238,12 +195,8 @@ module Qiita::Team::Services
238
195
  # @return [void]
239
196
  # @raise [Qiita::Team::Services::DeliveryError]
240
197
  def project_updated(event)
241
- fallback = "#{user_link(event.user)} updated #{project_link(event.project)} project"
242
198
  send_message(
243
- attachments: [
244
- fallback: fallback,
245
- pretext: fallback,
246
- ],
199
+ text: "#{user_link(event.user)} updated #{project_link(event.project)} project",
247
200
  )
248
201
  end
249
202
 
@@ -251,12 +204,8 @@ module Qiita::Team::Services
251
204
  # @return [void]
252
205
  # @raise [Qiita::Team::Services::DeliveryError]
253
206
  def project_destroyed(event)
254
- fallback = "#{user_link(event.user)} deleted #{project_link(event.project)} project"
255
207
  send_message(
256
- attachments: [
257
- fallback: fallback,
258
- pretext: fallback,
259
- ],
208
+ text: "#{user_link(event.user)} deleted #{project_link(event.project)} project",
260
209
  )
261
210
  end
262
211
 
@@ -264,12 +213,8 @@ module Qiita::Team::Services
264
213
  # @return [void]
265
214
  # @raise [Qiita::Team::Services::DeliveryError]
266
215
  def project_archived(event)
267
- fallback = "#{user_link(event.user)} archived #{project_link(event.project)} project"
268
216
  send_message(
269
- attachments: [
270
- fallback: fallback,
271
- pretext: fallback,
272
- ],
217
+ text: "#{user_link(event.user)} archived #{project_link(event.project)} project",
273
218
  )
274
219
  end
275
220
 
@@ -277,12 +222,8 @@ module Qiita::Team::Services
277
222
  # @return [void]
278
223
  # @raise [Qiita::Team::Services::DeliveryError]
279
224
  def project_activated(event)
280
- fallback = "#{user_link(event.user)} activated #{project_link(event.project)} project"
281
225
  send_message(
282
- attachments: [
283
- fallback: fallback,
284
- pretext: fallback,
285
- ],
226
+ text: "#{user_link(event.user)} activated #{project_link(event.project)} project",
286
227
  )
287
228
  end
288
229
 
@@ -13,7 +13,7 @@ module Qiita::Team::Services
13
13
 
14
14
  validates :token, format: %r{\A[A-Za-z0-9+/=]{20,40}\z}
15
15
  validates :url, presence: true,
16
- url: { scheme: ['http', 'https'],
16
+ url: { scheme: %w(http https),
17
17
  message: :invalid_scheme,
18
18
  allow_blank: true }
19
19
 
@@ -1,3 +1,3 @@
1
1
  module Qiita::Team::Services
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
@@ -28,6 +28,15 @@ module Qiita::Team::Services
28
28
  :team_member_removed,
29
29
  ].freeze
30
30
 
31
+ EVENT_NAMES_TO_SEND_WITH_ATTACHMENTS = [
32
+ :item_comment_created,
33
+ :item_created,
34
+ :project_comment_created,
35
+ ].freeze
36
+
37
+ EVENT_NAMES_TO_SEND_WITH_TEXT =
38
+ (EXPECTED_AVAILABLE_EVENT_NAMES - EVENT_NAMES_TO_SEND_WITH_ATTACHMENTS).freeze
39
+
31
40
  included do
32
41
  shared_examples "Slack hook" do |hook:|
33
42
  describe ".service_name" do
@@ -51,9 +60,9 @@ module Qiita::Team::Services
51
60
  send(hook).ping
52
61
  end
53
62
 
54
- it "sends message with proper attachments" do
63
+ it "sends proper text message" do
55
64
  expect(send(hook)).to receive(:send_message) do |request_body|
56
- expect(request_body).to match_slack_attachments_request
65
+ expect(request_body).to match_slack_text_request
57
66
  end.once
58
67
  subject
59
68
  end
@@ -71,7 +80,34 @@ module Qiita::Team::Services
71
80
  end
72
81
  end
73
82
 
74
- EXPECTED_AVAILABLE_EVENT_NAMES.each do |event_name|
83
+ EVENT_NAMES_TO_SEND_WITH_TEXT.each do |event_name|
84
+ describe "##{event_name}" do
85
+ subject do
86
+ send(hook).public_send(event_name, public_send("#{event_name}_event"))
87
+ end
88
+
89
+ it "sends proper text message" do
90
+ expect(send(hook)).to receive(:send_message) do |request_body|
91
+ expect(request_body).to match_slack_text_request
92
+ end.once
93
+ subject
94
+ end
95
+
96
+ context "when message is delivered successfully" do
97
+ include_context "Delivery success"
98
+
99
+ it { expect { subject }.not_to raise_error }
100
+ end
101
+
102
+ context "when message is not delivered successfully" do
103
+ include_context "Delivery fail"
104
+
105
+ it { expect { subject }.to raise_error(Qiita::Team::Services::DeliveryError) }
106
+ end
107
+ end
108
+ end
109
+
110
+ EVENT_NAMES_TO_SEND_WITH_ATTACHMENTS.each do |event_name|
75
111
  describe "##{event_name}" do
76
112
  subject do
77
113
  send(hook).public_send(event_name, public_send("#{event_name}_event"))
@@ -0,0 +1,8 @@
1
+ RSpec::Matchers.define :match_slack_text_request do
2
+ match do |request_body|
3
+ request_body.is_a?(Hash) && \
4
+ request_body.key?(:text) && \
5
+ !request_body.key?(:attachments) && \
6
+ request_body[:text].is_a?(String)
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qiita_team_services
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuku Takahashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-23 00:00:00.000000000 Z
11
+ date: 2015-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel-url_validator
@@ -302,6 +302,7 @@ files:
302
302
  - spec/support/helpers/http_client_stub_helper.rb
303
303
  - spec/support/helpers/slack_hook_helper.rb
304
304
  - spec/support/matchers/match_slack_attachments_request.rb
305
+ - spec/support/matchers/match_slack_text_request.rb
305
306
  - spec/support/resources/base.rb
306
307
  - spec/support/resources/comment.rb
307
308
  - spec/support/resources/item.rb