<commit_before>require 'spec_helper'

describe TinyDyno::Fields::RangeKey do

  it 'does register fields marked as range_type in the attribute_definitions' do
    expect(Account.attribute_definitions).to eq([{:attribute_name=>"id", :attribute_type=>"S"}, {:attribute_name=>"email", :attribute_type=>"S"}])
  end

  it 'does register fields marked as range_type in the key_schema' do
    expect(Account.key_schema).to eq([{:attribute_name=>"id", :key_type=>"HASH"}, {:attribute_name=>"email", :key_type=>"RANGE"}])
  end

  context 'LOOKUPS' do
    before(:each) {
      TinyDyno::Adapter.disconnect!
      Account.delete_table
      Account.create_table
    }

    after(:each) {
      Account.delete_table
    }
  end

  it 'enables look ups by range key' do
    account = Fabricate(:account)
    account.save
    same_account = Account.where(id: account.id, email: account.email)
    expect(account.attributes).to eq(same_account.attributes)
  end

  it 'raises an error, when specifying a non key field as selector' do
    expect { Account.where(id: '1', label: 'foo') }.to raise_error (TinyDyno::Errors::InvalidSelector)
  end

end<commit_msg>move specs for persistance related range key tests into the right scope<commit_after>require 'spec_helper'

describe TinyDyno::Fields::RangeKey do

  it 'does register fields marked as range_type in the attribute_definitions' do
    expect(Account.attribute_definitions).to eq([{:attribute_name=>"id", :attribute_type=>"S"}, {:attribute_name=>"email", :attribute_type=>"S"}])
  end

  it 'does register fields marked as range_type in the key_schema' do
    expect(Account.key_schema).to eq([{:attribute_name=>"id", :key_type=>"HASH"}, {:attribute_name=>"email", :key_type=>"RANGE"}])
  end

  context 'LOOKUPS' do
    before(:each) {
      TinyDyno::Adapter.disconnect!
      Account.delete_table
      Account.create_table
    }

    after(:each) {
      Account.delete_table
    }

    it 'enables look ups by range key' do
      account = Fabricate(:account)
      account.save
      same_account = Account.where(id: account.id, email: account.email)
      expect(account.attributes).to eq(same_account.attributes)
    end

    it 'raises an error, when specifying a non key field as selector' do
      expect { Account.where(id: '1', label: 'foo') }.to raise_error (TinyDyno::Errors::InvalidSelector)
    end

  end

end
{'fraction_non_alphanumeric': 0.12399831294812315, 'fraction_numerical': 0.0008435259384226065, 'mean_word_length': 4.259423503325943, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '7199214', 'n_tokens_mistral': 771, 'n_tokens_neox': 746, 'n_words': 192}