Project

General

Profile

Defect #38182 ยป 38182-with-test.patch

Takenori TAKAKI, 2023-02-01 04:06

View differences:

app/controllers/users_controller.rb
61 61
        format.csv do
62 62
          # Export all entries
63 63
          @entries = scope.to_a
64
          send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'users.csv')
64
          send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => "#{filename_for_export(@query, 'users')}.csv")
65 65
        end
66 66
        format.api do
67 67
          @offset, @limit = api_offset_and_limit
test/functional/users_controller_test.rb
280 280
    assert_equal 'text/csv; header=present', @response.media_type
281 281
  end
282 282

  
283
  def test_index_csv_filename_without_query_id_param
284
    get :index, :params => {:format => 'csv'}
285
    assert_response :success
286
    assert_match /users.csv/, @response.headers['Content-Disposition']
287
  end
288

  
289
  def test_index_csv_filename_with_query_id_param
290
    query = UserQuery.create!(:name => 'My Query Name', :visibility => UserQuery::VISIBILITY_PUBLIC)
291
    get :index, :params => {:query_id => query.id, :format => 'csv'}
292
    assert_response :success
293
    assert_match /my_query_name\.csv/, @response.headers['Content-Disposition']
294
  end
295

  
283 296
  def test_show
284 297
    @request.session[:user_id] = nil
285 298
    get :show, :params => {:id => 2}
    (1-1/1)