Skip to content

Commit

Permalink
add stats download tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cesswairimu committed Mar 27, 2019
1 parent d5e3279 commit 0b62e12
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def to_keyword(param)

def format(data, name)
respond_to do |format|
format.csv { send_data data.to_csv }
format.csv { send_data data.to_csv, type: 'text/csv' }
format.json { send_data data.to_json, type: 'application/json; header=present', disposition: "attachment; filename=#{name}.json" }
end
end
Expand Down
1 change: 1 addition & 0 deletions app/models/concerns/raw_stats.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'csv'
module RawStats
extend ActiveSupport::Concern

Expand Down
23 changes: 23 additions & 0 deletions test/functional/stats_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
require 'test_helper'
require 'csv'

class StatsControllerTest < ActionController::TestCase
def setup
@start = 1.month.ago.to_time
@end = Date.today.to_time
@stats = [:notes, :comments, :users, :wikis, :questions, :answers]
end

test 'should assign correct value to graph_notes on GET stats' do
Expand Down Expand Up @@ -45,4 +47,25 @@ def setup
assert_response :success
end

def csv_stats_download
@stats.each do |action|
test "should download #{action} as csv" do
get action, params: { format: 'csv' }
assert_response :success
assert_equal "text/csv", response.content_type
assert_equal "attachment", response['Content-Disposition']
end
end
end

def json_stats_downloads
@stats.each do |action|
test "should download #{action} as json" do
get action, params: { format: 'json' }
assert_response :success
assert_equal "application/json", response.content_type
assert_equal "attachment", response['Content-Disposition']
end
end
end
end

0 comments on commit 0b62e12

Please sign in to comment.