twitter4r 0.3.0 → 0.3.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.
Files changed (39) hide show
  1. data/CHANGES +129 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +37 -0
  4. data/TODO +7 -0
  5. data/lib/twitter/client/account.rb +24 -0
  6. data/lib/twitter/client/base.rb +16 -5
  7. data/lib/twitter/client/blocks.rb +35 -0
  8. data/lib/twitter/client/favorites.rb +37 -37
  9. data/lib/twitter/client/friendship.rb +32 -32
  10. data/lib/twitter/client/graph.rb +37 -0
  11. data/lib/twitter/client/messaging.rb +3 -4
  12. data/lib/twitter/client/profile.rb +29 -0
  13. data/lib/twitter/client/search.rb +27 -0
  14. data/lib/twitter/client/status.rb +9 -3
  15. data/lib/twitter/client/timeline.rb +1 -0
  16. data/lib/twitter/client/user.rb +20 -9
  17. data/lib/twitter/client.rb +13 -9
  18. data/lib/twitter/config.rb +6 -0
  19. data/lib/twitter/console.rb +3 -0
  20. data/lib/twitter/core.rb +1 -1
  21. data/lib/twitter/ext/stdlib.rb +17 -1
  22. data/lib/twitter/model.rb +39 -10
  23. data/lib/twitter/version.rb +1 -1
  24. data/lib/twitter.rb +13 -4
  25. data/spec/twitter/client/account_spec.rb +28 -0
  26. data/spec/twitter/client/base_spec.rb +10 -0
  27. data/spec/twitter/client/blocks_spec.rb +76 -0
  28. data/spec/twitter/client/friendship_spec.rb +7 -7
  29. data/spec/twitter/client/graph_spec.rb +67 -0
  30. data/spec/twitter/client/messaging_spec.rb +3 -3
  31. data/spec/twitter/client/profile_spec.rb +91 -0
  32. data/spec/twitter/client/search_spec.rb +68 -0
  33. data/spec/twitter/client/status_spec.rb +27 -0
  34. data/spec/twitter/client/user_spec.rb +0 -17
  35. data/spec/twitter/ext/stdlib_spec.rb +20 -3
  36. data/spec/twitter/model_spec.rb +46 -26
  37. metadata +92 -67
  38. data/lib/twitter/rails.rb +0 -89
  39. data/spec/twitter/rails_spec.rb +0 -110
@@ -0,0 +1,68 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ describe Twitter::Client, "#search" do
4
+ before(:each) do
5
+ @twitter = client_context
6
+ @uris = Twitter::Client.class_eval("@@SEARCH_URIS")
7
+ @request = mas_net_http_get(:basic_auth => nil)
8
+ @response = mas_net_http_response(:success, "{\"results\": [], \"refresh_url\":\"?since_id=1768746401&q=blabla\"}")
9
+ @connection = mas_net_http(@response)
10
+ Net::HTTP.stub!(:new).and_return(@connection)
11
+ @statuses = []
12
+ Twitter::Status.stub!(:unmarshal).and_return(@statuses)
13
+ @page = 2
14
+ @keywords = "twitter4r"
15
+ @to = "SusanPotter"
16
+ @from = "twitter4r"
17
+ end
18
+
19
+ it "should create expected HTTP GET request using :to" do
20
+ @twitter.should_receive(:create_http_get_request).with(@uris[:basic], {:to => @to}).and_return(@request)
21
+ @twitter.search(:to => @to)
22
+ end
23
+
24
+ it "should bless the Array returned from Twitter for :to case" do
25
+ @twitter.should_receive(:bless_models).with(@statuses).and_return(@statuses)
26
+ @twitter.search(:to => @to)
27
+ end
28
+
29
+ it "should create expected HTTP GET request using :from" do
30
+ @twitter.should_receive(:create_http_get_request).with(@uris[:basic], {:from => @from}).and_return(@request)
31
+ @twitter.search(:from => @from)
32
+ end
33
+
34
+ it "should bless the Array returned from Twitter for :to case" do
35
+ @twitter.should_receive(:bless_models).with(@statuses).and_return(@statuses)
36
+ @twitter.search(:from => @from)
37
+ end
38
+
39
+ it "should create expected HTTP GET request using :keywords" do
40
+ @twitter.should_receive(:create_http_get_request).with(@uris[:basic], {:keywords => @keywords}).and_return(@request)
41
+ @twitter.search(:keywords => @keywords)
42
+ end
43
+
44
+ it "should bless the Array returned from Twitter for :keywords case" do
45
+ @twitter.should_receive(:bless_models).with(@statuses).and_return(@statuses)
46
+ @twitter.search(:keywords => @keywords)
47
+ end
48
+
49
+ it "should accept paging option" do
50
+ lambda {
51
+ @twitter.search(:keywords => @keywords, :page => @page)
52
+ }.should_not raise_error(Exception)
53
+ end
54
+
55
+ it "should generate expected GET HTTP request for paging case" do
56
+ @twitter.should_receive(:create_http_get_request).with(@uris[:basic], {:page => @page}).and_return(@request)
57
+ @twitter.search(:page => @page)
58
+ end
59
+
60
+ it "should bless models for paging case" do
61
+ @twitter.should_receive(:bless_models).with(@statuses).and_return(@statuses)
62
+ @twitter.search(:page => @page)
63
+ end
64
+
65
+ after(:each) do
66
+ nilize(@twitter, @uris, @request, @response, @connection, @statuses)
67
+ end
68
+ end
@@ -11,6 +11,7 @@ describe Twitter::Client, "#status" do
11
11
  @connection = mas_net_http(@response)
12
12
  @float = 43.3434
13
13
  @status = Twitter::Status.new(:id => 2349343)
14
+ @reply_to_status_id = 3495293
14
15
  @source = Twitter::Client.class_eval("@@defaults[:source]")
15
16
  end
16
17
 
@@ -55,6 +56,32 @@ describe Twitter::Client, "#status" do
55
56
  @twitter.status(:post, @message)
56
57
  end
57
58
 
59
+ it "should return nil if no :status key-value given in the value argument for :reply case" do
60
+ status = @twitter.status(:reply, {})
61
+ status.should be_nil
62
+ end
63
+
64
+ it "should return nil if nil is passed as value argument for :reply case" do
65
+ status = @twitter.status(:reply, nil)
66
+ status.should be_nil
67
+ end
68
+
69
+ it "should not call @twitter#http_connect when passing a value Hash argument that has no :status key-value in :reply case" do
70
+ @twitter.should_not_receive(:http_connect)
71
+ @twitter.status(:reply, {})
72
+ end
73
+
74
+ it "should not call @twitter#http_connect when passing nil for value argument in :reply case" do
75
+ @twitter.should_not_receive(:http_connect)
76
+ @twitter.status(:reply, nil)
77
+ end
78
+
79
+ it "should create expected HTTP POST request for :reply case" do
80
+ @twitter.should_receive(:create_http_post_request).with(@uris[:reply]).and_return(@request)
81
+ @connection.should_receive(:request).with(@request, {:status => @message, :source => @source, :in_reply_to_status_id => @reply_to_status_id}.to_http_str).and_return(@response)
82
+ @twitter.status(:reply, :status => @message, :in_reply_to_status_id => @reply_to_status_id)
83
+ end
84
+
58
85
  it "should return nil if nil is passed as value argument for :delete case" do
59
86
  status = @twitter.status(:delete, nil)
60
87
  status.should be_nil
@@ -1,22 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
2
 
3
- describe Twitter::Client, "#user(id, :followers)" do
4
- before(:each) do
5
- @twitter = client_context
6
- @id = 395783
7
- end
8
-
9
- it "should raise ArgumentError" do
10
- lambda {
11
- @twitter.user(@id, :followers)
12
- }.should raise_error(ArgumentError)
13
- end
14
-
15
- after(:each) do
16
- nilize(@twitter, @id)
17
- end
18
- end
19
-
20
3
  describe Twitter::Client, "#user(id, :info)" do
21
4
  before(:each) do
22
5
  @twitter = client_context
@@ -3,9 +3,9 @@ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
3
3
  describe Hash, "#to_http_str" do
4
4
  before(:each) do
5
5
  @http_params = {:id => 'otherlogin', :since_id => 3953743, :full_name => 'Lucy Cross'}
6
- @id_regexp = Regexp.new("id=#{URI.encode(@http_params[:id].to_s)}")
7
- @since_id_regexp = Regexp.new("since_id=#{URI.encode(@http_params[:since_id].to_s)}")
8
- @full_name_regexp = Regexp.new("full_name=#{URI.encode(@http_params[:full_name].to_s)}")
6
+ @id_regexp = Regexp.new("id=#{CGI.escape(@http_params[:id].to_s)}")
7
+ @since_id_regexp = Regexp.new("since_id=#{CGI.escape(@http_params[:since_id].to_s)}")
8
+ @full_name_regexp = Regexp.new("full_name=Lucy\\+Cross")
9
9
  end
10
10
 
11
11
  it "should generate expected URL encoded string" do
@@ -40,3 +40,20 @@ describe Time, "#to_s" do
40
40
  nilize(@time, @expected_string)
41
41
  end
42
42
  end
43
+
44
+ # TODO: figure out how to stub the gem method to do what we want rather than this monstrousity. It is dependent on the system installation, which is always a bad thing. For now it will do so we can ship with 100% C0 coverage.
45
+ describe Kernel, "#gem_present?" do
46
+ before(:each) do
47
+ @present_gem = "rake"
48
+ @uninstalled_gem = "uninstalled-gem-crap"
49
+ end
50
+
51
+ it "should return true when a gem isn't present on system" do
52
+ gem_present?(@present_gem).should eql(true)
53
+ end
54
+
55
+ it "should return false when a gem isn't present on system" do
56
+ gem_present?(@uninstalled_gem).should eql(false)
57
+ end
58
+ end
59
+
@@ -194,30 +194,6 @@ describe Twitter::User, "#is_me?" do
194
194
  end
195
195
  end
196
196
 
197
- describe Twitter::User, "#bless(client)" do
198
- before(:each) do
199
- @twitter = Twitter::Client.from_config('config/twitter.yml')
200
- @user_not_me = Twitter::User.new(:screen_name => 'notmylogin')
201
- @user_me = Twitter::User.new(:screen_name => @twitter.instance_eval("@login"))
202
- end
203
-
204
- it "should add a followers method" do
205
- @user_me.should_not respond_to?(:followers)
206
- @user_me.bless(@twitter)
207
- @user_me.should respond_to?(:followers)
208
- end
209
-
210
- it "should not add a followers method" do
211
- @user_not_me.should_not respond_to?(:followers)
212
- @user_not_me.bless(@twitter)
213
- @user_not_me.should_not respond_to?(:followers)
214
- end
215
-
216
- after(:each) do
217
- nilize(@twitter, @user_not_me, @user_me)
218
- end
219
- end
220
-
221
197
  describe Twitter::User, "#friends" do
222
198
  before(:each) do
223
199
  @twitter = Twitter::Client.from_config('config/twitter.yml')
@@ -245,7 +221,7 @@ describe Twitter::User, "#followers" do
245
221
  end
246
222
 
247
223
  it "should delegate to @client.my(:followers)" do
248
- @twitter.should_receive(:my).with(:followers)
224
+ @twitter.should_receive(:my).with(:followers, {})
249
225
  @user.followers
250
226
  end
251
227
 
@@ -457,9 +433,53 @@ describe Twitter::User, "#defriend" do
457
433
  end
458
434
  end
459
435
 
436
+ describe Twitter::Status, "#reply?" do
437
+ before(:each) do
438
+ @status = Twitter::Status.new(
439
+ :id => 123456789,
440
+ :text => "Wazzup?",
441
+ :user => mock(Twitter::User)
442
+ )
443
+ @reply = Twitter::Status.new(
444
+ :text => "No much bro. You?",
445
+ :user => mock(Twitter::User),
446
+ :in_reply_to_status_id => @status.id
447
+ )
448
+ end
449
+
450
+ it "should return false for the original status" do
451
+ @status.reply?.should be(false)
452
+ end
453
+
454
+ it "should return true for the reply to the original status" do
455
+ @reply.reply?.should be(true)
456
+ end
457
+ end
458
+
459
+ describe Twitter::Status, "#reply(status_text)" do
460
+ before(:each) do
461
+ @twitter = client_context
462
+ @status = Twitter::Status.new(
463
+ :id => 1234,
464
+ :text => "The status text",
465
+ :client => @twitter)
466
+ @reply_text = "Reply text goes here"
467
+ @reply_status = Twitter::Status.new()
468
+ end
469
+
470
+ it "should invoke #status(:reply, :status => ..., :in_reply_to_status_id => ...) on client context" do
471
+ @twitter.should_receive(:status).with(:reply, :status => @reply_text, :in_reply_to_status_id => @status.id).and_return(@reply_status)
472
+ @status.reply(@reply_text)
473
+ end
474
+
475
+ after(:each) do
476
+ nilize(@twitter, @status)
477
+ end
478
+ end
479
+
460
480
  describe Twitter::Status, "#to_s" do
461
481
  before(:each) do
462
- @text = 'Aloha'
482
+ @text = 'Aloha'
463
483
  @status = Twitter::Status.new(:text => @text)
464
484
  end
465
485
 
metadata CHANGED
@@ -1,93 +1,118 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: twitter4r
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.3.0
7
- date: 2007-11-05 00:00:00 -06:00
8
- summary: A clean Twitter client API in pure Ruby. Will include Twitter add-ons also in Ruby.
9
- require_paths:
10
- - lib
11
- email: twitter4r-users@googlegroups.com
12
- homepage: http://twitter4r.rubyforge.org
13
- rubyforge_project: twitter4r
14
- description:
15
- autorequire: twitter
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.8.2
24
- version:
4
+ version: 0.3.1
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Susan Potter
8
+ autorequire: twitter
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-11 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.1
24
+ version:
25
+ description:
26
+ email: twitter4r-users@googlegroups.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ - CHANGES
34
+ - TODO
35
+ - MIT-LICENSE
31
36
  files:
32
- - lib/twitter/extras.rb
37
+ - lib/twitter.rb
33
38
  - lib/twitter/config.rb
34
- - lib/twitter/core.rb
39
+ - lib/twitter/model.rb
40
+ - lib/twitter/ext/stdlib.rb
41
+ - lib/twitter/ext.rb
42
+ - lib/twitter/meta.rb
43
+ - lib/twitter/client.rb
44
+ - lib/twitter/console.rb
45
+ - lib/twitter/client/graph.rb
46
+ - lib/twitter/client/blocks.rb
47
+ - lib/twitter/client/profile.rb
48
+ - lib/twitter/client/status.rb
35
49
  - lib/twitter/client/timeline.rb
36
- - lib/twitter/client/messaging.rb
37
- - lib/twitter/client/base.rb
38
50
  - lib/twitter/client/favorites.rb
39
- - lib/twitter/client/status.rb
51
+ - lib/twitter/client/account.rb
52
+ - lib/twitter/client/base.rb
53
+ - lib/twitter/client/messaging.rb
40
54
  - lib/twitter/client/friendship.rb
41
- - lib/twitter/client/auth.rb
55
+ - lib/twitter/client/search.rb
42
56
  - lib/twitter/client/user.rb
43
- - lib/twitter/rails.rb
44
- - lib/twitter/client.rb
45
- - lib/twitter/console.rb
57
+ - lib/twitter/client/auth.rb
46
58
  - lib/twitter/version.rb
47
- - lib/twitter/model.rb
48
- - lib/twitter/meta.rb
49
- - lib/twitter/ext.rb
50
- - lib/twitter/ext/stdlib.rb
51
- - lib/twitter.rb
52
- - spec/twitter/config_spec.rb
53
- - spec/twitter/core_spec.rb
59
+ - lib/twitter/extras.rb
60
+ - lib/twitter/core.rb
61
+ - spec/twitter/client_spec.rb
62
+ - spec/twitter/ext/stdlib_spec.rb
63
+ - spec/twitter/console_spec.rb
64
+ - spec/twitter/version_spec.rb
54
65
  - spec/twitter/model_spec.rb
66
+ - spec/twitter/config_spec.rb
67
+ - spec/twitter/client/messaging_spec.rb
68
+ - spec/twitter/client/friendship_spec.rb
69
+ - spec/twitter/client/graph_spec.rb
70
+ - spec/twitter/client/base_spec.rb
71
+ - spec/twitter/client/favorites_spec.rb
72
+ - spec/twitter/client/account_spec.rb
55
73
  - spec/twitter/client/status_spec.rb
74
+ - spec/twitter/client/search_spec.rb
75
+ - spec/twitter/client/blocks_spec.rb
56
76
  - spec/twitter/client/timeline_spec.rb
57
77
  - spec/twitter/client/auth_spec.rb
58
78
  - spec/twitter/client/user_spec.rb
59
- - spec/twitter/client/messaging_spec.rb
60
- - spec/twitter/client/base_spec.rb
61
- - spec/twitter/client/favorites_spec.rb
62
- - spec/twitter/client/friendship_spec.rb
63
- - spec/twitter/version_spec.rb
64
- - spec/twitter/rails_spec.rb
65
- - spec/twitter/client_spec.rb
66
- - spec/twitter/meta_spec.rb
67
- - spec/twitter/console_spec.rb
79
+ - spec/twitter/client/profile_spec.rb
68
80
  - spec/twitter/extras_spec.rb
69
- - spec/twitter/ext/stdlib_spec.rb
70
- test_files: []
81
+ - spec/twitter/meta_spec.rb
82
+ - spec/twitter/core_spec.rb
83
+ - README
84
+ - CHANGES
85
+ - TODO
86
+ - MIT-LICENSE
87
+ has_rdoc: true
88
+ homepage: http://twitter4r.rubyforge.org
89
+ licenses: []
71
90
 
91
+ post_install_message:
72
92
  rdoc_options: []
73
93
 
74
- extra_rdoc_files: []
75
-
76
- executables: []
77
-
78
- extensions: []
79
-
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 1.8.2
101
+ version:
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: "0"
107
+ version:
80
108
  requirements:
81
109
  - Ruby 1.8.4+
82
110
  - json gem, version 0.4.3 or higher
83
111
  - jcode (for unicode support)
84
- dependencies:
85
- - !ruby/object:Gem::Dependency
86
- name: json
87
- version_requirement:
88
- version_requirements: !ruby/object:Gem::Version::Requirement
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: 0.4.3
93
- version:
112
+ rubyforge_project: twitter4r
113
+ rubygems_version: 1.3.2
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: A clean Twitter client API in pure Ruby. Will include Twitter add-ons also in Ruby.
117
+ test_files: []
118
+
data/lib/twitter/rails.rb DELETED
@@ -1,89 +0,0 @@
1
- # File that contains extensions to the Twitter4R library directly related to providing
2
- # seamless Rails integration.
3
-
4
- require 'active_support'
5
- #require 'active_support/core_ext'
6
- require 'active_record/xml_serialization'
7
-
8
- # Extend +String+ with +#xmlize+ method for convenience.
9
- class String
10
- def xmlize
11
- # Forget module/namespace for now as this is totally broken in Rails 1.2.x
12
- # (search for namespaced models on the Rails Trac site)
13
- cls = self.split('::').pop
14
- cls.dasherize.downcase
15
- end
16
- end
17
-
18
- # Parent mixin module that defines +InstanceMethods+ for Twitter4R model classes.
19
- #
20
- # Defines/overrides the following methods for:
21
- # * Twitter::RailsPatch::InstanceMethods#to_param
22
- # * Twitter::RailsPatch::InstanceMethods#to_xml
23
- # * Twitter::RailsPatch::InstanceMethods#to_json
24
- module Twitter::RailsPatch
25
- class << self
26
- def included(base)
27
- base.send(:include, InstanceMethods)
28
- base.extend ClassMethods
29
- end
30
-
31
- module ClassMethods
32
- # Dummy method to satisfy ActiveRecord's XmlSerializer.
33
- def inheritance_column
34
- nil
35
- end
36
-
37
- # Returns Hash of name-column pairs
38
- def columns_hash
39
- {}
40
- end
41
- end
42
-
43
- module InstanceMethods
44
- # Returns an Array of attribute names of the model
45
- def attribute_names
46
- self.class.class_eval("@@ATTRIBUTES").collect {|att| att.to_s }
47
- end
48
-
49
- # Override default +#to_param+ implementation.
50
- def to_param
51
- self.id.to_s
52
- end
53
-
54
- # Returns XML representation of model.
55
- def to_xml(options = {})
56
- ActiveRecord::XmlSerializer.new(self, options.merge(:root => self.class.name.xmlize)).to_s
57
- end
58
-
59
- # Returns JSON representation of model.
60
- #
61
- # The current implementation basically ignoring +options+, so reopen and override
62
- # this implementation or live with it for the moment:)
63
- def to_json(options = {})
64
- JSON.unparse(self.to_hash)
65
- end
66
- end
67
- end
68
- end
69
-
70
- class Twitter::User
71
- include Twitter::RailsPatch
72
- end
73
-
74
- class Twitter::Status
75
- include Twitter::RailsPatch
76
- end
77
-
78
- class Twitter::Message
79
- include Twitter::RailsPatch
80
- end
81
-
82
- class Twitter::RESTError
83
- include Twitter::RailsPatch
84
- alias :id :code
85
- def to_hash
86
- { :code => @code, :message => @message, :uri => @uri }
87
- end
88
- end
89
-
@@ -1,110 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
-
3
- describe String, "representing a class name" do
4
-
5
- before(:each) do
6
- @class_name = Twitter::User.class.name
7
- @xmlized_name = @class_name.downcase # simple case for the moment...since Rails' support for namespaced models sucks!
8
- end
9
-
10
- it "should be downcased (minus module namespaces) when xmlized" do
11
- @class_name.xmlize.should eql(@xmlized_name)
12
- end
13
-
14
- after(:each) do
15
- nilize(@class_name, @xmlized_name)
16
- end
17
- end
18
-
19
- describe "Rails model extensions for model classes", :shared => true do
20
-
21
- before(:each) do
22
- @id = 3242334
23
- @id_s = @id.to_s
24
- @model = model(@id)
25
- @model_hash = @model.to_hash
26
- @json = JSON.unparse(@model_hash)
27
- @serializer = ActiveRecord::XmlSerializer.new(@model, {:root => @model.class.name.downcase})
28
- @xml = @serializer.to_s
29
- end
30
-
31
- it "should invoke #to_param as expected" do
32
- @model.should_receive(:id).and_return(@id)
33
- @model.to_param
34
- end
35
-
36
- it "should return string representation for id for #to_param" do
37
- @model.to_param.class.should eql(String)
38
- end
39
-
40
- it "should return output from JSON.unparse for #to_json" do
41
- @model.should_receive(:to_hash).and_return(@model_hash)
42
- JSON.should_receive(:unparse).and_return(@json)
43
- @model.to_json
44
- end
45
-
46
- it "should return XmlSerializer string output for #to_xml" do
47
- ActiveRecord::XmlSerializer.should_receive(:new).and_return(@serializer)
48
- @serializer.should_receive(:to_s).and_return(@xml)
49
- @model.to_xml
50
- end
51
-
52
- after(:each) do
53
- nilize(@id, @model)
54
- end
55
- end
56
-
57
- describe Twitter::User, "Rails extensions" do
58
-
59
- def model(id)
60
- Twitter::User.new(:id => id)
61
- end
62
-
63
- it_should_behave_like "Rails model extensions for model classes"
64
- end
65
-
66
- describe Twitter::Status, "Rails extensions" do
67
-
68
- def model(id)
69
- Twitter::Status.new(:id => id)
70
- end
71
-
72
- it_should_behave_like "Rails model extensions for model classes"
73
- end
74
-
75
- describe Twitter::Message, "Rails extensions" do
76
-
77
- def model(id)
78
- Twitter::Message.new(:id => id)
79
- end
80
-
81
- it_should_behave_like "Rails model extensions for model classes"
82
- end
83
-
84
- describe Twitter::RESTError, "Rails extensions" do
85
-
86
- before(:each) do
87
- @attributes = { :code => 200, :message => 'Success', :uri => 'http://twitter.com/statuses' }
88
- @model = Twitter::RESTError.new(@attributes)
89
- @json = "JSON" # doesn't really matter what the value is
90
- end
91
-
92
- it "should return a Hash of attribute name-value pairs for #to_hash" do
93
- @model.to_hash.should === @attributes
94
- end
95
-
96
- it "should invoke XmlSerializer for #to_xml" do
97
-
98
- @model.to_xml
99
- end
100
-
101
- it "should return expected JSON for #to_json" do
102
- @model.to_hash
103
- JSON.should_receive(:unparse).and_return(@json)
104
- @model.to_json
105
- end
106
-
107
- after(:each) do
108
- nilize(@attributes, @model)
109
- end
110
- end