Sha256: 473d47b3673762baaaa024c30a7d10bd4665cdb932fb6600b4c4c1fce0e3c55e

Contents?: true

Size: 883 Bytes

Versions: 15

Compression:

Stored size: 883 Bytes

Contents

require 'spec_helper'

describe Virtus, '#freeze' do
  subject { object.freeze }

  let(:model) {
    Class.new {
      include Virtus

      attribute :name, String,  :default => 'foo', :lazy => true
      attribute :age,  Integer, :default => 30
      attribute :rand, Float,   :default => Proc.new { rand }
    }
  }

  let(:object) { model.new }

  it { is_expected.to be_frozen }

  describe '#name' do
    subject { super().name }
    it { is_expected.to eql('foo') }
  end

  describe '#age' do
    subject { super().age }
    it { is_expected.to be(30) }
  end

  it "does not change dynamic default values" do
    original_value = object.rand
    object.freeze
    expect(object.rand).to eq original_value
  end

  it "does not change default attributes that have been explicitly set" do
    object.rand = 3.14
    object.freeze
    expect(object.rand).to eq 3.14
  end
end

Version data entries

15 entries across 13 versions & 5 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/spec/unit/virtus/freeze_spec.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/spec/unit/virtus/freeze_spec.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/spec/unit/virtus/freeze_spec.rb
virtus2-2.1.0 spec/unit/virtus/freeze_spec.rb
virtus2-2.0.2 spec/unit/virtus/freeze_spec.rb
virtus2-2.0.1 spec/unit/virtus/freeze_spec.rb
virtus-2.0.0 spec/unit/virtus/freeze_spec.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/virtus-1.0.5/spec/unit/virtus/freeze_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/virtus-1.0.5/spec/unit/virtus/freeze_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/spec/unit/virtus/freeze_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/spec/unit/virtus/freeze_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/spec/unit/virtus/freeze_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/spec/unit/virtus/freeze_spec.rb
virtus-1.0.5 spec/unit/virtus/freeze_spec.rb
virtus-1.0.4 spec/unit/virtus/freeze_spec.rb