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

Add tests for controllers #615

Merged
merged 19 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20150715162314) do
ActiveRecord::Schema.define(:version => 20190420025012) do

create_table "annotations", :force => true do |t|
t.integer "map_id"
Expand Down Expand Up @@ -48,6 +48,7 @@
t.text "bands_string", :null => false
t.string "export_type", :default => "normal", :null => false
t.integer "user_id", :default => 0
t.string "export_url"
end

create_table "maps", :force => true do |t|
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/annotations.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
one:
id: 3
map_id: 1
user_id: 1
annotation_type: polygon
coordinates: [12,77]
text: This is an annotation
created_at: <%= Time.now %>

lorem:
id: 1
map_id: 1
Expand Down
6 changes: 4 additions & 2 deletions test/fixtures/exports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
bands_string: ''
cm_per_pixel: 10

two:
two:
map_id: 2
user_id: 1
bands_string: ''
cm_per_pixel: 5
status: 'complete'

three:
three:
map_id: 3
user_id: 2
bands_string: ''
cm_per_pixel: 3
status: 'failed'
76 changes: 76 additions & 0 deletions test/functional/annotations_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require 'test_helper'

class AnnotationsControllerTest < ActionController::TestCase

# called before every single test
def setup
@map = maps(:saugus)
@annotation = annotations(:one)
end

# called after every single test
def teardown
end

test "should create annotation if logged in " do
before_count = @map.annotations.count
session[:user_id] = 1
post :create,
{
format: :json,
map_id: 1,
annotation: {
properties: {
annotation_type: 'polyline',
textContent: 'Some cool text'
},
geometry: { coordinates: [10,33] }
}
}

@map.reload
assert_response 302
assert_not_equal before_count, @map.annotations.count
assert_redirected_to map_annotation_url(@map,@map.annotations.last)
end

test "should create annotation if not logged in " do
before_count = @map.annotations.count
post :create,
{
format: :json,
map_id: 1,
annotation: {
properties: {
annotation_type: 'polyline',
textContent: 'Some cool text'
},
geometry: { coordinates: [10,33] }
}
}

@map.reload
assert_response 302
assert_not_equal before_count, @map.annotations.count
assert_redirected_to map_annotation_url(@map,@map.annotations.last)
end

# test 'should show annotations' do
# get :show, map_id: 1, id: @annotation.id

# assert_response 200
# assert_includes @response.body, @annotation.text
# end

test 'should update annotations' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be blank?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The update and destroy actions don't work
So i left them blank for now.

end

test 'should destroy annotations' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be blank?

end

# test 'should display index' do
# get :index, map_id: 1
# assert_response :success
# assert_includes @response.body, @annotation.text
# end
end
32 changes: 32 additions & 0 deletions test/functional/export_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,36 @@ def teardown
assert_equal 'export not running', @response.body
assert_equal 'text/html', @response.content_type
end

test 'progress with no export' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get :progress, id: 4
assert_response :success
assert_equal 'export has not been run', @response.body
end

test 'progress completed' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get :progress, id: 2
assert_response :success
assert_equal 'complete', @response.body
end

test 'progress failed' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get :progress, id: 3
assert_response :success
assert_equal 'export failed', @response.body
end

#does not test the exporter client
test "should display export status" do
session[:user_id] = 1
get :status, id: @map.id
assert_response :success
end

test "should display error if no export" do
session[:user_id] = 1
get :status, id: 4
assert_response :success
#assert_equal { status: 'export has not been run' }.to_json, @response.body
end
end
15 changes: 15 additions & 0 deletions test/functional/images_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def fetch_in_production
points = "-71.39,41.83:-71.39,41.83:-71.39,41.83:-71.39,41.83"
put :update, id: @map.id, warpable_id: @warp.id, locked: false, points: points
assert_not_nil @warp.nodes
assert_equal 'success', response.body
assert_equal "text/html", response.content_type
end

Expand All @@ -72,4 +73,18 @@ def fetch_in_production
assert_redirected_to '/login'
assert_not_nil flash[:error]
end

# Imports don't work. Relevent issue: https://github.com/publiclab/mapknitter/issues/614
# test 'should import an image' do
# get :import, name: @map.name, url: 'https://edit.co.uk/uploads/2016/12/Image-2-Alternatives-to-stock-photography-Thinkstock.jpg'
# assert_response :redirect
# assert_redirected_to '/maps/' + @map.name
# end

# test 'should display error if import failed' do
# get :import, name: @map.name, url: 'fake url'
# assert_response :redirect
# assert_redirected_to '/map/edit/' + @map.name
# assert_not_nil flash[:notice]
# end
end
3 changes: 3 additions & 0 deletions test/functional/sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class SessionsControllerTest < ActionController::TestCase
assert_nil session[:user_id]
assert_redirected_to '/'
end

test 'should create session' do
end
# def test_should_login_and_redirect
# post :create, :login => 'quentin', :password => 'monkey'
# assert session[:user_id]
Expand Down
16 changes: 16 additions & 0 deletions test/functional/utility_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'test_helper'

class UtilityControllerTest < ActionController::TestCase

kaustubh-nair marked this conversation as resolved.
Show resolved Hide resolved
test "tms_alt" do
get(:tms_alt,
kaustubh-nair marked this conversation as resolved.
Show resolved Hide resolved
id: 1,
kaustubh-nair marked this conversation as resolved.
Show resolved Hide resolved
x: 10,
y: 30,
z: 40
)
kaustubh-nair marked this conversation as resolved.
Show resolved Hide resolved
kaustubh-nair marked this conversation as resolved.
Show resolved Hide resolved

y = 2**40.to_i - 30.to_i - 1
assert_redirected_to "/tms/1/40/10/#{y}.png"
end
end