spec/validations_spec.rb in asset_cloud-2.5.3 vs spec/validations_spec.rb in asset_cloud-2.6.0
- old
+ new
@@ -1,19 +1,21 @@
+# frozen_string_literal: true
require 'spec_helper'
class ValidatedAsset < AssetCloud::Asset
validate :no_cats
private
+
def no_cats
add_error('no cats allowed!') if value =~ /cat/i
add_warning('bad dog!', 'wet dog smell!') if value =~ /dog/i
end
end
class BasicCloud < AssetCloud::Base
- bucket :dog_pound, AssetCloud::MemoryBucket, :asset_class => ValidatedAsset
+ bucket :dog_pound, AssetCloud::MemoryBucket, asset_class: ValidatedAsset
end
describe ValidatedAsset do
before(:each) do
@cloud = BasicCloud.new(File.dirname(__FILE__) + '/files', 'http://assets/')
@@ -21,43 +23,43 @@
@dog = @cloud.build('dog_pound/fido', 'dog')
end
describe "#store" do
it "should not store the asset unless validations pass" do
- @cloud.should_receive(:write).with('dog_pound/fido', 'dog').and_return(true)
+ expect(@cloud).to(receive(:write).with('dog_pound/fido', 'dog').and_return(true))
@cat.store
- @cat.store.should == false
- @cat.errors.should == ['no cats allowed!']
- @dog.store.should == true
+ expect(@cat.store).to(eq(false))
+ expect(@cat.errors).to(eq(['no cats allowed!']))
+ expect(@dog.store).to(eq(true))
end
it "should store asset with warnings and save them in the warnings array" do
- @dog.store.should == true
- @dog.warnings.should == ['bad dog!', 'wet dog smell!']
- @cat.store.should == false
- @cat.warnings.should == []
+ expect(@dog.store).to(eq(true))
+ expect(@dog.warnings).to(eq(['bad dog!', 'wet dog smell!']))
+ expect(@cat.store).to(eq(false))
+ expect(@cat.warnings).to(eq([]))
end
end
describe "#store!" do
it "should raise AssetNotFound with error message when validation fails" do
- expect { @cat.store! }.to raise_error(AssetCloud::AssetNotSaved, "Validation failed: no cats allowed!")
+ expect { @cat.store! }.to(raise_error(AssetCloud::AssetNotSaved, "Validation failed: no cats allowed!"))
end
it "should return true when validations pass" do
- @dog.store!.should == true
+ expect(@dog.store!).to(eq(true))
end
end
describe "#valid?" do
it "should clear errors, run validations, and return validity" do
@cat.store
- @cat.errors.should == ['no cats allowed!']
- @cat.valid?.should == false
- @cat.errors.should == ['no cats allowed!']
+ expect(@cat.errors).to(eq(['no cats allowed!']))
+ expect(@cat.valid?).to(eq(false))
+ expect(@cat.errors).to(eq(['no cats allowed!']))
@cat.value = 'disguised feline'
- @cat.valid?.should == true
- @cat.errors.should be_empty
+ expect(@cat.valid?).to(eq(true))
+ expect(@cat.errors).to(be_empty)
end
end
end