Sha256: 6c1ec12adbac50ea222de0eff21e251810399227e9659298d3086e18e283b0c6

Contents?: true

Size: 708 Bytes

Versions: 29

Compression:

Stored size: 708 Bytes

Contents

require 'spec_helper'
require 'volt/models'

class ExampleModelWithField < Volt::Model
  field :name
  field :value, Numeric
end

describe 'field helpers' do
  it 'should allow a user to setup a field that can be written to and read' do
    model = ExampleModelWithField.new

    expect(model.name).to eq(nil)
    model.name = 'jimmy'
    expect(model.name).to eq('jimmy')

    expect(model.value).to eq(nil)
    model.value = '20.5'

    # Should be cast to float
    expect(model.value).to eq(20.5)
  end

  it 'should raise an error when an invalid cast type is provided' do
    expect do
      ExampleModelWithField.field :awesome, Array
    end.to raise_error(FieldHelpers::InvalidFieldClass)
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
volt-0.9.3 spec/models/field_helpers_spec.rb
volt-0.9.3.pre6 spec/models/field_helpers_spec.rb
volt-0.9.3.pre5 spec/models/field_helpers_spec.rb
volt-0.9.3.pre4 spec/models/field_helpers_spec.rb
volt-0.9.3.pre3 spec/models/field_helpers_spec.rb
volt-0.9.3.pre2 spec/models/field_helpers_spec.rb
volt-0.9.3.pre1 spec/models/field_helpers_spec.rb
volt-0.9.2 spec/models/field_helpers_spec.rb
volt-0.9.1 spec/models/field_helpers_spec.rb
volt-0.9.1.pre5 spec/models/field_helpers_spec.rb
volt-0.9.1.pre4 spec/models/field_helpers_spec.rb
volt-0.9.1.pre3 spec/models/field_helpers_spec.rb
volt-0.9.1.pre2 spec/models/field_helpers_spec.rb
volt-0.9.1.pre1 spec/models/field_helpers_spec.rb
volt-0.9.0 spec/models/field_helpers_spec.rb
volt-0.9.0.pre7 spec/models/field_helpers_spec.rb
volt-0.9.0.pre6 spec/models/field_helpers_spec.rb
volt-0.9.0.pre5 spec/models/field_helpers_spec.rb
volt-0.9.0.pre4 spec/models/field_helpers_spec.rb
volt-0.9.0.pre3 spec/models/field_helpers_spec.rb