Sha256: ddcbefcfa0efb10d9e43ad23eb5e9d53229fde72397e54aeaff8440610000def

Contents?: true

Size: 1.26 KB

Versions: 30

Compression:

Stored size: 1.26 KB

Contents

require 'test_helper'

module PushType
  class StructureFieldTest < ActiveSupport::TestCase

    class TestPage < PushType::Node
      field :foo, :structure do
        field :key, :string
        field :val, :text
      end
      field :location, :structure
      field :bar, :structure, class: :location
    end

    let(:node)  { TestPage.create FactoryGirl.attributes_for(:node, foo: val) }
    let(:val)   { { key: 'a', val: 'b' } }
    let(:field) { node.fields[:foo] }

    it { field.template.must_equal 'structure' }
    it { field.fields.keys.must_include :key, :val }
    it { field.fields.values.map { |v| v.class }.must_include PushType::StringField, PushType::TextField }
    it { field.json_value.must_equal({ 'key' => 'a', 'val' => 'b' }) }
    it { field.value.class.name.must_equal 'PushType::Structure' }
    it { field.value.fields.keys.must_include :key, :val }
    it { field.value.key.must_equal 'a' }
    it { field.value.val.must_equal 'b' }

    it { node.foo.class.ancestors.must_include PushType::Structure }
    it { node.location.must_be_instance_of Location }
    it { node.bar.must_be_instance_of Location }
    it { node.location.class.ancestors.must_include PushType::Structure }
    it { node.bar.class.ancestors.must_include PushType::Structure }

  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
push_type_core-0.11.2 test/fields/push_type/structure_field_test.rb
push_type_core-0.11.1 test/fields/push_type/structure_field_test.rb
push_type_core-0.11.0.beta.2 test/fields/push_type/structure_field_test.rb
push_type_core-0.11.0.beta.1 test/fields/push_type/structure_field_test.rb
push_type_core-0.10.4 test/fields/push_type/structure_field_test.rb
push_type_core-0.10.3 test/fields/push_type/structure_field_test.rb
push_type_core-0.10.2 test/fields/push_type/structure_field_test.rb
push_type_core-0.10.1 test/fields/push_type/structure_field_test.rb
push_type_core-0.10.0 test/fields/push_type/structure_field_test.rb
push_type_core-0.10.0.beta.5 test/fields/push_type/structure_field_test.rb
push_type_core-0.10.0.beta.3 test/fields/push_type/structure_field_test.rb
push_type_core-0.9.5 test/fields/push_type/structure_field_test.rb
push_type_core-0.9.3 test/fields/push_type/structure_field_test.rb
push_type_core-0.9.2 test/fields/push_type/structure_field_test.rb
push_type_core-0.9.1 test/fields/push_type/structure_field_test.rb
push_type_core-0.9.0 test/fields/push_type/structure_field_test.rb
push_type_core-0.9.0.beta.4 test/fields/push_type/structure_field_test.rb
push_type_core-0.9.0.beta.3 test/fields/push_type/structure_field_test.rb
push_type_core-0.9.0.beta.2 test/fields/push_type/structure_field_test.rb
push_type_core-0.8.2 test/fields/push_type/structure_field_test.rb