fetcher-microdata 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ module Fetcher
2
+ class Microdata
3
+ class Review < Fetcher::Microdata
4
+
5
+ def initialize *args
6
+ super *args
7
+ @_type = "http://schema.org/Review"
8
+ end
9
+
10
+ attribute :additionalType
11
+ attribute :id
12
+ attribute :articleBody
13
+ attribute :author
14
+ attribute :viewer
15
+ attribute :dateCreated
16
+ attribute :provider
17
+ attribute :url
18
+ attribute :original_tweet
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  module Fetcher
2
2
  class Microdata
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -39,6 +39,8 @@ end
39
39
  require 'fetcher-microdata/version'
40
40
  require 'fetcher-microdata/person_user'
41
41
  require 'fetcher-microdata/article_small'
42
+ require 'fetcher-microdata/review'
42
43
 
43
44
  require 'writer/fetcher-microdata/person_user'
44
- require 'writer/fetcher-microdata/article_small'
45
+ require 'writer/fetcher-microdata/article_small'
46
+ require 'writer/fetcher-microdata/review'
@@ -0,0 +1,47 @@
1
+ module Writer
2
+ module Fetcher
3
+ module Microdata
4
+ class Review
5
+ attr_accessor :source
6
+
7
+ def initialize the_source
8
+ self.source = the_source
9
+ end
10
+
11
+ def hash
12
+ @attributes = @source.attributes
13
+ {
14
+ "type" => [@source._type],
15
+ "properties" => {
16
+ "additionalType" => [
17
+ @attributes[:additionalType]
18
+ ],
19
+ "Item#id" => [
20
+ @attributes[:id]
21
+ ],
22
+ "articleBody" => [
23
+ @attributes[:articleBody]
24
+ ],
25
+ "author" => [
26
+ @attributes[:author].to.hash
27
+ ],
28
+ "Item#viewer" => [
29
+ @attributes[:viewer].to.hash
30
+ ],
31
+ "dateCreated" => [
32
+ @attributes[:dateCreated]
33
+ ],
34
+ "provider" => @attributes[:provider],
35
+ "url" => [
36
+ @attributes[:url]
37
+ ],
38
+ "itemReviewed" => [
39
+ @attributes[:itemReviewed]
40
+ ]
41
+ }
42
+ }
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fetcher::Microdata::Review do
4
+ describe '.new' do
5
+ it 'should set the _type to schema.org/Review' do
6
+ article = Fetcher::Microdata::Review.new @argument, @viewer
7
+ article._type.should == "http://schema.org/Review"
8
+ end
9
+ end
10
+
11
+ it 'should inherit from Fetcher::Microdata' do
12
+ Fetcher::Microdata::Review.superclass.should == Fetcher::Microdata
13
+ end
14
+
15
+ describe 'attributes' do
16
+ before do
17
+ Fetcher::Microdata::Review.any_instance.stub :coerce
18
+ end
19
+
20
+ it 'should set attribute additionalType' do
21
+ Fetcher::Microdata::Review.new(@argument_stub, @viewer_stub)
22
+ .attributes.should have_key :additionalType
23
+ end
24
+
25
+ it 'should set attribute id' do
26
+ Fetcher::Microdata::Review.new(@argument_stub, @viewer_stub)
27
+ .attributes.should have_key :id
28
+ end
29
+
30
+ it 'should set attribute articleBody' do
31
+ Fetcher::Microdata::Review.new(@argument_stub, @viewer_stub)
32
+ .attributes.should have_key :articleBody
33
+ end
34
+
35
+ it 'should set attribute author' do
36
+ Fetcher::Microdata::Review.new(@argument_stub, @viewer_stub)
37
+ .attributes.should have_key :author
38
+ end
39
+
40
+ it 'should set attribute viewer' do
41
+ Fetcher::Microdata::Review.new(@argument_stub, @viewer_stub)
42
+ .attributes.should have_key :viewer
43
+ end
44
+
45
+ it 'should set attribute dateCreated' do
46
+ Fetcher::Microdata::Review.new(@argument_stub, @viewer_stub)
47
+ .attributes.should have_key :dateCreated
48
+ end
49
+
50
+ it 'should set attribute provider' do
51
+ Fetcher::Microdata::Review.new(@argument_stub, @viewer_stub)
52
+ .attributes.should have_key :provider
53
+ end
54
+
55
+ it 'should set attribute url' do
56
+ Fetcher::Microdata::Review.new(@argument_stub, @viewer_stub)
57
+ .attributes.should have_key :url
58
+ end
59
+
60
+ it 'should set attribute original_tweet' do
61
+ Fetcher::Microdata::Review.new(@argument_stub, @viewer_stub)
62
+ .attributes.should have_key :original_tweet
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,142 @@
1
+ require 'spec_helper'
2
+
3
+ describe Writer::Fetcher::Microdata::Review do
4
+ describe '#hash' do
5
+ before do
6
+ @schema_stub = stub 'schema'
7
+ @author_stub = stub 'author', :to => stub( :hash => nil)
8
+ @viewer_stub = stub 'viewer', :to => stub( :hash => nil)
9
+ end
10
+
11
+ it 'should return a hash with the type' do
12
+ final_hash = {
13
+ "type" => [
14
+ 'the type'
15
+ ]
16
+ }
17
+ @schema_stub.should_receive(:_type).and_return "the type"
18
+ @schema_stub.should_receive(:attributes).and_return stub('the hash', :[] => @author_stub)
19
+
20
+ writer = Writer::Fetcher::Microdata::Review.new @schema_stub
21
+ writer.hash.should include final_hash
22
+ end
23
+
24
+ describe 'properties hash' do
25
+ before do
26
+ @schema_stub.should_receive(:_type).and_return nil
27
+ end
28
+
29
+ it 'should include the additionalType' do
30
+ @properties_hash = {
31
+ "additionalType" => [
32
+ "http://getfetcher.net/Item"
33
+ ]
34
+ }
35
+ @schema_stub.should_receive(:attributes)
36
+ .and_return :additionalType => "http://getfetcher.net/Item",
37
+ :author => @author_stub,
38
+ :viewer => @viewer_stub
39
+ end
40
+
41
+ it 'should include the Item#id' do
42
+ @properties_hash = {
43
+ "Item#id" => [
44
+ 234536234
45
+ ]
46
+ }
47
+
48
+ @schema_stub.should_receive(:attributes)
49
+ .and_return :id => 234536234, :author => @author_stub, :viewer => @viewer_stub
50
+ end
51
+
52
+ it 'should include the articleBody' do
53
+ @properties_hash = {
54
+ "articleBody" => [
55
+ "some body"
56
+ ]
57
+ }
58
+
59
+ @schema_stub.should_receive(:attributes)
60
+ .and_return :articleBody => "some body", :author => @author_stub, :viewer => @viewer_stub
61
+ end
62
+
63
+ it 'should include the author' do
64
+ @author = stub 'author'
65
+ @author_writer = stub 'author writer'
66
+ @author_writer.should_receive(:hash).and_return "hi Im the author"
67
+ @author.should_receive(:to).and_return @author_writer
68
+ @properties_hash = {
69
+ "author" => [
70
+ "hi Im the author"
71
+ ]
72
+ }
73
+
74
+ @schema_stub.should_receive(:attributes)
75
+ .and_return :author => @author, :viewer => @viewer_stub
76
+ end
77
+
78
+ it 'should include the viewer' do
79
+ @viewer = stub 'viewer'
80
+ @viewer_writer = stub 'viewer writer'
81
+ @viewer_writer.should_receive(:hash).and_return "hi Im the viewer"
82
+ @viewer.should_receive(:to).and_return @viewer_writer
83
+ @properties_hash = {
84
+ "Item#viewer" => [
85
+ "hi Im the viewer"
86
+ ]
87
+ }
88
+
89
+ @schema_stub.should_receive(:attributes)
90
+ .and_return :viewer => @viewer, :author => @author_stub
91
+ end
92
+
93
+ it 'should include the dateCreated' do
94
+ @properties_hash = {
95
+ "dateCreated" => [
96
+ 23456235
97
+ ]
98
+ }
99
+
100
+ @schema_stub.should_receive(:attributes)
101
+ .and_return :dateCreated => 23456235, :author => @author_stub, :viewer => @viewer_stub
102
+ end
103
+
104
+ it 'should include the provider' do
105
+ @properties_hash = {
106
+ "provider" => [
107
+ "twitter",
108
+ "fetcher"
109
+ ]
110
+ }
111
+
112
+ @schema_stub.should_receive(:attributes)
113
+ .and_return :provider => ["twitter", "fetcher"], :author => @author_stub, :viewer => @viewer_stub
114
+ end
115
+
116
+ it 'should include the url' do
117
+ @properties_hash = {
118
+ "url" => [
119
+ "http://myurl.info"
120
+ ]
121
+ }
122
+ @schema_stub.should_receive(:attributes)
123
+ .and_return :url => "http://myurl.info", :author => @author_stub, :viewer => @viewer_stub
124
+ end
125
+
126
+ it 'should include the original tweet' do
127
+ @properties_hash = {
128
+ "itemReviewed" => [
129
+ "Im the original tweet that was retreeted"
130
+ ]
131
+ }
132
+ @schema_stub.should_receive(:attributes)
133
+ .and_return :itemReviewed => "Im the original tweet that was retreeted", :author => @author_stub, :viewer => @viewer_stub
134
+ end
135
+
136
+ after :each do
137
+ writer = Writer::Fetcher::Microdata::Review.new @schema_stub
138
+ writer.hash["properties"].should include @properties_hash
139
+ end
140
+ end
141
+ end
142
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fetcher-microdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-09 00:00:00.000000000 Z
12
+ date: 2012-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: discoverer
@@ -76,15 +76,19 @@ files:
76
76
  - lib/fetcher-microdata.rb
77
77
  - lib/fetcher-microdata/article_small.rb
78
78
  - lib/fetcher-microdata/person_user.rb
79
+ - lib/fetcher-microdata/review.rb
79
80
  - lib/fetcher-microdata/version.rb
80
81
  - lib/writer/fetcher-microdata/article_small.rb
81
82
  - lib/writer/fetcher-microdata/person_user.rb
83
+ - lib/writer/fetcher-microdata/review.rb
82
84
  - spec/fetcher/microdata/article_small_spec.rb
83
85
  - spec/fetcher/microdata/person_user_spec.rb
86
+ - spec/fetcher/microdata/review_spec.rb
84
87
  - spec/fetcher/microdata_spec.rb
85
88
  - spec/spec_helper.rb
86
89
  - spec/writer/fetcher/microdata/article_small_spec.rb
87
90
  - spec/writer/fetcher/microdata/person_user_spec.rb
91
+ - spec/writer/fetcher/microdata/review_spec.rb
88
92
  homepage: http://github.com/Fetcher/fetcher-microdata
89
93
  licenses: []
90
94
  post_install_message:
@@ -112,7 +116,9 @@ summary: Abstract classes for Fetcher Microdata serialization of social network
112
116
  test_files:
113
117
  - spec/fetcher/microdata/article_small_spec.rb
114
118
  - spec/fetcher/microdata/person_user_spec.rb
119
+ - spec/fetcher/microdata/review_spec.rb
115
120
  - spec/fetcher/microdata_spec.rb
116
121
  - spec/spec_helper.rb
117
122
  - spec/writer/fetcher/microdata/article_small_spec.rb
118
123
  - spec/writer/fetcher/microdata/person_user_spec.rb
124
+ - spec/writer/fetcher/microdata/review_spec.rb