Skip to content

Commit

Permalink
Stubbing adapter method and model methods for mocked objects (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuenmichelle1 authored Aug 27, 2024
1 parent 8c4b571 commit 2bdc61d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion spec/support/shared_examples_for_data_export_worker.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

RSpec.shared_examples_for 'a data export worker' do
it{ is_expected.to be_a Sidekiq::Worker }
it { is_expected.to be_a Sidekiq::Worker }
let!(:data_request){ create :data_request }

describe '#compress' do
Expand Down Expand Up @@ -172,6 +172,9 @@ def expect_close

before(:each) do
allow(DataRequest).to receive(:find).with(data_request.id).and_return data_request
allow_any_instance_of(DataRequest).to receive(:started!)
allow_any_instance_of(DataRequest).to receive(:finished!)
allow_any_instance_of(DataRequest).to receive(:failed!)
allow(subject).to receive :process_data
allow(Time).to receive_message_chain('now.utc.to_date.to_s'){ '2015-07-21' }
end
Expand Down Expand Up @@ -203,6 +206,9 @@ def expect_close

it 'should indicate failure' do
allow(subject).to receive(:process_data).and_raise 'hell'
data_request.state = 'failed'
allow_any_instance_of(DataRequest).to receive(:failed!).and_return(data_request)


expect{
subject.perform data_request.id
Expand Down
8 changes: 7 additions & 1 deletion spec/workers/comment_export_worker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
require 'spec_helper'

RSpec.describe CommentExportWorker, type: :worker do
it_behaves_like 'a data export worker'
describe 'a data export worker' do
before(:each) do
allow_any_instance_of(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter).to receive(:query)
end

it_behaves_like 'a data export worker'
end

def format_of(comment)
{
Expand Down

0 comments on commit 2bdc61d

Please sign in to comment.