spec/models/attachy/file/default_spec.rb in attachy-0.3.0 vs spec/models/attachy/file/default_spec.rb in attachy-0.4.0

- old
+ new

@@ -1,28 +1,48 @@ # frozen_string_literal: true require 'rails_helper' RSpec.describe Attachy::File, '#default' do - before do - allow(::Rails).to receive_message_chain(:application, :config_for).with(:attachy) do - { - 'default' => { - 'image' => { - 'public_id' => 'default', - 'format' => 'png', - 'version' => 1 + context 'when default image is present' do + before do + allow(::Rails).to receive_message_chain(:application, :config_for).with(:attachy) do + { + 'default' => { + 'image' => { + 'public_id' => 'default', + 'format' => 'png', + 'version' => 1 + } } } - } + end end + + it 'returns a new file object with the config values' do + default = described_class.default + + expect(default).to be_new_record + expect(default.format).to eq 'png' + expect(default.public_id).to eq 'default' + expect(default.version).to eq '1' + end end - it 'returns a new file object with the config values' do - default = described_class.default + context 'when default image is not present' do + before do + allow(::Rails).to receive_message_chain(:application, :config_for).with(:attachy) do + { 'default' => {} } + end + end - expect(default).to be_new_record - expect(default.format).to eq 'png' - expect(default.public_id).to eq 'default' - expect(default.version).to eq '1' + specify { expect(described_class.default).to eq nil } + end + + context 'when default image is not present' do + before do + allow(::Rails).to receive_message_chain(:application, :config_for).with(:attachy) { {} } + end + + specify { expect(described_class.default).to eq nil } end end