Sha256: 4f94bb04a52e1afa4552456822b88b9d00eb1cd446114c25ac7425eca599b932

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

require_relative 'test_helper'

class PluckTest < Hario::Test
  def test_simple_pluck
    brands = Brand.search(nil, ["name"])

    assert_equal ["id", "name"], brands.flat_map(&:keys).uniq,
        "Pluck not returning correct attributes"
  end

  def test_pluck_through_association
    # TODO: fix this so that it returns the association_name.attribute as
    # the hash key, rather than table_name.attribute (different to input)
    products = Product.search(nil, ["name", "brand.name"])

    assert_equal ["id", "name", "brands.name"], products.flat_map(&:keys).uniq,
        "Pluck not returning correct attributes with association pluck"
  end

  def test_hidden_column_pluck
    assert_raises Hario::PluckParser::InvalidAttributeError do
      Product.search(nil, %w( hidden_column ))
    end
  end

  def test_hidden_column_pluck_with_join
    assert_raises Hario::PluckParser::InvalidAttributeError do
      Brand.search(nil, %w( products.hidden_column ))
    end
  end

  def test_empty_string_ignored
    Product.search(nil, [""])

    # no exception
    assert true
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hario-0.3.2 test/pluck_test.rb
hario-0.3.1 test/pluck_test.rb