<p><b>@tomhughes</b> requested changes on this pull request.</p>
<p>I'm really confused by all the stubbing as there doesn't seem to be any obvious need to stub things that just return strings like <code>large_picture_name</code>?</p>
<p>I got the impression it was related to the mime ype stuff but as the files exist I don't see any reason why that wouldn't work in the test environment?</p><hr>
<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/1347#pullrequestreview-6369996">test/controllers/trace_controller_test.rb</a>:</p>
<pre style='color:#555'>> get :view, { :display_name => users(:public_user).display_name, :id => 0 }, { :user => users(:public_user).id }
assert_response :redirect
assert_redirected_to :action => :list
- # And finally we should be able to do it with the owner of the trace
- get :view, { :display_name => users(:public_user).display_name, :id => 5 }, { :user => users(:public_user).id }
+ # And finally we should not be able to view a deleted trace
+ deleted_trace_file = create(:trace, :deleted)
</pre>
<p>This should be created at the start of the method or the previous tests aren't really testing what they are supposed to test.</p>
<hr>
<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/1347#pullrequestreview-6369996">test/controllers/trace_controller_test.rb</a>:</p>
<pre style='color:#555'>> assert_response :redirect
assert_redirected_to :action => :list
end
# Test downloading a trace
def test_data
- # First with no auth, which should work since the trace is public
- get :data, :display_name => users(:normal_user).display_name, :id => gpx_files(:public_trace_file).id
- check_trace_data gpx_files(:public_trace_file)
-
- # Now with some other user, which should work since the trace is public
- get :data, { :display_name => users(:normal_user).display_name, :id => gpx_files(:public_trace_file).id }, { :user => users(:public_user).id }
- check_trace_data gpx_files(:public_trace_file)
-
- # And finally we should be able to do it with the owner of the trace
- get :data, { :display_name => users(:normal_user).display_name, :id => gpx_files(:public_trace_file).id }, { :user => users(:normal_user).id }
- check_trace_data gpx_files(:public_trace_file)
+ public_trace_file = create(:trace, :visibility => "public", :user => users(:normal_user))
+ Trace.stub_any_instance :trace_name, "#{GPX_TRACE_DIR}/1.gpx" do
</pre>
<p>Don't we need to replace <code>1.gpx</code> here with whatever trace ID the factory allocated? That is what <code>check_trace_data</code> expects?</p>
<hr>
<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/1347#pullrequestreview-6369996">test/controllers/trace_controller_test.rb</a>:</p>
<pre style='color:#555'>> @@ -353,38 +367,45 @@ def test_data_not_found
assert_response :not_found
# Now with a trace that has been deleted
- get :data, { :display_name => users(:public_user).display_name, :id => 5 }, { :user => users(:public_user).id }
+ deleted_trace_file = create(:trace, :deleted)
</pre>
<p>As before this needs to go at the start of the method.</p>
<hr>
<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/1347#pullrequestreview-6369996">test/controllers/trace_controller_test.rb</a>:</p>
<pre style='color:#555'>> - assert_not_equal "trackable", users(:public_user).preferences.where(:k => "gps.trace.visibility").first.v
- post :create, { :trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" } }, { :user => users(:public_user).id }
- assert_response :redirect
- assert_redirected_to :action => :list, :display_name => users(:public_user).display_name
- assert_match /file has been uploaded/, flash[:notice]
- trace = Trace.order(:id => :desc).first
- assert_equal "1.gpx", trace.name
- assert_equal "New Trace", trace.description
- assert_equal %w(new trace), trace.tags.order(:tag).collect(&:tag)
- assert_equal "trackable", trace.visibility
- assert_equal false, trace.inserted
- assert_equal File.new(gpx_files(:public_trace_file).trace_name).read, File.new(trace.trace_name).read
- trace.destroy
- assert_equal "trackable", users(:public_user).preferences.where(:k => "gps.trace.visibility").first.v
+ public_trace_file = create(:trace, :visibility => "public")
+ public_trace_file.stub :trace_name, "#{GPX_TRACE_DIR}/1.gpx" do
</pre>
<p>This seems different to the way other ones are stubbed?</p>
<hr>
<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/1347#pullrequestreview-6369996">test/controllers/trace_controller_test.rb</a>:</p>
<pre style='color:#555'>> - # Now authenticated, with the legacy private flag
- assert_nil users(:second_public_user).preferences.where(:k => "gps.trace.visibility").first
- basic_authorization(users(:second_public_user).display_name, "test")
- post :api_create, :file => file, :description => "New Trace", :tags => "new,trace", :public => 0
- assert_response :success
- trace = Trace.find(response.body.to_i)
- assert_equal "1.gpx", trace.name
- assert_equal "New Trace", trace.description
- assert_equal %w(new trace), trace.tags.order(:tag).collect(&:tag)
- assert_equal "private", trace.visibility
- assert_equal false, trace.inserted
- assert_equal File.new(gpx_files(:public_trace_file).trace_name).read, File.new(trace.trace_name).read
- trace.destroy
- assert_equal "private", users(:second_public_user).preferences.where(:k => "gps.trace.visibility").first.v
+ public_trace_file = create(:trace, :visibility => "public", :user => users(:normal_user))
+ public_trace_file.stub :trace_name, "#{GPX_TRACE_DIR}/1.gpx" do
</pre>
<p>Another one where the stubbing is different.</p>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/1347#pullrequestreview-6369996">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABWnLc85OE4dZFXIJlyx7nLmUJVf55Itks5q5PbygaJpZM4KkH9o">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/ABWnLeL7iyFqEV7yIw_oPdRhuoWKiwKpks5q5PbygaJpZM4KkH9o.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
<link itemprop="url" href="https://github.com/openstreetmap/openstreetmap-website/pull/1347#pullrequestreview-6369996"></link>
<meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/openstreetmap/openstreetmap-website","title":"openstreetmap/openstreetmap-website","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/openstreetmap/openstreetmap-website"}},"updates":{"snippets":[{"icon":"PERSON","message":"@tomhughes requested changes on #1347"}],"action":{"name":"View Pull Request","url":"https://github.com/openstreetmap/openstreetmap-website/pull/1347#pullrequestreview-6369996"}}}</script>