<commit_before># encoding: utf-8
require 'spec_helper'

describe Dataset do

  let(:dataset){ 
    create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand( rows: 10, columns: 4 ) )
  }

  describe "#data" do
    subject{ Dataset.find( dataset.id ).data }
    its(:count){ should eq 10 }
    its(:to_h){ should be_a Hash }
  end
  
  context "updated" do
    
    subject{
      dataset.updated_at
      sleep(0.75)
      Dataset.find( dataset.id )
    }
    
    describe "#data" do
      before(:each){ subject.data = Quandl::Fabricate::Data.rand( rows: 12, columns: 4 ); sleep(1); subject.save }
      its(:updated_at){ should_not eq dataset.updated_at }
      its(:data){ should_not eq dataset.data }<commit_msg>add failing specs for data scopes<commit_after># encoding: utf-8
require 'spec_helper'

describe Quandl::Client::Dataset::Data do

  let(:dataset){ 
    create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand( rows: 10, columns: 4 ) )
  }
  
  describe ".with_id" do
    subject{ Quandl::Client::Dataset::Data.with_id(6668) }
    let(:data){ Quandl::Client::Dataset::Data.with_id(6668).to_table }
    
    let(:beginning_of_last_week){ Date.today.jd - Date.today.beginning_of_week.jd }
    
    it("data"){ data.count.should > 100 }
    it(".row(:beginning_of_last_week)"){ subject.row( beginning_of_last_week ).to_table.count.should eq 1 }
    it(".rows(5)"){ subject.rows(5).to_table.count.should eq 5 }
    it(".limit(2)"){ subject.limit(2).to_table.count.should eq 2 }
    it(".column(2)"){ subject.column(2).to_table.first.count.should eq 2 }
    it(".order('asc')"){ subject.order('asc').to_table.first.first.should eq data.sort_ascending!.first.first }
    it(".order('desc')"){ subject.order('desc').to_table.first.first.should eq data.sort_descending!.first.first }
    it(".trim_start().trim_end()"){ subject.trim_start( data[11].first ).trim_end(data[10].first).to_table.first.first.should eq data[10].first }
    it(".collapse('monthly')"){ subject.collapse('monthly').to_table.frequency.should eq :monthly }
    it(".transform('rdiff')"){ subject.transform('rdiff').to_table[0][1].should_not eq data[0][1] }
  end
  
  describe "#data" do
    subject{ Dataset.find( dataset.id ).data }
    its(:count){ should eq 10 }
    its(:to_h){ should be_a Hash }
  end
  
  context "updated" do
    
    subject{
      dataset.updated_at
      sleep(0.75)
      Dataset.find( dataset.id )
    }
    
    describe "#data" do
      before(:each){ subject.data = Quandl::Fabricate::Data.rand( rows: 12, columns: 4 ); sleep(1); subject.save }
      its(:updated_at){ should_not eq dataset.updated_at }
      its(:data){ should_not eq dataset.data }
{'fraction_non_alphanumeric': 0.16216216216216217, 'fraction_numerical': 0.020818115412710007, 'mean_word_length': 3.763478260869565, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '309', 'n_tokens_mistral': 994, 'n_tokens_neox': 940, 'n_words': 183}