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.1.4 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.1.3 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.1.2 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.1.1.pre.6 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.1.1.pre.5 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.1.1.pre.4 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.1.1.pre.3 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.1.1.pre.2 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.1.1.pre.1 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.1.0 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.0.8.pre.alpha.112 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.0.8.pre.alpha.111 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.0.8.pre.alpha.110 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.0.8.pre.alpha.109 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.0.8.pre.alpha.108 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.0.8.pre.alpha.107 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.0.8.pre.alpha.106 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.0.8.pre.alpha.105 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.0.8.pre.alpha.104 pg_engine/spec/lib/pg_form_builder_spec.rb
pg_rails-7.0.8.pre.alpha.103 pg_engine/spec/lib/pg_form_builder_spec.rb