Sha256: 9f213d5c06e4097451abf6d6df0ff18d48b9192d975b53dddb036411abef5ea0

Contents?: true

Size: 1.13 KB

Versions: 28

Compression:

Stored size: 1.13 KB

Contents

require 'spec_helper'

unless RUBY_PLATFORM == 'opal'
  describe 'validations block' do
    let(:model) { test_model_class.new }

    let(:test_model_class) do
      Class.new(Volt::Model) do
        validations do
          if _is_ready == true
            validate :name, length: 5
          end
        end
      end
    end

    let(:test_model_action_pass_class) do
      Class.new(Volt::Model) do
        validations do |action|
          # Only validation the name on update
          if action == :update
            validate :name, length: 5
          end
        end
      end
    end

    it 'should run conditional validations in the validations block' do
      a = test_model_class.new(name: 'Jo')

      a.validate!.sync
      expect(a.errors.size).to eq(0)

      a._is_ready = true
      a.validate!.sync

      expect(a.errors.size).to eq(1)
    end

    it 'should send the action name to the validations block' do
      jo = test_model_action_pass_class.new(name: 'Jo')

      jo.validate!.sync
      expect(jo.errors.size).to eq(0)

      store._people << jo

      jo.validate!.sync
      expect(jo.errors.size).to eq(1)

    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
volt-0.9.6 spec/models/validators/block_validations_spec.rb
volt-0.9.6.pre3 spec/models/validators/block_validations_spec.rb
volt-0.9.6.pre2 spec/models/validators/block_validations_spec.rb
volt-0.9.6.pre1 spec/models/validators/block_validations_spec.rb
volt-0.9.5 spec/models/validators/block_validations_spec.rb
volt-0.9.5.pre12 spec/models/validators/block_validations_spec.rb
volt-0.9.5.pre11 spec/models/validators/block_validations_spec.rb
volt-0.9.5.pre9 spec/models/validators/block_validations_spec.rb
volt-0.9.5.pre8 spec/models/validators/block_validations_spec.rb
volt-0.9.5.pre7 spec/models/validators/block_validations_spec.rb
volt-0.9.5.pre6 spec/models/validators/block_validations_spec.rb
volt-0.9.5.pre5 spec/models/validators/block_validations_spec.rb
volt-0.9.5.pre4 spec/models/validators/block_validations_spec.rb
volt-0.9.5.pre3 spec/models/validators/block_validations_spec.rb
volt-0.9.5.pre2 spec/models/validators/block_validations_spec.rb
volt-0.9.5.pre1 spec/models/validators/block_validations_spec.rb
volt-0.9.4 spec/models/validators/block_validations_spec.rb
volt-0.9.4.pre5 spec/models/validators/block_validations_spec.rb
volt-0.9.4.pre3 spec/models/validators/block_validations_spec.rb
volt-0.9.4.pre2 spec/models/validators/block_validations_spec.rb