<commit_before>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'streamer_app'  # <-- your sinatra app
require 'spec'
require 'rack/test'
require 'rr'
require 'iconv'
require 'utf_16_bom'

set :environment, :test
require 'streamer_app'

describe StreamerApp do
  include Rack::Test::Methods

  def app
    StreamerApp
  end

  before do
    @shops = [Shop.create(:name=>'shop'),Shop.create(:name=>'shop2')]
    @shop = @shops.first
    @products = [1,2,5].collect do |num|
      Product.create(:shop => @shop,
        :id => num,
        :title => "title #{num}",
        :description => "description #{num}",
        :price => num*100
      )
    end
    csv_sequence = CsvStreamer.csv_sequence(Product)
    p csv_sequence
    rows = ([csv_sequence] + @products.collect do |product|
      csv_sequence.collect do |field|
        product.send(field)
      end
    end)
    p rows
    @csv = rows.collect {|values| values.join(CsvStreamer::COLUMN_SEPARATOR)}.join(CsvStreamer::ROW_SEPARATOR)+CsvStreamer::ROW_SEPARATOR
  utf_16_le_iconv = Iconv.new('UTF-16LE', 'UTF-8')
  @csv =  utf16le_bom + utf_16_le_iconv.iconv(@csv)
  @json = Product.all.to_json
  end

  ["csv", "json"].each do |format|
    it "should respond to URLs like /demo/$/products.#{format}" do
      get "/demo/1/products.#{format}"
      last_response.should be_ok
    end
  end

  it "should return csv for all products of the shop" do
     get '/demo/1/products.csv'
     last_response.body.should == @csv
  end

  it "should return json for all products of the shop" do
     get '/demo/1/products.json'
     last_response.body.should == @json
  end<commit_msg>Check for response content type in specs.<commit_after>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'streamer_app'  # <-- your sinatra app
require 'spec'
require 'rack/test'
require 'rr'
require 'iconv'
require 'utf_16_bom'

set :environment, :test
require 'streamer_app'

describe StreamerApp do
  include Rack::Test::Methods

  def app
    StreamerApp
  end

  before do
    @shops = [Shop.create(:name=>'shop'),Shop.create(:name=>'shop2')]
    @shop = @shops.first
    @products = [1,2,5].collect do |num|
      Product.create(:shop => @shop,
        :id => num,
        :title => "title #{num}",
        :description => "description #{num}",
        :price => num*100
      )
    end
    csv_sequence = CsvStreamer.csv_sequence(Product)
    p csv_sequence
    rows = ([csv_sequence] + @products.collect do |product|
      csv_sequence.collect do |field|
        product.send(field)
      end
    end)
    p rows
    @csv = rows.collect {|values| values.join(CsvStreamer::COLUMN_SEPARATOR)}.join(CsvStreamer::ROW_SEPARATOR)+CsvStreamer::ROW_SEPARATOR
  utf_16_le_iconv = Iconv.new('UTF-16LE', 'UTF-8')
  @csv =  utf16le_bom + utf_16_le_iconv.iconv(@csv)
  @json = Product.all.to_json
  end

  ["csv", "json"].each do |format|
    it "should respond to URLs like /demo/$/products.#{format}" do
      get "/demo/1/products.#{format}"
      last_response.should be_ok
    end
  end

  it "should return csv for all products of the shop" do
     get '/demo/1/products.csv'
     last_response.body.should == @csv
     last_response.content_type.should == 'text/csv'
  end

  it "should return json for all products of the shop" do
     get '/demo/1/products.json'
     last_response.body.should == @json
     last_response.content_type.should == 'application/json'
  end
{'fraction_non_alphanumeric': 0.1347045191193511, 'fraction_numerical': 0.01216685979142526, 'mean_word_length': 3.294776119402985, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3363626', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1178, 'n_words': 279}