Sha256: f1d96a8b7cb7006b588fc3c352d1d53763cacff08e0db26b4784686d74dfacd2

Contents?: true

Size: 1.27 KB

Versions: 26

Compression:

Stored size: 1.27 KB

Contents

require 'test_helper'
require 'active_model'
require 'roar/rails/validations_representer'


class ValidationsTest < MiniTest::Spec
 class Comment
    include ActiveModel::Validations
    validates :name, :presence => true
  end

  describe "ValidatorRepresenter" do
    it "renders a representation in #to_json" do
      assert_equal "{\"kind\":\"presence\",\"options\":{}}", Comment._validators[:name].first.extend(ValidatorsRepresenter::ValidatorRepresenter).to_json
    end
    
    it "parses validator config in #from_json" do
      validator = ValidatorsRepresenter::ValidatorClient.new.extend(ValidatorsRepresenter::ValidatorRepresenter).from_json("{\"kind\":\"presence\",\"attributes\":[\"name\"],\"options\":{}}")
      assert_equal "presence", validator.kind
      assert_equal({}, validator.options)
    end
  end
  
  describe "ValidatorsRepresenter" do
    it "renders a collection in #to_json" do
      assert_equal "{\"name\":[{\"kind\":\"presence\",\"options\":{}}]}", Comment._validators.extend(ValidatorsRepresenter).to_json
    end
    
    it "parses validators in #from_json" do
      validations = {}.extend(ValidatorsRepresenter).from_json("{\"name\":[{\"kind\":\"presence\",\"options\":[]}]}")
      assert_equal "presence", validations["name"].first.kind
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/roar-rails-1.2.0/test/validations_test.rb
roar-rails-1.2.0 test/validations_test.rb
roar-rails-1.1.0 test/validations_test.rb
roar-rails-1.0.2 test/validations_test.rb
roar-rails-1.0.1 test/validations_test.rb
roar-rails-1.0.0 test/validations_test.rb
roar-rails-0.1.6 test/validations_test.rb
roar-rails-0.1.5 test/validations_test.rb
roar-rails-0.1.4 test/validations_test.rb
roar-rails-0.1.3 test/validations_test.rb
roar-rails-0.1.2 test/validations_test.rb
roar-rails-0.1.1 test/validations_test.rb
roar-rails-0.1.0 test/validations_test.rb
roar-rails-0.0.15 test/validations_test.rb
roar-rails-0.0.14 test/validations_test.rb
roar-rails-0.0.13 test/validations_test.rb
roar-rails-0.0.12 test/validations_test.rb
roar-rails-0.0.11 test/validations_test.rb
roar-rails-0.0.10 test/validations_test.rb
roar-rails-0.0.9 test/validations_test.rb