Sha256: 17df86eaf9c6ba402e90bd379b7eda117e752a2501263912efb73c6adca1e6c1

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

require 'test_helper'

module PushType
  class AssetFieldTest < ActiveSupport::TestCase

    let(:field) { PushType::AssetField.new :foo }
    
    it { field.json_key.must_equal :foo_id }
    it { field.template.must_equal 'asset' }
    it { field.id_attr.must_equal 'foo-asset-modal' }
    it { field.relation_class.must_equal PushType::Asset }
    
    describe 'initialized on node' do
      before do
        TestPage.instance_variable_set '@fields', ActiveSupport::OrderedHash.new
        TestPage.field :foo, :asset
      end
      after { TestPage.instance_variable_set '@fields', ActiveSupport::OrderedHash.new }

      let(:node)  { TestPage.create attrs }
      let(:attrs) { FactoryGirl.attributes_for(:node) }

      describe 'without asset' do
        it { node.foo_id.must_be_nil }
        it { node.foo.must_be_nil }
      end

      describe 'with asset' do
        let(:attrs) { FactoryGirl.attributes_for(:node).merge(foo_id: asset.id) }
        let(:asset) { FactoryGirl.create :asset }
        it { node.foo_id.must_equal asset.id }
        it { node.foo.must_equal asset }
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
push_type_core-0.5.3 test/fields/push_type/asset_field_test.rb
push_type_core-0.5.2 test/fields/push_type/asset_field_test.rb