Sha256: 3d89be4d5e27cb3894a0c5acf35beb94ccfd2d999769f16db4d5c45da5011c86

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

require 'test_helper'

class FeebableTest < ActiveSupport::TestCase
  test "exists" do
    assert_kind_of Module, Feedable, "feedable isn't what it seems to be"
  end

  test "feedable all" do
    @stuff = feedable Post, Rooster, Alligator
    assert_equal @stuff.length, 9, "not 9 things"
    assert_equal @stuff[0], roosters(:roostr3),  "wrong order"
    assert_equal @stuff[1], posts(:post3),       "wrong order"
    assert_equal @stuff[2], alligators(:gator3), "wrong order"
    assert_equal @stuff[3], roosters(:roostr2),  "wrong order"
    assert_equal @stuff[4], posts(:post2),       "wrong order"
    assert_equal @stuff[5], alligators(:gator2), "wrong order"
    assert_equal @stuff[6], roosters(:roostr1),  "wrong order"
    assert_equal @stuff[7], posts(:post1),       "wrong order"
    assert_equal @stuff[8], alligators(:gator1), "wrong order"
  end

  test "feedable limit" do
    @stuff = feedable Alligator, Post, Rooster, :limit => 5
    assert_equal @stuff.length, 5, "not 5 things"
  end

  test "feedable offset" do
    @stuff = feedable Alligator, Post, Rooster, :limit => 5, :offset => 2
    assert_equal @stuff.length, 5, "not 5 things"
    assert_equal @stuff[0], alligators(:gator3), "not offset"
  end

  test "feedable order" do
    @stuff = feedable Alligator, Post, Rooster, :order => 'asc'
    assert_equal @stuff[0], alligators(:gator1), "not ordered asc"

    @stuff = feedable Alligator, Post, Rooster, :order => 'desc'
    assert_equal @stuff[0], roosters(:roostr3), "not ordered desc"
  end

  test "feedable where conditions" do
    @stuff = feedable Post.where("title='Poster 3'"),
      Rooster.where("kind='DNE'"),
      Alligator.where("name is not null")

    assert_equal @stuff.length, 4, "not 4 things"
  end

  test "unfeedable in query" do
    assert_raise RuntimeError do
      @stuff = feedable Post, Rooster, Trumpet, Alligator
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
feedable-0.9.0 test/feedable_test.rb