fetcher-microdata-twitter 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ And /^the viewer:$/ do |json_viewer|
7
7
  end
8
8
 
9
9
  When /^I convert it into schema.org\/Article\/Small$/ do
10
- @translated = Fetcher::Microdata::Twitter::ArticleSmall.new @tweet, @viewer
10
+ @translated = Fetcher::Microdata::ArticleSmall.new :twitter, @tweet, @viewer
11
11
  end
12
12
 
13
13
  Then /^I should have:$/ do |json_schema|
@@ -21,5 +21,5 @@ Given /^the user:$/ do |json_user|
21
21
  end
22
22
 
23
23
  When /^I convert it into schema.org\/Person\/User$/ do
24
- @translated = Fetcher::Microdata::Twitter::PersonUser.new @user
24
+ @translated = Fetcher::Microdata::PersonUser.new :twitter, @user
25
25
  end
@@ -1,4 +1,4 @@
1
1
  $LOAD_PATH << File.expand_path('../../../lib', __FILE__)
2
- require 'fetcher/microdata/twitter'
2
+ require 'fetcher-microdata-twitter'
3
3
 
4
4
  require 'pry'
@@ -10,6 +10,7 @@ Gem::Specification.new do |gem|
10
10
 
11
11
  gem.add_dependency 'discoverer'
12
12
  gem.add_dependency 'virtus'
13
+ gem.add_dependency 'fetcher-microdata'
13
14
 
14
15
  gem.add_development_dependency 'rspec'
15
16
 
@@ -0,0 +1,8 @@
1
+ require 'fetcher-microdata'
2
+ require 'singleton'
3
+ require 'json'
4
+
5
+ require 'fetcher/microdata/person_user/twitter/coercer'
6
+ require 'fetcher/microdata/article_small/twitter/coercer'
7
+
8
+ require 'fetcher/microdata/twitter/service'
@@ -0,0 +1,20 @@
1
+ module Fetcher
2
+ class Microdata
3
+ class ArticleSmall
4
+ module Twitter
5
+ Coercer = proc { |original_tweet, viewer|
6
+ {
7
+ :id => original_tweet["id"],
8
+ :additionalType => "http://getfetcher.net/Item",
9
+ :articleBody => original_tweet["text"],
10
+ :author => PersonUser.new(:twitter, original_tweet["user"]),
11
+ :viewer => PersonUser.new(:twitter, viewer),
12
+ :dateCreated => Fetcher::Microdata::Twitter::Service.instance.created_at_to_timestamp(original_tweet["created_at"]),
13
+ :provider => ["twitter", original_tweet["source"]],
14
+ :url => "https://twitter.com/#{original_tweet["user"]["screen_name"]}/status/#{original_tweet["id"]}"
15
+ }
16
+ }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ module Fetcher
2
+ class Microdata
3
+ class PersonUser
4
+ module Twitter
5
+ Coercer = proc { |original_tweet|
6
+ {
7
+ :additionalType => "http://getfetcher.net/Item",
8
+ :id => original_tweet["id"],
9
+ :name => original_tweet["name"],
10
+ :dateRegistered => Fetcher::Microdata::Twitter::Service.instance.created_at_to_timestamp(original_tweet["created_at"]),
11
+ :description => original_tweet["description"],
12
+ :url => "https://twitter.com/#{original_tweet["screen_name"]}"
13
+ }
14
+ }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  module Fetcher
2
- module Microdata
2
+ class Microdata
3
3
  module Twitter
4
4
  class Service
5
5
  include Singleton
@@ -1,7 +1,7 @@
1
1
  module Fetcher
2
- module Microdata
2
+ class Microdata
3
3
  module Twitter
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Fetcher::Microdata::ArticleSmall::Twitter::Coercer' do
4
+ context 'the adapter receives a valid tweet and a valid viewer' do
5
+ before do
6
+ @tweet = JSON.parse File.read 'spec/tweet.json'
7
+ @viewer = JSON.parse File.read 'spec/viewer.json'
8
+ @adapter = Fetcher::Microdata::ArticleSmall::Twitter::Coercer.call @tweet, @viewer
9
+ end
10
+
11
+ it 'should set #id with the value of "id"' do
12
+ @adapter[:id].should == @tweet["id"]
13
+ end
14
+
15
+ it 'should set #additionalType as the getfetcher/Item type' do
16
+ @adapter[:additionalType].should == "http://getfetcher.net/Item"
17
+ end
18
+
19
+ it 'should set #articleBody with the value of "text"' do
20
+ @adapter[:articleBody].should == @tweet["text"]
21
+ end
22
+
23
+ it 'should set #author with the Person from the value of "user" > "name"' do
24
+ @adapter[:author].attributes.should == Fetcher::Microdata::PersonUser.new(:twitter, @tweet["user"]).attributes
25
+ end
26
+
27
+ it 'should set #viewer with the Person from the value of "user" > "name"' do
28
+ @adapter[:viewer].attributes.should == Fetcher::Microdata::PersonUser.new(:twitter, @viewer).attributes
29
+ end
30
+
31
+ it 'should set #dateCreated with the timestamp obtained from "created_at"' do
32
+ @adapter[:dateCreated].should == 1329859747
33
+ end
34
+
35
+ it 'should set #provider as an array, coming Twitter first and then the "source"' do
36
+ @adapter[:provider].should == ["twitter", @tweet["source"]]
37
+ end
38
+
39
+ it 'should set #url compiling the basic url with the "id" and the "user" > "screen_name"' do
40
+ @adapter[:url].should == "https://twitter.com/#{@tweet["user"]["screen_name"]}/status/#{@tweet["id"]}"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Fetcher::Microdata::PersonUser::Twitter::Coercer' do
4
+ context 'a valid twitter user hash is passed' do
5
+ before do
6
+ @user = JSON.parse File.read 'spec/user.json'
7
+ @result = ::Fetcher::Microdata::PersonUser::Twitter::Coercer.call @user
8
+ end
9
+
10
+ it 'should initialize the additionalType as getfetcher.net/Item' do
11
+ @result[:additionalType].should == "http://getfetcher.net/Item"
12
+ end
13
+
14
+ it 'should assign to :id the "id"' do
15
+ @result[:id].should == @user["id"]
16
+ end
17
+
18
+ it 'should assign to :name the "name"' do
19
+ @result[:name].should == @user["name"]
20
+ end
21
+
22
+ it 'should assign to :dateRegistered the timestamp corresponding to "created_at"' do
23
+ @result[:dateRegistered].should == 1249685355
24
+ end
25
+
26
+ it 'should assign to :description the "description"' do
27
+ @result[:description].should == @user["description"]
28
+ end
29
+
30
+ it 'should assign to :url the "screen_name" after the twitter url' do
31
+ @result[:url].should == "https://twitter.com/#{@user["screen_name"]}"
32
+ end
33
+ end
34
+ end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,3 @@
1
- require 'fetcher/microdata/twitter'
1
+ require 'pry'
2
+
3
+ require 'fetcher-microdata-twitter'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fetcher-microdata-twitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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-01 00:00:00.000000000 Z
12
+ date: 2012-11-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: discoverer
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: fetcher-microdata
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: rspec
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -78,22 +94,18 @@ files:
78
94
  - features/translate_tweet_to_schema.feature
79
95
  - features/translate_user_to_schema.feature
80
96
  - fetcher-microdata-twitter.gemspec
81
- - lib/fetcher/microdata/twitter.rb
82
- - lib/fetcher/microdata/twitter/article_small.rb
83
- - lib/fetcher/microdata/twitter/person_user.rb
97
+ - lib/fetcher-microdata-twitter.rb
98
+ - lib/fetcher/microdata/article_small/twitter/coercer.rb
99
+ - lib/fetcher/microdata/person_user/twitter/coercer.rb
84
100
  - lib/fetcher/microdata/twitter/service.rb
85
101
  - lib/fetcher/microdata/twitter/version.rb
86
- - lib/writer/fetcher/microdata/twitter/article_small.rb
87
- - lib/writer/fetcher/microdata/twitter/person_user.rb
88
- - spec/fetcher/microdata/twitter/article_small_spec.rb
89
- - spec/fetcher/microdata/twitter/person_user_spec.rb
102
+ - spec/fetcher/microdata/article_small/twitter/coercer_spec.rb
103
+ - spec/fetcher/microdata/person_user/twitter/coercer_spec.rb
90
104
  - spec/fetcher/microdata/twitter/service_spec.rb
91
105
  - spec/spec_helper.rb
92
106
  - spec/tweet.json
93
107
  - spec/user.json
94
108
  - spec/viewer.json
95
- - spec/writer/fetcher/microdata/twitter/article_small_spec.rb
96
- - spec/writer/fetcher/microdata/twitter/person_user_spec.rb
97
109
  - tweet.yaml
98
110
  homepage: http://github.com/Fetcher/fetcher-microdata-twitter
99
111
  licenses: []
@@ -109,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
121
  version: '0'
110
122
  segments:
111
123
  - 0
112
- hash: -976156881
124
+ hash: -956730701
113
125
  required_rubygems_version: !ruby/object:Gem::Requirement
114
126
  none: false
115
127
  requirements:
@@ -118,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
130
  version: '0'
119
131
  segments:
120
132
  - 0
121
- hash: -976156881
133
+ hash: -956730701
122
134
  requirements: []
123
135
  rubyforge_project:
124
136
  rubygems_version: 1.8.24
@@ -130,12 +142,10 @@ test_files:
130
142
  - features/support/env.rb
131
143
  - features/translate_tweet_to_schema.feature
132
144
  - features/translate_user_to_schema.feature
133
- - spec/fetcher/microdata/twitter/article_small_spec.rb
134
- - spec/fetcher/microdata/twitter/person_user_spec.rb
145
+ - spec/fetcher/microdata/article_small/twitter/coercer_spec.rb
146
+ - spec/fetcher/microdata/person_user/twitter/coercer_spec.rb
135
147
  - spec/fetcher/microdata/twitter/service_spec.rb
136
148
  - spec/spec_helper.rb
137
149
  - spec/tweet.json
138
150
  - spec/user.json
139
151
  - spec/viewer.json
140
- - spec/writer/fetcher/microdata/twitter/article_small_spec.rb
141
- - spec/writer/fetcher/microdata/twitter/person_user_spec.rb
@@ -1,12 +0,0 @@
1
- require 'discoverer'
2
- require 'virtus'
3
- require 'json'
4
- require 'singleton'
5
-
6
- require 'writer/fetcher/microdata/twitter/article_small'
7
- require 'writer/fetcher/microdata/twitter/person_user'
8
-
9
- require 'fetcher/microdata/twitter/article_small'
10
- require 'fetcher/microdata/twitter/person_user'
11
-
12
- require 'fetcher/microdata/twitter/service'
@@ -1,38 +0,0 @@
1
- module Fetcher
2
- module Microdata
3
- module Twitter
4
- class ArticleSmall
5
- include Virtus
6
- include Discoverer::Writer
7
-
8
- attr_accessor :_type
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
-
19
- def initialize original_tweet, viewer
20
- @_type = 'http://schema.org/Article/Small'
21
- @additionalType = 'http://getfetcher.net/Item'
22
-
23
- coerce original_tweet, viewer
24
- end
25
-
26
- def coerce original_tweet, viewer
27
- @id = original_tweet["id"]
28
- @articleBody = original_tweet["text"]
29
- @author = PersonUser.new original_tweet["user"]
30
- @viewer = PersonUser.new viewer
31
- @dateCreated = Service.instance.created_at_to_timestamp original_tweet["created_at"]
32
- @provider = ["twitter", original_tweet["source"]]
33
- @url = "https://twitter.com/#{original_tweet["user"]["screen_name"]}/status/#{original_tweet["id"]}"
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -1,34 +0,0 @@
1
- module Fetcher
2
- module Microdata
3
- module Twitter
4
- class PersonUser
5
- include Virtus
6
- include Discoverer::Writer
7
-
8
- attr_reader :_type
9
-
10
- attribute :additionalType
11
- attribute :id
12
- attribute :name
13
- attribute :dateRegistered
14
- attribute :description
15
- attribute :url
16
-
17
- def initialize twitter_user
18
- @_type = "http://schema.org/Person/User"
19
-
20
- coerce twitter_user
21
- end
22
-
23
- def coerce twitter_user
24
- @additionalType = "http://getfetcher.net/Item"
25
- @id = twitter_user["id"]
26
- @name = twitter_user["name"]
27
- @dateRegistered = Service.instance.created_at_to_timestamp twitter_user["created_at"]
28
- @description = twitter_user["description"]
29
- @url = "https://twitter.com/#{twitter_user["screen_name"]}"
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,46 +0,0 @@
1
- module Writer
2
- module Fetcher
3
- module Microdata
4
- module Twitter
5
- class ArticleSmall
6
- attr_accessor :source
7
-
8
- def initialize the_source
9
- @source = the_source
10
- end
11
-
12
- def hash
13
- @attributes = @source.attributes
14
- {
15
- "type" => [@source._type],
16
- "properties" => {
17
- "additionalType" => [
18
- @attributes[:additionalType]
19
- ],
20
- "Item#id" => [
21
- @attributes[:id]
22
- ],
23
- "articleBody" => [
24
- @attributes[:articleBody]
25
- ],
26
- "author" => [
27
- @attributes[:author].to.hash
28
- ],
29
- "Item#viewer" => [
30
- @attributes[:viewer].to.hash
31
- ],
32
- "dateCreated" => [
33
- @attributes[:dateCreated]
34
- ],
35
- "provider" => @attributes[:provider],
36
- "url" => [
37
- @attributes[:url]
38
- ]
39
- }
40
- }
41
- end
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,44 +0,0 @@
1
- module Writer
2
- module Fetcher
3
- module Microdata
4
- module Twitter
5
- class PersonUser
6
- attr_reader :source
7
-
8
- def initialize the_source
9
- @source = the_source
10
- end
11
-
12
- def hash
13
- @attributes = @source.attributes
14
- {
15
- "type" => [
16
- @source._type
17
- ],
18
- "properties" => {
19
- "additionalType" => [
20
- @attributes[:additionalType]
21
- ],
22
- "Item#id" => [
23
- @attributes[:id]
24
- ],
25
- "name" => [
26
- @attributes[:name]
27
- ],
28
- "User#dateRegistered" => [
29
- @attributes[:dateRegistered]
30
- ],
31
- "description" => [
32
- @attributes[:description]
33
- ],
34
- "url" => [
35
- @attributes[:url]
36
- ]
37
- }
38
- }
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
@@ -1,129 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Fetcher::Microdata::Twitter::ArticleSmall do
4
- describe '.new' do
5
- before do
6
- @argument_stub = stub 'arg'
7
- @viewer_stub = stub 'viewer'
8
- end
9
-
10
- it 'should receive two arguments' do
11
- Fetcher::Microdata::Twitter::ArticleSmall.any_instance.stub :coerce
12
- Fetcher::Microdata::Twitter::ArticleSmall.new @argument_stub, @viewer_stub
13
- end
14
-
15
- it 'should set up the additionalType' do
16
- Fetcher::Microdata::Twitter::ArticleSmall.any_instance.stub :coerce
17
- adapter = Fetcher::Microdata::Twitter::ArticleSmall.new @argument_stub, @viewer_stub
18
- adapter.additionalType.should == 'http://getfetcher.net/Item'
19
- end
20
-
21
- it 'should call coerce to coerce the values the argument values into the final form' do
22
- Fetcher::Microdata::Twitter::ArticleSmall.any_instance.should_receive(:coerce)
23
- .with @argument_stub, @viewer_stub
24
- Fetcher::Microdata::Twitter::ArticleSmall.new @argument_stub, @viewer_stub
25
- end
26
- end
27
-
28
- describe '#_type' do
29
- it 'should return the schema.org type' do
30
- Fetcher::Microdata::Twitter::ArticleSmall.any_instance.stub :coerce
31
- argument_stub = stub 'argument'
32
- viewer_stub = stub 'viewer'
33
- adapter = Fetcher::Microdata::Twitter::ArticleSmall.new argument_stub, viewer_stub
34
- adapter._type.should == 'http://schema.org/Article/Small'
35
- end
36
- end
37
-
38
- describe '#coerce' do
39
- context 'the adapter receives a valid tweet and a valid viewer' do
40
- before do
41
- @tweet = JSON.parse File.read 'spec/tweet.json'
42
- @viewer = JSON.parse File.read 'spec/viewer.json'
43
- @adapter = Fetcher::Microdata::Twitter::ArticleSmall.new @tweet, @viewer
44
- end
45
-
46
- it 'should set #id with the value of "id"' do
47
- @adapter.id.should == @tweet["id"]
48
- end
49
-
50
- it 'should set #articleBody with the value of "text"' do
51
- @adapter.articleBody.should == @tweet["text"]
52
- end
53
-
54
- it 'should set #author with the Person from the value of "user" > "name"' do
55
- @adapter.author.attributes.should == Fetcher::Microdata::Twitter::PersonUser.new(@tweet["user"]).attributes
56
- end
57
-
58
- it 'should set #viewer with the Person from the value of "user" > "name"' do
59
- @adapter.viewer.attributes.should == Fetcher::Microdata::Twitter::PersonUser.new(@viewer).attributes
60
- end
61
-
62
- it 'should set #dateCreated with the timestamp obtained from "created_at"' do
63
- @adapter.dateCreated.should == 1329859747
64
- end
65
-
66
- it 'should set #provider as an array, coming Twitter first and then the "source"' do
67
- @adapter.provider.should == ["twitter", @tweet["source"]]
68
- end
69
-
70
- it 'should set #url compiling the basic url with the "id" and the "user" > "screen_name"' do
71
- @adapter.url.should == "https://twitter.com/#{@tweet["user"]["screen_name"]}/status/#{@tweet["id"]}"
72
- end
73
- end
74
- end
75
-
76
- it 'should include Discoverer::Writer' do
77
- Fetcher::Microdata::Twitter::ArticleSmall.ancestors.should include Discoverer::Writer
78
- end
79
-
80
- it 'should include Virtus' do
81
- Fetcher::Microdata::Twitter::ArticleSmall.ancestors.should include Virtus
82
- end
83
-
84
- describe 'attributes' do
85
- before do
86
- Fetcher::Microdata::Twitter::ArticleSmall.any_instance.stub :coerce
87
- end
88
-
89
- it 'should set attribute additionalType' do
90
- Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub, @viewer_stub)
91
- .attributes.should have_key :additionalType
92
- end
93
-
94
- it 'should set attribute id' do
95
- Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub, @viewer_stub)
96
- .attributes.should have_key :id
97
- end
98
-
99
- it 'should set attribute articleBody' do
100
- Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub, @viewer_stub)
101
- .attributes.should have_key :articleBody
102
- end
103
-
104
- it 'should set attribute author' do
105
- Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub, @viewer_stub)
106
- .attributes.should have_key :author
107
- end
108
-
109
- it 'should set attribute viewer' do
110
- Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub, @viewer_stub)
111
- .attributes.should have_key :viewer
112
- end
113
-
114
- it 'should set attribute dateCreated' do
115
- Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub, @viewer_stub)
116
- .attributes.should have_key :dateCreated
117
- end
118
-
119
- it 'should set attribute provider' do
120
- Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub, @viewer_stub)
121
- .attributes.should have_key :provider
122
- end
123
-
124
- it 'should set attribute url' do
125
- Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub, @viewer_stub)
126
- .attributes.should have_key :url
127
- end
128
- end
129
- end
@@ -1,97 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Fetcher::Microdata::Twitter::PersonUser do
4
- describe '.new' do
5
- before do
6
- @argument = stub 'argument'
7
- end
8
-
9
- it 'should accept an argument' do
10
- Fetcher::Microdata::Twitter::PersonUser.any_instance.stub :coerce
11
- Fetcher::Microdata::Twitter::PersonUser.new @argument
12
- end
13
-
14
- it 'should set the _type to schema.org/Person/User' do
15
- Fetcher::Microdata::Twitter::PersonUser.any_instance.stub :coerce
16
- person = Fetcher::Microdata::Twitter::PersonUser.new @argument
17
- person._type.should == "http://schema.org/Person/User"
18
- end
19
-
20
- it 'should call coerce with the argument' do
21
- Fetcher::Microdata::Twitter::PersonUser.any_instance.should_receive(:coerce).with @argument
22
- Fetcher::Microdata::Twitter::PersonUser.new @argument
23
- end
24
- end
25
-
26
- describe '#coerce' do
27
- context 'a valid twitter user hash is passed' do
28
- before do
29
- @user = JSON.parse File.read 'spec/user.json'
30
- @person_user = Fetcher::Microdata::Twitter::PersonUser.new @user
31
- end
32
-
33
- it 'should initialize the additionalType as getfetcher.net/Item' do
34
- @person_user.additionalType.should == "http://getfetcher.net/Item"
35
- end
36
-
37
- it 'should assign to :id the "id"' do
38
- @person_user.id.should == @user["id"]
39
- end
40
-
41
- it 'should assign to :name the "name"' do
42
- @person_user.name.should == @user["name"]
43
- end
44
-
45
- it 'should assign to :dateRegistered the timestamp corresponding to "created_at"' do
46
- @person_user.dateRegistered.should == 1249685355
47
- end
48
-
49
- it 'should assign to :description the "description"' do
50
- @person_user.description.should == @user["description"]
51
- end
52
-
53
- it 'should assign to :url the "screen_name" after the twitter url' do
54
- @person_user.url.should == "https://twitter.com/#{@user["screen_name"]}"
55
- end
56
- end
57
- end
58
-
59
- it 'should include Discoverer::Writer' do
60
- Fetcher::Microdata::Twitter::PersonUser.ancestors.should include Discoverer::Writer
61
- end
62
-
63
- it 'should include Virtus' do
64
- Fetcher::Microdata::Twitter::PersonUser.ancestors.should include Virtus
65
- end
66
-
67
- describe 'attributes' do
68
- before do
69
- @argument_stub = stub 'argument'
70
- Fetcher::Microdata::Twitter::PersonUser.any_instance.stub :coerce
71
- end
72
-
73
- it 'should have the attribute additionalType' do
74
- Fetcher::Microdata::Twitter::PersonUser.new(@argument_stub).attributes.should have_key :additionalType
75
- end
76
-
77
- it 'should have the attribute id' do
78
- Fetcher::Microdata::Twitter::PersonUser.new(@argument_stub).attributes.should have_key :id
79
- end
80
-
81
- it 'should have the attribute name' do
82
- Fetcher::Microdata::Twitter::PersonUser.new(@argument_stub).attributes.should have_key :name
83
- end
84
-
85
- it 'should have the attribute dateRegistered' do
86
- Fetcher::Microdata::Twitter::PersonUser.new(@argument_stub).attributes.should have_key :dateRegistered
87
- end
88
-
89
- it 'should have the attribute description' do
90
- Fetcher::Microdata::Twitter::PersonUser.new(@argument_stub).attributes.should have_key :description
91
- end
92
-
93
- it 'should have the attribute url' do
94
- Fetcher::Microdata::Twitter::PersonUser.new(@argument_stub).attributes.should have_key :url
95
- end
96
- end
97
- end
@@ -1,133 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Writer::Fetcher::Microdata::Twitter::ArticleSmall 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::Twitter::ArticleSmall.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
-
123
- @schema_stub.should_receive(:attributes)
124
- .and_return :url => "http://myurl.info", :author => @author_stub, :viewer => @viewer_stub
125
- end
126
-
127
- after :each do
128
- writer = Writer::Fetcher::Microdata::Twitter::ArticleSmall.new @schema_stub
129
- writer.hash["properties"].should include @properties_hash
130
- end
131
- end
132
- end
133
- end
@@ -1,93 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Writer::Fetcher::Microdata::Twitter::PersonUser do
4
- it 'should have a proper initializer to a Writer' do
5
- user_stub = stub 'user'
6
- writer = Writer::Fetcher::Microdata::Twitter::PersonUser.new user_stub
7
- writer.source.should == user_stub
8
- end
9
-
10
- describe '#hash' do
11
- before do
12
- @user_stub = stub 'user'
13
- end
14
-
15
- it 'should return the type' do
16
- final_hash = {
17
- "type" => [
18
- "some type"
19
- ]
20
- }
21
-
22
- @user_stub.should_receive(:_type).and_return "some type"
23
- @user_stub.should_receive(:attributes).and_return stub :[] => nil
24
- writer = Writer::Fetcher::Microdata::Twitter::PersonUser.new @user_stub
25
- writer.hash.should include final_hash
26
- end
27
-
28
- describe 'properties hash' do
29
- before do
30
- @user_stub.should_receive :_type
31
- end
32
-
33
- it 'should include the additionalType' do
34
- @properties_hash = {
35
- "additionalType" => [
36
- "http://getfetcher.net/Item"
37
- ]
38
- }
39
- @user_stub.should_receive(:attributes).and_return :additionalType => "http://getfetcher.net/Item"
40
- end
41
-
42
- it 'should include the Item#id' do
43
- @properties_hash = {
44
- "Item#id" => [
45
- 234525
46
- ]
47
- }
48
- @user_stub.should_receive(:attributes).and_return :id => 234525
49
- end
50
-
51
- it 'should include the name' do
52
- @properties_hash = {
53
- "name" => [
54
- "Marcus"
55
- ]
56
- }
57
- @user_stub.should_receive(:attributes).and_return :name => "Marcus"
58
- end
59
-
60
- it 'should include the dateRegistered' do
61
- @properties_hash = {
62
- "User#dateRegistered" => [
63
- 456468768
64
- ]
65
- }
66
- @user_stub.should_receive(:attributes).and_return :dateRegistered => 456468768
67
- end
68
-
69
- it 'should include the description' do
70
- @properties_hash = {
71
- "description" => [
72
- 456468768
73
- ]
74
- }
75
- @user_stub.should_receive(:attributes).and_return :description => 456468768
76
- end
77
-
78
- it 'should include the url' do
79
- @properties_hash = {
80
- "url" => [
81
- 456468768
82
- ]
83
- }
84
- @user_stub.should_receive(:attributes).and_return :url => 456468768
85
- end
86
-
87
- after :each do
88
- writer = Writer::Fetcher::Microdata::Twitter::PersonUser.new @user_stub
89
- writer.hash["properties"].should include @properties_hash
90
- end
91
- end
92
- end
93
- end