diff --git a/lib/connectors/ctgov.rb b/lib/connectors/ctgov.rb index 7381bb4..292ee40 100644 --- a/lib/connectors/ctgov.rb +++ b/lib/connectors/ctgov.rb @@ -94,14 +94,12 @@ def site_nct_ids nct_ids_for_location(SystemInfo.search_term) end - def stray_trials(nct_ids = nil) - nct_ids ||= site_nct_ids - Trial.where(parser_id: @parser_id).where.not(nct_id: nct_ids) + def stray_trials + Trial.where(parser_id: @parser_id).where.not(nct_id: self.site_nct_ids) end - def cleanup_stray_trials(nct_ids = nil) - nct_ids ||= site_nct_ids - stray_trials(nct_ids).update!(visible: false) + def cleanup_stray_trials + stray_trials.update_all(visible: false) end def nct_ids_for_location(location, page_token = nil) diff --git a/spec/connectors/ctgov_spec.rb b/spec/connectors/ctgov_spec.rb index 650d869..dc1e3f7 100644 --- a/spec/connectors/ctgov_spec.rb +++ b/spec/connectors/ctgov_spec.rb @@ -14,10 +14,12 @@ expect(will_hide.visible).to be_truthy expect(wont_hide.first.visible).to be_truthy - strays = ctgov.stray_trials(remaining_ids) + allow(ctgov).to receive(:site_nct_ids).and_return(remaining_ids) + + strays = ctgov.stray_trials expect(strays.map { |e| e.nct_id }).to include(will_hide.nct_id) - ctgov.cleanup_stray_trials(remaining_ids) + ctgov.cleanup_stray_trials will_hide.reload expect(will_hide.visible).to be_falsey expect(wont_hide.first.visible).to be_truthy @@ -36,7 +38,9 @@ expect(will_hide.visible).to be_truthy expect(wont_hide_2.visible).to be_truthy - ctgov.cleanup_stray_trials(remaining_ids) + allow(ctgov).to receive(:site_nct_ids).and_return(remaining_ids) + + ctgov.cleanup_stray_trials will_hide.reload expect(will_hide.visible).to be_falsey