Sha256: 07f910c3958a69518365802d8f85f818b8cc377463adbf2802128f232894574d

Contents?: true

Size: 924 Bytes

Versions: 4

Compression:

Stored size: 924 Bytes

Contents

require 'spec_helper'

RSpec.describe 'BetterActiveModelErrors' do
  class DummyModel
    def self.human_attribute_name(attr, default='')
      return attr.capitalize
    end
  end

  let(:test_model) { DummyModel.new }
  let(:errors) { Lev::BetterActiveModelErrors.new(test_model) }

  it 'can record errors' do
    errors[:foo] = 'bar'
    expect(errors.any?).to be(true)
  end

  it 'can add using strings' do
    errors.add('crash', 'is a bad bad value')
    expect(errors[:crash]).to eq ['is a bad bad value']
    expect(errors.include?('crash')).to be true
  end

  it 'duplicates when copy called' do
    model = OpenStruct.new

    error = Lev::BetterActiveModelErrors.new(model)
    error.set(:code, 'error')
    expect(error.get(:code)).to eq 'error'

    other = Lev::BetterActiveModelErrors.new(model)
    other.set(:code, 'warning')
    error.copy!(other)
    expect(error.get(:code)).to eq 'warning'
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lev-10.1.0 spec/better_active_model_errors_spec.rb
lev-10.0.0 spec/better_active_model_errors_spec.rb
lev-9.0.4 spec/better_active_model_errors_spec.rb
lev-9.0.3 spec/better_active_model_errors_spec.rb