Sha256: 2db878a2064fda485483bb69923b52788e93a5a4f17f673c869df5f44366609f

Contents?: true

Size: 1.67 KB

Versions: 8

Compression:

Stored size: 1.67 KB

Contents

require_relative '../../spec_helper'
require 'virtus'

module Barometer
  class TestClass
    include Virtus.model
    attribute :temperature, Data::Attribute::Temperature
  end

  describe Data::Attribute::Temperature do
    let(:model) { TestClass.new }

    context 'when setting to nil' do
      it 'resets the value' do
        model.temperature = Data::Temperature.new(12)
        model.temperature = nil
        expect( model.temperature ).to be_nil
      end
    end

    context 'when setting with data of exact values' do
      it 'initializes Barometer::Data::Temperature' do
        model.temperature = [12]
        expect( model.temperature ).to be_a Data::Temperature
      end

      it 'defaults to :metric' do
        model.temperature = [12]
        expect( model.temperature.to_s ).to eq '12 C'
      end
    end

    context 'when setting to multiple values' do
      it 'initializes Barometer::Data::Temperature' do
        model.temperature = [12, 53]
        expect( model.temperature ).to be_a Data::Temperature
      end

      it 'prints correctly (as metric)' do
        model.temperature = [12, 53]
        expect( model.temperature.to_s ).to eq '12 C'
      end

      it 'prints correctly (as imperial)' do
        model.temperature = [:imperial, 12, 53]
        expect( model.temperature.to_s ).to eq '53 F'
      end
    end

    context 'when setting with Barometer::Data::Temperature' do
      it 'uses the passed in value' do
        temperature = Data::Temperature.new(12)
        model.temperature = temperature

        expect( model.temperature ).to eq temperature
        expect( model.temperature.object_id ).to eq temperature.object_id
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
barometer-0.9.7 spec/data/attributes/temperature_spec.rb
barometer-0.9.6 spec/data/attributes/temperature_spec.rb
barometer-0.9.5 spec/data/attributes/temperature_spec.rb
barometer-0.9.4 spec/data/attributes/temperature_spec.rb
barometer-0.9.3 spec/data/attributes/temperature_spec.rb
barometer-0.9.2 spec/data/attributes/temperature_spec.rb
barometer-0.9.1 spec/data/attributes/temperature_spec.rb
barometer-0.9.0 spec/data/attributes/temperature_spec.rb