Sha256: f8af146e734563ee19244caecd44ada605c4359ab4df68ba60562aa69484caf9

Contents?: true

Size: 1.18 KB

Versions: 53

Compression:

Stored size: 1.18 KB

Contents

require 'spec_helper'

require 'active_model'

describe ActiveModel::Validations do
  class ActiveModelValidationsExample < Flexirest::BaseWithoutValidation
    include ActiveModel::Validations

    validates :first_name, :last_name, presence: true
    validates :password, length: { within: 6..12, message: 'Invalid password length, must be 6-12 characters' }
  end

  let(:first_name) { 'Foo '}
  let(:last_name) { 'Bar' }
  let(:password) { 'eiChahya6i' }
  let(:attributes) { { first_name: first_name, last_name: last_name, password: password } }
  subject(:instance) { ActiveModelValidationsExample.new(attributes) }

  it { is_expected.to be_valid }

  context 'when the first name is invalid' do
    let(:first_name) { '' }

    it { is_expected.to_not be_valid }
  end

  context 'when the last name is invalid' do
    let(:last_name) { '' }

    it { is_expected.to_not be_valid }
  end

  context 'when the password is invalid' do
    let(:password) { 'foo' }

    it { is_expected.to_not be_valid }

    it 'should include the custom error message' do
      instance.valid?

      expect(instance.errors[:password]).to include('Invalid password length, must be 6-12 characters')
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
flexirest-1.12.4 spec/lib/activemodel_validations_spec.rb
flexirest-1.12.3 spec/lib/activemodel_validations_spec.rb
flexirest-1.12.2 spec/lib/activemodel_validations_spec.rb
flexirest-1.12.1 spec/lib/activemodel_validations_spec.rb
flexirest-1.12.0 spec/lib/activemodel_validations_spec.rb
flexirest-1.11.3 spec/lib/activemodel_validations_spec.rb
flexirest-1.11.2 spec/lib/activemodel_validations_spec.rb
flexirest-1.11.1 spec/lib/activemodel_validations_spec.rb
flexirest-1.11.0 spec/lib/activemodel_validations_spec.rb
flexirest-1.10.12 spec/lib/activemodel_validations_spec.rb
flexirest-1.10.11 spec/lib/activemodel_validations_spec.rb
flexirest-1.10.10 spec/lib/activemodel_validations_spec.rb
flexirest-1.10.9 spec/lib/activemodel_validations_spec.rb
flexirest-1.10.8 spec/lib/activemodel_validations_spec.rb
flexirest-1.10.7 spec/lib/activemodel_validations_spec.rb
flexirest-1.10.6 spec/lib/activemodel_validations_spec.rb
flexirest-1.10.5 spec/lib/activemodel_validations_spec.rb
flexirest-1.10.4 spec/lib/activemodel_validations_spec.rb
flexirest-1.10.3 spec/lib/activemodel_validations_spec.rb
flexirest-1.10.2 spec/lib/activemodel_validations_spec.rb