socialcastr 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.markdown +29 -6
- data/examples/parse_messages.rb +16 -0
- data/examples/post_comment.rb +11 -0
- data/examples/post_message.rb +15 -0
- data/examples/search.rb +19 -0
- data/lib/socialcastr/api.rb +70 -78
- data/lib/socialcastr/base.rb +151 -0
- data/lib/socialcastr/collection.rb +30 -0
- data/lib/socialcastr/comment.rb +2 -2
- data/lib/socialcastr/exceptions.rb +75 -0
- data/lib/socialcastr/external_resource.rb +2 -2
- data/lib/socialcastr/flag.rb +5 -0
- data/lib/socialcastr/like.rb +1 -1
- data/lib/socialcastr/message.rb +45 -11
- data/lib/socialcastr/version.rb +2 -2
- data/lib/socialcastr.rb +19 -11
- data/socialcastr.gemspec +2 -0
- data/spec/api_spec.rb +167 -0
- data/spec/base_spec.rb +235 -0
- data/spec/comment_spec.rb +4 -0
- data/spec/configuration_spec.rb +97 -0
- data/spec/fixtures/demo_config.yml +3 -0
- data/spec/fixtures/message.xml +69 -0
- data/spec/fixtures/messages.xml +3338 -0
- data/spec/message_spec.rb +173 -0
- data/spec/socialcastr_spec.rb +58 -0
- data/spec/spec_helper.rb +54 -0
- metadata +62 -19
- data/lib/socialcastr/attachment_list.rb +0 -5
- data/lib/socialcastr/comment_list.rb +0 -5
- data/lib/socialcastr/external_resource_list.rb +0 -5
- data/lib/socialcastr/group_list.rb +0 -5
- data/lib/socialcastr/group_membership_list.rb +0 -5
- data/lib/socialcastr/like_list.rb +0 -5
- data/lib/socialcastr/media_file_list.rb +0 -5
- data/lib/socialcastr/message_list.rb +0 -5
- data/lib/socialcastr/recipient_list.rb +0 -6
- data/lib/socialcastr/stream_list.rb +0 -5
- data/lib/socialcastr/tag_list.rb +0 -5
data/lib/socialcastr/message.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Socialcastr
|
2
2
|
class Message < Base
|
3
3
|
|
4
|
+
id_element :id
|
4
5
|
element :title
|
5
6
|
element :body
|
6
7
|
element :url
|
@@ -8,7 +9,6 @@ module Socialcastr
|
|
8
9
|
element :action
|
9
10
|
element :external_url
|
10
11
|
element :icon
|
11
|
-
element :id
|
12
12
|
element :likable
|
13
13
|
element :created_at
|
14
14
|
element :updated_at
|
@@ -17,8 +17,8 @@ module Socialcastr
|
|
17
17
|
element :thumbnail_url
|
18
18
|
element :player_params
|
19
19
|
element :user, :class => Socialcastr::User
|
20
|
-
element :group, :class => Socialcastr::Group
|
21
|
-
|
20
|
+
#element :group, :class => Socialcastr::Group
|
21
|
+
elements :group, :as => :groups, :class => Socialcastr::Group
|
22
22
|
element :source, :class => Socialcastr::Source
|
23
23
|
|
24
24
|
element :editable
|
@@ -26,7 +26,7 @@ module Socialcastr
|
|
26
26
|
element :category_id
|
27
27
|
element :subscribed
|
28
28
|
# element :ratings_average
|
29
|
-
element :flag
|
29
|
+
element :flag, :class => Socialcastr::Flag
|
30
30
|
element :deletable
|
31
31
|
element :comments_count
|
32
32
|
element :verb
|
@@ -36,17 +36,51 @@ module Socialcastr
|
|
36
36
|
# element :target_user
|
37
37
|
element :ratable
|
38
38
|
element :message_type
|
39
|
-
|
39
|
+
elements :recipient, :as => :recipients, :class => Socialcastr::Recipient
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
elements :attachment, :as => :attachments, :class => Socialcastr::Attachment
|
42
|
+
elements :tag, :as => :tags, :class => Socialcastr::Tag
|
43
|
+
elements :like, :as => :likes, :class => Socialcastr::Like
|
44
|
+
elements :external_resource, :as => :external_resources, :class => Socialcastr::ExternalResource
|
45
|
+
elements :media_files, :as => :media_file, :class => Socialcastr::MediaFile
|
46
46
|
element :likes_count
|
47
47
|
element :hidden
|
48
48
|
|
49
|
-
|
49
|
+
elements :comment, :as => :comments, :class => Socialcastr::Comment
|
50
50
|
|
51
|
+
def flag!
|
52
|
+
return true if flagged?
|
53
|
+
flag.copy_attributes_from_object(Flag.parse(api.post(element_path + "/flags")))
|
54
|
+
end
|
55
|
+
|
56
|
+
def flagged?
|
57
|
+
!flag.id.nil?
|
58
|
+
end
|
59
|
+
|
60
|
+
def unflag!
|
61
|
+
return unless flagged?
|
62
|
+
api.delete(element_path + "/flags/#{flag.id}")
|
63
|
+
@flag = Flag.new
|
64
|
+
end
|
65
|
+
|
66
|
+
def like!
|
67
|
+
likes << Like.parse(api.post(element_path + "/likes"))
|
68
|
+
end
|
69
|
+
|
70
|
+
def unlike!
|
71
|
+
likes.reject! do |l|
|
72
|
+
l.unlikable && api.delete(element_path + "/likes/#{l.id}")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def comment!(arguments={})
|
77
|
+
comment = Socialcastr::Comment.new(arguments)
|
78
|
+
api.post(element_path + "/comments", comment.to_params)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def self.search(arguments={})
|
83
|
+
parse_collection(api.get(collection_path + "/search", arguments))
|
84
|
+
end
|
51
85
|
end
|
52
86
|
end
|
data/lib/socialcastr/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Socialcastr
|
2
|
-
VERSION = "0.0
|
3
|
-
end
|
2
|
+
VERSION = "0.1.0"
|
3
|
+
end
|
data/lib/socialcastr.rb
CHANGED
@@ -1,41 +1,48 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
|
2
2
|
|
3
|
+
require 'socialcastr/exceptions'
|
3
4
|
require 'socialcastr/base'
|
5
|
+
require 'socialcastr/collection'
|
4
6
|
require 'socialcastr/api'
|
5
7
|
require 'socialcastr/attachment'
|
6
|
-
require 'socialcastr/attachment_list'
|
7
8
|
require 'socialcastr/avatar_list'
|
8
9
|
require 'socialcastr/user'
|
10
|
+
require 'socialcastr/flag'
|
9
11
|
require 'socialcastr/like'
|
10
|
-
require 'socialcastr/like_list'
|
11
12
|
require 'socialcastr/comment'
|
12
|
-
require 'socialcastr/comment_list'
|
13
13
|
require 'socialcastr/group'
|
14
|
-
require 'socialcastr/group_list'
|
15
14
|
require 'socialcastr/group_membership'
|
16
|
-
require 'socialcastr/group_membership_list'
|
17
15
|
require 'socialcastr/stream'
|
18
|
-
require 'socialcastr/stream_list'
|
19
16
|
require 'socialcastr/source'
|
20
17
|
require 'socialcastr/tag'
|
21
|
-
require 'socialcastr/tag_list'
|
22
18
|
require 'socialcastr/recipient'
|
23
|
-
require 'socialcastr/recipient_list'
|
24
19
|
require 'socialcastr/thumbnail_list'
|
25
20
|
require 'socialcastr/media_file'
|
26
|
-
require 'socialcastr/media_file_list'
|
27
21
|
require 'socialcastr/external_resource'
|
28
|
-
require 'socialcastr/external_resource_list'
|
29
22
|
require 'socialcastr/message'
|
30
|
-
require 'socialcastr/message_list'
|
31
23
|
|
32
24
|
require 'singleton'
|
25
|
+
require 'yaml'
|
33
26
|
|
34
27
|
module Socialcastr
|
28
|
+
|
29
|
+
class MissingConfiguration < StandardError; end;
|
30
|
+
|
35
31
|
class Configuration
|
36
32
|
include Singleton
|
37
33
|
ATTRIBUTES = [:domain, :username, :password, :config_file]
|
38
34
|
attr_accessor *ATTRIBUTES
|
35
|
+
|
36
|
+
def ready?
|
37
|
+
[@domain, @username, @password].map(&:nil?).none?
|
38
|
+
end
|
39
|
+
|
40
|
+
def reset
|
41
|
+
ATTRIBUTES.each do |attribute|
|
42
|
+
send(attribute.to_s + "=", nil)
|
43
|
+
end
|
44
|
+
return self
|
45
|
+
end
|
39
46
|
end
|
40
47
|
|
41
48
|
def self.configuration
|
@@ -53,6 +60,7 @@ module Socialcastr
|
|
53
60
|
|
54
61
|
def self.api
|
55
62
|
config = Configuration.instance
|
63
|
+
raise MissingConfiguration unless config.username
|
56
64
|
API.new(config.username, config.password, config.domain)
|
57
65
|
end
|
58
66
|
|
data/socialcastr.gemspec
CHANGED
@@ -4,6 +4,8 @@ require File.expand_path('../lib/socialcastr/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.add_development_dependency('rake', '~> 0.8')
|
6
6
|
s.add_development_dependency('rspec', '~> 2.5')
|
7
|
+
s.add_development_dependency('yard')
|
8
|
+
s.add_development_dependency('artifice')
|
7
9
|
s.add_runtime_dependency('sax-machine')
|
8
10
|
s.authors = ["Riccardo Cambiassi"]
|
9
11
|
s.description = %q{A Ruby wrapper for the Socialcast REST API}
|
data/spec/api_spec.rb
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialcastr::API do
|
4
|
+
before :each do
|
5
|
+
@api = Socialcastr::API.new("demo", "password", "demo.socialcast.com")
|
6
|
+
end
|
7
|
+
|
8
|
+
context "trying to use an invalid HTTP method" do
|
9
|
+
it "should raise an InvalidMethod exception" do
|
10
|
+
lambda {@api.https_request(:wrong, nil, nil)}.should raise_error(Socialcastr::InvalidMethod)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
context "trying to access a non existing resource" do
|
14
|
+
it "should throw a ResourceNotFound exception" do
|
15
|
+
Artifice.activate_with(generate_fake_endpoint("", 404)) do
|
16
|
+
lambda { @api.get :messages }.should raise_error(Socialcastr::ResourceNotFound)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
context "being redirected" do
|
21
|
+
it "should throw a Redirection exception" do
|
22
|
+
Artifice.activate_with(generate_fake_endpoint("", 301)) do
|
23
|
+
lambda { @api.get :messages }.should raise_error(Socialcastr::Redirection)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
context "receiving a bad request response" do
|
28
|
+
it "should throw a BadRequest exception" do
|
29
|
+
Artifice.activate_with(generate_fake_endpoint("", 400)) do
|
30
|
+
lambda { @api.get :messages }.should raise_error(Socialcastr::BadRequest)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
context "receiving a unauthorized access response" do
|
35
|
+
it "should throw a Unauthorized exception" do
|
36
|
+
Artifice.activate_with(generate_fake_endpoint("", 401)) do
|
37
|
+
lambda { @api.get :messages }.should raise_error(Socialcastr::UnauthorizedAccess)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
context "receiving a forbidden access response" do
|
42
|
+
it "should throw a ForbiddenAccess xception" do
|
43
|
+
Artifice.activate_with(generate_fake_endpoint("", 403)) do
|
44
|
+
lambda { @api.get :messages }.should raise_error(Socialcastr::ForbiddenAccess)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
context "receiving a method not allowed response" do
|
49
|
+
it "should throw a MethodNotAllowed exception" do
|
50
|
+
Artifice.activate_with(generate_fake_endpoint("", 405)) do
|
51
|
+
lambda { @api.get :messages }.should raise_error(Socialcastr::MethodNotAllowed)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
context "receiving a resource conflict response" do
|
56
|
+
it "should throw a ResourceConflict exception" do
|
57
|
+
Artifice.activate_with(generate_fake_endpoint("", 409)) do
|
58
|
+
lambda { @api.get :messages }.should raise_error(Socialcastr::ResourceConflict)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
context "receiving a resource gone response" do
|
63
|
+
it "should throw a ResourceGone exception" do
|
64
|
+
Artifice.activate_with(generate_fake_endpoint("", 410)) do
|
65
|
+
lambda { @api.get :messages }.should raise_error(Socialcastr::ResourceGone)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
context "receiving a resource invalid response" do
|
70
|
+
it "should throw a ResourceInvalid exception" do
|
71
|
+
Artifice.activate_with(generate_fake_endpoint("", 422)) do
|
72
|
+
lambda { @api.get :messages }.should raise_error(Socialcastr::ResourceInvalid)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
context "receiving a server error response" do
|
77
|
+
it "should throw a ServerError exception" do
|
78
|
+
Artifice.activate_with(generate_fake_endpoint("", 500)) do
|
79
|
+
lambda { @api.get :messages }.should raise_error(Socialcastr::ServerError)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
context "#get" do
|
84
|
+
it "should call Net::HTTP::Get" do
|
85
|
+
req = Net::HTTP::Get.new("/")
|
86
|
+
Net::HTTP::Get.should_receive(:new).and_return(req)
|
87
|
+
@messages = nil
|
88
|
+
fake_socialcast_api_for :message do
|
89
|
+
@messages = @api.get :message
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should return an xml string" do
|
94
|
+
fake_socialcast_api_for :message do
|
95
|
+
@messages = @api.get :message
|
96
|
+
end
|
97
|
+
|
98
|
+
@messages.should_not be_nil
|
99
|
+
@messages.class.should == String
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "#put" do
|
104
|
+
it "should call Net::HTTP::Get" do
|
105
|
+
req = Net::HTTP::Put.new("/")
|
106
|
+
Net::HTTP::Put.should_receive(:new).and_return(req)
|
107
|
+
@messages = nil
|
108
|
+
fake_socialcast_api_for :message do
|
109
|
+
@messages = @api.put :message
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "#post" do
|
115
|
+
it "should call Net::HTTP::Get" do
|
116
|
+
req = Net::HTTP::Post.new("/")
|
117
|
+
Net::HTTP::Post.should_receive(:new).and_return(req)
|
118
|
+
@messages = nil
|
119
|
+
fake_socialcast_api_for :message do
|
120
|
+
@messages = @api.post :message
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "#delete" do
|
126
|
+
it "should call Net::HTTP::Get" do
|
127
|
+
req = Net::HTTP::Delete.new("/")
|
128
|
+
Net::HTTP::Delete.should_receive(:new).and_return(req)
|
129
|
+
@messages = nil
|
130
|
+
fake_socialcast_api_for :message do
|
131
|
+
@messages = @api.delete :message
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "#setup_https" do
|
137
|
+
before :each do
|
138
|
+
@https = @api.setup_https
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should return an instance of Net::HTTP" do
|
142
|
+
@https.class.should == Net::HTTP
|
143
|
+
end
|
144
|
+
it "should use ssl" do
|
145
|
+
@https.use_ssl.should be_true
|
146
|
+
end
|
147
|
+
it "should not verify SSL" do
|
148
|
+
@https.verify_mode.should == OpenSSL::SSL::VERIFY_NONE
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
context "#build_query_string" do
|
154
|
+
it "should return a string" do
|
155
|
+
@api.build_query_string("").class.should == String
|
156
|
+
end
|
157
|
+
it "should prepend /api/ to the path" do
|
158
|
+
@api.build_query_string("test").should match(/^\/api\/test/)
|
159
|
+
end
|
160
|
+
it "should append the format to the path" do
|
161
|
+
@api.build_query_string("test").should match(/test\.xml$/)
|
162
|
+
end
|
163
|
+
it "should append a well formed query string when passing a parameters hash" do
|
164
|
+
@api.build_query_string("test", :hallo => "world").should match(/\?hallo=world$/)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
data/spec/base_spec.rb
ADDED
@@ -0,0 +1,235 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialcastr::Base do
|
4
|
+
context 'api' do
|
5
|
+
context 'when Socialcastr has not been configured' do
|
6
|
+
it 'should raise an exception' do
|
7
|
+
lambda { Socialcastr::Base.api }.should raise_error
|
8
|
+
end
|
9
|
+
end
|
10
|
+
context 'when Socialcastr has been configured' do
|
11
|
+
before :each do
|
12
|
+
configure_socialcastr
|
13
|
+
end
|
14
|
+
it "should return the instance of Socialcastr::API" do
|
15
|
+
Socialcastr::Base.api.class.should == Socialcastr::API
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'creating a new object with new()' do
|
21
|
+
it 'should return a new instance' do
|
22
|
+
class Post < Socialcastr::Base; end
|
23
|
+
post = Post.new
|
24
|
+
post.should_not be_nil
|
25
|
+
post.class.should == Post
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'for a class that has an element \'author\'' do
|
29
|
+
before :each do
|
30
|
+
class Post < Socialcastr::Base
|
31
|
+
element 'author'
|
32
|
+
end
|
33
|
+
@post = Post.new
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should be possible to access the author attribute' do
|
37
|
+
lambda { @post.author }.should_not raise_error
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should not initialize the author attribute' do
|
41
|
+
@post.author.should be_nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'initializing a new object with author="john doe"' do
|
47
|
+
before :each do
|
48
|
+
class Post < Socialcastr::Base
|
49
|
+
id_element :id
|
50
|
+
element 'author'
|
51
|
+
end
|
52
|
+
@post = Post.new(:author => "john doe")
|
53
|
+
end
|
54
|
+
|
55
|
+
context '#author' do
|
56
|
+
it 'should return "john doe"' do
|
57
|
+
@post.author.should == "john doe"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context '#new?' do
|
62
|
+
it 'should return true' do
|
63
|
+
@post.new?.should be_true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context '#id' do
|
68
|
+
it 'should be nil' do
|
69
|
+
@post.id.should be_nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context '#to_params' do
|
74
|
+
it 'should return a Hash ' do
|
75
|
+
@post.to_params.class.should == Hash
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context '#param_name' do
|
80
|
+
it 'should return a string like model_name[variable_name]' do
|
81
|
+
@post.param_name("@author").should == "post[author]"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "#copy_attributes_from_object" do
|
86
|
+
it "should copy the instance variables of on another object's to the current one" do
|
87
|
+
@another_post = Post.new(:author => "jane doe")
|
88
|
+
@post.copy_attributes_from_object(@another_post)
|
89
|
+
@post.author.should == "jane doe"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'saving it with #save' do
|
94
|
+
before :each do
|
95
|
+
@api = mock('api', :post => "")
|
96
|
+
Socialcastr.stub!(:api).and_return(@api)
|
97
|
+
end
|
98
|
+
it 'should POST to the socialcast api' do
|
99
|
+
response = "<post><id>4</id><author>john doe</author></post>"
|
100
|
+
@api.should_receive(:post).and_return(response)
|
101
|
+
@post.save
|
102
|
+
@post.id.should == 4
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'find_single or find(id)' do
|
109
|
+
before :each do
|
110
|
+
fake_socialcast_api_for(:message) do
|
111
|
+
@message = Socialcastr::Message.find(425)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should return a Socialcastr::Base object' do
|
116
|
+
@message.class.should == Socialcastr::Message
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should not be new' do
|
120
|
+
@message.new?.should be_false
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'after modifying one attribute' do
|
124
|
+
before :each do
|
125
|
+
@message.title = 'new title'
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'the attribute should be changed' do
|
129
|
+
@message.title.should == "new title"
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'saving the object with #save' do
|
133
|
+
it 'should PUT to the Socialcast API' do
|
134
|
+
@api = mock('api', :post => "")
|
135
|
+
Socialcastr::Message.stub!(:api).and_return(@api)
|
136
|
+
response = "<message></message>"
|
137
|
+
@api.should_receive(:put).and_return(response)
|
138
|
+
@message.save
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'find_every or find(:all)' do
|
145
|
+
before :each do
|
146
|
+
fake_socialcast_api_for(:message) do
|
147
|
+
@messages = Socialcastr::Base.find(:all)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should return an enumerable' do
|
152
|
+
@messages.class.should == BaseList
|
153
|
+
lambda { @messages.first }.should_not raise_error
|
154
|
+
end
|
155
|
+
end
|
156
|
+
context 'first or find(:first)' do
|
157
|
+
before :each do
|
158
|
+
fake_socialcast_api_for(:message) do
|
159
|
+
@message = Socialcastr::Message.first
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'should return an object' do
|
164
|
+
@message.class.should == Socialcastr::Message
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'last or find(:last)' do
|
169
|
+
before :each do
|
170
|
+
fake_socialcast_api_for(:message) do
|
171
|
+
@message = Socialcastr::Message.last
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should return an object' do
|
176
|
+
@message.class.should == Socialcastr::Message
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'model_name' do
|
181
|
+
it 'should return a lowercase string containing the object\'s classname' do
|
182
|
+
class Tree < Socialcastr::Base; end
|
183
|
+
Tree.model_name.should == 'Tree'
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'should not include any module or prefix' do
|
187
|
+
class Socialcastr::Tree < Socialcastr::Base; end
|
188
|
+
Socialcastr::Tree.model_name.should == 'Tree'
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'prefix' do
|
193
|
+
context 'being passed {:post_id => 3} as arguments' do
|
194
|
+
it 'should return posts/3/' do
|
195
|
+
Socialcastr::Base.prefix(:post_id => 3).should == 'posts/3/'
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'collection_name' do
|
201
|
+
it 'should return a pluralized and downcase string' do
|
202
|
+
Socialcastr::Base.collection_name.should == 'bases'
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context 'collection_class' do
|
207
|
+
before do
|
208
|
+
class Post < Socialcastr::Base; end
|
209
|
+
end
|
210
|
+
it 'should return a class' do
|
211
|
+
Post.collection_class.class.should == Class
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'should return a class that inherits from Socialcastr::Collection' do
|
215
|
+
Post.collection_class.superclass.should == Socialcastr::Collection
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
context 'element_path' do
|
220
|
+
context 'with 5 as an argument' do
|
221
|
+
it 'should return collection_name/5' do
|
222
|
+
class Post < Socialcastr::Base; end
|
223
|
+
Post.element_path(5).should == '/posts/5'
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
context 'collection_path' do
|
229
|
+
it 'should return collection_name' do
|
230
|
+
class Post < Socialcastr::Base; end
|
231
|
+
Post.collection_path.should == '/posts'
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialcastr::Configuration do
|
4
|
+
|
5
|
+
it 'should be a singleton' do
|
6
|
+
lambda {Socialcastr::Configuration.new }.should raise_error
|
7
|
+
|
8
|
+
config1 = Socialcastr::Configuration.instance
|
9
|
+
config2 = Socialcastr::Configuration.instance
|
10
|
+
config1.equal?(config2).should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when called for the first time' do
|
14
|
+
before :each do
|
15
|
+
@config = Socialcastr::Configuration.instance
|
16
|
+
end
|
17
|
+
it 'should not set a username' do
|
18
|
+
@config.username.should be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should not set a password' do
|
22
|
+
@config.password.should be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should not set a domain' do
|
26
|
+
@config.domain.should be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should not be ready' do
|
30
|
+
@config.ready?.should be_false
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'then setting the username' do
|
34
|
+
before :each do
|
35
|
+
@config.username = "demo"
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should have a username' do
|
39
|
+
@config.username.should == "demo"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'then setting the password' do
|
44
|
+
before :each do
|
45
|
+
@config.password = "password"
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should have a username' do
|
49
|
+
@config.password.should == "password"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'then setting the domain' do
|
54
|
+
before :each do
|
55
|
+
@config.domain = "demo"
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should have a username' do
|
59
|
+
@config.domain.should == "demo"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when properly configured' do
|
65
|
+
before do
|
66
|
+
@config = Socialcastr::Configuration.instance
|
67
|
+
@config.username = "demo"
|
68
|
+
@config.password = "password"
|
69
|
+
@config.domain = "demo.socialcast.com"
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should be ready' do
|
73
|
+
@config.ready?.should be_true
|
74
|
+
end
|
75
|
+
context '#reset' do
|
76
|
+
before :each do
|
77
|
+
@config.reset
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should have no password' do
|
81
|
+
@config.password.should be_nil
|
82
|
+
end
|
83
|
+
it 'should have no username' do
|
84
|
+
@config.username.should be_nil
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should have no domain' do
|
88
|
+
@config.domain.should be_nil
|
89
|
+
end
|
90
|
+
it 'should not be ready' do
|
91
|
+
@config.ready?.should be_false
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|