Sha256: d4cc9b433558a1aba7d8d77ddfac1c66c9bd9f119954b0da3ad0ad956a45e9e8

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

require 'test_helper'

module PushType
  class CustomizableTest < ActiveSupport::TestCase

    let(:page) { TestPage.new }
    let(:fields) { page.fields }

    it { TestPage.fields.must_be_instance_of ActiveSupport::OrderedHash }
    it { fields.must_be_instance_of ActiveSupport::OrderedHash }

    describe '.field' do
      before do
        TestPage.instance_variable_set '@fields', ActiveSupport::OrderedHash.new
        TestPage.field :foo
        TestPage.field :bar, :text
        TestPage.field :baz, validates: { presence: true }
        TestPage.field :qux, :number, validates: { presence: true }
      end

      after do
        TestPage.instance_variable_set '@fields', ActiveSupport::OrderedHash.new
        TestPage.clear_validators!
      end

      it { fields[:foo].must_be_instance_of StringField }
      it { fields[:bar].must_be_instance_of TextField }
      it { fields[:baz].must_be_instance_of StringField }
      it { TestPage.validators_on(:baz).map(&:class).must_include ActiveRecord::Validations::PresenceValidator }
      it { fields[:qux].must_be_instance_of NumberField }
      it { TestPage.validators_on(:qux).map(&:class).must_include ActiveRecord::Validations::PresenceValidator }
    end

    describe '#field_params' do
      before do
        TestPage.instance_variable_set '@fields', ActiveSupport::OrderedHash.new
        TestPage.field :foo
        TestPage.field :bar, :text
        TestPage.field :baz, :tag_list
      end
      after { TestPage.instance_variable_set '@fields', ActiveSupport::OrderedHash.new }

      it { page.field_params.must_equal [:foo, :bar, { baz: [] }] }
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
push_type_core-0.5.3 test/models/concerns/push_type/customizable_test.rb
push_type_core-0.5.2 test/models/concerns/push_type/customizable_test.rb