spec/dynamoid/persistence_spec.rb in dynamoid-0.5.0 vs spec/dynamoid/persistence_spec.rb in dynamoid-0.6.0
- old
+ new
@@ -87,10 +87,24 @@
it 'dumps and undump a serialized field' do
@address.options = (hash = {:x => [1, 2], "foobar" => 3.14})
Address.undump(@address.send(:dump))[:options].should == hash
end
+
+ it 'dumps a boolean field' do
+ @address.deliverable = true
+ Address.undump(@address.send(:dump))[:deliverable].should == true
+ end
+
+ it 'raises on an invalid boolean value' do
+ expect do
+ @address.deliverable = true
+ data = @address.send(:dump)
+ data[:deliverable] = 'foo'
+ Address.undump(data)
+ end.to raise_error(ArgumentError)
+ end
it 'loads a hash into a serialized field' do
hash = {foo: :bar}
Address.new(options: hash).options.should == hash
end
@@ -123,9 +137,41 @@
it 'works with a HashWithIndifferentAccess' do
hash = ActiveSupport::HashWithIndifferentAccess.new("city" => "Atlanta")
lambda {Address.create(hash)}.should_not raise_error
+ end
+
+ context 'create' do
+ {
+ Tweet => ['with range', { :tweet_id => 1, :group => 'abc' }],
+ Message => ['without range', { :message_id => 1, :text => 'foo', :time => DateTime.now }]
+ }.each_pair do |clazz, fields|
+ it "checks for existence of an existing object #{fields[0]}" do
+ t1 = clazz.new(fields[1])
+ t2 = clazz.new(fields[1])
+
+ t1.save
+ expect do
+ t2.save!
+ end.to raise_exception AWS::DynamoDB::Errors::ConditionalCheckFailedException
+ end
+ end
+ end
+
+ it 'raises when dumping a column with an unknown field type' do
+ clazz = Class.new do
+ include Dynamoid::Document
+ table :name => :addresses
+
+ field :city
+ field :options, :serialized
+ field :deliverable, :bad_type_specifier
+ end
+
+ expect do
+ clazz.new(:deliverable => true).dump
+ end.to raise_error(ArgumentError)
end
context 'update' do
before :each do