/
xml_mini_spec.rb
executable file
·47 lines (39 loc) · 1.62 KB
/
xml_mini_spec.rb
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
require File.dirname(__FILE__) + '/../spec_helper'
describe PoxPaginate::XmlMini do
before :all do
@date = DateTime.parse('2010-02-06T21:09:48+05:30')
end
%w(REXML LibXML Nokogiri).each do |deserialiser|
describe "using #{deserialiser}" do
before :all do
ActiveSupport::XmlMini.backend = deserialiser
end
it "should be using the #{deserialiser} backend" do
ActiveSupport::XmlMini.backend.name.should == "ActiveSupport::XmlMini_#{deserialiser}"
end
it "should decorate backend= to extend the XmlMini_#{deserialiser} module" do
"ActiveSupport::XmlMini_#{deserialiser}".constantize.should respond_to(:root_node_attributes)
ActiveSupport::XmlMini.backend.name.should == "ActiveSupport::XmlMini_#{deserialiser}"
end
it "should parse xml with header attributes into a hash" do
Hash.from_xml(paginated_xml(@date)).should == {"oogas"=>[
{"name"=>"Foo", "updated_at"=>@date, "id"=>3, "created_at"=>@date},
{"name"=>"Baz", "updated_at"=>@date, "id"=>4, "created_at"=>@date}
]}
end
it "should know how to extract root node attributes" do
ActiveSupport::XmlMini.root_node_attributes(paginated_xml(@date)).should == {
'type' => "array",
'total_entries' => "10",
'per_page' => "2",
'current_page' => "2"
}
end
it "should not add root node attributes if there are none" do
ActiveSupport::XmlMini.root_node_attributes(unpaginated_xml(@date)).should == {
'type' => "array",
}
end
end
end
end