require "spec_helper"

describe RedditApi::Posts do

  describe "#top" do
    it "returns n top posts of a subreddit" do
      posts_api = RedditApi::Posts.new
      subreddit_params = { "display_name" => "AskReddit" }
      subreddit = RedditApi::Subreddit.new(subreddit_params)

      result = posts_api.top(subreddit, 5)

      expect(result.length).to eq(5)
    end

    it "excludes stickied posts that are included by default" do
      posts_api = RedditApi::Posts.new
      subreddit_params = { "display_name" => "AskReddit" }
      subreddit = RedditApi::Subreddit.new(subreddit_params)

      result = posts_api.top(subreddit, 5)

      stickied = result.any? { |p| p.stickied }
      expect(stickied).to be false
    end
  end

end

require "spec_helper"

describe RedditApi::Posts do

  describe "#top" do
    it "returns n top posts of a subreddit" do
      posts_api = RedditApi::Posts.new
      subreddit_params = { "display_name" => "AskReddit" }
      subreddit = RedditApi::Subreddit.new(subreddit_params)

      posts = posts_api.top(subreddit, 5)

      expect(posts.length).to eq(5)
    end

    it "posts are unique" do
      posts_api = RedditApi::Posts.new
      subreddit_params = { "display_name" => "AskReddit" }
      subreddit = RedditApi::Subreddit.new(subreddit_params)
      count = 5

      posts = posts_api.top(subreddit, count)
      unique_posts = posts.uniq { |p| p.reddit_id }

      expect(unique_posts.length).to eq(count)
    end

    it "excludes stickied posts that are included by default" do
      posts_api = RedditApi::Posts.new
      subreddit_params = { "display_name" => "AskReddit" }
      subreddit = RedditApi::Subreddit.new(subreddit_params)

      posts = posts_api.top(subreddit, 5)

      stickied = posts.any? { |p| p.stickied }
      expect(stickied).to be false
    end
  end

end

Add uniqueness expectation to RedditApi::Posts
Add uniqueness expectation to RedditApi::Posts

RedditApi::Posts#top
