livefyre 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,212 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Livefyre::Site do
4
- context "an instance" do
5
- subject { Livefyre::Site.new("my.site") }
6
-
7
- describe "#properties" do
8
- context "on success" do
9
- before do
10
- body = {:id => "bar", :api_secret => "secret"}.to_json
11
- client = double( :get => double(:success? => true, :body => body), :system_token => "x" )
12
- subject.stub(:client).and_return(client)
13
- subject.properties
14
- end
15
-
16
- its(:options) { should == {"id" => "bar", "api_secret" => "secret"} }
17
- its(:secret) { should == "secret" }
18
- end
19
-
20
- context "on failure" do
21
- before do
22
- client = double( :get => double(:success? => false, :body => ""), :system_token => "x" )
23
- subject.stub(:client).and_return(client)
24
- end
25
-
26
- it "should raise an exception" do
27
- expect { subject.properties }.to raise_error(Livefyre::APIException)
28
- end
29
- end
30
- end
31
-
32
- describe "#set_postback_url" do
33
- context "on success" do
34
- before do
35
- client = double( :post => double(:success? => true), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
36
- client.should_receive(:get).with("/site/my.site/", {:actor_token => "x"}).and_return(double(:success? => true, :body => "{}"))
37
- subject.stub(:client).and_return(client)
38
- end
39
-
40
- it "should return true" do
41
- subject.set_postback_url("http://foo.bar/").should be true
42
- end
43
- end
44
-
45
- context "on failure" do
46
- let(:client) { double( :system_token => "x" ) }
47
- before do
48
- response = double(:success? => false, :body => "")
49
- client.should_receive(:post).with("/site/my.site/", {:actor_token => "x", :postback_url => "http://foo.bar/"}).and_return(response)
50
- subject.stub(:client).and_return(client)
51
- end
52
-
53
- it "should raise an exception" do
54
- expect { subject.set_postback_url("http://foo.bar/") }.to raise_error(Livefyre::APIException)
55
- end
56
- end
57
- end
58
-
59
-
60
- describe "#owners" do
61
- context "on success" do
62
- before do
63
- client = double( :get => double(:success? => true, :body => ["foo@bar"].to_json), :system_token => "x" )
64
- client.should_receive(:user).with("foo").and_return( Livefyre.client.user("foo") )
65
- subject.stub(:client).and_return(client)
66
- end
67
-
68
- its(:owners) { should be_a Array }
69
-
70
- its("owners.first") { should be_a Livefyre::User }
71
- its("owners.first.id") { should == "foo" }
72
- end
73
-
74
- context "on failure" do
75
- before do
76
- client = double( :get => double(:success? => false, :body => ""), :system_token => "x" )
77
- subject.stub(:client).and_return(client)
78
- end
79
-
80
- it "should raise an exception" do
81
- expect { subject.owners }.to raise_error(Livefyre::APIException)
82
- end
83
- end
84
- end
85
-
86
- describe "#add_owner" do
87
- context "on success" do
88
- before do
89
- client = double( :post => double(:success? => true), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
90
- subject.stub(:client).and_return(client)
91
- end
92
-
93
- it "should return true" do
94
- subject.add_owner("some ID").should be true
95
- end
96
- end
97
-
98
- context "on failure" do
99
- before do
100
- client = double( :post => double(:success? => false, :body => ""), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
101
- subject.stub(:client).and_return(client)
102
- end
103
-
104
- it "should raise an exception" do
105
- expect { subject.add_owner("some user ID") }.to raise_error(Livefyre::APIException)
106
- end
107
- end
108
- end
109
-
110
- describe "#remove_owner" do
111
- context "on success" do
112
- before do
113
- client = double( :delete => double(:success? => true), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
114
- subject.stub(:client).and_return(client)
115
- end
116
-
117
- it "should return true" do
118
- subject.remove_owner("some ID").should be true
119
- end
120
- end
121
-
122
- context "on failure" do
123
- before do
124
- client = double( :delete => double(:success? => false, :body => ""), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
125
- subject.stub(:client).and_return(client)
126
- end
127
-
128
- it "should raise an exception" do
129
- expect { subject.remove_owner("some user ID") }.to raise_error(Livefyre::APIException)
130
- end
131
- end
132
- end
133
-
134
- describe "#admins" do
135
- context "on success" do
136
- before do
137
- client = double( :get => double(:success? => true, :body => ["foo@bar"].to_json), :system_token => "x" )
138
- client.should_receive(:user).with("foo").and_return( Livefyre.client.user("foo") )
139
- subject.stub(:client).and_return(client)
140
- end
141
-
142
- its(:admins) { should be_a Array }
143
-
144
- its("admins.first") { should be_a Livefyre::User }
145
- its("admins.first.id") { should == "foo" }
146
- end
147
-
148
- context "on failure" do
149
- before do
150
- client = double( :get => double(:success? => false, :body => ""), :system_token => "x" )
151
- subject.stub(:client).and_return(client)
152
- end
153
-
154
- it "should raise an exception" do
155
- expect { subject.admins }.to raise_error(Livefyre::APIException)
156
- end
157
- end
158
- end
159
-
160
- describe "#add_admin" do
161
- context "on success" do
162
- before do
163
- client = double( :post => double(:success? => true), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
164
- subject.stub(:client).and_return(client)
165
- end
166
-
167
- it "should return true" do
168
- subject.add_admin("some ID").should be true
169
- end
170
- end
171
-
172
- context "on failure" do
173
- before do
174
- client = double( :post => double(:success? => false, :body => ""), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
175
- subject.stub(:client).and_return(client)
176
- end
177
-
178
- it "should raise an exception" do
179
- expect { subject.add_admin("some user ID") }.to raise_error(Livefyre::APIException)
180
- end
181
- end
182
- end
183
-
184
- describe "#remove_admin" do
185
- context "on success" do
186
- before do
187
- client = double( :delete => double(:success? => true), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
188
- subject.stub(:client).and_return(client)
189
- end
190
-
191
- it "should return true" do
192
- subject.remove_admin("some ID").should be true
193
- end
194
- end
195
-
196
- context "on failure" do
197
- before do
198
- client = double( :delete => double(:success? => false, :body => ""), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
199
- subject.stub(:client).and_return(client)
200
- end
201
-
202
- it "should raise an exception" do
203
- expect { subject.remove_admin("some user ID") }.to raise_error(Livefyre::APIException)
204
- end
205
- end
206
- end
207
-
208
- it "should have a valid string representation" do
209
- subject.to_s.should match(/Livefyre::Site.*id='#{subject.id}'/)
210
- end
211
- end
212
- end
@@ -1,111 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Livefyre::User do
4
- describe "#initialize" do
5
- context "when no client is passed" do
6
- it "should use the default client" do
7
- Livefyre::User.new(123).instance_variable_get("@client").should eql(Livefyre.client)
8
- end
9
- end
10
-
11
- context "when a client is passed" do
12
- it "should use the passed client" do
13
- client = Livefyre::Client.new(:host => "x", :key => "x", :system_token => "x")
14
- Livefyre::User.new(123, client).tap do |user|
15
- user.instance_variable_get("@client").should eql client
16
- user.instance_variable_get("@client").should_not eql Livefyre.client
17
- end
18
- end
19
- end
20
- end
21
-
22
- describe "::get_user_id" do
23
- it "should return an ID when passed a string" do
24
- Livefyre::User.get_user_id("foobar").should == "foobar"
25
- end
26
-
27
- it "should return an ID when passed a User" do
28
- Livefyre::User.get_user_id( Livefyre::User.new("foobar") ).should == "foobar"
29
- end
30
-
31
- it "should return an ID when passed an integer" do
32
- Livefyre::User.get_user_id(123).should == 123
33
- end
34
-
35
- it "should raise an exception when passed an invalid value" do
36
- expect { Livefyre::User.get_user_id(nil) }.to raise_error("Invalid user ID")
37
- end
38
- end
39
-
40
- describe "::get_user" do
41
- context "should return a user when passed a user ID" do
42
- subject { Livefyre::User.get_user("foobar", Livefyre.client) }
43
- it { should be_a Livefyre::User }
44
- its(:id) { should == "foobar" }
45
- end
46
-
47
- context "should return a user when passed a User object" do
48
- subject { Livefyre::User.get_user( Livefyre::User.new("123", Object.new) , Livefyre.client) }
49
- it { should be_a Livefyre::User }
50
- its(:id) { should == "123" }
51
- end
52
-
53
- it "should raise an exception when passed an invalid value" do
54
- expect { Livefyre::User.get_user( nil , Livefyre.client ) }.to raise_error("Invalid user ID")
55
- end
56
- end
57
-
58
- context "an instance" do
59
- let(:client) { double("client", :system_token => "x", :host => "foo.bar", :key => "z") }
60
- subject { Livefyre::User.new(123, client) }
61
-
62
- its(:jid) { should == "123@foo.bar" }
63
- its(:token) { should be_a String }
64
-
65
- context "#push" do
66
- context "on success" do
67
- before do
68
- client
69
- .should_receive(:post)
70
- .with("/profiles/?actor_token=#{client.system_token}&id=#{subject.id}", {:data => {:some => "data"}.to_json})
71
- .and_return(double(:success? => true))
72
- end
73
-
74
- it "returns true" do
75
- subject.push(:some => "data").should == true
76
- end
77
- end
78
-
79
- context "on failure" do
80
- before do
81
- client
82
- .should_receive(:post)
83
- .with("/profiles/?actor_token=#{client.system_token}&id=#{subject.id}", {:data => {:some => "data"}.to_json})
84
- .and_return(double(:success? => false, :body => "error"))
85
- end
86
-
87
- it "raises an APIException" do
88
- expect { subject.push(:some => "data") }.to raise_error(Livefyre::APIException)
89
- end
90
- end
91
- end
92
-
93
- context "#refresh" do
94
- it "should post to the ping-to-pull endpoint" do
95
- client.should_receive(:post).with("/api/v3_0/user/#{subject.id}/refresh", {:lftoken => client.system_token})
96
- .and_return( double(:success? => true) )
97
- subject.refresh.should == true
98
- end
99
-
100
- it "should raise an exception when it fails to post to the ping-to-pull endpoint" do
101
- client.should_receive(:post).with("/api/v3_0/user/#{subject.id}/refresh", {:lftoken => client.system_token})
102
- .and_return( double(:success? => false, :body => "Temporal failure in the primary quantum induction matrix") )
103
- expect { subject.refresh.should }.to raise_error(Livefyre::APIException)
104
- end
105
- end
106
-
107
- it "should have a valid string representation" do
108
- subject.to_s.should match(/Livefyre::User.*id='#{subject.id}'/)
109
- end
110
- end
111
- end
data/spec/spec_helper.rb DELETED
@@ -1,26 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
-
4
- begin
5
- require 'rails'
6
- require 'resque'
7
- rescue LoadError
8
- end
9
-
10
- if ENV['COVERAGE']
11
- require 'simplecov'
12
- if ENV['RCOV']
13
- require 'simplecov-rcov'
14
- SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
15
- end
16
- SimpleCov.start do
17
- add_group 'Gem', 'lib'
18
- add_filter "spec"
19
- end
20
- end
21
-
22
- require 'livefyre'
23
- Livefyre.config = {:host => "foo.bar", :key => "x", :system_token => "x"}
24
-
25
- RSpec.configure do |config|
26
- end
data.tar.gz.sig DELETED
@@ -1 +0,0 @@
1
- 5`� �$�T�\$bDśic�+K��/tA��QӐe��y���9�Ir�U>w@�G�%pM�}�&ֻJ����\�x�{$����\�ӗ:L:CŇl�S������6�ȕ�I����;ͱ��Y�8�&Ю�Ua�u0H����'�'yA�!��syx{QKd�������K� �?�S�,���s��uaڃ��mlUg?�w�J ��`�lڍ."\)��Q/K^WW��e9��;&������a��
metadata.gz.sig DELETED
Binary file