From cfafdcfcabdb5750484379b9ba02daf704084854 Mon Sep 17 00:00:00 2001 From: Kaustubh Nair Date: Wed, 15 May 2019 23:13:47 +0530 Subject: [PATCH 1/7] Add annotation tests and remove redundant code --- app/models/user.rb | 5 ----- app/models/way.rb | 4 ---- test/unit/annotation_test.rb | 10 ++++++++++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 25cc2d7ee..b2ccf4cff 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -27,11 +27,6 @@ class User < ActiveRecord::Base # We really need a Dispatch Chain here or something. # This will also let us return a human error message. # - def self.authenticate(login, password) - return nil if login.blank? || password.blank? - u = find_by_login(login.downcase) # need to get the salt - u && u.authenticated?(password) ? u : nil - end def login=(value) write_attribute :login, (value ? value.downcase : nil) diff --git a/app/models/way.rb b/app/models/way.rb index 4e8ba65bb..8f5bf675f 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -2,8 +2,4 @@ class Way < ActiveRecord::Base attr_accessible :body, :lat, :lon, :map_id, :color has_many :nodes, :dependent => :destroy - def bbox=(bbox) - # counting from left, counter-clockwise - self.lon1,self.lat2,self.lon2,self.lat1 = bbox - end end diff --git a/test/unit/annotation_test.rb b/test/unit/annotation_test.rb index f3fdcb99f..94aa7e86a 100644 --- a/test/unit/annotation_test.rb +++ b/test/unit/annotation_test.rb @@ -17,6 +17,16 @@ def setup end test 'geometry type' do + @annotation.annotation_type = 'Some random Geometry' assert_equal @annotation.geometry_type, 'Point' + + @annotation.annotation_type = 'polyline' + assert_equal @annotation.geometry_type, 'LineString' + + @annotation.annotation_type = 'polygon' + assert_equal @annotation.geometry_type, 'Polygon' + + @annotation.annotation_type = 'rectangle' + assert_equal @annotation.geometry_type, 'Polygon' end end From 162ef371990dc113524a6784f53a44068cfc9b65 Mon Sep 17 00:00:00 2001 From: Kaustubh Nair Date: Wed, 15 May 2019 23:28:20 +0530 Subject: [PATCH 2/7] Add export tests --- test/unit/export_test.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/unit/export_test.rb b/test/unit/export_test.rb index 73e9d0de8..64e76ac06 100644 --- a/test/unit/export_test.rb +++ b/test/unit/export_test.rb @@ -9,6 +9,10 @@ class ExportTest < ActiveSupport::TestCase assert_not_nil Export.histogram_cm_per_pixel_in_tens assert_not_nil Export.export_count assert_not_nil Export.exporting + + Export.delete_all + assert_empty Export.histogram_cm_per_pixel + assert_equal 0, Export.average_cm_per_pixel end test "export running" do From e0c305b89a53828006f20de422da2bbffb53a21b Mon Sep 17 00:00:00 2001 From: Kaustubh Nair Date: Thu, 16 May 2019 00:11:00 +0530 Subject: [PATCH 3/7] Remove some code --- app/models/map.rb | 17 ++--------------- test/unit/map_test.rb | 11 +++++++++++ test/unit/warpable_test.rb | 4 ++++ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/models/map.rb b/app/models/map.rb index d6e2c8981..37f756559 100755 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -31,27 +31,14 @@ class Map < ActiveRecord::Base has_many :annotations, :dependent => :destroy belongs_to :user - has_many :warpables do - def public_filenames - filenames = {} - self.each do |warpable| - filenames[warpable.id] = {} - sizes = Array.new(Warpable::THUMBNAILS.keys).push(nil) - sizes.each do |size| - key = size != nil ? size : "original" - filenames[warpable.id][key] = warpable.public_filename(size) - end - end - filenames - end - end + has_many :warpables def validate self.name != 'untitled' self.lat >= -90 && self.lat <= 90 && self.lon >= -180 && self.lat <= 180 end - # Hash the password before saving the record + #Hash the password before saving the record def before_create self.password = Password::update(self.password) if self.password != "" end diff --git a/test/unit/map_test.rb b/test/unit/map_test.rb index e1245fb28..a8efc4692 100644 --- a/test/unit/map_test.rb +++ b/test/unit/map_test.rb @@ -29,6 +29,7 @@ class MapTest < ActiveSupport::TestCase assert_not_nil map.images_histogram assert_not_nil map.grouped_images_histogram(10) assert_not_nil map.nearby_maps(100) # in degrees lat/lon + assert_true Map.first.validate assert_equal Map.count, Map.new_maps.size end @@ -47,6 +48,10 @@ class MapTest < ActiveSupport::TestCase assert_not_nil map.nodes assert_not_nil map.average_cm_per_pixel + #use a map fixture with no warpables + village = maps(:village) + assert_equal 0, village.average_cm_per_pixel + resolution = 20 assert_not_nil map.run_export(users(:quentin), resolution) #map.average_cm_per_pixel) @@ -94,6 +99,11 @@ class MapTest < ActiveSupport::TestCase near_maps = map.nearby_maps(5) assert_not_nil near_maps assert_includes near_maps, maps(:village) + + saugus = maps(:saugus) + saugus.lat = 0 + assert_empty saugus.nearby_maps(100) + end test "tag basics" do @@ -103,4 +113,5 @@ class MapTest < ActiveSupport::TestCase assert map.has_tag('test') end + end diff --git a/test/unit/warpable_test.rb b/test/unit/warpable_test.rb index a6aba48c8..e36c0c60d 100644 --- a/test/unit/warpable_test.rb +++ b/test/unit/warpable_test.rb @@ -48,6 +48,9 @@ def setup assert_not_nil @warp.user_id assert_equal @warp.map.user_id, @warp.user_id + + Warpable.delete_all + assert_empty Warpable.histogram_cm_per_pixel end test "try export" do @@ -61,4 +64,5 @@ def setup assert_not_nil @warp.user_id assert File.exist?('public/warps/saugus-landfill-incinerator/1-geo.tif') end + end From f2510dedae88207a1502f8d6b7caeb373c94390a Mon Sep 17 00:00:00 2001 From: Kaustubh Nair Date: Thu, 16 May 2019 00:45:23 +0530 Subject: [PATCH 4/7] Fix codeclimate issues --- test/unit/map_test.rb | 4 +--- test/unit/warpable_test.rb | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/test/unit/map_test.rb b/test/unit/map_test.rb index a8efc4692..ae98c18bb 100644 --- a/test/unit/map_test.rb +++ b/test/unit/map_test.rb @@ -48,7 +48,7 @@ class MapTest < ActiveSupport::TestCase assert_not_nil map.nodes assert_not_nil map.average_cm_per_pixel - #use a map fixture with no warpables + # use a map fixture with no warpables village = maps(:village) assert_equal 0, village.average_cm_per_pixel @@ -112,6 +112,4 @@ class MapTest < ActiveSupport::TestCase assert map.add_tag('test', User.first) assert map.has_tag('test') end - - end diff --git a/test/unit/warpable_test.rb b/test/unit/warpable_test.rb index e36c0c60d..17e30a6cd 100644 --- a/test/unit/warpable_test.rb +++ b/test/unit/warpable_test.rb @@ -64,5 +64,4 @@ def setup assert_not_nil @warp.user_id assert File.exist?('public/warps/saugus-landfill-incinerator/1-geo.tif') end - end From ca689977157b8428f0357bc609cddfd579318bd0 Mon Sep 17 00:00:00 2001 From: Kaustubh Nair Date: Thu, 16 May 2019 21:57:36 +0530 Subject: [PATCH 5/7] Fix codeclimate issues --- app/models/map.rb | 2 +- app/models/way.rb | 1 - test/unit/map_test.rb | 2 -- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/models/map.rb b/app/models/map.rb index 37f756559..8251756de 100755 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -38,7 +38,7 @@ def validate self.lat >= -90 && self.lat <= 90 && self.lon >= -180 && self.lat <= 180 end - #Hash the password before saving the record + # Hash the password before saving the record. def before_create self.password = Password::update(self.password) if self.password != "" end diff --git a/app/models/way.rb b/app/models/way.rb index 8f5bf675f..fa8ed931c 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -1,5 +1,4 @@ class Way < ActiveRecord::Base attr_accessible :body, :lat, :lon, :map_id, :color has_many :nodes, :dependent => :destroy - end diff --git a/test/unit/map_test.rb b/test/unit/map_test.rb index ae98c18bb..31efd7302 100644 --- a/test/unit/map_test.rb +++ b/test/unit/map_test.rb @@ -6,7 +6,6 @@ class MapTest < ActiveSupport::TestCase assert_not_nil Map.bbox(0,0,90,180) assert_not_nil Map.authors assert_not_nil Map.new_maps - map = maps(:saugus) assert_not_nil map.license_link assert_not_nil map.author @@ -25,7 +24,6 @@ class MapTest < ActiveSupport::TestCase assert_not_nil map.user assert_not_nil map.private assert_not_nil map.anonymous? - assert_not_nil map.images_histogram assert_not_nil map.grouped_images_histogram(10) assert_not_nil map.nearby_maps(100) # in degrees lat/lon From 0ca6decd6153d4493c1e53ca11a6e8738783fa65 Mon Sep 17 00:00:00 2001 From: Kaustubh Nair Date: Mon, 27 May 2019 20:37:44 +0530 Subject: [PATCH 6/7] Fix rubocop block length --- .rubocop.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 000000000..7298c0252 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,2 @@ +Metrics/BlockLength: + Max: 100 From 0c69df60e4fc20058649ab584d1661414a37e996 Mon Sep 17 00:00:00 2001 From: Alax Alves Date: Fri, 31 May 2019 22:52:30 -0300 Subject: [PATCH 7/7] Removing rubocop cfg since https://github.com/publiclab/mapknitter/pull/547 and renaming tests --- .rubocop.yml | 2 -- test/unit/annotation_test.rb | 7 ++++--- test/unit/export_test.rb | 4 ++-- test/unit/exporter_test.rb | 2 +- test/unit/map_test.rb | 21 ++++++++++++++------- test/unit/node_test.rb | 4 ---- test/unit/tag_test.rb | 4 +++- test/unit/user_test.rb | 2 +- test/unit/warpable_test.rb | 9 +++++---- 9 files changed, 30 insertions(+), 25 deletions(-) delete mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index 7298c0252..000000000 --- a/.rubocop.yml +++ /dev/null @@ -1,2 +0,0 @@ -Metrics/BlockLength: - Max: 100 diff --git a/test/unit/annotation_test.rb b/test/unit/annotation_test.rb index 94aa7e86a..f50d04c03 100644 --- a/test/unit/annotation_test.rb +++ b/test/unit/annotation_test.rb @@ -5,18 +5,19 @@ def setup @annotation = annotations(:lorem) end - test 'should save annotation' do + test 'should save an annotation' do map = maps(:saugus) ann = map.annotations.new ann.save! + assert_equal Annotation.count, @count + 1 end - test 'should return author' do + test 'should return an author' do assert_equal 'quentin', @annotation.author end - test 'geometry type' do + test 'should retrieve a geometry type' do @annotation.annotation_type = 'Some random Geometry' assert_equal @annotation.geometry_type, 'Point' diff --git a/test/unit/export_test.rb b/test/unit/export_test.rb index 64e76ac06..8b50569ff 100644 --- a/test/unit/export_test.rb +++ b/test/unit/export_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class ExportTest < ActiveSupport::TestCase - test "count methods" do + test 'should count methods' do average = Export.all.map(&:cm_per_pixel).sum/Export.count assert_not_nil Export.average_cm_per_pixel assert_equal average, Export.average_cm_per_pixel @@ -15,7 +15,7 @@ class ExportTest < ActiveSupport::TestCase assert_equal 0, Export.average_cm_per_pixel end - test "export running" do + test 'should export running' do assert !Export.last.running? end end diff --git a/test/unit/exporter_test.rb b/test/unit/exporter_test.rb index d372e6688..b6d74f564 100644 --- a/test/unit/exporter_test.rb +++ b/test/unit/exporter_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class ExporterTest < ActiveSupport::TestCase - test "isolated exporter lib" do + test 'should export warpable using isolated exporter lib' do # make a sample image system('mkdir -p public/system/images/1/original') diff --git a/test/unit/map_test.rb b/test/unit/map_test.rb index 31efd7302..c90e20f30 100644 --- a/test/unit/map_test.rb +++ b/test/unit/map_test.rb @@ -2,11 +2,15 @@ class MapTest < ActiveSupport::TestCase - test "basics" do + test 'should not have empty default attributes' do assert_not_nil Map.bbox(0,0,90,180) assert_not_nil Map.authors assert_not_nil Map.new_maps + end + + test 'should create map' do map = maps(:saugus) + assert_not_nil map.license_link assert_not_nil map.author assert_not_nil map.name @@ -31,14 +35,14 @@ class MapTest < ActiveSupport::TestCase assert_equal Map.count, Map.new_maps.size end - test "export functions" do + test 'should export map related functions' do map = maps(:saugus) assert_not_nil map.average_scale placed = map.warpables(&:placed?) + assert_not_nil map.placed_warpables assert_equal placed, map.placed_warpables - assert_not_nil map.best_cm_per_pixel assert_not_nil map.exporting? assert_not_nil map.export @@ -83,29 +87,32 @@ class MapTest < ActiveSupport::TestCase end - test 'histograms' do + test 'should have histograms' do map = maps(:saugus) hist = map.images_histogram + assert_not_nil hist assert_not_nil map.grouped_images_histogram(3) assert_equal hist.count/3, map.grouped_images_histogram(3).count end - test 'nearby maps' do + test 'should have nearby maps' do map = maps(:nairobi) near_maps = map.nearby_maps(5) + assert_not_nil near_maps assert_includes near_maps, maps(:village) saugus = maps(:saugus) saugus.lat = 0 - assert_empty saugus.nearby_maps(100) + assert_empty saugus.nearby_maps(100) end - test "tag basics" do + test 'should create tag basics in map' do map = Map.first + assert !map.has_tag('test') assert map.add_tag('test', User.first) assert map.has_tag('test') diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index a311b8487..b980218d6 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb @@ -1,8 +1,4 @@ require 'test_helper' class NodeTest < ActiveSupport::TestCase - # Replace this with your real tests. - test "the truth" do - assert true - end end diff --git a/test/unit/tag_test.rb b/test/unit/tag_test.rb index 108f1936e..36374ae9c 100644 --- a/test/unit/tag_test.rb +++ b/test/unit/tag_test.rb @@ -2,12 +2,14 @@ class TagTest < ActiveSupport::TestCase - test "basics" do + test 'should create sample tag' do tag = Tag.first + assert_not_nil tag.name assert_not_nil tag.maps tag = Tag.find_by_name 'nice' + assert_not_nil tag.name assert_not_nil tag.maps assert_not_nil tag.maps.last.has_tag('nice') diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index e7351fa8b..40e2c67bf 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -30,7 +30,7 @@ class UserTest < ActiveSupport::TestCase ) end - test 'user simple query methods' do + test 'should edit and delete map' do user = users(:quentin) map = maps(:saugus) assert user.owns?(map) diff --git a/test/unit/warpable_test.rb b/test/unit/warpable_test.rb index 17e30a6cd..4573de588 100644 --- a/test/unit/warpable_test.rb +++ b/test/unit/warpable_test.rb @@ -6,7 +6,7 @@ def setup @warp = warpables(:one) end - test 'basic warpable attributes' do + test 'should have basic warpable attributes' do assert_equal "demo.png", @warp.image_file_name assert_equal "image/png", @warp.image_content_type assert_equal 392, @warp.height @@ -18,7 +18,7 @@ def setup assert_equal "1,2,3,4", @warp.nodes end - test "json format methods" do + test 'should output json format methods' do assert_not_nil @warp.as_json assert_equal Hash, @warp.as_json.class assert_equal @warp.attributes.size + 2, @warp.as_json.size @@ -32,7 +32,7 @@ def setup assert_equal 3, @warp.fup_error_json.size end - test 'warpable small methods' do + test 'should execute warpable small methods' do assert_not_nil @warp.placed? assert @warp.placed? assert_equal false, Warpable.new.placed? @@ -53,12 +53,13 @@ def setup assert_empty Warpable.histogram_cm_per_pixel end - test "try export" do + test 'should try export warpables' do # make a sample image system('mkdir -p public/system/images/1/original') system('cp test/fixtures/demo.png public/system/images/1/original/') system('mkdir -p public/warps/saugus-landfill-incinerator') system('touch public/warps/saugus-landfill-incinerator/folder') + assert File.exist?('public/warps/saugus-landfill-incinerator/folder') assert_not_nil @warp.save_dimensions assert_not_nil @warp.user_id