File: makerss_spec.rb

package info (click to toggle)
tdiary 5.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,088 kB
  • sloc: ruby: 23,031; javascript: 1,029; xml: 325; makefile: 26; sh: 4
file content (77 lines) | stat: -rw-r--r-- 2,315 bytes parent folder | download | duplicates (4)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require File.expand_path("../plugin_helper", __FILE__)
require "rexml/document"

describe "makerss plugin" do
	before do
		@conf = PluginFake::Config.new.tap {|conf|
			conf.plugin_path = "spec/fixtures/plugin"
			conf.options["base_url"] = "http://example.com/diary/"
		}
		@plugin = TDiary::Plugin.new(
			conf: @conf,
		).tap {|plugin|
			plugin.load_plugin("misc/plugin/makerss.rb")
		}
	end

	describe "#makerss_header" do
		subject(:rdf) do
			REXML::Document.new(@plugin.makerss_header(uri) + "</channel>" + @plugin.makerss_footer)
				.elements["//rdf:RDF"]
		end
		let(:uri) { "http://example.com/test" }
		let(:channel) { rdf.elements["channel"] }
		let(:about) { channel.attributes["about"] }
		let(:description) { channel.elements["description"] }
		let(:rights) { channel.elements["dc:rights"] }

		before do
			@conf.html_lang = "ja-JP"
			@conf.html_title = "<タイトル>"
			@conf.author_name = "<著者>"
		end

		it { expect(rdf.attributes["lang"]).to eq(@conf.html_lang) }
		it { expect(channel.elements["title"].text).to eq(@conf.html_title) }
		it { expect(channel.elements["link"].text).to eq(uri) }
		it { expect(channel.elements["dc:creator"].text).to eq(@conf.author_name) }

		context "with makerss.url" do
			before { @conf["makerss.url"] = "http://example.com/rss" }
			it { expect(about).to eq(@conf["makerss.url"]) }
		end

		context "without makerss.url" do
			before { @conf["makerss.url"] = nil }
			it { expect(about).to eq(@conf["base_url"] + "index.rdf") }
		end

		context "with description" do
			before { @conf["description"] = "<makerss.rbのテスト>" }
			it { expect(description.text).to eq(@conf.description) }
		end

		context "without description" do
			before { @conf["description"] = nil }
			it { expect(description.text).to eq(nil) }
		end

		context "with author_mail" do
			before { @conf.author_mail = "author@example.com" }
			it do
				expect(rights.text).to eq(
					"Copyright #{Time.now.year} #{@conf.author_name} <#{@conf.author_mail}>" \
					", copyright of comments by respective authors")
			end
		end

		context "without author_mail" do
			before { @conf.author_mail = nil }
			it do
				expect(rights.text).to eq(
					"Copyright #{Time.now.year} #{@conf.author_name}" \
					", copyright of comments by respective authors")
			end
		end
	end
end