Sha256: fa6c712d58abd9846e8a55dd96e2ffc4f553f05caf0f7c1bccc2a44922ec99a9

Contents?: true

Size: 927 Bytes

Versions: 3

Compression:

Stored size: 927 Bytes

Contents

require 'test_helper'
require 'encrypted_form_fields/helpers/form_helper'

class FormBuilderTest < MiniTest::Unit::TestCase
  def setup
    super
    @template = Object.new
    @template.extend ActionView::Helpers::FormHelper
    @template.extend EncryptedFormFields::Helpers::FormHelper
    @template.extend ActionView::Helpers::FormOptionsHelper
    @object = Struct.new(:bar).new(SecureRandom.base64)
  end

  def test_encrypted_form_tag
    form_builder = ActionView::Helpers::FormBuilder.new(:foo, @object, @template, {})
    tag = HTML::Document.new(form_builder.encrypted_field(:bar)).find(tag: "input")
    decrypted_value = EncryptedFormFields.decrypt_and_verify(tag.attributes["value"])
    assert_equal @object.bar, decrypted_value
    assert_equal "_encrypted[foo][bar]", tag.attributes["name"]
    assert_equal "hidden", tag.attributes["type"]
    assert_equal "_encrypted_foo_bar", tag.attributes["id"]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
encrypted_form_fields-0.2.1 test/form_builder_test.rb
encrypted_form_fields-0.2.0 test/form_builder_test.rb
encrypted_form_fields-0.1.0 test/form_builder_test.rb