From: Tom Hughes Date: Sun, 5 Feb 2017 15:56:04 +0000 (+0000) Subject: Merge remote-tracking branch 'openstreetmap/pull/1347' into master X-Git-Tag: live~3637 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/0814b4096c443e2ab3c09baa058aa81a00d205d1?hp=-c;ds=sidebyside Merge remote-tracking branch 'openstreetmap/pull/1347' into master --- 0814b4096c443e2ab3c09baa058aa81a00d205d1 diff --combined Gemfile index 34768095f,039216f93..c2578d6f5 --- a/Gemfile +++ b/Gemfile @@@ -38,33 -38,32 +38,33 @@@ gem "r2 gem "autoprefixer-rails" # Use image_optim to optimise images -gem "image_optim", ">= 0.22.0" +gem "image_optim_rails" # Load rails plugins -gem "rails-i18n", "~> 4.0.0" -gem "dynamic_form" -gem "rinku", ">= 1.2.2", :require => "rails_rinku" -gem "oauth-plugin", ">= 0.5.1" -gem "validates_email_format_of", ">= 1.5.1" +gem "actionpack-page_caching" gem "composite_primary_keys", "~> 8.1.0" -gem "http_accept_language", "~> 2.0.0" -gem "paperclip", "~> 4.0" gem "deadlock_retry", ">= 1.2.0" +gem "dynamic_form" +gem "http_accept_language", "~> 2.0.0" gem "i18n-js", ">= 3.0.0.rc10" +gem "oauth-plugin", ">= 0.5.1" +gem "paperclip", "~> 4.0" gem "rack-cors" -gem "actionpack-page_caching" +gem "rails-i18n", "~> 4.0.0" +gem "rinku", ">= 1.2.2", :require => "rails_rinku" +gem "validates_email_format_of", ">= 1.5.1" # Sanitise URIs gem "rack-uri_sanitizer" # Omniauth for authentication gem "omniauth" -gem "omniauth-openid" -gem "omniauth-google-oauth2", ">= 0.2.7" gem "omniauth-facebook" -gem "omniauth-windowslive" gem "omniauth-github" +gem "omniauth-google-oauth2", ">= 0.2.7" +gem "omniauth-mediawiki", ">= 0.0.3" +gem "omniauth-openid" +gem "omniauth-windowslive" # Markdown formatting support gem "redcarpet" @@@ -73,8 -72,8 +73,8 @@@ gem "libxml-ruby", ">= 2.0.5", :require => "libxml" # Use for HTML sanitisation -gem "sanitize" gem "htmlentities" +gem "sanitize" # Load SystemTimer for implementing request timeouts gem "SystemTimer", ">= 1.1.3", :require => "system_timer", :platforms => :ruby_18 @@@ -85,9 -84,6 +85,9 @@@ gem "faraday # Load geoip for querying Maxmind GeoIP database gem "geoip" +# Load rotp to generate TOTP tokens +gem "rotp" + # Load memcache client in case we are using it gem "dalli" gem "kgio" @@@ -102,17 -98,17 +102,18 @@@ en # Gems needed for running tests group :test do - gem "rubocop" - gem "timecop" gem "minitest", "~> 5.1", :platforms => [:ruby_19, :ruby_20] + gem "minitest-stub_any_instance" + gem "rubocop" + gem "timecop" + gem "webmock" end # Needed in development as well so rake can see konacha tasks group :development, :test do + gem "coveralls", :require => false + gem "factory_girl_rails" gem "jshint" gem "konacha" gem "poltergeist" - gem "factory_girl_rails" - gem "coveralls", :require => false end diff --combined Gemfile.lock index a8c91f460,f4573658b..1fade149c --- a/Gemfile.lock +++ b/Gemfile.lock @@@ -15,8 -15,8 +15,8 @@@ GE rack-test (~> 0.6.2) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionpack-page_caching (1.0.2) - actionpack (>= 4.0.0, < 5) + actionpack-page_caching (1.1.0) + actionpack (>= 4.0.0, < 6) actionview (4.2.7.1) activesupport (= 4.2.7.1) builder (~> 3.1) @@@ -39,22 -39,22 +39,22 @@@ minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.4.0) - arel (6.0.3) + addressable (2.5.0) + public_suffix (~> 2.0, >= 2.0.2) + arel (6.0.4) ast (2.3.0) - autoprefixer-rails (6.5.1) + autoprefixer-rails (6.7.2) execjs bigdecimal (1.1.0) - builder (3.2.2) - capybara (2.10.1) + builder (3.2.3) + capybara (2.12.0) addressable mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - climate_control (0.0.3) - activesupport (>= 3.0) + climate_control (0.1.0) cliver (0.3.2) cocaine (0.5.8) climate_control (>= 0.0.3, < 1.0) @@@ -64,19 -64,17 +64,19 @@@ coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.10.0) + coffee-script-source (1.12.2) colorize (0.8.1) composite_primary_keys (8.1.4) activerecord (~> 4.2.0) - concurrent-ruby (1.0.2) - coveralls (0.8.15) + concurrent-ruby (1.0.4) + coveralls (0.8.19) json (>= 1.8, < 3) simplecov (~> 0.12.0) term-ansicolor (~> 1.3) thor (~> 0.19.1) - tins (>= 1.6.0, < 2) + tins (~> 1.6) + crack (0.4.3) + safe_yaml (~> 1.0.0) crass (1.0.2) dalli (2.7.6) deadlock_retry (1.2.0) @@@ -85,52 -83,47 +85,52 @@@ erubis (2.7.0) execjs (2.7.0) exifr (1.2.5) - factory_girl (4.7.0) + factory_girl (4.8.0) activesupport (>= 3.0.0) - factory_girl_rails (4.7.0) - factory_girl (~> 4.7.0) + factory_girl_rails (4.8.0) + factory_girl (~> 4.8.0) railties (>= 3.0.0) - faraday (0.9.2) + faraday (0.10.1) multipart-post (>= 1.2, < 3) fspath (3.0.1) - geoip (1.6.2) + geoip (1.6.3) globalid (0.3.7) activesupport (>= 4.1.0) + hashdiff (0.3.2) hashie (3.4.6) htmlentities (4.3.4) http_accept_language (2.0.5) - i18n (0.7.0) - i18n-js (3.0.0.rc14) + i18n (0.8.0) + i18n-js (3.0.0.rc15) i18n (~> 0.6, >= 0.6.6) - image_optim (0.24.0) + image_optim (0.24.1) exifr (~> 1.2, >= 1.2.2) fspath (~> 3.0) - image_size (~> 1.3) + image_size (~> 1.5) in_threads (~> 1.3) progress (~> 3.0, >= 3.0.1) - image_size (1.4.2) + image_optim_rails (0.2.0) + image_optim (~> 0.24.0) + rails + sprockets + image_size (1.5.0) in_threads (1.3.1) - jquery-rails (4.2.1) + jquery-rails (4.2.2) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - jshint (1.4.0) + jshint (1.5.0) execjs (>= 1.4.0) multi_json (~> 1.0) therubyracer (~> 0.12.1) - json (1.8.3) + json (1.8.6) jsonify (0.3.1) multi_json (~> 1.0) jsonify-rails (0.3.2) actionpack jsonify (< 0.4.0) jwt (1.5.6) - kgio (2.10.0) + kgio (2.11.0) konacha (4.0.0) actionpack (>= 4.1, < 5) capybara @@@ -139,10 -132,10 +139,10 @@@ sprockets (>= 2, < 4) sprockets-rails (>= 2, < 4) tilt - libv8 (3.16.14.15) + libv8 (3.16.14.17) libxml-ruby (2.9.0) logstash-event (1.2.02) - logstasher (1.0.1) + logstasher (1.1.1) activerecord (>= 4.0) activesupport (>= 4.0) logstash-event (~> 1.2.0) @@@ -156,13 -149,14 +156,14 @@@ mime-types-data (3.2016.0521) mimemagic (0.3.0) mini_portile2 (2.1.0) - minitest (5.9.1) + minitest (5.10.1) + minitest-stub_any_instance (1.0.1) multi_json (1.12.1) - multi_xml (0.5.5) + multi_xml (0.6.0) multipart-post (2.0.0) - nokogiri (1.6.8.1) + nokogiri (1.7.0.1) mini_portile2 (~> 2.1.0) - nokogumbo (1.4.9) + nokogumbo (1.4.10) nokogiri oauth (0.4.7) oauth-plugin (0.5.1) @@@ -170,31 -164,25 +171,31 @@@ oauth (~> 0.4.4) oauth2 (>= 0.5.0) rack - oauth2 (1.2.0) - faraday (>= 0.8, < 0.10) + oauth2 (1.3.0) + faraday (>= 0.8, < 0.11) jwt (~> 1.0) multi_json (~> 1.3) multi_xml (~> 0.5) rack (>= 1.2, < 3) - omniauth (1.3.1) + omniauth (1.3.2) hashie (>= 1.2, < 4) rack (>= 1.0, < 3) omniauth-facebook (4.0.0) omniauth-oauth2 (~> 1.2) - omniauth-github (1.1.2) - omniauth (~> 1.0) - omniauth-oauth2 (~> 1.1) + omniauth-github (1.2.0) + omniauth (~> 1.3.2) + omniauth-oauth2 (>= 1.4.0, < 2.0) omniauth-google-oauth2 (0.4.1) jwt (~> 1.5.2) multi_json (~> 1.3) omniauth (>= 1.1.1) omniauth-oauth2 (>= 1.3.1) + omniauth-mediawiki (0.0.3) + jwt (~> 1.0) + omniauth-oauth (~> 1.0) + omniauth-oauth (1.1.0) + oauth + omniauth (~> 1.0) omniauth-oauth2 (1.4.0) oauth2 (~> 1.0) omniauth (~> 1.2) @@@ -210,20 -198,19 +211,20 @@@ cocaine (~> 0.5.5) mime-types mimemagic (= 0.3.0) - parser (2.3.1.4) + parser (2.3.3.1) ast (~> 2.2) pg (0.19.0) - poltergeist (1.11.0) + poltergeist (1.13.0) capybara (~> 2.1) cliver (~> 0.3.1) websocket-driver (>= 0.2.0) powerpack (0.1.1) - progress (3.2.2) - psych (2.1.1) + progress (3.3.0) + psych (2.2.2) + public_suffix (2.0.5) r2 (0.2.6) - rack (1.6.4) - rack-cors (0.4.0) + rack (1.6.5) + rack-cors (0.4.1) rack-openid (1.3.1) rack (>= 1.1.0) ruby-openid (>= 2.1.8) @@@ -243,9 -230,9 +244,9 @@@ sprockets-rails rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.7) + rails-dom-testing (1.0.8) activesupport (>= 4.2.0.beta, < 5.0) - nokogiri (~> 1.6.0) + nokogiri (~> 1.6) rails-deprecated_sanitizer (>= 1.0.1) rails-html-sanitizer (1.0.3) loofah (~> 2.0) @@@ -257,27 -244,25 +258,27 @@@ activesupport (= 4.2.7.1) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rainbow (2.1.0) - rake (11.3.0) - redcarpet (3.3.4) + rainbow (2.2.1) + rake (12.0.0) + redcarpet (3.4.0) ref (2.0.0) - request_store (1.3.1) + request_store (1.3.2) rinku (2.0.2) - rubocop (0.44.1) - parser (>= 2.3.1.1, < 3.0) + rotp (3.3.0) + rubocop (0.47.1) + parser (>= 2.3.3.1, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) ruby-openid (2.7.0) ruby-progressbar (1.8.1) + safe_yaml (1.0.4) sanitize (4.4.0) crass (~> 1.0.2) nokogiri (>= 1.4.4) nokogumbo (~> 1.4.1) - sass (3.4.22) + sass (3.4.23) sass-rails (5.0.6) railties (>= 4.0.0, < 6) sass (~> 3.1) @@@ -289,7 -274,7 +290,7 @@@ json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.0) - sprockets (3.7.0) + sprockets (3.7.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.2.0) @@@ -298,27 -283,23 +299,27 @@@ sprockets (>= 3.0.0) term-ansicolor (1.4.0) tins (~> 1.0) - therubyracer (0.12.2) - libv8 (~> 3.16.14.0) + therubyracer (0.12.3) + libv8 (~> 3.16.14.15) ref - thor (0.19.1) + thor (0.19.4) thread_safe (0.3.5) - tilt (2.0.5) + tilt (2.0.6) timecop (0.8.1) - tins (1.12.0) + tins (1.13.2) tzinfo (1.2.2) thread_safe (~> 0.1) - uglifier (3.0.2) + uglifier (3.0.4) execjs (>= 0.3.0, < 3) - unicode-display_width (1.1.1) + unicode-display_width (1.1.3) validates_email_format_of (1.6.3) i18n vendorer (0.1.16) - websocket-driver (0.6.4) + webmock (2.3.2) + addressable (>= 2.3.6) + crack (>= 0.3.2) + hashdiff + websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) xpath (2.0.0) @@@ -344,7 -325,7 +345,7 @@@ DEPENDENCIE htmlentities http_accept_language (~> 2.0.0) i18n-js (>= 3.0.0.rc10) - image_optim (>= 0.22.0) + image_optim_rails jquery-rails jshint json @@@ -354,12 -335,12 +355,13 @@@ libxml-ruby (>= 2.0.5) logstasher minitest (~> 5.1) + minitest-stub_any_instance oauth-plugin (>= 0.5.1) omniauth omniauth-facebook omniauth-github omniauth-google-oauth2 (>= 0.2.7) + omniauth-mediawiki (>= 0.0.3) omniauth-openid omniauth-windowslive paperclip (~> 4.0) @@@ -373,7 -354,6 +375,7 @@@ rails-i18n (~> 4.0.0) redcarpet rinku (>= 1.2.2) + rotp rubocop sanitize sass-rails (~> 5.0) @@@ -381,7 -361,6 +383,7 @@@ uglifier (>= 1.3.0) validates_email_format_of (>= 1.5.1) vendorer + webmock BUNDLED WITH - 1.10.6 + 1.12.5 diff --combined test/controllers/amf_controller_test.rb index fde8883b0,8f58aa980..6272f6fe2 --- a/test/controllers/amf_controller_test.rb +++ b/test/controllers/amf_controller_test.rb @@@ -473,7 -473,7 +473,7 @@@ class AmfControllerTest < ActionControl end def test_findgpx_by_id - trace = gpx_files(:anon_trace_file) + trace = create(:trace, :visibility => "private", :user => users(:public_user)) amf_content "findgpx", "/1", [trace.id, "test@example.com:test"] post :amf_read @@@ -531,10 -531,7 +531,10 @@@ def test_findrelations_by_tags visible_relation = current_relations(:visible_relation) + create(:relation_tag, :relation => visible_relation, :k => "test", :v => "yes") used_relation = current_relations(:used_relation) + create(:relation_tag, :relation => used_relation, :k => "test", :v => "yes") + create(:relation_tag, :relation => used_relation, :k => "name", :v => "Test Relation") amf_content "findrelations", "/1", ["yes"] post :amf_read diff --combined test/controllers/api_controller_test.rb index bcc544263,67469d094..540f303ed --- a/test/controllers/api_controller_test.rb +++ b/test/controllers/api_controller_test.rb @@@ -53,7 -53,6 +53,7 @@@ class ApiControllerTest < ActionControl def test_map node = current_nodes(:used_node_1) + tag = create(:node_tag, :node => node) # Need to split the min/max lat/lon out into their own variables here # so that we can test they are returned later. minlon = node.lon - 0.1 @@@ -71,7 -70,7 +71,7 @@@ assert_select "bounds[minlon='#{minlon}'][minlat='#{minlat}'][maxlon='#{maxlon}'][maxlat='#{maxlat}']", :count => 1 assert_select "node[id='#{node.id}'][lat='#{node.lat}'][lon='#{node.lon}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do # This should really be more generic - assert_select "tag[k='test'][v='yes']" + assert_select "tag[k='#{tag.k}'][v='#{tag.v}']" end assert_select "way", :count => 2 assert_select "way[id='1']", :count => 1 @@@ -85,7 -84,6 +85,7 @@@ # the same as the node we are looking at def test_map_inclusive node = current_nodes(:used_node_1) + tag = create(:node_tag, :node => node) bbox = "#{node.lon},#{node.lat},#{node.lon},#{node.lat}" get :map, :bbox => bbox assert_response :success, "The map call should have succeeded" @@@ -93,7 -91,7 +93,7 @@@ assert_select "bounds[minlon='#{node.lon}'][minlat='#{node.lat}'][maxlon='#{node.lon}'][maxlat='#{node.lat}']", :count => 1 assert_select "node[id='#{node.id}'][lat='#{node.lat}'][lon='#{node.lon}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do # This should really be more generic - assert_select "tag[k='test'][v='yes']" + assert_select "tag[k='#{tag.k}'][v='#{tag.v}']" end assert_select "way", :count => 2 assert_select "way[id='1']", :count => 1 @@@ -134,7 -132,9 +134,9 @@@ end def test_tracepoints - point = gpx_files(:public_trace_file) + point = create(:trace, :visibility => "public", :latitude => 1, :longitude => 1) do |trace| + create(:tracepoint, :trace => trace, :latitude => 1 * GeoRecord::SCALE, :longitude => 1 * GeoRecord::SCALE) + end minlon = point.longitude - 0.001 minlat = point.latitude - 0.001 maxlon = point.longitude + 0.001 @@@ -150,7 -150,10 +152,10 @@@ end def test_tracepoints_trackable - point = gpx_files(:trackable_trace_file) + point = create(:trace, :visibility => "trackable", :latitude => 51.51, :longitude => -0.14) do |trace| + create(:tracepoint, :trace => trace, :trackid => 1, :latitude => (51.510 * GeoRecord::SCALE).to_i, :longitude => (-0.140 * GeoRecord::SCALE).to_i) + create(:tracepoint, :trace => trace, :trackid => 2, :latitude => (51.511 * GeoRecord::SCALE).to_i, :longitude => (-0.141 * GeoRecord::SCALE).to_i) + end minlon = point.longitude - 0.002 minlat = point.latitude - 0.002 maxlon = point.longitude + 0.002 @@@ -172,7 -175,9 +177,9 @@@ end def test_tracepoints_identifiable - point = gpx_files(:identifiable_trace_file) + point = create(:trace, :visibility => "identifiable", :latitude => 51.512, :longitude => 0.142) do |trace| + create(:tracepoint, :trace => trace, :latitude => (51.512 * GeoRecord::SCALE).to_i, :longitude => (0.142 * GeoRecord::SCALE).to_i) + end minlon = point.longitude - 0.002 minlat = point.latitude - 0.002 maxlon = point.longitude + 0.002 diff --combined test/controllers/site_controller_test.rb index 5efddd52e,7e387f684..e1eeac294 --- a/test/controllers/site_controller_test.rb +++ b/test/controllers/site_controller_test.rb @@@ -6,10 -6,8 +6,10 @@@ class SiteControllerTest < ActionContro ## # setup oauth keys def setup - Object.const_set("ID_KEY", client_applications(:oauth_web_app).key) - Object.const_set("POTLATCH2_KEY", client_applications(:oauth_web_app).key) + Object.const_set("ID_KEY", create(:client_application).key) + Object.const_set("POTLATCH2_KEY", create(:client_application).key) + + stub_hostip_requests end ## @@@ -282,7 -280,7 +282,7 @@@ # Test editing a specific GPX trace def test_edit_with_gpx user = users(:public_user) - gpx = gpx_files(:public_trace_file) + gpx = create(:trace, :latitude => 1, :longitude => 1) get :edit, { :gpx => gpx.id }, { :user => user.id } assert_response :success diff --combined test/controllers/user_controller_test.rb index 95eccb2c5,9e499b605..a5d723c91 --- a/test/controllers/user_controller_test.rb +++ b/test/controllers/user_controller_test.rb @@@ -3,10 -3,6 +3,10 @@@ require "test_helper class UserControllerTest < ActionController::TestCase api_fixtures + def setup + stub_hostip_requests + end + ## # test all routes which lead to this controller def test_routes @@@ -396,7 -392,6 +396,7 @@@ def test_confirm_success_no_token_no_referer user = users(:inactive_user) + stub_gravatar_request(user.email) confirm_string = user.tokens.create.token @request.cookies["_osm_session"] = user.display_name @@@ -407,7 -402,6 +407,7 @@@ def test_confirm_success_good_token_no_referer user = users(:inactive_user) + stub_gravatar_request(user.email) confirm_string = user.tokens.create.token token = user.tokens.create.token @@@ -418,7 -412,6 +418,7 @@@ def test_confirm_success_bad_token_no_referer user = users(:inactive_user) + stub_gravatar_request(user.email) confirm_string = user.tokens.create.token token = users(:normal_user).tokens.create.token @@@ -430,7 -423,6 +430,7 @@@ def test_confirm_success_no_token_with_referer user = users(:inactive_user) + stub_gravatar_request(user.email) confirm_string = user.tokens.create(:referer => diary_new_path).token @request.cookies["_osm_session"] = user.display_name @@@ -441,7 -433,6 +441,7 @@@ def test_confirm_success_good_token_with_referer user = users(:inactive_user) + stub_gravatar_request(user.email) confirm_string = user.tokens.create(:referer => diary_new_path).token token = user.tokens.create.token @@@ -452,7 -443,6 +452,7 @@@ def test_confirm_success_bad_token_with_referer user = users(:inactive_user) + stub_gravatar_request(user.email) confirm_string = user.tokens.create(:referer => diary_new_path).token token = users(:normal_user).tokens.create.token @@@ -531,7 -521,6 +531,7 @@@ def test_confirm_email_success user = users(:second_public_user) + stub_gravatar_request(user.new_email) confirm_string = user.tokens.create.token post :confirm_email, :confirm_string => confirm_string @@@ -562,33 -551,35 +562,33 @@@ # this happens when the email is actually changed # which is triggered by the confirmation mail def test_gravatar_auto_enable - with_http_stubs "gravatar" do - # switch to email that has a gravatar - user = users(:first_gravatar_user) - confirm_string = user.tokens.create.token - # precondition gravatar should be turned off - assert !user.image_use_gravatar - post :confirm_email, :confirm_string => confirm_string - assert_response :redirect - assert_redirected_to :action => :account, :display_name => user.display_name - assert_match /Confirmed your change of email address/, flash[:notice] - # gravatar use should now be enabled - assert User.find(users(:first_gravatar_user).id).image_use_gravatar - end + # switch to email that has a gravatar + user = users(:first_gravatar_user) + stub_gravatar_request(user.new_email, 200) + confirm_string = user.tokens.create.token + # precondition gravatar should be turned off + assert !user.image_use_gravatar + post :confirm_email, :confirm_string => confirm_string + assert_response :redirect + assert_redirected_to :action => :account, :display_name => user.display_name + assert_match /Confirmed your change of email address/, flash[:notice] + # gravatar use should now be enabled + assert User.find(users(:first_gravatar_user).id).image_use_gravatar end def test_gravatar_auto_disable - with_http_stubs "gravatar" do - # switch to email without a gravatar - user = users(:second_gravatar_user) - confirm_string = user.tokens.create.token - # precondition gravatar should be turned on - assert user.image_use_gravatar - post :confirm_email, :confirm_string => confirm_string - assert_response :redirect - assert_redirected_to :action => :account, :display_name => user.display_name - assert_match /Confirmed your change of email address/, flash[:notice] - # gravatar use should now be disabled - assert !User.find(users(:second_gravatar_user).id).image_use_gravatar - end + # switch to email without a gravatar + user = users(:second_gravatar_user) + stub_gravatar_request(user.new_email, 404) + confirm_string = user.tokens.create.token + # precondition gravatar should be turned on + assert user.image_use_gravatar + post :confirm_email, :confirm_string => confirm_string + assert_response :redirect + assert_redirected_to :action => :account, :display_name => user.display_name + assert_match /Confirmed your change of email address/, flash[:notice] + # gravatar use should now be disabled + assert !User.find(users(:second_gravatar_user).id).image_use_gravatar end def test_terms_new_user @@@ -813,7 -804,7 +813,7 @@@ assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected]", false # Changing to an uploaded image should work - image = Rack::Test::UploadedFile.new("test/traces/1.gif", "image/gif") + image = Rack::Test::UploadedFile.new("test/traces/a.gif", "image/gif") post :account, { :display_name => user.display_name, :image_action => "new", :user => user.attributes.merge(:image => image) }, { :user => user.id } assert_response :success assert_template :account @@@ -1094,6 -1085,12 +1094,12 @@@ end def test_api_gpx_files + trace1 = create(:trace, :user => users(:normal_user)) do |trace| + create(:tracetag, :trace => trace, :tag => "London") + end + trace2 = create(:trace, :user => users(:normal_user)) do |trace| + create(:tracetag, :trace => trace, :tag => "Birmingham") + end # check that nothing is returned when not logged in get :api_gpx_files assert_response :unauthorized @@@ -1105,10 -1102,10 +1111,10 @@@ assert_equal "text/xml", response.content_type # check the data that is returned - assert_select "gpx_file[id='1']", 1 do + assert_select "gpx_file[id='#{trace1.id}']", 1 do assert_select "tag", "London" end - assert_select "gpx_file[id='4']", 1 do + assert_select "gpx_file[id='#{trace2.id}']", 1 do assert_select "tag", "Birmingham" end end @@@ -1384,7 -1381,7 +1390,7 @@@ get :list, :page => 3 assert_response :success assert_template :list - assert_select "table#user_list tr", :count => 25 + assert_select "table#user_list tr", :count => 26 end def test_list_post_confirm diff --combined test/integration/oauth_test.rb index ceee95892,ad3d5383d..8971b7a2b --- a/test/integration/oauth_test.rb +++ b/test/integration/oauth_test.rb @@@ -1,28 -1,23 +1,27 @@@ require "test_helper" class OAuthTest < ActionDispatch::IntegrationTest - fixtures :users, :gpx_files - set_fixture_class :gpx_files => Trace - fixtures :users, :client_applications ++ fixtures :users include OAuth::Helper + def setup + stub_hostip_requests + end + def test_oauth10_web_app - client = client_applications(:oauth_web_app) + client = create(:client_application, :callback_url => "http://some.web.app.example.org/callback", :user => users(:public_user), :allow_read_prefs => true, :allow_write_api => true, :allow_read_gpx => true) post_via_redirect "/login", :username => client.user.email, :password => "test" assert_response :success oauth10_without_callback(client) - oauth10_with_callback(client, "http://another.web.app.org/callback") + oauth10_with_callback(client, "http://another.web.app.example.org/callback") oauth10_refused(client) end def test_oauth10_desktop_app - client = client_applications(:oauth_desktop_app) + client = create(:client_application, :user => users(:public_user), :allow_read_prefs => true, :allow_write_api => true, :allow_read_gpx => true) post_via_redirect "/login", :username => client.user.email, :password => "test" assert_response :success @@@ -32,18 -27,18 +31,18 @@@ end def test_oauth10a_web_app - client = client_applications(:oauth_web_app) + client = create(:client_application, :callback_url => "http://some.web.app.example.org/callback", :user => users(:public_user), :allow_read_prefs => true, :allow_write_api => true, :allow_read_gpx => true) post_via_redirect "/login", :username => client.user.email, :password => "test" assert_response :success oauth10a_without_callback(client) - oauth10a_with_callback(client, "http://another.web.app.org/callback") + oauth10a_with_callback(client, "http://another.web.app.example.org/callback") oauth10a_refused(client) end def test_oauth10a_desktop_app - client = client_applications(:oauth_desktop_app) + client = create(:client_application, :user => users(:public_user), :allow_read_prefs => true, :allow_write_api => true, :allow_read_gpx => true) post_via_redirect "/login", :username => client.user.email, :password => "test" assert_response :success @@@ -168,7 -163,8 +167,8 @@@ assert_nil token.invalidated_at assert_allowed token, [:allow_write_api, :allow_read_gpx] - signed_get "/api/0.6/gpx/2", :consumer => client, :token => token + trace = create(:trace, :user => users(:public_user)) + signed_get "/api/0.6/gpx/#{trace.id}", :consumer => client, :token => token assert_response :success signed_get "/api/0.6/user/details", :consumer => client, :token => token @@@ -196,7 -192,7 +196,7 @@@ if client.callback_url assert_response :redirect verifier = parse_verifier(response) - assert_redirected_to "http://some.web.app.org/callback?oauth_token=#{token.token}&oauth_verifier=#{verifier}" + assert_redirected_to "http://some.web.app.example.org/callback?oauth_token=#{token.token}&oauth_verifier=#{verifier}" else assert_response :success assert_template :authorize_success @@@ -230,7 -226,8 +230,8 @@@ signed_get "/api/0.6/user/preferences", :consumer => client, :token => token assert_response :success - signed_get "/api/0.6/gpx/2", :consumer => client, :token => token + trace = create(:trace, :user => users(:public_user)) + signed_get "/api/0.6/gpx/#{trace.id}", :consumer => client, :token => token assert_response :forbidden post "/oauth/revoke", :token => token.token @@@ -278,7 -275,8 +279,8 @@@ assert_nil token.invalidated_at assert_allowed token, [:allow_write_api, :allow_read_gpx] - signed_get "/api/0.6/gpx/2", :consumer => client, :token => token + trace = create(:trace, :user => users(:public_user)) + signed_get "/api/0.6/gpx/#{trace.id}", :consumer => client, :token => token assert_response :success signed_get "/api/0.6/user/details", :consumer => client, :token => token @@@ -333,7 -331,7 +335,7 @@@ assert_not_nil token.created_at assert_nil token.authorized_at assert_nil token.invalidated_at - assert_equal options[:oauth_callback], token.callback_url + assert_equal_allowing_nil options[:oauth_callback], token.callback_url assert_allowed token, client.permissions token diff --combined test/test_helper.rb index 10a4eb397,77674147f..dba005145 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@@ -4,7 -4,6 +4,7 @@@ Coveralls.wear!("rails" ENV["RAILS_ENV"] = "test" require File.expand_path("../../config/environment", __FILE__) require "rails/test_help" +require "webmock/minitest" load "composite_primary_keys/fixtures.rb" module ActiveSupport @@@ -15,41 -14,46 +15,36 @@@ def self.api_fixtures # print "setting up the api_fixtures" fixtures :users, :user_roles - fixtures :changesets, :changeset_tags + fixtures :changesets fixtures :current_nodes, :nodes set_fixture_class :current_nodes => Node set_fixture_class :nodes => OldNode - fixtures :current_node_tags, :node_tags - set_fixture_class :current_node_tags => NodeTag - set_fixture_class :node_tags => OldNodeTag - fixtures :current_ways set_fixture_class :current_ways => Way - fixtures :current_way_nodes, :current_way_tags + fixtures :current_way_nodes set_fixture_class :current_way_nodes => WayNode - set_fixture_class :current_way_tags => WayTag fixtures :ways set_fixture_class :ways => OldWay - fixtures :way_nodes, :way_tags + fixtures :way_nodes set_fixture_class :way_nodes => OldWayNode - set_fixture_class :way_tags => OldWayTag fixtures :current_relations set_fixture_class :current_relations => Relation - fixtures :current_relation_members, :current_relation_tags + fixtures :current_relation_members set_fixture_class :current_relation_members => RelationMember - set_fixture_class :current_relation_tags => RelationTag fixtures :relations set_fixture_class :relations => OldRelation - fixtures :relation_members, :relation_tags + fixtures :relation_members set_fixture_class :relation_members => OldRelationMember - set_fixture_class :relation_tags => OldRelationTag - - fixtures :client_applications - fixtures :gpx_files, :gps_points, :gpx_file_tags - set_fixture_class :gpx_files => Trace - set_fixture_class :gps_points => Tracepoint - set_fixture_class :gpx_file_tags => Tracetag - fixtures :redactions end @@@ -67,19 -71,6 +62,19 @@@ end end + ## + # work round minitest insanity that causes it to tell you + # to use assert_nil to test for nil, which is fine if you're + # comparing to a nil constant but not if you're comparing + # an expression that might be nil sometimes + def assert_equal_allowing_nil(exp, act, msg = nil) + if exp.nil? + assert_nil act, msg + else + assert_equal exp, act, msg + end + end + ## # for some reason assert_equal a, b fails when the relations are # actually equal, so this method manually checks the fields... @@@ -164,33 -155,22 +159,33 @@@ ## # execute a block with a given set of HTTP responses stubbed def with_http_stubs(stubs_file) - http_client_save = OSM.http_client + stubs = YAML.load_file(File.expand_path("../http/#{stubs_file}.yml", __FILE__)) + stubs.each do |url, response| + stub_request(:get, Regexp.new(Regexp.quote(url))).to_return(:status => response["code"], :body => response["body"]) + end - begin - stubs = YAML.load_file(File.expand_path("../http/#{stubs_file}.yml", __FILE__)) - - OSM.http_client = Faraday.new do |builder| - builder.adapter :test do |stub| - stubs.each do |url, response| - stub.get(url) { |_env| [response["code"], {}, response["body"]] } - end - end - end + yield + end - yield - ensure - OSM.http_client = http_client_save + def stub_gravatar_request(email, status = 200, body = nil) + hash = Digest::MD5.hexdigest(email.downcase) + url = "https://www.gravatar.com/avatar/#{hash}?d=404" + stub_request(:get, url).and_return(:status => status, :body => body) + end + + def stub_hostip_requests + # Controller tests and integration tests use different IPs + stub_request(:get, "http://api.hostip.info/country.php?ip=0.0.0.0") + stub_request(:get, "http://api.hostip.info/country.php?ip=127.0.0.1") + end + + def email_text_parts(message) + message.parts.each_with_object([]) do |part, text_parts| + if part.content_type.start_with?("text/") + text_parts.push(part) + elsif part.multipart? + text_parts.concat(email_text_parts(part)) + end end end end