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

Replace trace-related fixtures with factories. #1347

Merged
merged 7 commits into from Feb 5, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -101,6 +101,7 @@ group :test do
gem "rubocop"
gem "timecop"
gem "minitest", "~> 5.1", :platforms => [:ruby_19, :ruby_20]
gem "minitest-stub_any_instance"
end

# Needed in development as well so rake can see konacha tasks
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -150,6 +150,7 @@ GEM
mimemagic (0.3.0)
mini_portile2 (2.1.0)
minitest (5.9.1)
minitest-stub_any_instance (1.0.1)
multi_json (1.12.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
Expand Down Expand Up @@ -334,6 +335,7 @@ DEPENDENCIES
libxml-ruby (>= 2.0.5)
logstasher
minitest (~> 5.1)
minitest-stub_any_instance
oauth-plugin (>= 0.5.1)
omniauth
omniauth-facebook
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/amf_controller_test.rb
Expand Up @@ -473,7 +473,7 @@ def test_findgpx_bad_user
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
Expand Down
13 changes: 10 additions & 3 deletions test/controllers/api_controller_test.rb
Expand Up @@ -132,7 +132,9 @@ def test_map_empty
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
Expand All @@ -148,7 +150,10 @@ def test_tracepoints
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
Expand All @@ -170,7 +175,9 @@ def test_tracepoints_trackable
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
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/site_controller_test.rb
Expand Up @@ -280,7 +280,7 @@ def test_edit_with_note
# 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
Expand Down
8 changes: 8 additions & 0 deletions test/controllers/swf_controller_test.rb
Expand Up @@ -15,6 +15,14 @@ def test_routes
##
# basic test that trackpoints at least returns some sort of flash movie
def test_trackpoints
create(:trace, :visibility => "trackable", :latitude => 51.51, :longitude => -0.14, :user => users(:public_user)) 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
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

get :trackpoints, :xmin => -1, :xmax => 1, :ymin => 51, :ymax => 52, :baselong => 0, :basey => 0, :masterscale => 1
assert_response :success
assert_equal "application/x-shockwave-flash", response.content_type
Expand Down
651 changes: 359 additions & 292 deletions test/controllers/trace_controller_test.rb

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions test/controllers/user_controller_test.rb
Expand Up @@ -1085,6 +1085,12 @@ def test_api_details
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
Expand All @@ -1096,10 +1102,10 @@ def test_api_gpx_files
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
Expand Down
11 changes: 11 additions & 0 deletions test/factories/tracepoints.rb
@@ -0,0 +1,11 @@
FactoryGirl.define do
factory :tracepoint do
trackid 1
latitude 1 * GeoRecord::SCALE
longitude 1 * GeoRecord::SCALE
# tile QuadTile.tile_for_point(1,1)
timestamp Time.now

trace
end
end
16 changes: 16 additions & 0 deletions test/factories/traces.rb
@@ -0,0 +1,16 @@
FactoryGirl.define do
factory :trace do
sequence(:name) { |n| "Trace #{n}.gpx" }
sequence(:description) { |n| "This is trace #{n}" }

# Fixme requires User Factory
user_id 1

timestamp Time.now
inserted true

trait :deleted do
visible false
end
end
end
7 changes: 7 additions & 0 deletions test/factories/tracetags.rb
@@ -0,0 +1,7 @@
FactoryGirl.define do
factory :tracetag do
sequence(:tag) { |n| "Tag #{n}" }

trace
end
end
35 changes: 0 additions & 35 deletions test/fixtures/gps_points.yml

This file was deleted.

19 changes: 0 additions & 19 deletions test/fixtures/gpx_file_tags.yml

This file was deleted.

129 changes: 0 additions & 129 deletions test/fixtures/gpx_files.yml

This file was deleted.

12 changes: 7 additions & 5 deletions test/integration/oauth_test.rb
@@ -1,8 +1,7 @@
require "test_helper"

class OAuthTest < ActionDispatch::IntegrationTest
fixtures :users, :client_applications, :gpx_files
set_fixture_class :gpx_files => Trace
fixtures :users, :client_applications

include OAuth::Helper

Expand Down Expand Up @@ -164,7 +163,8 @@ def oauth10_with_callback(client, callback_url)
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
Expand Down Expand Up @@ -226,7 +226,8 @@ def oauth10a_without_callback(client)
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
Expand Down Expand Up @@ -274,7 +275,8 @@ def oauth10a_with_callback(client, callback_url)
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
Expand Down