Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test warpable code #331

Merged
merged 7 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions app/models/warpable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ def placed?
!self.width.nil? && self.nodes != ''
end

########################################################
# this is for migration to paperclip only; remove later!
# Returns true/false if an attachment is thumbnailable. A thumbnailable attachment has an image content type and the parent_id attribute.
def thumbnailable?
!self.image.nil? && self.parent_id.nil?
end
########################################################

def poly_area
area = 0
nodes = self.nodes_array
Expand Down
Binary file added test/fixtures/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 56 additions & 5 deletions test/fixtures/nodes.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,58 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

# one:
# column: value
#
# two:
# column: value
one:
id: 1
color: "black"
author: "anonymous"
lat: 41.8403113680142
lon: -71.3983854668186
way_id: 0
order: 0
name: ""
description: ""
map_id: 1
way_order: 0
body: nil

two:
id: 2
color: "black"
author: "anonymous"
lat: 41.8397358653566
lon: -71.3916477577732
way_id: 0
order: 0
name: ""
description: ""
map_id: 1
way_order: 0
body: nil

three:
id: 3
color: "black"
author: "anonymous"
lat: 41.8351476451765
lon: -71.392699183707
way_id: 0
order: 0
name: ""
description: ""
map_id: 1
way_order: 0
body: nil

four:
id: 4
color: "black"
author: "anonymous"
lat: 41.8377535388085
lon: -71.3981708900974
way_id: 0
order: 0
name: ""
description: ""
map_id: 1
way_order: 0
body: nil

21 changes: 16 additions & 5 deletions test/fixtures/warpables.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

# one:
# column: value
#
# two:
# column: value
one:
id: 1
parent_id: nil
image_content_type: "image/png"
image_file_name: "demo.png"
thumbnail: nil
image_file_size: 574286
width: 756
height: 392
history: ''
map_id: 1
nodes: "1,2,3,4"
locked: false
deleted: false
cm_per_pixel: 99.86133660017036>

39 changes: 39 additions & 0 deletions test/unit/warpable_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'test_helper'

class WarpableTest < ActiveSupport::TestCase
test "basics" do
w = warpables(:one)
assert_not_nil w.as_json
assert_not_nil w.fup_json
assert_not_nil w.fup_error_json
assert_not_nil w.placed?
assert w.placed?
assert !Warpable.new.placed?
assert_not_nil w.poly_area
assert_not_nil w.get_cm_per_pixel

assert_not_nil Warpable.histogram_cm_per_pixel
assert_not_nil w.nodes
assert_not_nil w.nodes_array
assert_equal 4, w.nodes_array.length

# TODO: test with local image?
#assert_not_nil w.url()
end

test "try export" do
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')
w = warpables(:one)
assert_not_nil w.save_dimensions
assert_not_nil w.generate_perspectival_distort(10, w.map.slug)
assert_not_nil w.delete_temp_files(w.map.slug)
assert_not_nil w.working_directory(w.map.slug)
assert_not_nil w.warps_directory(w.map.slug)
assert_not_nil w.user_id
assert File.exist?('public/warps/saugus-landfill-incinerator/1-geo.tif')
end
end