ruboty-hibari_bento 0.0.3 → 0.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: 909e460dd6581209fe36be39452c44649a10b828
4
- data.tar.gz: 30f9fdab4b913d3a157996c320ca2861b02520e8
3
+ metadata.gz: 49a2f76be7bae7f2a12f940d508775ce5b3f442c
4
+ data.tar.gz: 1d036062c372f44615a08013c8ee4a31138f8115
5
5
  SHA512:
6
- metadata.gz: 19eefb6e17b96782a6a10c7881153a0508ee651513ec016a55a8705bfda2747b32f8d66c48e092a4f0a470dac22b98c8240d025d0f68483944e7cb1e849b0202
7
- data.tar.gz: 0217d225d4eae14064e6cc7442a00cf9d392de3817fcbf22b51535bda9c9badcde08df52f292e4546d68feddcacfa441771310d41da7886a3ed4425b4f56e9ce
6
+ metadata.gz: 27867ca919a8ba522705ee851a3c48ec10e42f6939d60f037fc330ac2f485da02176dacb70e9d25f13482bba70ccace32e392b5dca887083babaab4bb530efaa
7
+ data.tar.gz: e725658d7e18af0aca6d9d0fab0508addbaaa5ec74533b88133158cd9d4e012879f9d1008fd33627e269226b664baa93f4124fa867ed1c890e4130b6bbae029d
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task test: :spec
7
+ task default: :spec
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module HibariBento
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
  end
5
5
  end
@@ -22,4 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.add_runtime_dependency('redis-namespace')
23
23
  spec.add_development_dependency('bundler', '~> 1.7')
24
24
  spec.add_development_dependency('rake', '~> 10.0')
25
+ spec.add_development_dependency('rspec', '~> 3.0')
26
+ spec.add_development_dependency('simplecov')
27
+ spec.add_development_dependency('fakeredis')
28
+ spec.add_development_dependency('webmock')
25
29
  end
@@ -0,0 +1,11 @@
1
+ {
2
+ "data":[
3
+ {
4
+ "id":"1234567890123456",
5
+ "object_id":"2345678901234567",
6
+ "link":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1",
7
+ "message":"こんにちは!\n新規配達先受付中!",
8
+ "updated_time":"2015-02-19T23:30:05+0000"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "data":[
3
+ {
4
+ "id":"1234567890123456",
5
+ "object_id":"2345678901234567",
6
+ "link":"",
7
+ "message":"こんにちは!\n新規配達先受付中!",
8
+ "updated_time":"2015-02-19T23:30:05+0000"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "data":[
3
+ {
4
+ "id":"1234567890123456",
5
+ "object_id":"2345678901234567",
6
+ "link":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1",
7
+ "message":"",
8
+ "updated_time":"2015-02-19T23:30:05+0000"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "data":[
3
+ {
4
+ "id":"1234567890123456",
5
+ "object_id":"2345678901234567",
6
+ "message":"こんにちは!\n新規配達先受付中!",
7
+ "updated_time":"2015-02-19T23:30:05+0000"
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "data":[
3
+ {
4
+ "id":"1234567890123456",
5
+ "object_id":"2345678901234567",
6
+ "link":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1",
7
+ "updated_time":"2015-02-19T23:30:05+0000"
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "data":[
3
+ {
4
+ "id":"1234567890123456",
5
+ "link":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1",
6
+ "message":"こんにちは!\n新規配達先受付中!",
7
+ "updated_time":"2015-02-19T23:30:05+0000"
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "data":[
3
+ ]
4
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "data":[
3
+ {
4
+ "id":"1234567890123456",
5
+ "object_id":"2345678901234567",
6
+ "link":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1",
7
+ "message":"こんにちは!\n新規配達先受付中!",
8
+ "updated_time":"2015-02-19T23:30:05+0000"
9
+ },
10
+ {
11
+ "id":"9876543210987654",
12
+ "object_id":"8765432109876543",
13
+ "link":"https:\/\/www.facebook.com\/9876543210987654\/photos\/a.3456789012345678.1234567890.9876543210987654\/8765432109876543\/?type=1",
14
+ "message":"本日のお昼の弁当です。\nおかずのみ350円・ご飯250gとセットで440円。",
15
+ "updated_time":"2015-02-18T23:50:10+0000"
16
+ }
17
+ ]
18
+ }
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ruboty::Handlers::HibariBento do
4
+ describe '#pull' do
5
+ let(:pull) { double('Pull') }
6
+ let(:robot) { Ruboty::Robot.new }
7
+ let(:sender) { 'user1' }
8
+ let(:channel) { '#general' }
9
+
10
+ shared_examples_for 'common pull' do
11
+ it { is_expected.to receive(:call).with(no_args) }
12
+ end
13
+
14
+ before do
15
+ allow(Ruboty::HibariBento::Actions::Pull).to receive(:new).and_return(pull)
16
+ stub_const('ENV', { 'HIBARI_BENTO_FACEBOOK_ACCESS_TOKEN' => 'token'})
17
+ end
18
+
19
+ subject { pull }
20
+
21
+ %w(pull fetch show).each do |method|
22
+ context %Q(given "bento #{method}") do
23
+ after do
24
+ robot.receive(body: "@ruboty bento #{method}", from: sender, to: channel)
25
+ end
26
+ it_behaves_like 'common pull'
27
+ end
28
+
29
+ context %Q(given "bento #{method} 1") do
30
+ after do
31
+ robot.receive(body: "@ruboty bento #{method} 1", from: sender, to: channel)
32
+ end
33
+ it_behaves_like 'common pull'
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,201 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ruboty::HibariBento::Actions::Pull do
4
+ describe '#call' do
5
+ let(:message) do
6
+ class Message < Hash
7
+ def reply(message)
8
+ return message
9
+ end
10
+ end
11
+ Message.new
12
+ end
13
+ let(:pull) { Ruboty::HibariBento::Actions::Pull.new(message) }
14
+
15
+ describe 'reply message' do
16
+ let(:facebook_graph_api_url) { Ruboty::HibariBento::Actions::Pull::FACEBOOK_GRAPH_API_URL }
17
+ let(:request_url) { "#{facebook_graph_api_url}/#{Ruboty::HibariBento::Actions::Pull::FACEBOOK_PAGE_ID}/posts" }
18
+ let(:access_token) { 'token' }
19
+ let(:request_query) do
20
+ {
21
+ access_token: access_token,
22
+ fields: 'id,object_id,link,message,updated_time',
23
+ locale: 'ja_JP'
24
+ }
25
+ end
26
+
27
+ let(:post_id) { '1234567890123456' }
28
+ let(:post_object_id) { '2345678901234567' }
29
+ let(:expected_message) { /こんにちは!\n新規配達先受付中!/ }
30
+ let(:expected_picture_url) { Regexp.new(Regexp.escape("#{facebook_graph_api_url}/#{post_object_id}/picture")) }
31
+ let(:expected_link) { Regexp.new(Regexp.escape("https://www.facebook.com/#{post_id}/photos/a.3456789012345678.1234567890.#{post_id}/#{post_object_id}/?type=1")) }
32
+ let(:expected_updated_time) { /2015-02-20 08:30:05/ }
33
+ let(:expected_separator) { /\n--------------------\n/ }
34
+
35
+ let(:post_id_2) { '9876543210987654' }
36
+ let(:post_object_id_2) { '8765432109876543' }
37
+ let(:expected_message_2) { /本日のお昼の弁当です。\nおかずのみ350円・ご飯250gとセットで440円。/ }
38
+ let(:expected_picture_url_2) { Regexp.new(Regexp.escape("#{facebook_graph_api_url}/#{post_object_id_2}/picture")) }
39
+ let(:expected_link_2) { Regexp.new(Regexp.escape("https://www.facebook.com/#{post_id_2}/photos/a.3456789012345678.1234567890.#{post_id_2}/#{post_object_id_2}/?type=1")) }
40
+ let(:expected_updated_time_2) { /2015-02-19 08:50:10/ }
41
+
42
+ before do
43
+ stub_const('ENV', { 'HIBARI_BENTO_FACEBOOK_ACCESS_TOKEN' => access_token })
44
+ end
45
+
46
+ subject { pull.call }
47
+
48
+ context 'when get a post' do
49
+ context 'with all fields' do
50
+ before do
51
+ stub_request(:get, request_url)
52
+ .with(query: request_query)
53
+ .to_return(body: File.new('spec/fixtures/a_post_with_all_fields.json'), status: 200)
54
+ end
55
+
56
+ it { is_expected.to match(expected_message) }
57
+ it { is_expected.to match(expected_picture_url) }
58
+ it { is_expected.to match(expected_link) }
59
+ it { is_expected.to match(expected_updated_time) }
60
+ it { is_expected.not_to match(expected_separator) }
61
+ end
62
+
63
+ context 'with no message' do
64
+ before do
65
+ stub_request(:get, request_url)
66
+ .with(query: request_query)
67
+ .to_return(body: File.new('spec/fixtures/a_post_with_no_message.json'), status: 200)
68
+ end
69
+
70
+ it { is_expected.not_to match(expected_message) }
71
+ it { is_expected.to match(expected_picture_url) }
72
+ it { is_expected.to match(expected_link) }
73
+ it { is_expected.to match(expected_updated_time) }
74
+ it { is_expected.not_to match(expected_separator) }
75
+ end
76
+
77
+ context 'with empty message' do
78
+ before do
79
+ stub_request(:get, request_url)
80
+ .with(query: request_query)
81
+ .to_return(body: File.new('spec/fixtures/a_post_with_empty_message.json'), status: 200)
82
+ end
83
+
84
+ it { is_expected.not_to match(expected_message) }
85
+ it { is_expected.to match(expected_picture_url) }
86
+ it { is_expected.to match(expected_link) }
87
+ it { is_expected.to match(expected_updated_time) }
88
+ it { is_expected.not_to match(expected_separator) }
89
+ end
90
+
91
+ context 'with no object_id' do
92
+ before do
93
+ stub_request(:get, request_url)
94
+ .with(query: request_query)
95
+ .to_return(body: File.new('spec/fixtures/a_post_with_no_object_id.json'), status: 200)
96
+ end
97
+
98
+ it { is_expected.to match(expected_message) }
99
+ it { is_expected.not_to match(expected_picture_url) }
100
+ it { is_expected.to match(expected_link) }
101
+ it { is_expected.to match(expected_updated_time) }
102
+ it { is_expected.not_to match(expected_separator) }
103
+ end
104
+
105
+ context 'with no link' do
106
+ before do
107
+ stub_request(:get, request_url)
108
+ .with(query: request_query)
109
+ .to_return(body: File.new('spec/fixtures/a_post_with_no_link.json'), status: 200)
110
+ end
111
+
112
+ it { is_expected.to match(expected_message) }
113
+ it { is_expected.to match(expected_picture_url) }
114
+ it { is_expected.not_to match(expected_link) }
115
+ it { is_expected.to match(expected_updated_time) }
116
+ it { is_expected.not_to match(expected_separator) }
117
+ end
118
+
119
+ context 'with empty link' do
120
+ before do
121
+ stub_request(:get, request_url)
122
+ .with(query: request_query)
123
+ .to_return(body: File.new('spec/fixtures/a_post_with_empty_link.json'), status: 200)
124
+ end
125
+
126
+ it { is_expected.to match(expected_message) }
127
+ it { is_expected.to match(expected_picture_url) }
128
+ it { is_expected.not_to match(expected_link) }
129
+ it { is_expected.to match(expected_updated_time) }
130
+ it { is_expected.not_to match(expected_separator) }
131
+ end
132
+ end
133
+
134
+ context 'when get some posts' do
135
+ context 'with all fields' do
136
+ before do
137
+ stub_request(:get, request_url)
138
+ .with(query: request_query)
139
+ .to_return(body: File.new('spec/fixtures/some_posts_with_all_fields.json'), status: 200)
140
+ end
141
+
142
+ it { is_expected.to match(expected_message) }
143
+ it { is_expected.to match(expected_picture_url) }
144
+ it { is_expected.to match(expected_link) }
145
+ it { is_expected.to match(expected_updated_time) }
146
+ it { is_expected.to match(expected_separator) }
147
+ it { is_expected.to match(expected_message_2) }
148
+ it { is_expected.to match(expected_picture_url_2) }
149
+ it { is_expected.to match(expected_link_2) }
150
+ it { is_expected.to match(expected_updated_time_2) }
151
+ end
152
+ end
153
+
154
+ context 'when limit the number of posts' do
155
+ before do
156
+ stub_request(:get, request_url)
157
+ .with(query: request_query)
158
+ .to_return(body: File.new('spec/fixtures/some_posts_with_all_fields.json'), status: 200)
159
+ allow(message).to receive(:[]).with(:limit).and_return(1)
160
+ end
161
+
162
+ it { is_expected.to match(expected_message) }
163
+ it { is_expected.to match(expected_picture_url) }
164
+ it { is_expected.to match(expected_link) }
165
+ it { is_expected.to match(expected_updated_time) }
166
+ it { is_expected.not_to match(expected_separator) }
167
+ it { is_expected.not_to match(expected_message_2) }
168
+ it { is_expected.not_to match(expected_picture_url_2) }
169
+ it { is_expected.not_to match(expected_link_2) }
170
+ it { is_expected.not_to match(expected_updated_time_2) }
171
+ end
172
+
173
+ context 'when get no posts' do
174
+ before do
175
+ stub_request(:get, request_url)
176
+ .with(query: request_query)
177
+ .to_return(body: File.new('spec/fixtures/no_posts.json'), status: 200)
178
+ end
179
+
180
+ it { is_expected.to eq('There are no posts.') }
181
+ end
182
+ end
183
+
184
+ context 'when an error occurs' do
185
+ let(:redis_error_message) { 'Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)' }
186
+ let(:error_message) { Regexp.new(Regexp.escape("Error: Redis::CannotConnectError - #{redis_error_message}") + '.*') }
187
+
188
+ before do
189
+ allow(message).to receive(:reply).and_raise(Redis::CannotConnectError, redis_error_message)
190
+ allow_any_instance_of(Ruboty::HibariBento::Actions::Pull).to receive(:build_message)
191
+ end
192
+
193
+ after do
194
+ pull.call
195
+ end
196
+
197
+ subject { Ruboty.logger }
198
+ it { is_expected.to receive(:error).with(error_message) }
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,20 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'ruboty'
5
+ require 'ruboty/hibari_bento'
6
+ require 'rspec'
7
+ require 'fakeredis/rspec'
8
+
9
+ require 'webmock/rspec'
10
+ WebMock.disable_net_connect!
11
+
12
+ RSpec.configure do |config|
13
+ config.expect_with :rspec do |expectations|
14
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
15
+ end
16
+
17
+ config.mock_with :rspec do |mocks|
18
+ mocks.verify_partial_doubles = true
19
+ end
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-hibari_bento
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaki Enjo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-14 00:00:00.000000000 Z
11
+ date: 2015-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty
@@ -94,6 +94,62 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: fakeredis
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
97
153
  description:
98
154
  email:
99
155
  - emsk1987@gmail.com
@@ -102,6 +158,7 @@ extensions: []
102
158
  extra_rdoc_files: []
103
159
  files:
104
160
  - ".gitignore"
161
+ - ".rspec"
105
162
  - Gemfile
106
163
  - LICENSE.txt
107
164
  - README.md
@@ -111,6 +168,17 @@ files:
111
168
  - lib/ruboty/hibari_bento/actions/pull.rb
112
169
  - lib/ruboty/hibari_bento/version.rb
113
170
  - ruboty-hibari_bento.gemspec
171
+ - spec/fixtures/a_post_with_all_fields.json
172
+ - spec/fixtures/a_post_with_empty_link.json
173
+ - spec/fixtures/a_post_with_empty_message.json
174
+ - spec/fixtures/a_post_with_no_link.json
175
+ - spec/fixtures/a_post_with_no_message.json
176
+ - spec/fixtures/a_post_with_no_object_id.json
177
+ - spec/fixtures/no_posts.json
178
+ - spec/fixtures/some_posts_with_all_fields.json
179
+ - spec/ruboty/handlers/hibari_bento_spec.rb
180
+ - spec/ruboty/hibari_bento/actions/pull_spec.rb
181
+ - spec/spec_helper.rb
114
182
  homepage: http://github.com/emsk/ruboty-hibari_bento
115
183
  licenses:
116
184
  - MIT
@@ -136,4 +204,15 @@ signing_key:
136
204
  specification_version: 4
137
205
  summary: Ruboty handler to get information of Hibari Bento, the bento shop in Ruby
138
206
  City MATSUE.
139
- test_files: []
207
+ test_files:
208
+ - spec/fixtures/a_post_with_all_fields.json
209
+ - spec/fixtures/a_post_with_empty_link.json
210
+ - spec/fixtures/a_post_with_empty_message.json
211
+ - spec/fixtures/a_post_with_no_link.json
212
+ - spec/fixtures/a_post_with_no_message.json
213
+ - spec/fixtures/a_post_with_no_object_id.json
214
+ - spec/fixtures/no_posts.json
215
+ - spec/fixtures/some_posts_with_all_fields.json
216
+ - spec/ruboty/handlers/hibari_bento_spec.rb
217
+ - spec/ruboty/hibari_bento/actions/pull_spec.rb
218
+ - spec/spec_helper.rb