Sha256: fb6b7c3e9d121dcb7539c264f9d5e0fa5fbca68f9387627a6aba238d69346f81

Contents?: true

Size: 1.47 KB

Versions: 9

Compression:

Stored size: 1.47 KB

Contents

require 'test_helper'

module PushType
  class CustomizableTest < ActiveSupport::TestCase

    class TestPage < PushType::Node
      field :foo
      field :bar, :text
      field :baz, validates: { presence: true }
      field :qux, :number, validates: { presence: true }
    end

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

    it { TestPage.fields.must_be_instance_of Hash }
    it { fields.must_be_instance_of Hash }

    describe '.field' do
      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 '#attribute_for_inspect' do
      it { page.attribute_for_inspect(:field_store).must_equal "[:foo, :bar, :baz, :qux]" }
    end

    describe '#attribute_changed?' do
      it { page.foo_changed?.must_equal false }
      it { page.changes.key?(:foo).must_equal false }

      it 'returns true when attribute is changed' do
        page.foo = 'value'
        page.foo_changed?.must_equal true
      end

      it 'returns true when attribute is changed' do
        page.foo = 'value'
        page.changes.key?(:foo).must_equal true
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
push_type_core-0.12.1 test/models/concerns/push_type/customizable_test.rb
push_type_core-0.12.0 test/models/concerns/push_type/customizable_test.rb
push_type_core-0.12.0.beta.1 test/models/concerns/push_type/customizable_test.rb
push_type_core-0.11.2 test/models/concerns/push_type/customizable_test.rb
push_type_core-0.11.1 test/models/concerns/push_type/customizable_test.rb
push_type_core-0.11.0.beta.2 test/models/concerns/push_type/customizable_test.rb
push_type_core-0.11.0.beta.1 test/models/concerns/push_type/customizable_test.rb
push_type_core-0.10.4 test/models/concerns/push_type/customizable_test.rb
push_type_core-0.10.3 test/models/concerns/push_type/customizable_test.rb