Sha256: d1987bb86969c37a014a13fbe9be7448d3f193e49dc6c26f8bb6613909690e8d
Contents?: true
Size: 1.37 KB
Versions: 26
Compression:
Stored size: 1.37 KB
Contents
require 'test_helper' module PushType class MatrixFieldTest < ActiveSupport::TestCase class TestLocation < PushType::Structure field :key end class TestPage < PushType::Node field :foo, :matrix, grid: false do field :key, :string field :val, :text end field :bar, :matrix, class: 'push_type/matrix_field_test/test_location' end let(:node) { TestPage.create FactoryGirl.attributes_for(:node, foo: val, bar: [{key: '123'}]) } let(:val) { [{ key: 'a', val: 'b' }, { key: 'x', val: 'y' }] } let(:field) { node.fields[:foo] } it { field.template.must_equal 'matrix' } 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' }, { 'key' => 'x', 'val' => 'y' }] } it { field.value.all? { |v| v.class.name == 'PushType::Structure' }.must_equal true } it { field.value.first.fields.keys.must_include :key, :val } it { field.value[0].key.must_equal 'a' } it { field.value[1].val.must_equal 'y' } it { node.bar.first.must_be_instance_of TestLocation } it { node.bar.first.class.ancestors.must_include PushType::Structure } it { node.fields[:bar].grid?.must_equal true } it { node.fields[:foo].grid?.must_equal false } end end
Version data entries
26 entries across 26 versions & 1 rubygems