spec/gateway_spec.rb in mediawiki-gateway-0.1.3 vs spec/gateway_spec.rb in mediawiki-gateway-0.1.4
- old
+ new
@@ -1,7 +1,14 @@
-require 'active_support'
-require 'rr'
+require 'active_support/version'
+if ActiveSupport::VERSION::MAJOR >= 3
+ # :nodoc: Rails 3: #to_xml is defined in ActiveModel::Serializers::Xml
+ require 'active_model'
+ Hash.send(:include, ActiveModel::Serializers::Xml)
+else
+ # :nodoc: Rails 2.3.x: Hash#to_xml is defined in active_support
+ require 'active_support'
+end
require 'sham_rack'
require 'media_wiki'
require 'spec/fake_media_wiki/app'
@@ -204,19 +211,58 @@
end
describe "#render" do
describe "for an existing wiki page" do
-
+
before do
@pages = @gateway.render('Main Page')
end
- it "should return the page content" do
- expected = "Sample <B>HTML</B> content"
+ it "should return the page content" do
+ expected = 'Sample <B>HTML</B> content.'
@pages.to_s.should == expected
end
+
+ it "should raise an ArgumentError on illegal options" do
+ lambda do
+ @gateway.render("Main Page", :doesnotexist => :at_all)
+ end.should raise_error(ArgumentError)
+ end
+
+ describe "with option" do
+
+ it "should strip img tags" do
+ @pages = @gateway.render('Foopage', :noimages => true)
+
+ expected = 'Sample <B>HTML</B> content.'\
+ '<span class="editsection">[<a title="Edit section: Nomenclature" href="/w/index.php?title=Seat_of_local_government&action=edit&section=1">edit</a>]</span>'\
+ '<a title="Interpreted language" href="/wiki/Interpreted_language">interpreted language</a>'
+ @pages.to_s.should == expected
+ end
+
+ it "should strip edit sections" do
+ @pages = @gateway.render('Foopage', :noeditsections => true)
+
+ expected = 'Sample <B>HTML</B> content.' \
+ '<img width="150" height="150" class="thumbimage" src="http://upload.wikimedia.org/foo/Ruby_logo.svg" alt="Ruby logo.svg"/>' \
+ '<a title="Interpreted language" href="/wiki/Interpreted_language">interpreted language</a>'
+ @pages.to_s.should == expected
+ end
+
+ it "should make all links absolute" do
+ @pages = @gateway.render('Foopage', :linkbase => "http://en.wikipedia.org")
+
+ expected = 'Sample <B>HTML</B> content.' \
+ '<img width="150" height="150" class="thumbimage" src="http://upload.wikimedia.org/foo/Ruby_logo.svg" alt="Ruby logo.svg"/>' \
+ '<span class="editsection">[<a title="Edit section: Nomenclature" href="/w/index.php?title=Seat_of_local_government&action=edit&section=1">edit</a>]</span>'\
+ '<a title="Interpreted language" href="http://en.wikipedia.org/wiki/Interpreted_language">interpreted language</a>'
+ @pages.to_s.should == expected
+ end
+
+ end
+
end
describe "for a missing wiki page" do
before do
@@ -244,11 +290,11 @@
end
it "should create the page" do
expected = <<-XML
<api>
- <edit new='' result='Success' pageid='5' title='A New Page' oldrevid='0' newrevid='5'/>
+ <edit new='' result='Success' pageid='6' title='A New Page' oldrevid='0' newrevid='6'/>
</api>
XML
Hash.from_xml(@page.to_s).should == Hash.from_xml(expected)
end
@@ -267,11 +313,11 @@
end
it "should overwrite the existing page" do
expected = <<-XML
<api>
- <edit result='Success' pageid='5' title='Main Page' oldrevid='1' newrevid='5'/>
+ <edit result='Success' pageid='6' title='Main Page' oldrevid='1' newrevid='6'/>
</api>
XML
Hash.from_xml(@new_page.to_s).should == Hash.from_xml(expected)
end
@@ -433,11 +479,11 @@
before do
@list = @gateway.list("")
end
it "should list all pages" do
- @list.sort.should == [ "Book:Italy", "Level/Level/Index", "Main 2", "Main Page" ]
+ @list.sort.should == [ "Book:Italy", "Foopage", "Level/Level/Index", "Main 2", "Main Page" ]
end
end
describe "with a namespace as the key" do
@@ -542,10 +588,10 @@
before do
@response = @gateway.semantic_query('[[place::123]]', ['mainlabel=Page'])
end
it "should return an HTML string" do
- @response.should == "Sample <B>HTML</B> content"
+ @response.should == 'Sample <B>HTML</B> content.'
end
end
describe "#import" do