Sha256: 849586112c0eb5b9bbdfb48b23ad7765aa9ce5d08cd63aff0d5080cb359033ac

Contents?: true

Size: 1.95 KB

Versions: 28

Compression:

Stored size: 1.95 KB

Contents

require 'spec_helper'

describe AttributeType do
  it "can be instantiated" do
    AttributeType.new.should be_an_instance_of(AttributeType)
  end

  it "can be saved successfully" do
    new_attribute_type = AttributeType.create(:description => "Some description")
    new_attribute_type.should be_persisted
    new_attribute_type.internal_identifier.should eq("some_description")

  end

  describe "values_by_date_range" do
    it "should return all values attatched to AttributeType for the given date range" do
      attribute_type = AttributeType.new
      attribute_type.data_type = 'Date'
      attribute_type.description = 'Some Date Attribute'
      attribute_type.save

      in_range_value = AttributeValue.new
      in_range_value.value = "2011-12-15 00:00:00"
      attribute_type.attribute_values << in_range_value
      in_range_value.save

      out_of_range_value = AttributeValue.new
      out_of_range_value.value = "2011-12-31 00:00:00"
      attribute_type.attribute_values << out_of_range_value
      out_of_range_value.save
      
      start_date = Date.civil(2011, 12, 1)
      end_date = Date.civil(2011, 12, 30)

      date_range_values = attribute_type.values_by_date_range(start_date, end_date)

      date_range_values.should include(in_range_value)
    end
  end

  describe "find_by_iid_with_description" do
    it "should return an AttributeType object with the given description" do
      attribute_type = AttributeType.create(:description => "Some Description")
      found_attribute_type = AttributeType.find_by_iid_with_description("some description")
      found_attribute_type.should eq(attribute_type)
    end
  end

  describe "update_iid" do
    it "should set the iid to a snake case version of the description when a new attribute type is created" do
      attribute_type = AttributeType.create(:description => " Some attribute type ", :data_type => "text")
      attribute_type.internal_identifier.should eq("some_attribute_type")
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
knitkit-3.2.0 spec/models/attribute_type_spec.rb
knitkit-3.0.0 spec/models/attribute_type_spec.rb
knitkit-2.1.15 spec/models/attribute_type_spec.rb
knitkit-2.1.14 spec/models/attribute_type_spec.rb
knitkit-2.1.13 spec/models/attribute_type_spec.rb
knitkit-2.1.12 spec/models/attribute_type_spec.rb
knitkit-2.1.11 spec/models/attribute_type_spec.rb
knitkit-2.1.10 spec/models/attribute_type_spec.rb
knitkit-2.1.9 spec/models/attribute_type_spec.rb
knitkit-2.1.8 spec/models/attribute_type_spec.rb
knitkit-2.1.7 spec/models/attribute_type_spec.rb
knitkit-2.1.6 spec/models/attribute_type_spec.rb
knitkit-2.1.5 spec/models/attribute_type_spec.rb
knitkit-2.1.4 spec/models/attribute_type_spec.rb
knitkit-2.1.3 spec/models/attribute_type_spec.rb
knitkit-2.1.2 spec/models/attribute_type_spec.rb
knitkit-2.1.1 spec/models/attribute_type_spec.rb
knitkit-2.1.0 spec/models/attribute_type_spec.rb
knitkit-2.0.11 spec/models/attribute_type_spec.rb
knitkit-2.0.10 spec/models/attribute_type_spec.rb