spec/models/attachy/viewer/value_spec.rb in attachy-0.4.0 vs spec/models/attachy/viewer/value_spec.rb in attachy-0.4.1
- old
+ new
@@ -5,37 +5,61 @@
RSpec.describe Attachy::Viewer, '.value' do
let!(:object) { create :user }
before { allow(Cloudinary::Uploader).to receive(:remove_tag) }
+ context 'when has no attachments' do
+ subject { described_class.new method, object }
+
+ context 'as attachament' do
+ let!(:method) { :avatar }
+
+ specify { expect(subject.value).to eq '[]' }
+ end
+
+ context 'as attachaments' do
+ let!(:method) { :photos }
+
+ specify { expect(subject.value).to eq '[]' }
+ end
+ end
+
context 'when has one result' do
context 'as attachament' do
subject { described_class.new method, object }
let!(:method) { :avatar }
let!(:file) { create :file, attachable: object, scope: method }
- context 'and it is not default' do
- let!(:default) { Attachy::File.new public_id: 0 }
-
- before do
- allow(Attachy::File).to receive(:default) { default }
- end
-
- it 'is represented as an array of one json' do
+ context 'with no default image configured' do
+ it 'does not gives error trying to look :public_id and returns the file' do
expect(subject.value).to eq [file].to_json
end
end
- context 'and it is default' do
- let!(:default) { Attachy::File.new public_id: file.public_id }
+ context 'with default image configured' do
+ let!(:default) { Attachy::File.new public_id: 0 }
- before do
- allow(Attachy::File).to receive(:default) { default }
+ context 'and it is not default' do
+ before do
+ allow(Attachy::File).to receive(:default) { default }
+ end
+
+ it 'is represented as an array of one json' do
+ expect(subject.value).to eq [file].to_json
+ end
end
- it 'ignores the virtual default value and returns an empty data' do
- expect(subject.value).to eq '[]'
+ context 'and it is default' do
+ let!(:default) { Attachy::File.new public_id: file.public_id }
+
+ before do
+ allow(Attachy::File).to receive(:default) { default }
+ end
+
+ it 'ignores the virtual default value and returns an empty data' do
+ expect(subject.value).to eq '[]'
+ end
end
end
end
context 'as attachaments' do