Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added specs to test coord_mode :lng_lat and :lat_lng

  • Loading branch information...
commit 781a528463a0a52f324e01884da3a40545c4a6dc 1 parent d48a4be
@kristianmandrup authored
View
34 spec/geo_calc/core_ext/array_ext_spec.rb
@@ -39,37 +39,3 @@
end
end
-class GeoPoint
- mattr_accessor :coord_mode
-end
-
-describe 'coord mode' do
- context 'coord_mode = :lng_lat' do
- before do
- GeoPoint.coord_mode = :lng_lat
- end
-
- it 'should not reverse array' do
- [2, 3].to_lng_lat.should == [2, 3]
- end
-
- it 'should reverse array' do
- [2, 3].to_lat_lng.should == [3, 2]
- end
- end
-
- context 'coord_mode = :lat_lng' do
- before do
- GeoPoint.coord_mode = :lat_lng
- end
-
- it 'should not reverse array' do
- [2, 3].to_lat_lng.should == [2, 3]
- end
-
- it 'should reverse array' do
- [2, 3].to_lng_lat.should == [3, 2]
- end
- end
-end
-
View
103 spec/geo_calc/core_ext/coord_mode_spec.rb
@@ -0,0 +1,103 @@
+require 'spec_helper'
+# require 'geo_point'
+
+class GeoPoint
+ mattr_accessor :coord_mode
+end
+
+describe 'GeoPoint.coord_mode' do
+ context 'coord_mode is nil (default is :lat_lng)' do
+ before do
+ GeoPoint.coord_mode = nil
+ end
+ end
+
+ # make shared example for default mode!
+ context 'coord_mode is :lat_lng' do
+ before do
+ GeoPoint.coord_mode = :lat_lng
+ end
+
+ describe 'Array' do
+ describe '#to_lng_lat' do
+ it 'should reverse array' do
+ [2, 3].to_lng_lat.should == [3, 2]
+ end
+ end
+
+ describe '#to_lat_lng' do
+ it 'should not reverse array' do
+ [2, 3].to_lat_lng.should == [2, 3]
+ end
+ end
+ end # Array
+
+ describe 'String' do
+ describe '#to_lat_lng' do
+ it 'should return Array in same order' do
+ @str = "4, 3"
+ @str.to_lat_lng.should == [4, 3]
+ end
+ end
+
+ describe '#to_lng_lat' do
+ it 'should return reversed Array' do
+ @str = "4, 3"
+ @str.to_lng_lat.should == [3,4]
+ end
+ end
+ end # String
+ end
+
+ context 'coord_mode is :lng_lat' do
+ before do
+ GeoPoint.coord_mode = :lng_lat
+ end
+
+ describe 'Array' do
+ describe '#to_lng_lat' do
+ it 'should not reverse array' do
+ [2, 3].to_lng_lat.should == [2, 3]
+ end
+ end
+
+ describe '#to_lat_lng' do
+ it 'should reverse array' do
+ [2, 3].to_lat_lng.should == [3, 2]
+ end
+ end
+ end # Array
+
+ describe 'String' do
+ describe '#to_lng_lat' do
+ it 'should return Array in same order' do
+ @str = "4, 3"
+ @str.to_lng_lat.should == [4, 3]
+ end
+ end
+
+ describe '#to_lat_lng' do
+ it 'should return reversed Array' do
+ @str = "4, 3"
+ @str.to_lat_lng.should == [3,4]
+ end
+ end
+ end # String
+
+ describe 'Hash' do
+ describe '#to_lng_lat' do
+ it 'should return Array with lng, lat' do
+ hash = {:lng => 2, :lat => "3"}
+ hash.to_lng_lat.should == [2, 3]
+ end
+ end
+
+ describe '#to_lat_lng' do
+ it 'should return Array with lat, lng' do
+ hash = {:lng => 2, :lat => "3"}
+ hash.to_lat_lng.should == [3, 2]
+ end
+ end
+ end
+ end
+end
View
44 spec/geo_calc/core_ext/hash_ext_spec.rb
@@ -41,50 +41,6 @@
@hash.to_lng_lat.should == [2, 3]
end
end
-
- context 'GeoPoint.coord_mode == :lng_lat' do
- describe '#to_coords' do
- it 'should return Array with lng, lat' do
- GeoPoint.coord_mode = :lng_lat
- @hash = {:lng => 2, :lat => "3"}
- @hash.to_coords.should == [2, 3]
- end
- end
- end
-
- context 'GeoPoint.coord_mode == :lat_lng' do
- describe '#to_coords' do
- it 'should return Array with lat, lng' do
- GeoPoint.coord_mode = :lat_lng
- @hash = {:lng => 2, :lat => "3"}
- @hash.to_coords.should == [3, 2]
- end
- end
- end
-
- describe '#geo_point' do
- context 'GeoPoint.coord_mode == :lat_lng' do
- it 'should return Array with lng, lat' do
- GeoPoint.coord_mode = :lat_lng
- @hash = {:lng => 2, :lat => "3"}
- p = @hash.geo_point
- puts p.inspect
-
- p.to_lng_lat.should == [2, 3]
- end
- end
-
- context 'GeoPoint.coord_mode == :lng_lat' do
- it 'should return Array with lng, lat' do
- GeoPoint.coord_mode = :lng_lat
- @hash = {:lng => 2, :lat => "3"}
- p = @hash.geo_point
- puts p.inspect
-
- p.to_lng_lat.should == [2, 3]
- end
- end
- end
end # Hash
end
Please sign in to comment.
Something went wrong with that request. Please try again.