Sha256: 4abb2df22057a3318b9974ed28ac966addb55fa583ba3a9afc744df72078e298

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

require "render/array_attribute"

module Render
  describe ArrayAttribute do
    describe "#initialize" do
      it "sets name to title for faux_value generators to match" do
        ArrayAttribute.new({ title: "ids", items: { type: UUID } }).name.should == :ids
      end

      describe "#format" do
        it "is set from options" do
          ArrayAttribute.new({ items: { type: String, format: UUID } }).format.should == UUID
        end

        it "is nil for indeterminable types" do
          ArrayAttribute.new({ items: { type: String, format: "random-iso-format" } }).format.should == nil
        end
      end
    end

    describe "archetype" do
      it "returns only a value" do
        id = UUID.generate
        attribute = ArrayAttribute.new({ items: { format: UUID } })
        attribute.serialize([id]).should == [id]
      end
    end

    describe "#faux_data" do
      before(:each) do
        Render.stub({ live: false })
        @attribute = ArrayAttribute.new({ items: { type: Float, required: true } })
      end

      it "uses explicit value for faux data" do
        explicit_data = [rand(10.0)]
        @attribute.serialize(explicit_data).should == explicit_data
      end

      it "generates fake number of elements" do
        faux_data = @attribute.serialize
        faux_data.size.should be_between(0, ArrayAttribute::FAUX_DATA_UPPER_LIMIT)
        faux_data.sample.class.should == Float
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
render-0.0.3 spec/unit/array_attribute_spec.rb