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.8.0 spec/lib/activemodel_validations_spec.rb
flexirest-1.7.9 spec/lib/activemodel_validations_spec.rb
flexirest-1.7.8 spec/lib/activemodel_validations_spec.rb
flexirest-1.7.7 spec/lib/activemodel_validations_spec.rb
flexirest-1.7.6 spec/lib/activemodel_validations_spec.rb
flexirest-1.7.5 spec/lib/activemodel_validations_spec.rb
flexirest-1.7.4 spec/lib/activemodel_validations_spec.rb
flexirest-1.7.3 spec/lib/activemodel_validations_spec.rb
flexirest-1.7.2 spec/lib/activemodel_validations_spec.rb
flexirest-1.7.1 spec/lib/activemodel_validations_spec.rb
flexirest-1.7.0 spec/lib/activemodel_validations_spec.rb
flexirest-1.6.9 spec/lib/activemodel_validations_spec.rb
flexirest-1.6.8 spec/lib/activemodel_validations_spec.rb