Sha256: 0b1b2f57e32e321195ab868269d3551e6bfb5f7668dd8a9ff5830be6369d68c3

Contents?: true

Size: 1.79 KB

Versions: 136

Compression:

Stored size: 1.79 KB

Contents

require 'rails_helper'

describe PgFormBuilder do
  let(:categoria) { create :categoria_de_cosa }
  let(:template) do
    klass = Class.new
    klass.include ActionView::Helpers::TagHelper
    klass.new
  end

  let(:instancia) { described_class.new('bla', categoria, template, {}) }

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

  describe '#mensajes_de_error' do
    subject { instancia.mensajes_de_error }

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

      it { expect(subject).to include 'Por favor, revisá los campos obligatorios:' }
    end

    context 'cuando solo tiene errores de :base' do
      before do
        categoria.validate_base = true
        categoria.validate
      end

      it { expect(subject).to include 'Por favor, revisá los siguientes errores' }
    end
  end

  describe '#mensaje' do
    subject { instancia.mensaje }

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

      it { expect(subject).to eq 'Por favor, revisá los campos obligatorios:' }
    end

    context 'cuando solo tiene errores de presencia en nested' do
      before do
        categoria.reload
        categoria.cosas[0].nombre = nil
        categoria.validate
      end

      it { expect(subject).to eq 'Por favor, revisá los campos obligatorios:' }
    end
  end

  describe '#default_prefix' do
    context 'cuando el atributo es masculino' do
      subject { instancia.default_prefix(:nombre) }

      it { expect(subject).to eq 'El nombre' }
    end

    context 'cuando el atributo es femenino' do
      subject { instancia.default_prefix(:fecha) }

      it { expect(subject).to eq 'La fecha' }
    end
  end
end

Version data entries

136 entries across 136 versions & 1 rubygems

Version Path
pg_rails-7.6.5 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.6.4 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.6.3 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.6.2 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.6.1 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.6.0 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.5.7 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.5.6 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.5.5 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.5.4 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.5.3 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.5.2 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.5.1 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.5.0 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.4.3 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.4.2 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.4.1 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.4.0 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.3.5 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.3.4 pg_engine/spec/lib/pg_form_builder_spec.rb