Sha256: 8d7003b7eda1f0182e16a62bde52550d8e81932e110a27f031342e0412c2b1a0

Contents?: true

Size: 1.73 KB

Versions: 6

Compression:

Stored size: 1.73 KB

Contents

require "spec_helper"

module Uuids::Models
  describe Uuid do

    describe "#value" do

      before { subject.record = create(:record) }

      it "can be assigned manually" do
        value = SecureRandom.uuid
        subject.value = value
        subject.save!
        expect(subject.reload.value).to eq value
      end

      it "assigned by default" do
        expect(subject.value).not_to be_blank
      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 { build :uuid }
      before  { expect(subject).to be_valid }

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

      it "fails with wrong value" do
        subject.value = "not a valid uuid"
        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

6 entries across 6 versions & 1 rubygems

Version Path
uuids-4.1.3 spec/uuids/models/uuid_spec.rb
uuids-4.1.2 spec/uuids/models/uuid_spec.rb
uuids-4.1.1 spec/uuids/models/uuid_spec.rb
uuids-4.1.0 spec/models/uuid_spec.rb
uuids-4.0.1 spec/models/uuid_spec.rb
uuids-4.0.0 spec/models/uuid_spec.rb