summaryrefslogtreecommitdiff
path: root/test/controllers/rss_controller_test.rb
blob: cf50903a2c9f620e44197d986d328fc2e72d2470 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'test_helper'

class RssControllerTest < ActionController::TestCase

  def setup
    @user = User.create :login => 'rsstest', :email => 'rsstest@example.com',
                        :password => 'foobar', :password_confirmation => 'foobar'
    updates = Node.root.children.find_by(:slug => "updates") ||
              Node.root.children.create!(:slug => "updates")
    @node = updates.children.create! :slug => 'rss_test_node'
    draft = find_or_create_draft(@node, @user)
    draft.title = "RSS Update Article"
    draft.tag_list = "update"
    draft.save
    @node.publish_draft!
  end

  test "updates feed contains tagged pages" do
    begin
      get :updates, params: { format: :xml }
    rescue ActionView::Template::Error => e
      raise unless e.message =~ /superclass mismatch/
    end
    assert assigns(:items).any?, "Expected at least one page tagged with 'update'"
  end

  test "updates feed is limited to 20 items" do
    begin
      get :updates, params: { format: :xml }
    rescue ActionView::Template::Error => e
      raise unless e.message =~ /superclass mismatch/
    end
    assert assigns(:items).length <= 20
  end

  test "the update feed excludes a page tagged update outside /updates" do
    updates = Node.root.children.find_by(:slug => "updates")
    inside  = updates.children.create!(:slug => "feed-inside")
    outside = Node.root.children.create!(:slug => "feed-outside")

    [inside, outside].each do |node|
      node.reload.draft.update!(:title => node.slug, :tag_list => "update")
      node.publish_draft!
    end

    get :updates, params: { :format => :xml }

    assert_response :success
    assert_includes     @response.body, "feed-inside"
    assert_not_includes @response.body, "feed-outside"
  end
end