disqus_rails 0.0.5

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.
@@ -0,0 +1,68 @@
1
+ module DisqusRails
2
+ class User < Model
3
+ attr_accessor :id,
4
+ :username,
5
+ :about,
6
+ :name,
7
+ :url,
8
+ :isFollowing,
9
+ :isFollowedBy,
10
+ :profileUrl,
11
+ :emailHash,
12
+ :avatar,
13
+ :isAnonymous,
14
+ :email,
15
+ :disquser_id
16
+
17
+ class << self
18
+
19
+ def popular(attributes={})
20
+ Users.new :Threads, :listPopular, attributes
21
+ end
22
+
23
+ end
24
+
25
+ def change_name(name)
26
+ Api::Users.checkUsername(:user => self.id, :username => name)
27
+ end
28
+
29
+ def follow(target_id)
30
+ Api::Users.follow(:user => self.id, :target => target_id)
31
+ end
32
+
33
+ def unfollow(target_id)
34
+ Api::Users.unfollow(:user => self.id, :target => target_id)
35
+ end
36
+
37
+
38
+ def forums(attributes={})
39
+ attributes[:user] = self.id
40
+ Forums.new :Users, :listForums, attributes
41
+ end
42
+
43
+ def active_forums(attributes={})
44
+ attributes[:user] = self.id
45
+ Forums.new :Users, :listActiveForums, attributes
46
+ end
47
+
48
+ def active_threads(attributes={})
49
+ attributes[:user] = self.id
50
+ Threads.new :Users, :listActiveThreads, attributes
51
+ end
52
+
53
+ def posts(attributes={})
54
+ attributes[:user] = self.id
55
+ Posts.new :Users, :listPosts, attributes
56
+ end
57
+
58
+ def followers(attributes={})
59
+ attributes[:user] = self.id
60
+ Users.new :Users, :listFollowers, attributes
61
+ end
62
+
63
+ def following(attributes={})
64
+ attributes[:user] = self.id
65
+ Users.new :Users, :listFollowing, attributes
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module DisqusRails
2
+ VERSION = "0.0.5"
3
+ end
@@ -0,0 +1,118 @@
1
+ require 'spec_helper'
2
+
3
+ describe DisqusRails::Disqusable do
4
+
5
+ before :all do
6
+ ::ActiveRecord::Base.extend DisqusRails::Disqusable::ActiveRecordMethods
7
+
8
+ m = ActiveRecord::Migration.new
9
+ m.verbose = false
10
+ m.create_table :stubbed_disqusables
11
+ end
12
+
13
+ after :all do
14
+ m = ActiveRecord::Migration.new
15
+ m.verbose = false
16
+ m.drop_table :stubbed_disqusables
17
+ end
18
+
19
+ let(:stubbed_disqusable_instance) do
20
+ class StubbedDisqusable < ActiveRecord::Base
21
+ acts_as_disqusable
22
+ end
23
+
24
+ StubbedDisqusable.new()
25
+ end
26
+
27
+ let!(:thread_hash) do
28
+ {
29
+ :code => 0,
30
+ :response => {
31
+ "category" => "1",
32
+ "reactions" => 0,
33
+ "identifiers" => [
34
+ 2
35
+ ],
36
+ "forum" => "bobross",
37
+ "title" => "Hello World",
38
+ "dislikes" => 0,
39
+ "isDeleted" => false,
40
+ "author" => "1",
41
+ "userScore" => 0,
42
+ "id" => "3",
43
+ "isClosed" => false,
44
+ "posts" => 0,
45
+ "link" => "null",
46
+ "likes" => 0,
47
+ "message" => "",
48
+ "ipAddress" => "127.0.0.1",
49
+ "slug" => "hello_world",
50
+ "createdAt" => "2011-11-02T02:22:41"
51
+ }
52
+ }
53
+ end
54
+
55
+ let(:thread) do
56
+ DisqusRails::Thread.new thread_hash[:response]
57
+ end
58
+
59
+ let(:one_entrance_collection_hash) do
60
+ {
61
+ :cursor => {
62
+ "prev" => "null",
63
+ "hasNext" => true,
64
+ "next" => "1368581473195442:0:0",
65
+ "hasPrev" => false,
66
+ "total" => "null",
67
+ "id" => "1368581473195442:0:0",
68
+ "more" => true
69
+ },
70
+ :code => 0,
71
+ :response => [
72
+ {
73
+ "category" => "1",
74
+ "reactions" => 0,
75
+ "identifiers" => [
76
+ 1
77
+ ],
78
+ "forum" => "bobross",
79
+ "title" => "Hello World",
80
+ "dislikes" => 0,
81
+ "isDeleted" => false,
82
+ "author" => "1",
83
+ "userScore" => 0,
84
+ "id" => "3",
85
+ "isClosed" => false,
86
+ "posts" => 0,
87
+ "link" => "null",
88
+ "likes" => 0,
89
+ "message" => "",
90
+ "ipAddress" => "127.0.0.1",
91
+ "slug" => "hello_world",
92
+ "createdAt" => "2011-11-02T02:22:41"
93
+ }
94
+ ]
95
+ }
96
+ end
97
+
98
+ it "should create disqus_thread method on active record model that ran acts_as_disqusable method in class definition" do
99
+ stubbed_disqusable_instance.should respond_to("disqus_thread")
100
+ end
101
+
102
+ it "should return threads as DisqusRails::Threads class invoking disqus_thread method" do
103
+ stubbed_disqusable_instance.save()
104
+
105
+ DisqusRails::Api::Threads
106
+ .should_receive(:list)
107
+ .with(:forum=>nil, :"thread:ident"=>stubbed_disqusable_instance.id)
108
+ .and_return(one_entrance_collection_hash)
109
+
110
+ stubbed_disqusable_instance.disqus_thread.should be_a_kind_of(DisqusRails::Thread)
111
+ end
112
+
113
+ it "should return disqusable model instance that linked to that disqus thread" do
114
+ stubbed_disqusable_instance.save()
115
+ thread.disqusable.should be_a_kind_of(StubbedDisqusable)
116
+ end
117
+
118
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe DisqusRails::Disquser do
4
+
5
+ before :all do
6
+ ::ActiveRecord::Base.extend DisqusRails::Disquser::ActiveRecordMethods
7
+
8
+ m = ActiveRecord::Migration.new
9
+ m.verbose = false
10
+ m.create_table :stubbed_disqusers
11
+ end
12
+
13
+ after :all do
14
+ m = ActiveRecord::Migration.new
15
+ m.verbose = false
16
+ m.drop_table :stubbed_disqusers
17
+ end
18
+
19
+ let(:stubbed_disquser_instance) do
20
+ class StubbedDisquser < ActiveRecord::Base
21
+ acts_as_disquser :username => :fullname, :email => :email, :avatar => Proc.new{ "pic.jpg" }
22
+
23
+ def fullname
24
+ "stubbed_users_fullname"
25
+ end
26
+
27
+ def email
28
+ "stubbed_users_email"
29
+ end
30
+ end
31
+
32
+ StubbedDisquser.new()
33
+ end
34
+
35
+ it "should create disqus_params method on active record disquser model" do
36
+ stubbed_disquser_instance.should respond_to("disqus_params")
37
+ end
38
+
39
+ it "should return disqus params for user to use in disqus_init helper for sso" do
40
+ stubbed_disquser_instance.save()
41
+ stubbed_disquser_instance.disqus_params[:username].should == "stubbed_users_fullname"
42
+ end
43
+
44
+ end
@@ -0,0 +1,266 @@
1
+ #require 'spec_helper'
2
+ #
3
+ #describe DisqusRails::Api do
4
+ #
5
+ # before :all do
6
+ # DisqusRails.setup do |config|
7
+ # config::SHORT_NAME = "stubbed_short_name"
8
+ # config::SECRET_KEY = "stubbed_secret_key"
9
+ # config::PUBLIC_KEY = "stubbed_public_key"
10
+ # config::ACCESS_TOKEN = "stubbed_access_token"
11
+ # end
12
+ # end
13
+ #
14
+ # let(:forum){:stubbed_forum_name}
15
+ # describe DisqusRails::Api::Posts do
16
+ #
17
+ # it "lists posts" do
18
+ # DisqusRails::Api::Posts.list
19
+ # end
20
+ #
21
+ # #when spec was written disqus returned 500 and apparently got same server problems
22
+ # #it "lists popular posts" do
23
+ # # DisqusRails::Api::Posts.listPopular
24
+ # #end
25
+ #
26
+ # it "create post" do
27
+ # response = DisqusRails::Api::Posts.create(:message => "test message9...", :thread => 1329721966)
28
+ # post = response[:response]["id"]
29
+ #
30
+ # describe "in context of created post" do
31
+ # it "show created post details" do
32
+ # DisqusRails::Api::Posts.details(:post => post)
33
+ # end
34
+ #
35
+ # it "update created post" do
36
+ # DisqusRails::Api::Posts.update(:post => post, :message => "new updated message...")
37
+ # end
38
+ #
39
+ # it "approve post" do
40
+ # DisqusRails::Api::Posts.approve(:post => post)
41
+ # end
42
+ #
43
+ # it "highlight post" do
44
+ # DisqusRails::Api::Posts.highlight(:post => post)
45
+ # end
46
+ #
47
+ # it "unhighlight post" do
48
+ # DisqusRails::Api::Posts.unhighlight(:post => post)
49
+ # end
50
+ #
51
+ # it "vote for post" do
52
+ # DisqusRails::Api::Posts.vote(:post => post, :vote => 1)
53
+ # end
54
+ #
55
+ # it "report a post" do
56
+ # DisqusRails::Api::Posts.report(:post => post)
57
+ # end
58
+ #
59
+ # it "mark post as spam" do
60
+ # DisqusRails::Api::Posts.spam(:post => post)
61
+ # end
62
+ #
63
+ # it "remove a post" do
64
+ # DisqusRails::Api::Posts.remove(:post => post)
65
+ # end
66
+ #
67
+ # it "restore a post" do
68
+ # DisqusRails::Api::Posts.remove(:post => post)
69
+ # end
70
+ #
71
+ # it "remove a post" do
72
+ # DisqusRails::Api::Posts.remove(:post => post)
73
+ # end
74
+ # end
75
+ # end
76
+ # end
77
+ #
78
+ # describe DisqusRails::Api::Threads do
79
+ # it "lists threads" do
80
+ # DisqusRails::Api::Threads.list
81
+ # end
82
+ #
83
+ # it "lists popular threads" do
84
+ # DisqusRails::Api::Threads.listPopular(:forum => forum)
85
+ # end
86
+ #
87
+ # it "lists popular threads" do
88
+ # DisqusRails::Api::Threads.listPopular(:forum => forum)
89
+ # end
90
+ #
91
+ # it "lists hot threads" do
92
+ # DisqusRails::Api::Threads.listHot(:forum => forum)
93
+ # end
94
+ #
95
+ # it "create new thread" do
96
+ # result = DisqusRails::Api::Threads.create(:forum => forum, :title => "new title")
97
+ # thread = result[:response]["id"]
98
+ #
99
+ # describe "in context of new created thread" do
100
+ #
101
+ # it "show thread details" do
102
+ # DisqusRails::Api::Threads.details :thread => thread
103
+ # end
104
+ #
105
+ # it "list threads posts" do
106
+ # DisqusRails::Api::Threads.listPosts :thread => thread
107
+ # end
108
+ #
109
+ # it "list threads reactions" do
110
+ # DisqusRails::Api::Threads.listReactions :thread => thread
111
+ # end
112
+ #
113
+ # it "subscribe to thread" do
114
+ # DisqusRails::Api::Threads.subscribe :thread => thread
115
+ # end
116
+ #
117
+ # it "unsubscribe from thread" do
118
+ # DisqusRails::Api::Threads.unsubscribe :thread => thread
119
+ # end
120
+ #
121
+ # it "vote for thread" do
122
+ # DisqusRails::Api::Threads.vote :thread => thread, :vote => 1
123
+ # end
124
+ #
125
+ # it "updates thread" do
126
+ # DisqusRails::Api::Threads.update(:thread => thread, :title => "new updated thread")
127
+ # end
128
+ #
129
+ # it "close thread" do
130
+ # DisqusRails::Api::Threads.close(:thread => thread)
131
+ # end
132
+ #
133
+ # it "open thread" do
134
+ # DisqusRails::Api::Threads.open(:thread => thread)
135
+ # end
136
+ #
137
+ # it "remove thread" do
138
+ # DisqusRails::Api::Threads.remove(:thread => thread)
139
+ # end
140
+ #
141
+ # it "restore thread" do
142
+ # DisqusRails::Api::Threads.restore(:thread => thread)
143
+ # end
144
+ #
145
+ # it "remove thread" do
146
+ # DisqusRails::Api::Threads.remove(:thread => thread)
147
+ # end
148
+ # end
149
+ # end
150
+ # end
151
+ #
152
+ # describe DisqusRails::Api::Users do
153
+ # let(:user){15211395}
154
+ #
155
+ # it "show user details" do
156
+ # DisqusRails::Api::Users.details(:user => user)
157
+ # end
158
+ #
159
+ # it "follow" do
160
+ # DisqusRails::Api::Users.follow(:target => 2)
161
+ # end
162
+ #
163
+ # it "unfollow" do
164
+ # DisqusRails::Api::Users.unfollow(:target => 2)
165
+ # end
166
+ #
167
+ # it "change username" do
168
+ # DisqusRails::Api::Users.checkUsername(:username => "stubbed_username")
169
+ # end
170
+ #
171
+ # it "list user active forums" do
172
+ # DisqusRails::Api::Users.listActiveForums(:user => user)
173
+ # end
174
+ #
175
+ # it "list user forums" do
176
+ # DisqusRails::Api::Users.listForums(:user => user)
177
+ # end
178
+ #
179
+ # it "list user most active forums" do
180
+ # DisqusRails::Api::Users.listMostActiveForums(:user => user)
181
+ # end
182
+ #
183
+ # it "list user active threads" do
184
+ # DisqusRails::Api::Users.listActiveThreads(:user => user)
185
+ # end
186
+ #
187
+ # it "list user activity" do
188
+ # DisqusRails::Api::Users.listActivity(:user => user)
189
+ # end
190
+ #
191
+ # it "list user followers" do
192
+ # DisqusRails::Api::Users.listFollowers(:user => user)
193
+ # end
194
+ #
195
+ # it "list user following" do
196
+ # DisqusRails::Api::Users.listFollowing(:user => user)
197
+ # end
198
+ #
199
+ # it "list user posts" do
200
+ # DisqusRails::Api::Users.listPosts(:user => user)
201
+ # end
202
+ # end
203
+ #
204
+ # describe DisqusRails::Api::Forums do
205
+ # it "show forum details" do
206
+ # DisqusRails::Api::Forums.details(:forum => forum)
207
+ # end
208
+ #
209
+ # it "list forums categories" do
210
+ # DisqusRails::Api::Forums.listCategories(:forum => forum)
211
+ # end
212
+ #
213
+ # it "list forum threads" do
214
+ # DisqusRails::Api::Forums.listThreads(:forum => forum)
215
+ # end
216
+ #
217
+ # it "list forum users" do
218
+ # DisqusRails::Api::Forums.listUsers(:forum => forum)
219
+ # end
220
+ #
221
+ # it "list forums moderators" do
222
+ # DisqusRails::Api::Forums.listModerators(:forum => forum)
223
+ # end
224
+ #
225
+ # it "list forums most active users" do
226
+ # DisqusRails::Api::Forums.listMostActiveUsers(:forum => forum)
227
+ # end
228
+ #
229
+ # it "list forums most liked users" do
230
+ # DisqusRails::Api::Forums.listMostLikedUsers(:forum => forum)
231
+ # end
232
+ #
233
+ # it "list forum posts" do
234
+ # DisqusRails::Api::Forums.listPosts(:forum => forum)
235
+ # end
236
+ # end
237
+ #
238
+ # describe DisqusRails::Api::Categories do
239
+ # let(:category){2388690}
240
+ #
241
+ # it "list categories" do
242
+ # DisqusRails::Api::Categories.list(:forum => forum)
243
+ # end
244
+ #
245
+ # it "create new category" do
246
+ # result = DisqusRails::Api::Categories.create(:forum => forum, :title => "new category")
247
+ # category = result[:response]["id"]
248
+ #
249
+ # describe "in context of new created category" do
250
+ #
251
+ # it "show category details" do
252
+ # DisqusRails::Api::Categories.details(:category => category)
253
+ # end
254
+ #
255
+ # it "list category posts" do
256
+ # DisqusRails::Api::Categories.listPosts(:category => category)
257
+ # end
258
+ #
259
+ # it "list category threads" do
260
+ # DisqusRails::Api::Categories.listThreads(:category => category)
261
+ # end
262
+ # end
263
+ # end
264
+ # end
265
+ #
266
+ #end