norman-disqus 1.0.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.
data/tasks/rcov.rake ADDED
@@ -0,0 +1,23 @@
1
+ desc "Run RCov"
2
+ task :rcov do
3
+ run_coverage Dir["test/**/*_test.rb"]
4
+ end
5
+
6
+ def run_coverage(files)
7
+ rm_f "coverage"
8
+ rm_f "coverage.data"
9
+ if files.length == 0
10
+ puts "No files were specified for testing"
11
+ return
12
+ end
13
+ files = files.join(" ")
14
+ if PLATFORM =~ /darwin/
15
+ exclude = '--exclude "gems/"'
16
+ else
17
+ exclude = '--exclude "rubygems"'
18
+ end
19
+ rcov = "rcov -Ilib:test --sort coverage --text-report #{exclude} --no-validator-links"
20
+ cmd = "#{rcov} #{files}"
21
+ puts cmd
22
+ sh cmd
23
+ end
data/test/api_test.rb ADDED
@@ -0,0 +1,80 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ApiTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ require 'disqus'
7
+ Disqus.defaults[:api_key] = DISQUS_TEST["api_key"]
8
+ end
9
+
10
+ def test_create_post
11
+ mock_post_response('create_post.json')
12
+ the_post = Disqus::Api::create_post()
13
+ assert_equal "This is a mock post", the_post["message"]["message"]
14
+ end
15
+
16
+ def test_get_forum_list
17
+ mock_get_response('get_forum_list.json')
18
+ forum_list = Disqus::Api::get_forum_list
19
+ assert_equal "Disqus Test", forum_list["message"][0]["name"]
20
+ end
21
+
22
+ def test_get_forum_api_key
23
+ mock_get_response('get_forum_api_key.json')
24
+ forum_api_key = Disqus::Api::get_forum_api_key(:forum_id => 1234, :user_api_key=>"FAKE_KEY")
25
+ assert_equal "FAKE_FORUM_API_KEY", forum_api_key["message"]
26
+ end
27
+
28
+ def test_get_thread_list
29
+ mock_get_response('get_thread_list.json')
30
+ thread_list = Disqus::Api::get_thread_list(:forum_api_key=>"FAKE_KEY")
31
+ assert_equal "this_is_the_thread_identifier", thread_list["message"].first["identifier"]
32
+ end
33
+
34
+ def test_get_num_posts
35
+ mock_get_response('get_num_posts.json')
36
+ nums = Disqus::Api::get_num_posts(:thread_ids => [123,456], :forum_api_key=>"FAKE_KEY")
37
+ assert_equal [10,12], nums["message"][nums["message"].keys.first]
38
+ end
39
+
40
+ def test_get_thread_by_url
41
+ mock_get_response('get_thread_by_url.json')
42
+ thread = Disqus::Api::get_thread_by_url(:url => "FAKE_URL", :forum_api_key=>"FAKE_KEY")
43
+ assert_equal "test_thread", thread["message"]["slug"]
44
+ end
45
+
46
+ def test_get_thread_posts
47
+ mock_get_response('get_thread_posts.json')
48
+ thread_posts = Disqus::Api::get_thread_posts(:thread_id =>1234, :forum_api_key => "FAKE_KEY")
49
+ assert_equal "This is a mock post", thread_posts["message"].first["message"]
50
+ end
51
+
52
+ def test_thread_by_identifier
53
+ mock_post_response('thread_by_identifier.json')
54
+ thread = Disqus::Api::thread_by_identifier(:identifier =>'foo_bar', :title => "Foo Bar", :forum_api_key => "FAKE_KEY")
55
+ assert_equal "Test thread", thread["message"]["thread"]["title"]
56
+ end
57
+
58
+ def test_update_thread
59
+ mock_post_response('update_thread.json')
60
+ result = Disqus::Api::thread_by_identifier(:thread_id =>123, :title => "Foo Bar", :forum_api_key => "FAKE_KEY")
61
+ assert result["succeeded"]
62
+ end
63
+
64
+ def test_comment_form
65
+ c = Disqus::Api::comment_form("myforum", "mythread")
66
+ assert_match(/myforum/, c)
67
+ assert_match(/mythread/, c)
68
+ end
69
+
70
+ private
71
+
72
+ def mock_get_response(file)
73
+ Disqus::Api.expects(:get).returns(File.read(File.dirname(__FILE__) + "/responses/#{file}"))
74
+ end
75
+
76
+ def mock_post_response(file)
77
+ Disqus::Api.expects(:post).returns(File.read(File.dirname(__FILE__) + "/responses/#{file}"))
78
+ end
79
+
80
+ end
@@ -0,0 +1,3 @@
1
+ # This can be used to do actual calls to the API rather than use mocks during
2
+ # testing. This can be useful to verify tests against API changes.
3
+ api_key: 'YOUR DISQUS USER API KEY GOES HERE'
@@ -0,0 +1,70 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ForumTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ require 'disqus'
7
+ Disqus.defaults[:api_key] = DISQUS_TEST["api_key"]
8
+ stub_api_call(:get_forum_api_key).returns("FAKE_FORUM_API_KEY")
9
+ end
10
+
11
+ def test_forum_list
12
+ mock_api_call(:get_forum_list)
13
+ list = Disqus::Forum.list
14
+ expected = [create_forum]
15
+ assert_equal 1, list.size
16
+ assert_equal expected, list
17
+ end
18
+
19
+ def test_forum_find
20
+ mock_api_call(:get_forum_list)
21
+ forum = Disqus::Forum.find(1234)
22
+ assert_equal "disqus-test", forum.shortname
23
+ end
24
+
25
+ def test_forum_find_bad_id
26
+ mock_api_call(:get_forum_list)
27
+ forum = Disqus::Forum.find(666)
28
+ assert_equal nil, forum
29
+ end
30
+
31
+ def test_forum_find_no_forums
32
+ Disqus::Api.expects(:get_forum_list).returns({"succeeded"=>true, "code"=>"", "message" => []})
33
+ forum = Disqus::Forum.find(1234)
34
+ assert_equal nil, forum
35
+ end
36
+
37
+ def test_key
38
+ mock_api_call(:get_forum_api_key)
39
+ forum = Disqus::Forum.new(1234, "disqus-test", "Disqus Test", "2008-01-03 14:44:07.627492")
40
+ assert_equal "FAKE_FORUM_API_KEY", forum.key
41
+ end
42
+
43
+ def test_forum_threads
44
+ forum = create_forum
45
+ Disqus::Thread.expects(:list).with(forum).returns([thread = mock()])
46
+ assert_equal [thread], forum.forum_threads
47
+ end
48
+
49
+ def test_get_thread_by_url
50
+ mock_api_call(:get_thread_by_url)
51
+ forum = create_forum
52
+ thread = forum.get_thread_by_url("http://www.example.com")
53
+ expected = Disqus::Thread.new("7651269", forum, "test_thread", "Test thread", "2008-11-28T01:47", true, "FAKE_URL", nil)
54
+ assert_equal expected, thread
55
+ end
56
+
57
+ def test_thread_by_identifier
58
+ mock_api_call(:thread_by_identifier)
59
+ forum = create_forum
60
+ thread = forum.thread_by_identifier("FAKE_IDENTIFIER", "")
61
+ expected = Disqus::Thread.new("7651269", forum, "test_thread", "Test thread", "2008-11-28T01:47", true, "FAKE_URL", "FAKE_IDENTIFIER")
62
+ assert_equal expected, thread
63
+ end
64
+
65
+ def test_update_thread
66
+ 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})
67
+ forum = create_forum
68
+ forum.update_thread(1234, :title => 'Title', :slug => "a_slug", :url => "http://www.example.com", :allow_comments => true)
69
+ end
70
+ end
data/test/merb_test.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'test/unit'
2
+
3
+ module Merb
4
+ class Controller
5
+ end
6
+ end
7
+
8
+ class MerbTest < Test::Unit::TestCase
9
+
10
+ def test_view_helpers_should_be_included
11
+ require 'disqus'
12
+ assert Merb::Controller.new.disqus_thread
13
+ end
14
+
15
+ end
data/test/post_test.rb ADDED
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class PostTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ require 'disqus'
7
+ Disqus.defaults[:api_key] = DISQUS_TEST["api_key"]
8
+ end
9
+
10
+ def test_post_list
11
+ mock_api_call(:get_thread_posts)
12
+ list = Disqus::Post.list(create_thread)
13
+ assert_equal 2, list.size
14
+ assert_equal list.first.message, "This is a mock post"
15
+ end
16
+
17
+
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'test/unit'
2
+
3
+ class Rails
4
+ end
5
+
6
+ module ActionView
7
+ class Base
8
+ end
9
+ end
10
+
11
+ class RailsTest < Test::Unit::TestCase
12
+
13
+ def test_view_helpers_should_be_included
14
+ require 'disqus'
15
+ assert ActionView::Base.new.disqus_thread
16
+ end
17
+
18
+ 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,12 @@
1
+ {
2
+ "message": [
3
+ {
4
+ "created_at": "2008-01-03 14:44:07.627492",
5
+ "shortname": "disqus-test",
6
+ "id": "1234",
7
+ "name": "Disqus Test"
8
+ }
9
+ ],
10
+ "code": "ok",
11
+ "succeeded": true
12
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "message":{
3
+ "1001":[10,12],
4
+ "1002":[15,20],
5
+ "1003":[20,20],
6
+ "1004":[10,10],
7
+ "1005":[5,10]
8
+ },
9
+ "succeeded":true,
10
+ "code":"ok"
11
+ }
@@ -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
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "message":{},
3
+ "succeeded": true,
4
+ "code": "ok"
5
+ }
@@ -0,0 +1,32 @@
1
+ require 'test/unit'
2
+ require 'yaml'
3
+ require 'disqus/api'
4
+ require 'disqus/forum'
5
+ require 'disqus/thread'
6
+ require 'disqus/post'
7
+ require 'disqus/author'
8
+ require 'mocha'
9
+
10
+ DISQUS_TEST = YAML.load(File.read(File.dirname(__FILE__) + "/config.yml"))
11
+
12
+ def create_forum
13
+ forum = Disqus::Forum.new(1234, "disqus-test", "Disqus Test", "2008-01-03 14:44:07.627492")
14
+ forum.stubs(:key).returns("FAKE_FORUM_API_KEY")
15
+ forum
16
+ end
17
+
18
+ def create_thread
19
+ mock_forum = mock()
20
+ mock_forum.stubs(:key).returns("FAKE_FORUM_API_KEY")
21
+ Disqus::Thread.new("7651269", mock_forum, "test_thread", "Test thread", "2008-11-28T01:47", true, "FAKE_URL", nil)
22
+ end
23
+
24
+
25
+ def mock_api_call(method_name)
26
+ Disqus::Api.expects(method_name.to_sym).returns(JSON.parse(File.read(File.dirname(__FILE__) + "/responses/#{method_name}.json")))
27
+ end
28
+
29
+ def stub_api_call(method_name)
30
+ Disqus::Api.stubs(method_name.to_sym).returns(JSON.parse(File.read(File.dirname(__FILE__) + "/responses/#{method_name}.json")))
31
+ end
32
+
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ThreadTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ require 'disqus'
7
+ Disqus.defaults[:api_key] = DISQUS_TEST["api_key"]
8
+ stub_api_call(:get_forum_api_key)
9
+ end
10
+
11
+ def test_thread_list
12
+ mock_api_call(:get_thread_list)
13
+ forum = create_forum
14
+ list = Disqus::Thread.list(forum)
15
+ assert_equal 1, list.size
16
+ assert_equal list, [Disqus::Thread.new( 12345,
17
+ create_forum,
18
+ "this_is_a_thread",
19
+ "This is a thread",
20
+ "2008-01-03 14:44:07.627492",
21
+ true,
22
+ "http://www.example.com/testthread",
23
+ "this_is_the_thread_identifier" )]
24
+ end
25
+
26
+ end
27
+
28
+