Skip to content

Instantly share code, notes, and snippets.

@Talleyran
Created October 30, 2011 10:47
Show Gist options
  • Save Talleyran/1325775 to your computer and use it in GitHub Desktop.
Save Talleyran/1325775 to your computer and use it in GitHub Desktop.
spec для описания модели Layer
require 'spec_helper'
def valid_layer_attributes
{ structure: {
f1: :array,
f2: :big_decimal,
f3: :boolean,
f4: :date,
f5: :date_time,
f6: :float,
f7: :hash,
f8: :integer,
f9: :range,
f10: :string,
f11: :symbol,
f12: :time,
},
is_spatial: true
}
end
def valid_layers_object_attributes
{
f1: [1,2,3],
f2: 10000000,
f3: true,
f4: Date.parse('2011-01-01'),
f5: Time.parse('2011-01-01').to_datetime,
f6: 1.1,
f7: {a: 1, b: 2},
f8: 1,
f9: 1..10, #Cannot serialize an object of class Range (type 9) into BSON.
f10: 'aaa',
f11: :symbol,
f12: Time.parse('2011-01-01')
}
end
describe Layer do
before :all do
Layer.destroy_all
end
it 'should take structure.' do
layer = Layer.new valid_layer_attributes
layer.structure.should eq( valid_layer_attributes[:structure] )
end
it 'should save structure as json.' do
layer = Layer.new valid_layer_attributes
layer.save
layer.structure_json.should eq( layer.structure.to_json )
end
it 'should parse structure from json.' do
layer = Layer.new valid_layer_attributes
layer.save
layer.structure.should eq( valid_layer_attributes[:structure] )
end
it "should create layer's object." do
layer = Layer.new valid_layer_attributes
layer.new_layers_object( valid_layers_object_attributes ).class.should eq(LayersObject)
end
describe LayersObject do
it "should save if layer not saved" do
layer = Layer.new valid_layer_attributes
layers_object = layer.new_layers_object valid_layers_object_attributes
layers_object.save.should eq(true)
end
it "should store values in field's objects." do
layer = Layer.new valid_layer_attributes
layer.save
layers_object = layer.new_layers_object valid_layers_object_attributes
layers_object.save
layers_object.fields_objects.each{|field_object|
field_object.new_record?.should eq(false)
valid_layers_object_attributes[field_object.key].should eq(field_object.value)
}
end
it "should take values" do
layer = Layer.new valid_layer_attributes
layer.save
layers_object = layer.new_layers_object valid_layers_object_attributes
layers_object.save
valid_layers_object_attributes.each{|k,v|
layers_object.prop(k).should eq(v)
}
end
it "should get prop values if layer's object not saved" do
layer = Layer.new valid_layer_attributes
layers_object = layer.new_layers_object valid_layers_object_attributes
valid_layers_object_attributes.each{|k,v|
layers_object.prop(k).should eq(v)
}
end
pending "should write values by set_prop(k,v)"
pending "should write values by update_props(attrs)"
describe FieldsObject do
pending "should write values by value="
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment