diff --git a/app/models/map.rb b/app/models/map.rb index 20878f3d6..0ff3c51d4 100755 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -32,29 +32,15 @@ class Map < ActiveRecord::Base has_many :annotations, dependent: :destroy belongs_to :user + has_many :warpables scope :active, -> { where(archived: false) } scope :has_user, -> { where('user_id != ?', 0) } - has_many :warpables do - def public_filenames - filenames = {} - 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 - def validate lat >= -90 && lat <= 90 && lon >= -180 && lat <= 180 if name != 'untitled' end - # Hash the password before saving the record + # Hash the password before saving the record. def before_create self.password = Password.update(password) if password != "" end diff --git a/app/models/user.rb b/app/models/user.rb index 28050d3c2..0eaa31479 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -26,12 +26,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&.authenticated?(password) ? u : nil - end def login=(value) write_attribute :login, (value ? value.downcase : nil) diff --git a/test/unit/annotation_test.rb b/test/unit/annotation_test.rb index f3fdcb99f..f50d04c03 100644 --- a/test/unit/annotation_test.rb +++ b/test/unit/annotation_test.rb @@ -5,18 +5,29 @@ 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' + + @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 diff --git a/test/unit/export_test.rb b/test/unit/export_test.rb index 73e9d0de8..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 @@ -9,9 +9,13 @@ 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 + 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 e1245fb28..c90e20f30 100644 --- a/test/unit/map_test.rb +++ b/test/unit/map_test.rb @@ -2,12 +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 @@ -25,21 +28,21 @@ 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 + assert_true Map.first.validate 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 @@ -47,6 +50,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) @@ -80,27 +87,34 @@ 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) 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') end - end 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 17d6994bb..7551878c8 100644 --- a/test/unit/warpable_test.rb +++ b/test/unit/warpable_test.rb @@ -7,7 +7,7 @@ def setup @map = maps(:saugus) 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 @@ -19,7 +19,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 @@ -33,7 +33,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? @@ -49,9 +49,12 @@ 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 + test 'should try export warpables' do # make a sample image system('mkdir -p public/warps/saugus-landfill-incinerator-working') system('mkdir -p public/system/images/1/original')