mwilden-disqus 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +18 -0
- data/Rakefile +26 -0
- data/lib/disqus/api.rb +258 -0
- data/lib/disqus/author.rb +27 -0
- data/lib/disqus/forum.rb +125 -0
- data/lib/disqus/post.rb +51 -0
- data/lib/disqus/thread.rb +73 -0
- data/lib/disqus/version.rb +8 -0
- data/lib/disqus/view_helpers.rb +9 -0
- data/lib/disqus/widget.rb +185 -0
- data/lib/disqus.rb +52 -0
- data/test/api_test.rb +79 -0
- data/test/forum_test.rb +69 -0
- data/test/post_test.rb +17 -0
- data/test/responses/bad_api_key.json +1 -0
- data/test/responses/create_post.json +23 -0
- data/test/responses/get_forum_api_key.json +1 -0
- data/test/responses/get_forum_list.json +12 -0
- data/test/responses/get_num_posts.json +11 -0
- data/test/responses/get_thread_by_url.json +18 -0
- data/test/responses/get_thread_list.json +16 -0
- data/test/responses/get_thread_posts.json +37 -0
- data/test/responses/thread_by_identifier.json +17 -0
- data/test/responses/update_thread.json +5 -0
- data/test/test_helper.rb +33 -0
- data/test/thread_test.rb +27 -0
- data/test/widget_test.rb +55 -0
- metadata +118 -0
data/test/forum_test.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class ForumTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Disqus.defaults[:api_key] = DISQUS_TEST["api_key"]
|
7
|
+
stub_api_call(:get_forum_api_key).returns("FAKE_FORUM_API_KEY")
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_forum_list
|
11
|
+
mock_api_call(:get_forum_list)
|
12
|
+
list = Disqus::Forum.list
|
13
|
+
expected = [create_forum]
|
14
|
+
assert_equal 1, list.size
|
15
|
+
assert_equal expected, list
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_forum_find
|
19
|
+
mock_api_call(:get_forum_list)
|
20
|
+
forum = Disqus::Forum.find(1234)
|
21
|
+
assert_equal "disqus-test", forum.shortname
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_forum_find_bad_id
|
25
|
+
mock_api_call(:get_forum_list)
|
26
|
+
forum = Disqus::Forum.find(666)
|
27
|
+
assert_equal nil, forum
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_forum_find_no_forums
|
31
|
+
Disqus::Api.expects(:get_forum_list).returns({"succeeded"=>true, "code"=>"", "message" => []})
|
32
|
+
forum = Disqus::Forum.find(1234)
|
33
|
+
assert_equal nil, forum
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_key
|
37
|
+
mock_api_call(:get_forum_api_key)
|
38
|
+
forum = Disqus::Forum.new(1234, "disqus-test", "Disqus Test", "2008-01-03 14:44:07.627492")
|
39
|
+
assert_equal "FAKE_FORUM_API_KEY", forum.key
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_forum_threads
|
43
|
+
forum = create_forum
|
44
|
+
Disqus::Thread.expects(:list).with(forum).returns([thread = mock()])
|
45
|
+
assert_equal [thread], forum.forum_threads
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_get_thread_by_url
|
49
|
+
mock_api_call(:get_thread_by_url)
|
50
|
+
forum = create_forum
|
51
|
+
thread = forum.get_thread_by_url("http://www.example.com")
|
52
|
+
expected = Disqus::Thread.new("7651269", forum, "test_thread", "Test thread", "2008-11-28T01:47", true, "FAKE_URL", nil)
|
53
|
+
assert_equal expected, thread
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_thread_by_identifier
|
57
|
+
mock_api_call(:thread_by_identifier)
|
58
|
+
forum = create_forum
|
59
|
+
thread = forum.thread_by_identifier("FAKE_IDENTIFIER", "")
|
60
|
+
expected = Disqus::Thread.new("7651269", forum, "test_thread", "Test thread", "2008-11-28T01:47", true, "FAKE_URL", "FAKE_IDENTIFIER")
|
61
|
+
assert_equal expected, thread
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_update_thread
|
65
|
+
Disqus::Api.expects(:update_thread).with({:thread_id => 1234, :forum_api_key => "FAKE_FORUM_API_KEY", :title => 'Title', :slug => "a_slug", :url => "http://www.example.com", :allow_comments => true}).returns({"succeeded" => true})
|
66
|
+
forum = create_forum
|
67
|
+
forum.update_thread(1234, :title => 'Title', :slug => "a_slug", :url => "http://www.example.com", :allow_comments => true)
|
68
|
+
end
|
69
|
+
end
|
data/test/post_test.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class PostTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Disqus.defaults[:api_key] = DISQUS_TEST["api_key"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_post_list
|
10
|
+
mock_api_call(:get_thread_posts)
|
11
|
+
list = Disqus::Post.list(create_thread)
|
12
|
+
assert_equal 2, list.size
|
13
|
+
assert_equal list.first.message, "This is a mock post"
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"message": "user_api_key BAD could not be converted to UserKey object", "code": "input-invalid", "succeeded": false}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
{
|
2
|
+
"message": {
|
3
|
+
"id": "12345",
|
4
|
+
"forum": "1234",
|
5
|
+
"thread": "123",
|
6
|
+
"created_at": "2008-01-03 14:44:07.627492",
|
7
|
+
"message": "This is a mock post",
|
8
|
+
"parent_post": null,
|
9
|
+
"shown": true,
|
10
|
+
"is_anonymous": false,
|
11
|
+
"author": {
|
12
|
+
"id":12,
|
13
|
+
"username":"testuser",
|
14
|
+
"display_name":"Test User",
|
15
|
+
"url":"http://www.example.com/testuser",
|
16
|
+
"email_hash":"thisisanMD5hash",
|
17
|
+
"has_avatar": true
|
18
|
+
}
|
19
|
+
},
|
20
|
+
"code": "ok",
|
21
|
+
"succeeded": true
|
22
|
+
}
|
23
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
{"message": "FAKE_FORUM_API_KEY", "code": "ok", "succeeded": true}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"message":{
|
3
|
+
"slug": "test_thread",
|
4
|
+
"forum": "60732",
|
5
|
+
"title": "Test thread",
|
6
|
+
"url": "FAKE_URL",
|
7
|
+
"id": "7651269",
|
8
|
+
"identifier": null,
|
9
|
+
"created_at": "2008-11-28T01:47",
|
10
|
+
"allow_comments": true
|
11
|
+
},
|
12
|
+
"succeeded": true,
|
13
|
+
"code": "ok"
|
14
|
+
}
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"message": [
|
3
|
+
{
|
4
|
+
"id": "12345",
|
5
|
+
"forum": "1234",
|
6
|
+
"slug": "this_is_a_thread",
|
7
|
+
"title": "This is a thread",
|
8
|
+
"created_at": "2008-01-03 14:44:07.627492",
|
9
|
+
"allow_comments": true,
|
10
|
+
"url":"http://www.example.com/testthread",
|
11
|
+
"identifier": "this_is_the_thread_identifier"
|
12
|
+
}
|
13
|
+
],
|
14
|
+
"code": "ok",
|
15
|
+
"succeeded": true
|
16
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
{
|
2
|
+
"message": [{
|
3
|
+
"id": "12345",
|
4
|
+
"forum": "1234",
|
5
|
+
"thread": "123",
|
6
|
+
"created_at": "2008-01-03 14:44:07.627492",
|
7
|
+
"message": "This is a mock post",
|
8
|
+
"parent_post": null,
|
9
|
+
"shown": true,
|
10
|
+
"is_anonymous": false,
|
11
|
+
"author": {
|
12
|
+
"id":12,
|
13
|
+
"username":"testuser",
|
14
|
+
"display_name":"Test User",
|
15
|
+
"url":"http://www.example.com/testuser",
|
16
|
+
"email_hash":"thisisanMD5hash",
|
17
|
+
"has_avatar": true
|
18
|
+
}
|
19
|
+
},{
|
20
|
+
"id": "23456",
|
21
|
+
"forum": "1234",
|
22
|
+
"thread": "123",
|
23
|
+
"created_at": "2008-01-03 14:44:07.627492",
|
24
|
+
"message": "This is another mock post",
|
25
|
+
"parent_post": null,
|
26
|
+
"shown": true,
|
27
|
+
"is_anonymous": true,
|
28
|
+
"anonymous_author": {
|
29
|
+
"id":12,
|
30
|
+
"name":"Anonymous Coward",
|
31
|
+
"email_hash":"thisisanMD5hash"
|
32
|
+
}
|
33
|
+
}],
|
34
|
+
"code": "ok",
|
35
|
+
"succeeded": true
|
36
|
+
}
|
37
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"message":{
|
3
|
+
"thread":{
|
4
|
+
"slug": "test_thread",
|
5
|
+
"forum": "60732",
|
6
|
+
"title": "Test thread",
|
7
|
+
"url": "FAKE_URL",
|
8
|
+
"id": "7651269",
|
9
|
+
"identifier": "FAKE_IDENTIFIER",
|
10
|
+
"created_at": "2008-11-28T01:47",
|
11
|
+
"allow_comments": true
|
12
|
+
},
|
13
|
+
"created": false
|
14
|
+
},
|
15
|
+
"succeeded": true,
|
16
|
+
"code": "ok"
|
17
|
+
}
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'yaml'
|
4
|
+
require 'mocha'
|
5
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "disqus")
|
6
|
+
|
7
|
+
DISQUS_TEST = {
|
8
|
+
# Only if you want to run against a live server. Not generally useful, you
|
9
|
+
# should be using stubs.
|
10
|
+
:api_key => "YOUR API KEY GOES HERE"
|
11
|
+
}
|
12
|
+
|
13
|
+
def create_forum
|
14
|
+
forum = Disqus::Forum.new(1234, "disqus-test", "Disqus Test", "2008-01-03 14:44:07.627492")
|
15
|
+
forum.stubs(:key).returns("FAKE_FORUM_API_KEY")
|
16
|
+
forum
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_thread
|
20
|
+
mock_forum = mock()
|
21
|
+
mock_forum.stubs(:key).returns("FAKE_FORUM_API_KEY")
|
22
|
+
Disqus::Thread.new("7651269", mock_forum, "test_thread", "Test thread", "2008-11-28T01:47", true, "FAKE_URL", nil)
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def mock_api_call(method_name)
|
27
|
+
Disqus::Api.expects(method_name.to_sym).returns(JSON.parse(File.read(File.dirname(__FILE__) + "/responses/#{method_name}.json")))
|
28
|
+
end
|
29
|
+
|
30
|
+
def stub_api_call(method_name)
|
31
|
+
Disqus::Api.stubs(method_name.to_sym).returns(JSON.parse(File.read(File.dirname(__FILE__) + "/responses/#{method_name}.json")))
|
32
|
+
end
|
33
|
+
|
data/test/thread_test.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class ThreadTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Disqus.defaults[:api_key] = DISQUS_TEST["api_key"]
|
7
|
+
stub_api_call(:get_forum_api_key)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_thread_list
|
11
|
+
mock_api_call(:get_thread_list)
|
12
|
+
forum = create_forum
|
13
|
+
list = Disqus::Thread.list(forum)
|
14
|
+
assert_equal 1, list.size
|
15
|
+
assert_equal list, [Disqus::Thread.new( 12345,
|
16
|
+
create_forum,
|
17
|
+
"this_is_a_thread",
|
18
|
+
"This is a thread",
|
19
|
+
"2008-01-03 14:44:07.627492",
|
20
|
+
true,
|
21
|
+
"http://www.example.com/testthread",
|
22
|
+
"this_is_the_thread_identifier" )]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
|
data/test/widget_test.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
class DisqusWidgetTest < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def setup
|
4
|
+
Disqus::defaults[:account] = "tests"
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_thread
|
8
|
+
assert disqus_thread
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_comment_counts
|
12
|
+
assert disqus_comment_counts
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_combo
|
16
|
+
assert disqus_combo
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_recent_comments
|
20
|
+
assert disqus_recent_comments
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_popular_threads
|
24
|
+
assert disqus_popular_threads
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_top_commenters
|
28
|
+
assert disqus_top_commenters
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_invalid_default_tab
|
32
|
+
assert_raises ArgumentError do
|
33
|
+
disqus_combo(:default_tab => "test")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_invalid_color
|
38
|
+
assert_raises ArgumentError do
|
39
|
+
disqus_combo(:color => "test")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_invalid_num_items
|
44
|
+
assert_raises ArgumentError do
|
45
|
+
disqus_combo(:num_items => 100)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_invalid_avatar_size
|
50
|
+
assert_raises ArgumentError do
|
51
|
+
disqus_top_commenters(:avatar_size => 100)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mwilden-disqus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: 1.0.3
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Norman Clarke
|
13
|
+
- Matthew Van Horn
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-29 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: json
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mocha
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 0
|
42
|
+
version: "0"
|
43
|
+
type: :development
|
44
|
+
version_requirements: *id002
|
45
|
+
description: Integrates Disqus into your Ruby-powered site. Works with any Ruby website, and has view helpers for Rails and Merb.
|
46
|
+
email:
|
47
|
+
- norman@njclarke.com
|
48
|
+
- mattvanhorn@gmail.com
|
49
|
+
executables: []
|
50
|
+
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
extra_rdoc_files: []
|
54
|
+
|
55
|
+
files:
|
56
|
+
- lib/disqus/api.rb
|
57
|
+
- lib/disqus/author.rb
|
58
|
+
- lib/disqus/forum.rb
|
59
|
+
- lib/disqus/post.rb
|
60
|
+
- lib/disqus/thread.rb
|
61
|
+
- lib/disqus/version.rb
|
62
|
+
- lib/disqus/view_helpers.rb
|
63
|
+
- lib/disqus/widget.rb
|
64
|
+
- lib/disqus.rb
|
65
|
+
- LICENSE
|
66
|
+
- Rakefile
|
67
|
+
- test/api_test.rb
|
68
|
+
- test/forum_test.rb
|
69
|
+
- test/post_test.rb
|
70
|
+
- test/responses/bad_api_key.json
|
71
|
+
- test/responses/create_post.json
|
72
|
+
- test/responses/get_forum_api_key.json
|
73
|
+
- test/responses/get_forum_list.json
|
74
|
+
- test/responses/get_num_posts.json
|
75
|
+
- test/responses/get_thread_by_url.json
|
76
|
+
- test/responses/get_thread_list.json
|
77
|
+
- test/responses/get_thread_posts.json
|
78
|
+
- test/responses/thread_by_identifier.json
|
79
|
+
- test/responses/update_thread.json
|
80
|
+
- test/test_helper.rb
|
81
|
+
- test/thread_test.rb
|
82
|
+
- test/widget_test.rb
|
83
|
+
has_rdoc: true
|
84
|
+
homepage: http://github.com/norman/disqus
|
85
|
+
licenses: []
|
86
|
+
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
106
|
+
requirements: []
|
107
|
+
|
108
|
+
rubyforge_project: disqus
|
109
|
+
rubygems_version: 1.3.6
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: Integrates Disqus commenting system into your Ruby-powered site.
|
113
|
+
test_files:
|
114
|
+
- test/api_test.rb
|
115
|
+
- test/forum_test.rb
|
116
|
+
- test/post_test.rb
|
117
|
+
- test/thread_test.rb
|
118
|
+
- test/widget_test.rb
|