From d12f085d5bdc08af09fe4c2f1d0186439783cb78 Mon Sep 17 00:00:00 2001 From: Yuppymam Date: Wed, 1 Jan 2025 16:58:59 +0900 Subject: [PATCH] =?UTF-8?q?rspec=E4=BF=AE=E6=AD=A3:=20static=5Fyaml?= =?UTF-8?q?=E3=82=A4=E3=83=99=E3=83=B3=E3=83=88=E9=9B=86=E8=A8=88=E6=99=82?= =?UTF-8?q?=E3=81=AE=E3=82=A8=E3=83=A9=E3=83=BC=E3=82=92=E8=A7=A3=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/lib/statistics/aggregation_spec.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spec/lib/statistics/aggregation_spec.rb b/spec/lib/statistics/aggregation_spec.rb index f969112f8..cc8475e8e 100644 --- a/spec/lib/statistics/aggregation_spec.rb +++ b/spec/lib/statistics/aggregation_spec.rb @@ -14,17 +14,25 @@ end describe '.run' do + let(:yaml_provider) { instance_double(EventService::Providers::StaticYaml) } + before do d1 = create(:dojo, name: 'Dojo1', email: 'info@dojo1.com', description: 'CoderDojo1', tags: %w(CoderDojo1), url: 'https://dojo1.com') d2 = create(:dojo, name: 'Dojo2', email: 'info@dojo2.com', description: 'CoderDojo2', tags: %w(CoderDojo2), url: 'https://dojo2.com') create(:dojo_event_service, dojo_id: d1.id, name: :connpass, group_id: 9876) create(:dojo_event_service, dojo_id: d2.id, name: :doorkeeper, group_id: 5555) + + create(:dojo, id: 194, name: 'Dojo194', email: 'info@dojo194.com', description: 'CoderDojo194', tags: %w(CoderDojo194), url: 'https://dojo194.com') + allow(EventService::Providers::StaticYaml).to receive(:new).and_return(yaml_provider) + allow(yaml_provider).to receive(:fetch_events).and_return([ + { 'dojo_id' => 194, 'event_url' => 'https://example.com/event/12345', 'evented_at' => '2023-12-10 14:00', 'participants' => 1 } + ]) end subject { Statistics::Aggregation.new(from: Time.zone.today.prev_month.strftime('%Y%m')).run } it do - expect{ subject }.to change{ EventHistory.count }.from(0).to(2) + expect{ subject }.to change{ EventHistory.count }.from(0).to(3) end end @@ -94,7 +102,7 @@ ['201808', '2018-08-01'.to_date], ['2018/09', '2018-09-01'.to_date], ['2018-10', '2018-10-01'.to_date]] - + list.each do |d| expect(sa.send(:date_from, d[0])).to eq(d[1]) end