Sha256: d68cf32f31507d76b97acc43dc2b6994646ff1766e8ceda94672b7625b2e38d2
Contents?: true
Size: 1.89 KB
Versions: 1
Compression:
Stored size: 1.89 KB
Contents
require_relative "test_helper" class TestHightop < Minitest::Test def setup Visit.delete_all end def test_top create_city("San Francisco", 3) create_city("Chicago", 2) expected = { "San Francisco" => 3, "Chicago" => 2 } assert_equal expected, Visit.top(:city) end def test_limit create_city("San Francisco", 3) create_city("Chicago", 2) create_city("Boston", 1) expected = { "San Francisco" => 3, "Chicago" => 2 } assert_equal expected, Visit.top(:city, 2) assert_equal expected, Visit.limit(2).top(:city) end def test_nil_values create_city("San Francisco", 3) create_city(nil, 2) expected = { "San Francisco" => 3, } assert_equal expected, Visit.top(:city) end def test_nil_option create_city("San Francisco", 3) create_city(nil, 2) expected = { "San Francisco" => 3, nil => 2 } assert_equal expected, Visit.top(:city, nil: true) end def test_multiple_groups create_city("San Francisco") expected = { ["San Francisco", "San Francisco"] => 1 } assert_equal expected, Visit.top([:city, :city]) end def test_expressions create_city("San Francisco") expected = { "san francisco" => 1 } assert_equal expected, Visit.top("LOWER(city)") end def test_uniq create({city: "San Francisco", user_id: 1}) create({city: "San Francisco", user_id: 1}) expected = { "San Francisco" => 1 } assert_equal expected, Visit.top(:city, uniq: :user_id) end def test_min create_city("San Francisco", 3) create_city("Chicago", 2) expected = { "San Francisco" => 3 } assert_equal expected, Visit.top(:city, min: 3) end def create_city(city, count = 1) create({city: city}, count) end def create(attributes, count = 1) count.times{ Visit.create!(attributes) } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hightop-0.1.2 | test/hightop_test.rb |