Sha256: f806312f0f55f74ec62733f45dd76851b3d386acf679051ad52d947b443030b3
Contents?: true
Size: 1.42 KB
Versions: 1
Compression:
Stored size: 1.42 KB
Contents
require "spec_helper" module Uuids describe Base do describe ".included" do context "from non AR class" do before { class Test; end } after { begin; Uuids::Base.send :remove_constant, :Test; rescue; end } it "fails" do expect { Test.include Uuids::Base }.to raise_error end end context "from AR model" do # For running this specification, the Item AR model prepared in the # `spec dummy/app/models/item.rb`. before { Item.include Uuids::Base } subject(:item) { Item.new } it "defines the #uuids attribute properly" do subject.uuids.new value: SecureRandom.uuid subject.save! expect(Uuids::Uuid.first.try(:record)).to eq subject expect(subject.uuids.first).to eq Uuids::Uuid.first end it "creates the first uuid by default" do subject.save! expect(subject.uuids.reload).not_to be_blank end it "requires the #uuids attribute" do subject.save! subject.uuids.each(&:delete) expect(subject.reload).not_to be_valid end it "forbids destruction if uuids present" do subject.save! expect { subject.destroy! }.to raise_error subject.uuids.each(&:delete) subject.reload expect { subject.destroy! }.not_to raise_error end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
uuids-0.2.0 | spec/lib/uuids/base_spec.rb |