Sha256: c125191c9b54eb41e5b0424b9ba0529f2ff78a73005ca6c91c3edbe2baaad923

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

require "spec_helper"

module Uuids
  describe Uuid do

    describe "#value" do

      it "is set by default" do
        expect(subject.value).not_to be_blank
      end

      it "is a valid uuid" do
        UUID_FORMAT = /[a-z\d]{8}-[a-z\d]{4}-[a-z\d]{4}-[a-z\d]{4}-[a-z\d]{12}/
        expect(subject.value).to match UUID_FORMAT
      end
    end

    describe "#value=" do

      let!(:subject) { build :uuid }
      let!(:value)   { SecureRandom.uuid }

      it "sets #value before creation" do
        subject.value = value
        subject.save!
        expect { subject.reload }.not_to change { subject.value }.from value
      end

      it "doesn't change #value after creation" do
        subject.save!
        expect { subject.update_attributes! value: value }
          .not_to change { subject.reload }
      end
    end

    describe "#record=" do

      it "sets a #record" do
        record = create :record
        expect { subject.record = record }
          .to change { subject.record }.to record
      end
    end

    describe "#valid?" do

      subject { create :uuid }
      before  { expect(subject).to be_valid }

      it "fails with blank #record" do
        subject.record = nil
        expect(subject).not_to be_valid
      end
    end

    describe "#destroy!" do

      subject { create :uuid }

      it "is forbidden" do
        expect { subject.destroy! }.to raise_error
      end

      it "adds an error messages" do
        expect { subject.destroy }.to change { subject.errors.blank? }.to false
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
uuids-1.0.0.pre.rc1 spec/models/uuids/uuid_spec.rb
uuids-0.2.0 spec/models/uuids/uuid_spec.rb
uuids-0.1.0 spec/models/uuids/uuid_spec.rb