Permalink
Browse files

fixed tests to work in both textmate and terminal

  • Loading branch information...
1 parent 3de5122 commit a893cbc1c36db576d7e7a508fff1d2a1a7a8224c Matthew Van Horn committed Dec 1, 2008
Showing with 80 additions and 83 deletions.
  1. +5 −3 disqus.gemspec
  2. +15 −10 lib/disqus/post.rb
  3. +2 −7 test/api_test.rb
  4. +2 −27 test/forum_test.rb
  5. +2 −2 test/merb_test.rb
  6. +18 −0 test/post_test.rb
  7. +4 −7 test/responses/get_thread_posts.json
  8. +26 −0 test/test_helper.rb
  9. +6 −27 test/thread_test.rb
View
@@ -24,10 +24,12 @@ Gem::Specification.new do |s|
"Rakefile",
]
s.test_files = [
- "test/widget_test.rb",
- "test/view_helpers_test.rb",
+
"test/api_test.rb",
- "test/forum_test.rb"
+ "test/forum_test.rb",
+ "test/thread_test.rb",
+ "test/view_helpers_test.rb",
+ "test/widget_test.rb",
]
s.rdoc_options = ["--main", "README.textile", "--inline-source", "--line-numbers"]
s.extra_rdoc_files = ["README.textile"]
View
@@ -3,14 +3,27 @@ module Disqus
class Post
attr_reader :id, :forum, :thread, :created_at, :message, :parent_post, :shown, :is_anonymous, :author
- def initialize
+ def initialize(id, forum, thread, created_at, message, parent_post, shown, is_anonymous, author)
@id, @forum, @thread, @created_at, @message, @parent_post, @shown, @is_anonymous, @author = id.to_i, forum, thread, created_at, message, parent_post, shown, is_anonymous, author
end
def self.list(thread, opts = {})
response = Disqus::Api::get_thread_posts(opts.merge(:thread_id =>thread.id, :forum_api_key => thread.forum.key))
if response["succeeded"]
posts = response["message"].map do |post|
+ author = nil
+ if post["is_anonymous"]
+ author = AnonymousAuthor.new( post["anonymous_author"]["name"],
+ post["anonymous_author"]["url"],
+ post["anonymous_author"]["email_hash"])
+ else
+ author = Author.new(post["author"]["id"].to_i,
+ post["author"]["username"],
+ post["author"]["display_name"],
+ post["author"]["url"],
+ post["author"]["email_hash"],
+ post["author"]["has_avatar"] )
+ end
Post.new( post["id"],
thread.forum,
thread,
@@ -19,15 +32,7 @@ def self.list(thread, opts = {})
post["parent_post"],
post["shown"],
post["is_anonymous"],
- post["is_anonymous"] ? AnonymousAuthor.new( post["anonymous_author"]["name"],
- post["anonymous_author"]["url"],
- post["anonymous_author"]["email_hash"]) :
- Author.new(post["author"]["id"].to_i,
- post["author"]["username"],
- post["author"]["display_name"],
- post["author"]["url"],
- post["author"]["email_hash"],
- post["author"]["has_avatar"] ) )
+ author )
end
end
end
View
@@ -1,14 +1,9 @@
-require 'test/unit'
-require 'yaml'
-require 'disqus'
-require 'disqus/api'
-require 'mocha'
-
-DISQUS_TEST = YAML.load(File.read(File.dirname(__FILE__) + "/config.yml"))
+require File.dirname(__FILE__) + '/test_helper'
class ApiTest < Test::Unit::TestCase
def setup
+ require 'disqus'
Disqus.defaults[:api_key] = DISQUS_TEST["api_key"]
end
View
@@ -1,16 +1,9 @@
-require 'test/unit'
-require 'yaml'
-require 'disqus'
-require 'disqus/api'
-require 'disqus/forum'
-require 'disqus/thread'
-require 'mocha'
-
-DISQUS_TEST = YAML.load(File.read(File.dirname(__FILE__) + "/config.yml"))
+require File.dirname(__FILE__) + '/test_helper'
class ForumTest < Test::Unit::TestCase
def setup
+ require 'disqus'
Disqus.defaults[:api_key] = DISQUS_TEST["api_key"]
end
@@ -56,23 +49,5 @@ def test_get_thread_by_identifier
assert_equal expected, thread
end
-
-
-
- private
-
- def create_forum
- Disqus::Forum.new(1234, "disqus-test", "Disqus Test", "2008-01-03 14:44:07.627492")
- end
-
- def create_thread
- Disqus::Thread.new("7651269", forum, "test_thread", "Test thread", "2008-11-28T01:47", true, "FAKE_URL", nil)
- end
-
- def mock_api_call(method_name)
- Disqus::Api.expects(method_name.to_sym).returns(JSON.parse(File.read(File.dirname(__FILE__) + "/responses/#{method_name}.json")))
- end
-
-
end
View
@@ -1,10 +1,10 @@
require 'test/unit'
-
+
module Merb
class Controller
end
end
-
+
class MerbTest < Test::Unit::TestCase
def test_view_helpers_should_be_included
View
@@ -0,0 +1,18 @@
+require File.dirname(__FILE__) + '/test_helper'
+
+class PostTest < Test::Unit::TestCase
+
+ def setup
+ require 'disqus'
+ Disqus.defaults[:api_key] = DISQUS_TEST["api_key"]
+ end
+
+ def test_post_list
+ mock_api_call(:get_thread_posts)
+ list = Disqus::Post.list(create_thread)
+ assert_equal 2, list.size
+ assert_equal list.first.message, "This is a mock post"
+ end
+
+
+end
@@ -24,14 +24,11 @@
"message": "This is another mock post",
"parent_post": null,
"shown": true,
- "is_anonymous": false,
- "author": {
+ "is_anonymous": true,
+ "anonymous_author": {
"id":12,
- "username":"testuser",
- "display_name":"Test User",
- "url":"http://www.example.com/testuser",
- "email_hash":"thisisanMD5hash",
- "has_avatar": true
+ "name":"Anonymous Coward",
+ "email_hash":"thisisanMD5hash"
}
}],
"code": "ok",
View
@@ -0,0 +1,26 @@
+require 'test/unit'
+require 'yaml'
+require 'disqus/api'
+require 'disqus/forum'
+require 'disqus/thread'
+require 'disqus/post'
+require 'disqus/author'
+require 'mocha'
+
+DISQUS_TEST = YAML.load(File.read(File.dirname(__FILE__) + "/config.yml"))
+
+def create_forum
+ Disqus::Forum.new(1234, "disqus-test", "Disqus Test", "2008-01-03 14:44:07.627492")
+end
+
+def create_thread
+ mock_forum = mock()
+ mock_forum.stubs(:key).returns("FAKE_KEY")
+ Disqus::Thread.new("7651269", mock_forum, "test_thread", "Test thread", "2008-11-28T01:47", true, "FAKE_URL", nil)
+end
+
+
+def mock_api_call(method_name)
+ Disqus::Api.expects(method_name.to_sym).returns(JSON.parse(File.read(File.dirname(__FILE__) + "/responses/#{method_name}.json")))
+end
+
View
@@ -1,16 +1,9 @@
-require 'test/unit'
-require 'yaml'
-require 'disqus'
-require 'disqus/api'
-require 'disqus/forum'
-require 'disqus/thread'
-require 'mocha'
-
-DISQUS_TEST = YAML.load(File.read(File.dirname(__FILE__) + "/config.yml"))
+require File.dirname(__FILE__) + '/test_helper'
class ThreadTest < Test::Unit::TestCase
def setup
+ require 'disqus'
Disqus.defaults[:api_key] = DISQUS_TEST["api_key"]
end
@@ -19,30 +12,16 @@ def test_thread_list
forum = create_forum
list = Disqus::Thread.list(forum)
assert_equal 1, list.size
- assert_equal list, [create_thread]
- end
-
- private
-
- def create_thread
- Disqus::Thread.new( 12345,
+ assert_equal list, [Disqus::Thread.new( 12345,
create_forum,
"this_is_a_thread",
"This is a thread",
"2008-01-03 14:44:07.627492",
true,
"http://www.example.com/testthread",
- "this_is_the_thread_identifier" )
- end
-
- def create_forum
- Disqus::Forum.new(1234, "disqus-test", "Disqus Test", "2008-01-03 14:44:07.627492")
+ "this_is_the_thread_identifier" )]
end
-
- def mock_api_call(method_name)
- Disqus::Api.expects(method_name.to_sym).returns(JSON.parse(File.read(File.dirname(__FILE__) + "/responses/#{method_name}.json")))
- end
-
-
+
end
+

0 comments on commit a893cbc

Please sign in to comment.