discourse/spec/views/list/list.erb_spec.rb
Daniel Waterworth 6e161d3e75
DEV: Allow fab! without block (#24314)
The most common thing that we do with fab! is:

    fab!(:thing) { Fabricate(:thing) }

This commit adds a shorthand for this which is just simply:

    fab!(:thing)

i.e. If you omit the block, then, by default, you'll get a `Fabricate`d object using the fabricator of the same name.
2023-11-09 16:47:59 -06:00

34 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require "rails_helper"
RSpec.describe "list/list.erb" do
fab!(:category)
fab!(:topic)
it "add nofollow to RSS alternate link for category" do
view.stubs(:include_crawler_content?).returns(false)
view.stubs(:url_for).returns("https://www.example.com/test.rss")
view.instance_variable_set("@rss", false)
view.instance_variable_set("@category", category)
render template: "list/list", formats: []
expect(view.content_for(:head)).to match(
%r{<link rel="alternate nofollow" type="application/rss\+xml" title="[^"]+" href="https://www.example.com/test\.rss" />},
)
end
it "adds structured data" do
view.stubs(:include_crawler_content?).returns(true)
topic.posters = []
assign(:list, OpenStruct.new(topics: [topic]))
render template: "list/list", formats: []
topic_list = Nokogiri::HTML5.fragment(rendered).css(".topic-list")
first_item = topic_list.css('[itemprop="itemListElement"]')
expect(first_item.css('[itemprop="position"]')[0]["content"]).to eq("1")
expect(first_item.css('[itemprop="url"]')[0]["href"]).to eq(topic.url)
end
end