Skip to content

Commit

Permalink
Do not refresh assets that are not remote
Browse files Browse the repository at this point in the history
  • Loading branch information
emrojo committed Sep 27, 2019
1 parent 72c8f15 commit 0343186
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/models/assets/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@ def refresh(fact_changes=nil)
end

def refresh!(fact_changes=nil)
@import_step = Step.create(step_type: StepType.find_or_create_by(name: 'Refresh!!'), state: 'running')
remote_asset = SequencescapeClient::find_by_uuid(uuid)
raise RefreshSourceNotFoundAnymore unless remote_asset
_process_refresh(remote_asset, fact_changes)
if is_remote_asset?
@import_step = Step.create(step_type: StepType.find_or_create_by(name: 'Refresh!!'), state: 'running')
remote_asset = SequencescapeClient::find_by_uuid(uuid)
raise RefreshSourceNotFoundAnymore unless remote_asset
_process_refresh(remote_asset, fact_changes)
end
self
end

Expand Down
44 changes: 44 additions & 0 deletions spec/models/assets/import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,50 @@
RSpec.describe 'Assets::Import' do
include RemoteAssetsHelper


context '#refresh!' do
let(:asset) { create :asset }
let(:plate) { build_remote_plate }

before do
allow(asset).to receive(:_process_refresh)
allow(SequencescapeClient).to receive(:find_by_uuid).and_return(true)
end

context 'when it is not a remote asset' do
before do
allow(asset).to receive(:is_remote_asset?).and_return(false)
end

it 'does not refresh' do
asset.refresh!
expect(asset).not_to have_received(:_process_refresh)
end
end
context 'when it is a remote asset' do
before do
allow(asset).to receive(:is_remote_asset?).and_return(true)
end
context 'when the asset has changed' do
before do
allow(asset).to receive(:changed_remote?).and_return(true)
end
it 'refreshes the asset' do
asset.refresh!
expect(asset).to have_received(:_process_refresh)
end
end
context 'when the asset has not changed' do
before do
allow(asset).to receive(:changed_remote?).and_return(false)
end
it 'refreshes the asset' do
asset.refresh!
expect(asset).to have_received(:_process_refresh)
end
end
end
end
context '#refresh' do
let(:asset) { create :asset }
let(:plate) { build_remote_plate }
Expand Down

0 comments on commit 0343186

Please sign in to comment.