Skip to content

Commit 7668870

Browse files
committed
remove Thread context
1 parent 429ffeb commit 7668870

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

spec/lib/event_service/providers/connpass_spec.rb

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,15 @@
99

1010
it do
1111
expect(subject).to be_instance_of(Hash)
12-
expect(subject['results_returned']).to eq 2
12+
expect(subject['results_returned']).to eq 1
1313
expect(subject['events'].first['event_id']).to eq 12345
1414
expect(subject['events'].first['series']['url']).to eq 'https://coderdojo-okutama.connpass.com/'
1515
expect(subject['events'].first['series']['id']).to eq 9876
16-
expect(subject['events'].second['event_id']).to eq 12346 # assuming the second event has id 12346
17-
expect(subject['events'].second['series']['url']).to eq 'https://coderdojo-okutama2.connpass.com/'
18-
expect(subject['events'].second['series']['id']).to eq 9877
1916
end
2017
end
2118

2219
describe '#fetch_events' do
2320
context 'when a single series_id is given' do
24-
before do
25-
# Thread.currentを使用してテストのコンテキスト間でデータを共有する
26-
Thread.current[:series_ids] = [9876]
27-
end
28-
2921
subject { described_class.new.fetch_events(series_id: 9876) }
3022

3123
it do
@@ -38,14 +30,8 @@
3830
end
3931

4032
context 'when multiple series_ids are given' do
41-
before do
42-
# Thread.currentを使用してテストのコンテキスト間でデータを共有する
43-
Thread.current[:series_ids] = [9876, 9877]
44-
end
45-
4633
subject { described_class.new.fetch_events(series_id: [9876, 9877]) }
4734

48-
# Here, you need to modify connpass_response to return multiple events for different series_ids
4935
it do
5036
expect(subject).to be_instance_of(Array)
5137
expect(subject.size).to eq 2

spec/support/shared_contexts/statistics.rb

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
f.response :json, :content_type => /\bjson$/
55
f.adapter :test, Faraday::Adapter::Test::Stubs.new do |stub|
66
# connpass
7-
stub.get('/event/') { connpass_response }
7+
stub.get('/event/') do |env|
8+
if env.params["series_id"] == '9876,9877'
9+
multiple_series_ids_response
10+
else
11+
connpass_response
12+
end
13+
end
814

915
# doorkeeper
1016
stub.get('/events') { doorkeeper_response }
@@ -21,22 +27,22 @@
2127
RSpec.shared_context 'Use stubs for Connpass' do
2228
include_context 'Use stub connection of Faraday'
2329

30+
# response for multiple series_ids 9876 and 9877
31+
let(:multiple_series_ids_response) do
32+
[
33+
200,
34+
{ 'Content-Type' => 'application/json' },
35+
'{"results_returned": 2, "events": [{"event_url": "https://coderdojo-okutama.connpass.com/event/12345/", "event_type": "participation", "owner_nickname": "nalabjp", "series": {"url": "https://coderdojo-okutama.connpass.com/", "id": 9876, "title": "CoderDojo series"}, "updated_at": "2017-04-29T14:59:30+09:00", "lat": "35.801763000000", "started_at": "2017-05-07T10:00:00+09:00", "hash_tag": "CoderDojo", "title": "CoderDojo title", "event_id": 12345, "lon": "139.087656000000", "waiting": 2, "limit": 10, "owner_id": 2525, "owner_display_name": "nalabjp", "description": "CoderDojo description", "address": "Okutama-cho Tokyo", "catch": "CoderDojo catch", "accepted": 10, "ended_at": "2017-05-07T12:00:00+09:00", "place": "Tokyo"},{"event_url": "https://coderdojo-okutama.connpass.com/event/12346/", "event_type": "participation", "owner_nickname": "nalabjp", "series": {"url": "https://coderdojo-okutama2.connpass.com/", "id": 9877, "title": "CoderDojo series"}, "updated_at": "2017-04-29T14:59:30+09:00", "lat": "35.801763000000", "started_at": "2017-05-07T10:00:00+09:00", "hash_tag": "CoderDojo", "title": "CoderDojo title", "event_id": 12346, "lon": "139.087656000000", "waiting": 2, "limit": 10, "owner_id": 2525, "owner_display_name": "nalabjp", "description": "CoderDojo description", "address": "Okutama-cho Tokyo", "catch": "CoderDojo catch", "accepted": 10, "ended_at": "2017-05-07T12:00:00+09:00", "place": "Tokyo"}], "results_start": 200, "results_available": 518}'
36+
]
37+
end
38+
39+
# response for single series_id 9876, and for search
2440
let(:connpass_response) do
25-
if Thread.current[:series_ids] == [9876]
26-
# response for single series_id 9876
27-
[
28-
200,
29-
{ 'Content-Type' => 'application/json' },
30-
'{"results_returned": 1, "events": [{"event_url": "https://coderdojo-okutama.connpass.com/event/12345/", "event_type": "participation", "owner_nickname": "nalabjp", "series": {"url": "https://coderdojo-okutama.connpass.com/", "id": 9876, "title": "CoderDojo series"}, "updated_at": "2017-04-29T14:59:30+09:00", "lat": "35.801763000000", "started_at": "2017-05-07T10:00:00+09:00", "hash_tag": "CoderDojo", "title": "CoderDojo title", "event_id": 12345, "lon": "139.087656000000", "waiting": 2, "limit": 10, "owner_id": 2525, "owner_display_name": "nalabjp", "description": "CoderDojo description", "address": "Okutama-cho Tokyo", "catch": "CoderDojo catch", "accepted": 10, "ended_at": "2017-05-07T12:00:00+09:00", "place": "Tokyo"}], "results_start": 200, "results_available": 518}'
31-
]
32-
else
33-
# response for multiple series_ids 9876 and 9877
34-
[
35-
200,
36-
{ 'Content-Type' => 'application/json' },
37-
'{"results_returned": 2, "events": [{"event_url": "https://coderdojo-okutama.connpass.com/event/12345/", "event_type": "participation", "owner_nickname": "nalabjp", "series": {"url": "https://coderdojo-okutama.connpass.com/", "id": 9876, "title": "CoderDojo series"}, "updated_at": "2017-04-29T14:59:30+09:00", "lat": "35.801763000000", "started_at": "2017-05-07T10:00:00+09:00", "hash_tag": "CoderDojo", "title": "CoderDojo title", "event_id": 12345, "lon": "139.087656000000", "waiting": 2, "limit": 10, "owner_id": 2525, "owner_display_name": "nalabjp", "description": "CoderDojo description", "address": "Okutama-cho Tokyo", "catch": "CoderDojo catch", "accepted": 10, "ended_at": "2017-05-07T12:00:00+09:00", "place": "Tokyo"},{"event_url": "https://coderdojo-okutama.connpass.com/event/12346/", "event_type": "participation", "owner_nickname": "nalabjp", "series": {"url": "https://coderdojo-okutama2.connpass.com/", "id": 9877, "title": "CoderDojo series"}, "updated_at": "2017-04-29T14:59:30+09:00", "lat": "35.801763000000", "started_at": "2017-05-07T10:00:00+09:00", "hash_tag": "CoderDojo", "title": "CoderDojo title", "event_id": 12346, "lon": "139.087656000000", "waiting": 2, "limit": 10, "owner_id": 2525, "owner_display_name": "nalabjp", "description": "CoderDojo description", "address": "Okutama-cho Tokyo", "catch": "CoderDojo catch", "accepted": 10, "ended_at": "2017-05-07T12:00:00+09:00", "place": "Tokyo"}], "results_start": 200, "results_available": 518}'
38-
]
39-
end
41+
[
42+
200,
43+
{ 'Content-Type' => 'application/json' },
44+
'{"results_returned": 1, "events": [{"event_url": "https://coderdojo-okutama.connpass.com/event/12345/", "event_type": "participation", "owner_nickname": "nalabjp", "series": {"url": "https://coderdojo-okutama.connpass.com/", "id": 9876, "title": "CoderDojo series"}, "updated_at": "2017-04-29T14:59:30+09:00", "lat": "35.801763000000", "started_at": "2017-05-07T10:00:00+09:00", "hash_tag": "CoderDojo", "title": "CoderDojo title", "event_id": 12345, "lon": "139.087656000000", "waiting": 2, "limit": 10, "owner_id": 2525, "owner_display_name": "nalabjp", "description": "CoderDojo description", "address": "Okutama-cho Tokyo", "catch": "CoderDojo catch", "accepted": 10, "ended_at": "2017-05-07T12:00:00+09:00", "place": "Tokyo"}], "results_start": 200, "results_available": 518}'
45+
]
4046
end
4147
end
4248

0 commit comments

Comments
 (0)