muffins 0.0.7.pre → 0.0.7.pre.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/muffins/class_methods.rb +1 -1
- data/lib/muffins/document.rb +10 -1
- data/lib/muffins/mapping.rb +3 -13
- data/lib/muffins/mapping_parent.rb +4 -7
- data/lib/muffins/version.rb +1 -1
- data/spec/fixtures/books.xml +3497 -11
- data/spec/muffins/document_spec.rb +3 -3
- data/spec/muffins/mapping_parent_spec.rb +3 -3
- data/spec/muffins/mapping_spec.rb +0 -6
- data/spec/muffins_spec.rb +43 -5
- metadata +9 -9
@@ -26,11 +26,11 @@ describe Muffins::Document do
|
|
26
26
|
context "XML" do
|
27
27
|
|
28
28
|
let(:body) { fixture_file("books.xml") }
|
29
|
-
let(:path) { "
|
29
|
+
let(:path) { "Item" }
|
30
30
|
|
31
31
|
describe "#all" do
|
32
|
-
it "returns
|
33
|
-
subject.all(path).size.should eql(
|
32
|
+
it "returns 10 objects" do
|
33
|
+
subject.all(path).size.should eql(10)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Muffins::MappingParent do
|
4
4
|
|
5
|
-
class
|
5
|
+
class Foo
|
6
6
|
include Muffins
|
7
7
|
end
|
8
8
|
|
@@ -13,8 +13,8 @@ describe Muffins::MappingParent do
|
|
13
13
|
:klass => klass }
|
14
14
|
end
|
15
15
|
|
16
|
-
let(:klass) {
|
17
|
-
let(:path) { "#
|
16
|
+
let(:klass) { Foo }
|
17
|
+
let(:path) { "#foo" }
|
18
18
|
|
19
19
|
let(:name) { :foo }
|
20
20
|
let(:type) { String }
|
@@ -23,12 +23,6 @@ describe Muffins::Mapping do
|
|
23
23
|
its(:absolute_path) { should eql("#books > .book > .title") }
|
24
24
|
its(:relative_path) { should eql(".book > .title") }
|
25
25
|
|
26
|
-
describe "#coerce" do
|
27
|
-
it "coerces to the set type" do
|
28
|
-
subject.coerce(1).should be_a(String)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
26
|
describe "#parse" do
|
33
27
|
context "when collection is false" do
|
34
28
|
it { subject.parse(document).should eql("War and Peace (Vintage Classics)") }
|
data/spec/muffins_spec.rb
CHANGED
@@ -5,7 +5,18 @@ describe Muffins do
|
|
5
5
|
class Book
|
6
6
|
include Muffins
|
7
7
|
|
8
|
-
path "
|
8
|
+
path "Item"
|
9
|
+
|
10
|
+
map :asin, String, :to => "ASIN"
|
11
|
+
map :sales_rank, Integer, :to => "SalesRank"
|
12
|
+
|
13
|
+
map :description, String, :to => "Content", :within => "EditorialReview"
|
14
|
+
|
15
|
+
within "ItemAttributes" do |attributes|
|
16
|
+
attributes.map :isbn, String, :to => "ISBN"
|
17
|
+
attributes.map :release_date, Date, :to => "ReleaseDate"
|
18
|
+
end
|
19
|
+
|
9
20
|
end
|
10
21
|
|
11
22
|
subject { Book }
|
@@ -18,12 +29,39 @@ describe Muffins do
|
|
18
29
|
let(:mapping) { mock(Muffins::Mapping) }
|
19
30
|
let(:mappings) { [] }
|
20
31
|
|
21
|
-
|
32
|
+
context "XML" do
|
33
|
+
|
34
|
+
let(:document) { fixture_file("books.xml") }
|
35
|
+
|
36
|
+
describe ".parse" do
|
37
|
+
let(:books) { subject.parse(document) }
|
38
|
+
let(:book) { books.first }
|
39
|
+
|
40
|
+
let(:book_asin) { "160942168X" }
|
41
|
+
let(:book_sales_rank) { 693153 }
|
22
42
|
|
23
|
-
|
43
|
+
let(:book_isbn) { "160942168X" }
|
44
|
+
let(:book_release_date) { Date.parse("20011-09-01") }
|
24
45
|
|
25
|
-
|
26
|
-
|
46
|
+
let(:book_description) do
|
47
|
+
"This epic is considered one of the most celebrated works of"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "initializes an instance for each document node matching the path" do
|
51
|
+
books.size.should == 10
|
52
|
+
end
|
53
|
+
|
54
|
+
it "instantiates instances of the described class" do
|
55
|
+
books.each { |book| book.should be_a(Book) }
|
56
|
+
end
|
57
|
+
|
58
|
+
it "parses each node and sets instance attributes from the mappings" do
|
59
|
+
book.asin.should eql(book_asin)
|
60
|
+
book.sales_rank.should eql(book_sales_rank)
|
61
|
+
book.description.should include(book_description)
|
62
|
+
book.isbn.should eql(book_isbn)
|
63
|
+
book.release_date.should eql(book_release_date)
|
64
|
+
end
|
27
65
|
end
|
28
66
|
|
29
67
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: muffins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.7.pre
|
4
|
+
version: 0.0.7.pre.1
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-11-14 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement: &
|
16
|
+
requirement: &70204474423300 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.5.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70204474423300
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: virtus
|
27
|
-
requirement: &
|
27
|
+
requirement: &70204474422820 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.0.9
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70204474422820
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70204474422240 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.9.2
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70204474422240
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70204474421800 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 2.7.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70204474421800
|
58
58
|
description: An Object to XML/HTML mapping library using Virtus and Nokogiri
|
59
59
|
email:
|
60
60
|
- ryan@ryanclosner.com
|