Sha256: 0ba123ec5c6b8e95e63fa844296185eb1a08ea6074a5109fe786cd7261352c4e

Contents?: true

Size: 1.3 KB

Versions: 6

Compression:

Stored size: 1.3 KB

Contents

require 'spec_helper'

describe Tableficate::Finder do
  it 'should filter based on single input passed in' do
    # exact input
    npw = NobelPrizeWinner.tableficate({filter: {first_name: 'Albert'}})
    npw.size.should == 1
    npw.first.first_name.should == 'Albert'
    npw = NobelPrizeWinner.tableficate({filter: {first_name: 'Al'}})
    npw.size.should == 0
  end

  it 'should filter based on multiple inputs passed in' do
    npw = NobelPrizeWinner.tableficate({filter: {first_name: ['Albert', 'Marie']}})
    npw.size.should == 2
    npw.first.first_name.should == 'Albert'
    npw.last.first_name.should == 'Marie'
    npw = NobelPrizeWinner.tableficate({filter: {first_name: ['Al', 'Mar']}})
    npw.size.should == 0
  end

  it 'should attach the table name to the fields from the primary table to avoid ambiguity' do
    npw = NobelPrizeWinner.joins(:nobel_prizes).tableficate({sort: 'first_name'})
    npw.order_values.should == ["#{npw.table_name}.first_name ASC"]

    # secondary table fields are left vague for maximum flexibility
    npw = NobelPrizeWinner.joins(:nobel_prizes).tableficate({sort: 'year'})
    npw.order_values.should == ["year ASC"]
  end

  it 'should allow ranged input filters' do
    np = NobelPrize.tableficate({filter: {year: {start: 1900, stop: 1930}}})
    np.size.should == 4
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tableficate-0.2.1 spec/finder_spec.rb
tableficate-0.2.0 spec/finder_spec.rb
tableficate-0.1.3 spec/finder_spec.rb
tableficate-0.1.2 spec/finder_spec.rb
tableficate-0.1.1 spec/finder_spec.rb
tableficate-0.0.1 spec/finder_spec.rb