spec/adapter_spec.rb in carrierwave-base64-2.7.0 vs spec/adapter_spec.rb in carrierwave-base64-2.8.0
- old
+ new
@@ -28,15 +28,14 @@
).strip
end
it 'creates a file' do
subject.save!
- subject.reload
expect(
subject.image.current_path
- ).to eq file_path('../uploads', 'image.jpeg')
+ ).to eq file_path('../uploads', 'image.png')
end
end
end
context 'models with file_name options for the uploader' do
@@ -84,11 +83,10 @@
expect(subject.changed?).to be_truthy
end
it 'saves the file' do
subject.save!
- subject.reload
expect(
subject.image.current_path
).to eq file_path('../uploads', 'test.jpg')
end
@@ -101,15 +99,14 @@
).strip
end
it 'creates a file' do
subject.save!
- subject.reload
expect(
subject.image.current_path
- ).to eq file_path('../uploads', 'batman.jpeg')
+ ).to eq file_path('../uploads', 'batman.png')
end
it 'sets will_change for the attribute' do
expect(subject.changed?).to be_truthy
end
@@ -124,37 +121,54 @@
end
it 'should invoke the file_name proc upon each upload' do
subject.save!
another_subject.save!
- another_subject.reload
expect(
another_subject.image.current_path
- ).to eq file_path('../uploads', 'robin.jpeg')
+ ).to eq file_path('../uploads', 'robin.png')
end
end
end
context 'stored uploads exist for the field' do
before :each do
subject.image = File.read(
file_path('fixtures', 'base64_image.fixture')
).strip
subject.save!
- subject.reload
end
it 'keeps the file when setting the attribute to existing value' do
- expect(File.exist?(subject.reload.image.file.file)).to be_truthy
+ expect(File.exist?(subject.image.file.file)).to be_truthy
subject.update!(image: subject.image.to_s)
- expect(File.exist?(subject.reload.image.file.file)).to be_truthy
+ expect(File.exist?(subject.image.file.file)).to be_truthy
end
it 'removes files when remove_* is set to true' do
subject.remove_image = true
subject.save!
- expect(subject.reload.image.file).to be_nil
+ expect(subject.image.file).to be_nil
end
+ end
+ end
+
+ context 'models with presence validation on attribute with uploader' do
+ subject do
+ User.validates(:image, presence: true)
+ User.mount_base64_uploader(:image, uploader)
+ User.new
+ end
+
+ before(:each) do
+ subject.image = File.read(
+ file_path('fixtures', 'base64_image.fixture')
+ ).strip
+ subject.save!
+ end
+
+ it 'gives no false positive on presence validation' do
+ expect { subject.update!(username: 'new-username') }.not_to raise_error
end
end
end
end