diff --git a/app/models/export.rb b/app/models/export.rb index 94c96d17b..d37b52021 100644 --- a/app/models/export.rb +++ b/app/models/export.rb @@ -40,7 +40,7 @@ def self.histogram_cm_per_pixel def self.histogram_cm_per_pixel_in_tens e = Export.where('cm_per_pixel != "" AND cm_per_pixel < 500') - .order(cm_per_pixel: 'desc') + .order('cm_per_pixel desc') hist = [] (0..e.first.cm_per_pixel / 10.to_i).each do |bin| hist[bin] = 0 diff --git a/db/schema.rb b/db/schema.rb index ed064a2d1..9c3ddce87 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -159,3 +159,4 @@ end end + diff --git a/test/fixtures/annotations.yml b/test/fixtures/annotations.yml index 70256dab5..32bc10797 100644 --- a/test/fixtures/annotations.yml +++ b/test/fixtures/annotations.yml @@ -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 diff --git a/test/fixtures/exports.yml b/test/fixtures/exports.yml index c2f606daf..01ec70328 100644 --- a/test/fixtures/exports.yml +++ b/test/fixtures/exports.yml @@ -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' diff --git a/test/functional/annotations_controller_test.rb b/test/functional/annotations_controller_test.rb new file mode 100644 index 000000000..ea259ef1c --- /dev/null +++ b/test/functional/annotations_controller_test.rb @@ -0,0 +1,70 @@ +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 + end + + test 'should destroy annotations' do + end + + # test 'should display index' do + # get :index, map_id: 1 + # assert_response :success + # assert_includes @response.body, @annotation.text + # end +end diff --git a/test/functional/comments_controller_test.rb b/test/functional/comments_controller_test.rb index faef34ada..761d68717 100644 --- a/test/functional/comments_controller_test.rb +++ b/test/functional/comments_controller_test.rb @@ -1,11 +1,10 @@ require 'test_helper' class CommentsControllerTest < ActionController::TestCase - # called before every single test def setup @map = maps(:saugus) - end + end # called after every single test def teardown @@ -14,11 +13,11 @@ def teardown test "should not create comment if not logged in" do before_count = Comment.count - post(:create, - map_id: @map.slug, - comment: { - user_id: 1 - }) + post(:create, + map_id: @map.slug, + comment: { + user_id: 1 + }) assert_response :success assert_equal before_count, Comment.count @@ -28,11 +27,11 @@ def teardown session[:user_id] = 1 before_count = Comment.count - post(:create, - map_id: @map.slug, - comment: { - body: "I'm gonna troll you!" - }) + post(:create, + map_id: @map.slug, + comment: { + body: "I'm gonna troll you!" + }) assert_response :success assert_not_equal before_count, Comment.count @@ -44,13 +43,13 @@ def teardown session[:user_id] = 4 put(:update, - id: @comment.id, - map_id: @map.slug, - comment: { - body: "I'm gonna troll you!" - }) + id: @comment.id, + map_id: @map.slug, + comment: { + body: "I'm gonna troll you!" + }) - #refresh the object + # refresh the object @comment.reload assert_redirected_to "/maps/" + @map.slug @@ -62,15 +61,15 @@ def teardown session[:user_id] = 3 put(:update, - id: @comment.id, - map_id: @map.slug, - comment: { - body: "I'm gonna troll you!" - }) + id: @comment.id, + map_id: @map.slug, + comment: { + body: "I'm gonna troll you!" + }) @comment.reload - assert_redirected_to "/login" + assert_redirected_to "/login" assert_not_equal "I'm gonna troll you!", @comment.body assert_equal "I'll just leave a comment, why don't I.", @comment.body assert_equal "You do not have permissions to update that comment.", flash[:error] @@ -80,15 +79,15 @@ def teardown @comment = comments(:one) put(:update, - id: @comment.id, - map_id: @map.slug, - comment: { - body: "I'm gonna troll you!" - }) + id: @comment.id, + map_id: @map.slug, + comment: { + body: "I'm gonna troll you!" + }) @comment.reload - assert_redirected_to "/login" + assert_redirected_to "/login" assert_not_equal "I'm gonna troll you!", @comment.body assert_equal "I'll just leave a comment, why don't I.", @comment.body assert_equal "You do not have permissions to update that comment.", flash[:error] @@ -101,8 +100,7 @@ def teardown delete(:destroy, id: @comment.id, - map_id: @map.slug - ) + map_id: @map.slug) assert_redirected_to "/maps/" + @map.slug assert_not_equal before_count, Comment.count @@ -116,8 +114,7 @@ def teardown delete(:destroy, id: @comment.id, - map_id: @map.slug - ) + map_id: @map.slug) assert_redirected_to "/maps/" + @map.slug assert_equal before_count, Comment.count @@ -130,8 +127,7 @@ def teardown delete(:destroy, id: @comment.id, - map_id: @map.slug - ) + map_id: @map.slug) assert_redirected_to "/maps/" + @map.slug assert_equal before_count, Comment.count @@ -142,11 +138,11 @@ def teardown @user = users(:quentin) session[:user_id] = @user.id - post(:create, - map_id: @map.slug, - comment: { - body: "I'm gonna troll you!" - }) + post(:create, + map_id: @map.slug, + comment: { + body: "I'm gonna troll you!" + }) assert_response :success assert !ActionMailer::Base.deliveries.collect(&:to).include?([@user.email]) @@ -156,11 +152,11 @@ def teardown @user = users(:quentin) session[:user_id] = 3 - post(:create, - map_id: @map.slug, - comment: { - body: "I'm gonna troll you!" - }) + post(:create, + map_id: @map.slug, + comment: { + body: "I'm gonna troll you!" + }) email = ActionMailer::Base.deliveries.last @@ -175,19 +171,19 @@ def teardown session[:user_id] = @chris.id - post(:create, - map_id: @map.slug, - comment: { - body: "I'm gonna troll you!" - }) + post(:create, + map_id: @map.slug, + comment: { + body: "I'm gonna troll you!" + }) session[:user_id] = @joshua.id - post(:create, - map_id: @map.slug, - comment: { - body: "Yeah we'll see!" - }) + post(:create, + map_id: @map.slug, + comment: { + body: "Yeah we'll see!" + }) email = ActionMailer::Base.deliveries.last diff --git a/test/functional/export_controller_test.rb b/test/functional/export_controller_test.rb index 96668aab3..0d84c1f1d 100644 --- a/test/functional/export_controller_test.rb +++ b/test/functional/export_controller_test.rb @@ -1,7 +1,6 @@ require 'test_helper' class ExportControllerTest < ActionController::TestCase - def setup @map = maps(:saugus) end @@ -9,7 +8,7 @@ def setup def teardown end - test "index" do + test 'should display export index' do get :index assert_response :success assert assigns[:exports] @@ -17,36 +16,36 @@ def teardown assert assigns[:week] end - test "jpg" do + test 'should create jpg after export' do map = maps(:cubbon) system('mkdir -p public/warps/cubbon-park') system('cp test/fixtures/demo.png public/warps/cubbon-park/cubbon-park.jpg') get :jpg, id: map.slug assert_response :success - assert_includes '"image/jpeg', response.content_type + assert_includes 'image/jpeg', response.content_type end - test "geotiff" do + test 'should create geotiff after export' do map = maps(:cubbon) system('mkdir -p public/warps/cubbon-park') system('cp test/fixtures/demo.png public/warps/cubbon-park/cubbon-park-geo.tif') get :geotiff, id: map.slug assert_response :success - assert_includes '"image/tiff', response.content_type + assert_includes 'image/tiff', response.content_type end - test "cancel fails if not logged in" do + test 'should not cancel if not logged in' do get :cancel, id: @map.id assert_response :success - assert_equal "You must be logged in to export, unless the map is anonymous.", @response.body + assert_equal 'You must be logged in to export, unless the map is anonymous.', @response.body assert assigns[:map] assert_equal 'text/html', @response.content_type assert flash.empty? end - test "cancels export" do + test 'should cancel export' do session[:user_id] = 1 get :cancel, id: @map.id assert_response :success @@ -54,7 +53,7 @@ def teardown assert assigns[:map] end - test "exports cancelled if present" do + test 'should redirect after cancelling' do session[:user_id] = 1 get :cancel, id: @map.id, exports: 'cess' assert_response :redirect @@ -62,10 +61,42 @@ def teardown assert_redirected_to '/exports' end - test "progress" do + test 'should display export progress' do get :progress, id: @map.id assert_response :success assert_equal 'export not running', @response.body assert_equal 'text/html', @response.content_type end + + test 'should display progress with no export' do + get :progress, id: 4 + assert_response :success + assert_equal 'export has not been run', @response.body + end + + test 'should display progress completed' do + get :progress, id: 2 + assert_response :success + assert_equal 'complete', @response.body + end + + test 'should display progress failed' do + 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 diff --git a/test/functional/feeds_controller_test.rb b/test/functional/feeds_controller_test.rb index 77e1f5b5d..9a015cb0d 100644 --- a/test/functional/feeds_controller_test.rb +++ b/test/functional/feeds_controller_test.rb @@ -1,7 +1,6 @@ require 'test_helper' class FeedsControllerTest < ActionController::TestCase - # called before every single test def setup @map = maps(:saugus) diff --git a/test/functional/images_controller_test.rb b/test/functional/images_controller_test.rb index 75f1bf71d..d546182e5 100644 --- a/test/functional/images_controller_test.rb +++ b/test/functional/images_controller_test.rb @@ -1,7 +1,6 @@ require 'test_helper' class ImagesControllerTest < ActionController::TestCase - # called before every single test def setup @map = maps(:saugus) @@ -34,7 +33,7 @@ def fetch_in_production post :create, map_id: @map.id, uploaded_data: @uploaded_data assert_response :success - assert_equal before_count+1, Warpable.count + assert_equal before_count + 1, Warpable.count end test 'should return correct status and type on create' do @@ -46,9 +45,9 @@ def fetch_in_production test 'should show the image' do get :show, id: @warp.id, format: 'json' - json_response = JSON.parse(response.body) - assert_equal @warp.id, json_response["id"] - assert_response :success + json_response = JSON.parse(response.body) + assert_equal @warp.id, json_response["id"] + assert_response :success end test 'should update an image' do @@ -72,4 +71,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 diff --git a/test/functional/maps_controller_test.rb b/test/functional/maps_controller_test.rb index bdbae1d42..47acfc77b 100644 --- a/test/functional/maps_controller_test.rb +++ b/test/functional/maps_controller_test.rb @@ -1,7 +1,6 @@ require 'test_helper' class MapsControllerTest < ActionController::TestCase - # called before every single test def setup @map = maps(:saugus) @@ -11,11 +10,12 @@ def setup def teardown end - test "should display image url for maps by region" do - get :region , { minlat: 40, maxlat: 50, minlon: -80, maxlon: -60, format: :json} + test 'should display image url for maps by region' do + get :region, + { minlat: 40, maxlat: 50, minlon: -80, maxlon: -60, format: :json } image_urls = [] - @map.warpables.each do | warpable| + @map.warpables.each do |warpable| image_urls.append(warpable.image.url) end @@ -25,100 +25,100 @@ def teardown assert_equal image_urls, json_response[0]['image_urls'] end - test "should get index" do + test 'should get maps index' do get :index @maps = assigns(:maps) assert_response :success - assert @maps.collect(&:name).include?("Saugus Landfill Incinerator") - assert @maps.collect(&:name).include?("Cubbon Park") - assert @maps.collect{ |map| map.user.login}.include?("quentin") + assert @maps.collect(&:name).include?('Saugus Landfill Incinerator') + assert @maps.collect(&:name).include?('Cubbon Park') + assert @maps.collect { |map| map.user.login }.include?('quentin') end - test "should not display archived maps" do + test 'should not display archived maps' do session[:user_id] = 1 get(:archive, id: @map.slug) get :index @maps = assigns(:maps) assert_response :success - assert !@maps.collect(&:name).include?("Saugus Landfill Incinerator") - assert @maps.collect(&:name).include?("Cubbon Park") - assert @maps.collect{ |map| map.user.login}.include?("quentin") + assert !@maps.collect(&:name).include?('Saugus Landfill Incinerator') + assert @maps.collect(&:name).include?('Cubbon Park') + assert @maps.collect { |map| map.user.login }.include?('quentin') end - test "should get map of maps" do + test 'should get map of maps' do get :map assert_response :success assert_includes @response.body, @map.slug end - test "should get new" do + test 'should get new' do get :new assert_response :success assert_not_nil assigns(:map) end - test "should search for maps by name" do + test 'should search for maps by name' do get :search, q: 'Saugus' @maps = assigns(:maps) assert_response :success - assert @maps.collect(&:name).include?("Saugus Landfill Incinerator") - assert !@maps.collect(&:name).include?("Cubbon Park") + assert @maps.collect(&:name).include?('Saugus Landfill Incinerator') + assert !@maps.collect(&:name).include?('Cubbon Park') end - test "should search for maps by location" do + test 'should search for maps by location' do get :search, q: 'India' @maps = assigns(:maps) assert_response :success - assert !@maps.collect(&:name).include?("Saugus Landfill Incinerator") - assert @maps.collect(&:name).include?("Cubbon Park") + assert !@maps.collect(&:name).include?('Saugus Landfill Incinerator') + assert @maps.collect(&:name).include?('Cubbon Park') end - test "should search for maps by description" do + test 'should search for maps by description' do get :search, q: 'a park' @maps = assigns(:maps) assert_response :success - assert !@maps.collect(&:name).include?("Saugus Landfill Incinerator") - assert @maps.collect(&:name).include?("Cubbon Park") + assert !@maps.collect(&:name).include?('Saugus Landfill Incinerator') + assert @maps.collect(&:name).include?('Cubbon Park') end - test "should create map if logged in" do + test 'should create map if logged in' do session[:user_id] = 1 before_count = Map.count post(:create, map: { - name: "Coal terminal map", - slug: "coal-terminal", - location: "London", - lat: 42.43823313018592, - lon: -70.9849190711975 - }) + name: 'Coal terminal map', + slug: 'coal-terminal', + location: 'London', + lat: 42.43823313018592, + lon: -70.9849190711975 + }) @map = assigns(:map) assert_response 302 - assert_redirected_to '/maps/'+@map.slug + assert_redirected_to '/maps/' + @map.slug assert_not_equal before_count, Map.count - assert Map.all.collect(&:name).include?("Coal terminal map") - assert_equal @map.user.login, "quentin" + assert Map.all.collect(&:name).include?('Coal terminal map') + assert_equal @map.user.login, 'quentin' end - test "should create map if not logged in" do + test 'should create map if not logged in' do before_count = Map.count post(:create, map: { - name: "Coal terminal map", - slug: "coal-terminal", - location: "London", - lat: 42.43823313018592, - lon: -70.9849190711975 - }) + name: 'Coal terminal map', + slug: 'coal-terminal', + location: 'London', + lat: 42.43823313018592, + lon: -70.9849190711975 + }) @map = assigns(:map) - assert_redirected_to '/maps/'+@map.slug + assert_redirected_to '/maps/' + @map.slug assert_not_equal before_count, Map.count - assert Map.all.collect(&:name).include?("Coal terminal map") + assert Map.all.collect(&:name).include?('Coal terminal map') assert_nil @map.user assert_equal 'anonymous', @map.author end @@ -136,55 +136,55 @@ def teardown } @map = assigns(:map) - assert_redirected_to '/maps/'+@map.slug + assert_redirected_to '/maps/' + @map.slug assert_not_equal before_count, Map.count assert Map.all.collect(&:name).include?('Yaya Center') assert_equal user, @map.user assert_equal user.login, @map.author end - test "should render new if map not created" do + test 'should render new if map not created' do session[:user_id] = 1 before_count = Map.count post(:create, map: { - name: "Coal terminal map", - slug: "coal-terminal" - }) + name: 'Coal terminal map', + slug: 'coal-terminal' + }) @map = assigns(:map) assert_response :success assert_template :new assert_equal before_count, Map.count - assert !Map.all.collect(&:name).include?("Coal terminal map") + assert !Map.all.collect(&:name).include?('Coal terminal map') end - test "should not delete map if not owner" do + test 'should not delete map if not owner' do session[:user_id] = 3 before_count = Map.count post(:destroy, id: @map.id) - assert_redirected_to "/maps/" + @map.slug - assert_equal flash[:error], "Only admins or map owners may delete maps." + assert_redirected_to '/maps/' + @map.slug + assert_equal flash[:error], 'Only admins or map owners may delete maps.' assert_equal before_count, Map.count end - test "should delete map if owner" do + test 'should delete map if owner' do session[:user_id] = 1 before_count = Map.count post(:destroy, id: @map.id) assert_redirected_to '/' assert_not_equal before_count, Map.count - assert_equal flash[:notice], "Map deleted." + assert_equal flash[:notice], 'Map deleted.' end - test "should get show" do + test 'should get show' do get(:show, id: @map.id) assert_response :success assert_not_nil assigns(:map) end - test "should archive map" do + test 'should archive map' do session[:user_id] = 1 get(:archive, id: @map.slug) @map.reload @@ -193,7 +193,7 @@ def teardown assert_true @map.archived end - test "should not archive map without enough permissions" do + test 'should not archive map without enough permissions' do session[:user_id] = 3 get(:archive, id: @map.slug) @map.reload @@ -202,40 +202,40 @@ def teardown assert_false @map.archived end - test "should update map" do + test 'should update map' do session[:user_id] = 1 put(:update, id: 1, map: { - name: "Schrute farms", - location: "USA", + name: 'Schrute farms', + location: 'USA', lat: 44, lon: -74, - description: "A really green farm" + description: 'A really green farm' }, - tags: "beets bears") + tags: 'beets bears') @map.reload - assert_redirected_to "/maps/" + @map.id.to_s - assert_equal "Schrute farms", @map.name + assert_redirected_to '/maps/' + @map.id.to_s + assert_equal 'Schrute farms', @map.name assert_equal 44, @map.lat assert_equal -74, @map.lon - assert_equal "A really green farm", @map.description - assert @map.has_tag("beets") - assert @map.has_tag("bears") + assert_equal 'A really green farm', @map.description + assert @map.has_tag('beets') + assert @map.has_tag('bears') end test 'should not update unless logged in' do - put :update, id: 2, map: { name: 'Street 5'} + put :update, id: 2, map: { name: 'Street 5' } assert_redirected_to '/login?back_to=/map/2' end - test "should display maps by region"do - get :region , { minlat: 40, maxlat: 50, minlon: -80, maxlon: -60} + test 'should display maps by region' do + get :region, { minlat: 40, maxlat: 50, minlon: -80, maxlon: -60 } @maps = assigns(:maps) assert_response :success - assert @maps.collect(&:name).include?("Saugus Landfill Incinerator") + assert @maps.collect(&:name).include?('Saugus Landfill Incinerator') end test 'should annotate maps' do diff --git a/test/functional/sessions_controller_test.rb b/test/functional/sessions_controller_test.rb index 4ed0ec184..4087cf6b9 100644 --- a/test/functional/sessions_controller_test.rb +++ b/test/functional/sessions_controller_test.rb @@ -5,7 +5,6 @@ class SessionsController; def rescue_action(e) raise e end; end class SessionsControllerTest < ActionController::TestCase - test 'new when logged in' do session[:user_id] = 1 get :new @@ -44,72 +43,78 @@ class SessionsControllerTest < ActionController::TestCase assert_redirected_to '/' end -# def test_should_login_and_redirect -# post :create, :login => 'quentin', :password => 'monkey' -# assert session[:user_id] -# assert_response :redirect -# end - -# def test_should_fail_login_and_not_redirect -# post :create, :login => 'quentin', :password => 'bad password' -# assert_nil session[:user_id] -# assert_response :success -# end - -# def test_should_logout -# login_as :quentin -# get :destroy -# assert_nil session[:user_id] -# assert_response :redirect -# end - -# def test_should_remember_me -# @request.cookies["auth_token"] = nil -# post :create, :login => 'quentin', :password => 'monkey', :remember_me => "1" -# assert_not_nil @response.cookies["auth_token"] -# end - -# def test_should_not_remember_me -# @request.cookies["auth_token"] = nil -# post :create, :login => 'quentin', :password => 'monkey', :remember_me => "0" -# puts @response.cookies["auth_token"] -# assert @response.cookies["auth_token"].blank? -# end - -# def test_should_delete_token_on_logout -# login_as :quentin -# get :destroy -# assert @response.cookies["auth_token"].blank? -# end - -# def test_should_login_with_cookie -# users(:quentin).remember_me -# @request.cookies["auth_token"] = cookie_for(:quentin) -# get :new -# assert @controller.send(:logged_in?) -# end - -# def test_should_fail_expired_cookie_login -# users(:quentin).remember_me -# users(:quentin).update_attribute :remember_token_expires_at, 5.minutes.ago -# @request.cookies["auth_token"] = cookie_for(:quentin) -# get :new -# assert !@controller.send(:logged_in?) -# end - -# def test_should_fail_cookie_login -# users(:quentin).remember_me -# @request.cookies["auth_token"] = auth_token('invalid_auth_token') -# get :new -# assert !@controller.send(:logged_in?) -# end + # def test_should_login_and_redirect + # post :create, :login => 'quentin', :password => 'monkey' + # assert session[:user_id] + # assert_response :redirect + # end + + # def test_should_fail_login_and_not_redirect + # post :create, :login => 'quentin', :password => 'bad password' + # assert_nil session[:user_id] + # assert_response :success + # end + + # def test_should_logout + # login_as :quentin + # get :destroy + # assert_nil session[:user_id] + # assert_response :redirect + # end + + # def test_should_remember_me + # @request.cookies["auth_token"] = nil + # post :create, :login => 'quentin', + # :password => 'monkey', + # :remember_me => "1" + # assert_not_nil @response.cookies["auth_token"] + # end + + # def test_should_not_remember_me + # @request.cookies["auth_token"] = nil + # post :create, :login => 'quentin', + # :password => 'monkey', + # :remember_me => "0" + # puts @response.cookies["auth_token"] + # assert @response.cookies["auth_token"].blank? + # end + + # def test_should_delete_token_on_logout + # login_as :quentin + # get :destroy + # assert @response.cookies["auth_token"].blank? + # end + + # def test_should_login_with_cookie + # users(:quentin).remember_me + # @request.cookies["auth_token"] = cookie_for(:quentin) + # get :new + # assert @controller.send(:logged_in?) + # end + + # def test_should_fail_expired_cookie_login + # users(:quentin).remember_me + # users(:quentin).update_attribute + # :remember_token_expires_at, 5.minutes.ago + # @request.cookies["auth_token"] = cookie_for(:quentin) + # get :new + # assert !@controller.send(:logged_in?) + # end + + # def test_should_fail_cookie_login + # users(:quentin).remember_me + # @request.cookies["auth_token"] = auth_token('invalid_auth_token') + # get :new + # assert !@controller.send(:logged_in?) + # end protected - def auth_token(token) - CGI::Cookie.new('name' => 'auth_token', 'value' => token) - end - - def cookie_for(user) - auth_token users(user).remember_token - end + + def auth_token(token) + CGI::Cookie.new(name: 'auth_token', value: token) + end + + def cookie_for(user) + auth_token users(user).remember_token + end end diff --git a/test/functional/tags_controller_test.rb b/test/functional/tags_controller_test.rb index 01b3d266e..0269542e3 100644 --- a/test/functional/tags_controller_test.rb +++ b/test/functional/tags_controller_test.rb @@ -1,12 +1,11 @@ require 'test_helper' class TagsControllerTest < ActionController::TestCase - # called before every single test def setup @map = maps(:saugus) @tag = tags(:nice) - end + end test "should create tag" do session[:user_id] = 1 # log in diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 9f80e0fb6..d9bdd61f0 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -5,13 +5,12 @@ class UsersController; def rescue_action(e) raise e end; end class UsersControllerTest < ActionController::TestCase - fixtures :users # called before every single test def setup @user = users(:quentin) - end + end test "should get index" do get :index @@ -24,5 +23,4 @@ def setup assert_response :success assert_not_nil :user end - end diff --git a/test/functional/utility_controller_test.rb b/test/functional/utility_controller_test.rb new file mode 100644 index 000000000..87ae42f9f --- /dev/null +++ b/test/functional/utility_controller_test.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'test_helper' + +class UtilityControllerTest < ActionController::TestCase + test 'should translate tms format' do + get(:tms_alt, + id: 1, + x: 10, + y: 30, + z: 40) + + y = 2**40.to_i - 30.to_i - 1 + assert_redirected_to "/tms/1/40/10/#{y}.png" + end +end diff --git a/test/reports/TEST-ExportTest.xml b/test/reports/TEST-ExportTest.xml new file mode 100644 index 000000000..6c6d2d3a3 --- /dev/null +++ b/test/reports/TEST-ExportTest.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/test/reports/TEST-MapTest.xml b/test/reports/TEST-MapTest.xml new file mode 100644 index 000000000..9a15a2d15 --- /dev/null +++ b/test/reports/TEST-MapTest.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/test/reports/TEST-MapsControllerTest.xml b/test/reports/TEST-MapsControllerTest.xml new file mode 100644 index 000000000..b67e87d3b --- /dev/null +++ b/test/reports/TEST-MapsControllerTest.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Failure: +test_should_render_new_if_map_not_created(Minitest::Result) [/home/k/.rvm/gems/ruby-2.4.6/gems/actionpack-4.2.11.1/lib/action_dispatch/routing/route_set.rb:234]: +ActionView::Template::Error: No route matches {:action=>"index", :controller=>"warpables", :map_id=>nil} missing required keys: [:map_id] + app/views/images/_new.html.erb:13:in `_app_views_images__new_html_erb___582794143336601479_47432368697160' + app/views/layouts/knitter2.html.erb:195:in `_app_views_layouts_knitter__html_erb__1554220659803257588_47432335059940' + app/controllers/maps_controller.rb:41:in `create' + test/functional/maps_controller_test.rb:151:in `block in <class:MapsControllerTest>' + + + + + + + + + + + + + + + + + + + + diff --git a/test/reports/TEST-UserTest.xml b/test/reports/TEST-UserTest.xml new file mode 100644 index 000000000..4aea8b0da --- /dev/null +++ b/test/reports/TEST-UserTest.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + +