diff --git a/spec/uploadcare/rails/mongoid/mount_uploadcare_file_group_spec.rb b/spec/uploadcare/rails/mongoid/mount_uploadcare_file_group_spec.rb index d98a3b5..ed6bb38 100644 --- a/spec/uploadcare/rails/mongoid/mount_uploadcare_file_group_spec.rb +++ b/spec/uploadcare/rails/mongoid/mount_uploadcare_file_group_spec.rb @@ -7,7 +7,7 @@ before do allow(Rails).to receive(:cache).and_return(double(read: nil, write: nil)) allow(Uploadcare::Rails).to receive(:configuration).and_return( - OpenStruct.new( + double( store_files_async: false, delete_files_async: false, do_not_store: false, @@ -79,13 +79,13 @@ context 'when the file group is present' do it 'stores the file group synchronously if not configured for async storage' do - Uploadcare::Rails.configuration.store_files_async = false + allow(Uploadcare::Rails.configuration).to receive(:store_files_async).and_return(false) expect(Uploadcare::GroupApi).to receive(:store_group).with(group_id) model.send("uploadcare_store_#{attribute}!") end it 'performs the store job asynchronously if configured' do - Uploadcare::Rails.configuration.store_files_async = true + allow(Uploadcare::Rails.configuration).to receive(:store_files_async).and_return(true) expect(Uploadcare::Rails::StoreGroupJob).to receive(:perform_later).with(group_id) model.send("uploadcare_store_#{attribute}!") end @@ -93,7 +93,7 @@ context 'when do_not_store configuration is true' do it 'does not define the after_save callback' do - Uploadcare::Rails.configuration.do_not_store = true + allow(Uploadcare::Rails.configuration).to receive(:do_not_store).and_return(true) expect(TestModel).not_to receive(:after_save) TestModel.mount_uploadcare_file_group(:attribute) end @@ -101,7 +101,7 @@ context 'when do_not_store configuration is false' do it 'defines the after_save callback' do - Uploadcare::Rails.configuration.do_not_store = false + allow(Uploadcare::Rails.configuration).to receive(:do_not_store).and_return(false) expect(TestModel).to receive(:set_callback).with(:save, :after, :uploadcare_store_cdn_url!) TestModel.mount_uploadcare_file_group(attribute) end diff --git a/spec/uploadcare/rails/mongoid/mount_uploadcare_file_spec.rb b/spec/uploadcare/rails/mongoid/mount_uploadcare_file_spec.rb index fb332a3..470abcb 100644 --- a/spec/uploadcare/rails/mongoid/mount_uploadcare_file_spec.rb +++ b/spec/uploadcare/rails/mongoid/mount_uploadcare_file_spec.rb @@ -7,7 +7,7 @@ before do allow(Rails).to receive(:cache).and_return(double(read: nil, write: nil)) allow(Uploadcare::Rails).to receive(:configuration).and_return( - OpenStruct.new( + double( store_files_async: false, delete_files_async: false, do_not_store: false, @@ -69,7 +69,7 @@ context 'when store_files_async configuration is true' do before do - Uploadcare::Rails.configuration.store_files_async = true + allow(Uploadcare::Rails.configuration).to receive(:store_files_async).and_return(true) end it 'should enqueue StoreFileJob when calling uploadcare_store_cdn_url!' do @@ -80,7 +80,7 @@ context 'when store_files_async configuration is false' do before do - Uploadcare::Rails.configuration.store_files_async = false + allow(Uploadcare::Rails.configuration).to receive(:store_files_async).and_return(false) end it 'should call Uploadcare::FileApi.store_file when calling uploadcare_store_cdn_url!' do @@ -91,7 +91,7 @@ context 'when delete_files_async configuration is true' do before do - Uploadcare::Rails.configuration.delete_files_async = true + allow(Uploadcare::Rails.configuration).to receive(:delete_files_async).and_return(true) end it 'should enqueue DeleteFileJob when calling uploadcare_delete_cdn_url!' do @@ -102,7 +102,7 @@ context 'when delete_files_async configuration is false' do before do - Uploadcare::Rails.configuration.delete_files_async = false + allow(Uploadcare::Rails.configuration).to receive(:delete_files_async).and_return(false) end it 'should call Uploadcare::FileApi.delete_file when calling uploadcare_delete_cdn_url!' do @@ -113,7 +113,7 @@ context 'when do_not_store configuration is false' do before do - Uploadcare::Rails.configuration.do_not_store = false + allow(Uploadcare::Rails.configuration).to receive(:do_not_store).and_return(false) end it 'should set callback for saving to call uploadcare_store_cdn_url! if cdn_url attribute changed' do @@ -125,7 +125,7 @@ context 'when delete_files_after_destroy configuration is true' do before do - Uploadcare::Rails.configuration.delete_files_after_destroy = true + allow(Uploadcare::Rails.configuration).to receive(:delete_files_after_destroy).and_return(true) end it 'should set callback for destroying to call uploadcare_delete_cdn_url!' do