Skip to content

Commit d097157

Browse files
authored
Merge pull request #1650 from coderdojo-japan/fix_static_yaml_event_test_setup
rspec修正: static_yamlイベント集計時のエラーを解消
2 parents 449c13d + d12f085 commit d097157

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

spec/lib/statistics/aggregation_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,25 @@
1414
end
1515

1616
describe '.run' do
17+
let(:yaml_provider) { instance_double(EventService::Providers::StaticYaml) }
18+
1719
before do
1820
d1 = create(:dojo, name: 'Dojo1', email: '[email protected]', description: 'CoderDojo1', tags: %w(CoderDojo1), url: 'https://dojo1.com')
1921
d2 = create(:dojo, name: 'Dojo2', email: '[email protected]', description: 'CoderDojo2', tags: %w(CoderDojo2), url: 'https://dojo2.com')
2022
create(:dojo_event_service, dojo_id: d1.id, name: :connpass, group_id: 9876)
2123
create(:dojo_event_service, dojo_id: d2.id, name: :doorkeeper, group_id: 5555)
24+
25+
create(:dojo, id: 194, name: 'Dojo194', email: '[email protected]', description: 'CoderDojo194', tags: %w(CoderDojo194), url: 'https://dojo194.com')
26+
allow(EventService::Providers::StaticYaml).to receive(:new).and_return(yaml_provider)
27+
allow(yaml_provider).to receive(:fetch_events).and_return([
28+
{ 'dojo_id' => 194, 'event_url' => 'https://example.com/event/12345', 'evented_at' => '2023-12-10 14:00', 'participants' => 1 }
29+
])
2230
end
2331

2432
subject { Statistics::Aggregation.new(from: Time.zone.today.prev_month.strftime('%Y%m')).run }
2533

2634
it do
27-
expect{ subject }.to change{ EventHistory.count }.from(0).to(2)
35+
expect{ subject }.to change{ EventHistory.count }.from(0).to(3)
2836
end
2937
end
3038

@@ -94,7 +102,7 @@
94102
['201808', '2018-08-01'.to_date],
95103
['2018/09', '2018-09-01'.to_date],
96104
['2018-10', '2018-10-01'.to_date]]
97-
105+
98106
list.each do |d|
99107
expect(sa.send(:date_from, d[0])).to eq(d[1])
100108
end

0 commit comments

Comments
 (0)