Sha256: fe9cf5d388db463858c782f5be12c94a87c7614a17916da67c159d313afbffd6

Contents?: true

Size: 1.53 KB

Versions: 9

Compression:

Stored size: 1.53 KB

Contents

require 'spec_helper'

module MongoModel
  specs_for(Document, EmbeddedDocument) do
    define_class(:TestDocument, described_class) do
      property :timestamp, Time
      property :datestamp, Date
      property :datetime,  DateTime
    end
    
    subject { TestDocument.new }
    
    describe "multiparameter assignment from select" do
      context "setting a Time" do
        it "combines and assign parameters as Time" do
          subject.attributes = {
            "timestamp(1i)" => "2009",
            "timestamp(2i)" => "10",
            "timestamp(3i)" => "5",
            "timestamp(4i)" => "14",
            "timestamp(5i)" => "35"
          }
          
          subject.timestamp.should == Time.zone.local(2009, 10, 5, 14, 35)
        end
      end
      
      context "setting a Date" do
        it "combines and assign parameters as Date" do
          subject.attributes = {
            "datestamp(1i)" => "2008",
            "datestamp(2i)" => "4",
            "datestamp(3i)" => "9"
          }
          
          subject.datestamp.should == Date.new(2008, 4, 9)
        end
      end
      
      context "setting a DateTime" do
        it "combines and assign parameters as DateTime" do
          subject.attributes = {
            "datetime(1i)" => "2009",
            "datetime(2i)" => "10",
            "datetime(3i)" => "5",
            "datetime(4i)" => "14",
            "datetime(5i)" => "35"
          }
          
          subject.datetime.should == DateTime.civil(2009, 10, 5, 14, 35)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mongomodel-0.5.5 spec/mongomodel/concerns/attribute_methods/multi_parameter_assignment_spec.rb
mongomodel-0.5.4 spec/mongomodel/concerns/attribute_methods/multi_parameter_assignment_spec.rb
mongomodel-0.5.3 spec/mongomodel/concerns/attribute_methods/multi_parameter_assignment_spec.rb
mongomodel-0.5.2 spec/mongomodel/concerns/attribute_methods/multi_parameter_assignment_spec.rb
mongomodel-0.5.1 spec/mongomodel/concerns/attribute_methods/multi_parameter_assignment_spec.rb
mongomodel-0.5.0 spec/mongomodel/concerns/attribute_methods/multi_parameter_assignment_spec.rb
mongomodel-0.4.9 spec/mongomodel/concerns/attribute_methods/multi_parameter_assignment_spec.rb
mongomodel-0.4.8 spec/mongomodel/concerns/attribute_methods/multi_parameter_assignment_spec.rb
mongomodel-0.4.7 spec/mongomodel/concerns/attribute_methods/multi_parameter_assignment_spec.rb