Sha256: cbbd79f4e96bcec21b7ff18a026c332657776293786bc6d2cf1176460edc58a7

Contents?: true

Size: 1.27 KB

Versions: 147

Compression:

Stored size: 1.27 KB

Contents

require 'rails_helper'

describe PgEngine::ErrorHelper do
  let(:dummy) { Class.new { include PgEngine::ErrorHelper }.new }

  describe '#error_message_for' do
    subject do
      categoria.validate
      dummy.error_message_for(categoria, associations: [:cosas])
    end

    let!(:categoria) { create :categoria_de_cosa }

    before { create_list :cosa, 2, categoria_de_cosa: categoria }

    it do
      expect(subject).to be_nil
    end

    context 'cuando solo tiene errores de presencia' do
      before do
        categoria.nombre = nil
      end

      it do
        expect(subject).to eq :only_presence_errors
      end
    end

    context 'cuando solo tiene otros errores' do
      before do
        categoria.validate_base = true
      end

      it do
        expect(subject).to eq :not_presence_errors
      end
    end

    context 'cuando tiene multiples errores' do
      before do
        categoria.validate_base = true
        categoria.nombre = nil
      end

      it do
        expect(subject).to eq :multiple_error_types
      end
    end

    context 'cuando tiene errores anidados' do
      before do
        categoria.reload
        categoria.cosas[0].nombre = nil
      end

      it do
        expect(subject).to eq :only_presence_errors
      end
    end
  end
end

Version data entries

147 entries across 147 versions & 1 rubygems

Version Path
pg_rails-7.3.3 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.3.2 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.3.1 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.3.0 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.2.3 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.2.2 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.2.1 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.2.0 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.1.16 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.1.15 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.1.14 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.1.13 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.1.12 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.1.11 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.1.10 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.1.9 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.1.8 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.1.7 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.1.6 pg_engine/spec/lib/pg_engine/error_helper_spec.rb
pg_rails-7.1.5 pg_engine/spec/lib/pg_engine/error_helper_spec.rb