@@ -63,19 +63,69 @@ class IssueTest < GttTest
63
63
assert_geojson_collection Issue . geojson
64
64
end
65
65
66
- test 'should ignore small geom changes' do
66
+ test 'should ignore small point geom changes' do
67
67
coordinates = [ 135.220734222412 , 34.7056906000311 ]
68
68
69
- @issue . geojson = point_geojson ( coordinates )
70
- old_coordinates = JSON . parse ( @issue . geojson ) . fetch ( "geometry" ) . fetch ( "coordinates" )
71
- new_coordinates = old_coordinates . each { |c | c + 0.00000001 }
69
+ @issue . update_attribute :geojson , point_geojson ( coordinates )
70
+ @issue . instance_variable_set "@geojson" , nil
71
+ old_coordinates = @issue . geojson [ "geometry" ] [ "coordinates" ]
72
+
73
+ new_coordinates = old_coordinates . map { |c | c + 0.000000001 }
72
74
@issue . update_attribute :geojson , point_geojson ( new_coordinates )
73
- @issue . reload
74
- assert_equal old_coordinates , JSON . parse ( @issue . geojson ) . fetch ( "geometry" ) . fetch ( "coordinates" )
75
+ @issue . instance_variable_set "@geojson" , nil
76
+ assert_equal old_coordinates , @issue . geojson [ "geometry" ] [ "coordinates" ]
75
77
76
78
new_coordinates = [ old_coordinates [ 0 ] + 0.2 , old_coordinates [ 1 ] ]
77
79
@issue . update_attribute :geojson , point_geojson ( new_coordinates )
78
- @issue . reload
79
- assert_equal new_coordinates , JSON . parse ( @issue . geojson ) . fetch ( "geometry" ) . fetch ( "coordinates" )
80
+ @issue . instance_variable_set "@geojson" , nil
81
+ assert_equal new_coordinates , @issue . geojson [ "geometry" ] [ "coordinates" ]
82
+ end
83
+
84
+ test 'should ignore small linestring geom changes' do
85
+ coordinates = test_coordinates [ 0 ]
86
+
87
+ @issue . update_attribute :geojson , linestring_geojson ( coordinates )
88
+ @issue . instance_variable_set "@geojson" , nil
89
+ old_coordinates = @issue . geojson [ "geometry" ] [ "coordinates" ]
90
+
91
+ new_coordinates = old_coordinates . map { |c | [ c [ 0 ] + 0.000000001 , c [ 1 ] + 0.000000001 ] }
92
+ @issue . update_attribute :geojson , linestring_geojson ( new_coordinates )
93
+ @issue . instance_variable_set "@geojson" , nil
94
+ assert_equal old_coordinates , @issue . geojson [ "geometry" ] [ "coordinates" ]
95
+
96
+ new_coordinates = old_coordinates . map { |c | [ c [ 0 ] + 0.2 , c [ 1 ] ] }
97
+ @issue . update_attribute :geojson , linestring_geojson ( new_coordinates )
98
+ @issue . instance_variable_set "@geojson" , nil
99
+ assert_equal new_coordinates , @issue . geojson [ "geometry" ] [ "coordinates" ]
100
+
101
+ new_coordinates = old_coordinates . map { |c | [ c [ 0 ] , c [ 1 ] ] }
102
+ new_coordinates . delete_at ( 1 )
103
+ @issue . update_attribute :geojson , linestring_geojson ( new_coordinates )
104
+ @issue . instance_variable_set "@geojson" , nil
105
+ assert_equal new_coordinates , @issue . geojson [ "geometry" ] [ "coordinates" ]
106
+ end
107
+
108
+ test 'should ignore small polygon geom changes' do
109
+ coordinates = test_coordinates
110
+
111
+ @issue . update_attribute :geojson , polygon_geojson ( coordinates )
112
+ @issue . instance_variable_set "@geojson" , nil
113
+ old_coordinates = @issue . geojson [ "geometry" ] [ "coordinates" ]
114
+
115
+ new_coordinates = [ old_coordinates [ 0 ] . map { |c | [ c [ 0 ] + 0.000000001 , c [ 1 ] + 0.000000001 ] } ]
116
+ @issue . update_attribute :geojson , polygon_geojson ( new_coordinates )
117
+ @issue . instance_variable_set "@geojson" , nil
118
+ assert_equal old_coordinates , @issue . geojson [ "geometry" ] [ "coordinates" ]
119
+
120
+ new_coordinates = [ old_coordinates [ 0 ] . map { |c | [ c [ 0 ] + 0.2 , c [ 1 ] ] } ]
121
+ @issue . update_attribute :geojson , polygon_geojson ( new_coordinates )
122
+ @issue . instance_variable_set "@geojson" , nil
123
+ assert_equal new_coordinates , @issue . geojson [ "geometry" ] [ "coordinates" ]
124
+
125
+ new_coordinates = [ old_coordinates [ 0 ] . map { |c | [ c [ 0 ] , c [ 1 ] ] } ]
126
+ new_coordinates [ 0 ] . delete_at ( 1 )
127
+ @issue . update_attribute :geojson , polygon_geojson ( new_coordinates )
128
+ @issue . instance_variable_set "@geojson" , nil
129
+ assert_equal new_coordinates , @issue . geojson [ "geometry" ] [ "coordinates" ]
80
130
end
81
131
end
0 commit comments