File: freeze_spec.rb

package info (click to toggle)
ruby-virtus 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 660 kB
  • sloc: ruby: 4,378; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 883 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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