powncer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mocha'
4
+ require 'redgreen'
5
+ require 'flexmock/test_unit'
6
+
7
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
8
+ require 'powncer'
9
+
10
+ Dir.glob(File.join(File.dirname(__FILE__), 'examples', '*_examples.rb')).each{|f| require f}
11
+
12
+ class Test::Unit::TestCase
13
+ TEST_LIVE = false
14
+ include Powncer
15
+
16
+ def teardown
17
+ Powncer.disconnect!
18
+ end
19
+
20
+ end
21
+
22
+ class String
23
+ def mock_connection(response)
24
+ Powncer::Connection.any_instance.stubs(:get).with(self).returns(response) unless Test::Unit::TestCase::TEST_LIVE
25
+ end
26
+
27
+ def mock_auth_connection(response)
28
+ Powncer::Authentication::Basic.any_instance.stubs(:get).with(self).returns(response) unless Test::Unit::TestCase::TEST_LIVE
29
+ end
30
+
31
+ def mock_post(response, params)
32
+ Powncer::Authentication::Basic.any_instance.stubs(:post).with(self, params).returns(response) unless Test::Unit::TestCase::TEST_LIVE
33
+ end
34
+ end
@@ -0,0 +1,21 @@
1
+ def test_chaining_recipients_on_note_find
2
+ note = example_note
3
+ "/notes/#{note[:id]}.json".mock_connection(example_public_note)
4
+ "/notes/#{note[:id]}/recipients.json".mock_connection(example_public_note_recipients)
5
+ @recipients = Note.find(note[:id]).recipients
6
+ assert_not_nil @recipients
7
+ assert_kind_of Array, @recipients
8
+ assert_equal 1, @recipients.length
9
+ assert_kind_of Powncer::User, @recipients.first
10
+ end
11
+
12
+ def test_public_note_recipients
13
+ note = example_note
14
+ "/notes/#{note[:id]}.json".mock_connection(example_public_note)
15
+ @note = Note.find(note[:id])
16
+ "/notes/#{@note.id}/recipients.json".mock_connection(example_public_note_recipients)
17
+ assert_not_nil @note.recipients
18
+ assert_kind_of Array, @note.recipients
19
+ assert_equal 1, @note.recipients.length
20
+ assert_kind_of Powncer::User, @note.recipients.first
21
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class AuthenticationTest < Test::Unit::TestCase
4
+
5
+ def test_authentication_basic_header
6
+ sig = Authentication::Basic::Header.new("powncertest", "powncertest")
7
+ assert_equal "Basic #{example_auth_sig}", sig
8
+ end
9
+
10
+ def test_authentication_connection
11
+ connection = Authentication::Basic.connect!
12
+ assert_equal 1, Powncer.connections.length
13
+ "/users/jaehess.json".mock_auth_connection(example_profile_for)
14
+ "/note_lists/jaehess.json?filter=public".mock_auth_connection(auth_example_notes_for)
15
+ j = User.find('jaehess')
16
+ assert_equal 20, j.notes.length
17
+ end
18
+
19
+ def test_clear_authentication_connections
20
+ connection = Authentication::Basic.connect!
21
+ assert_not_nil Powncer.connections
22
+ assert_equal 1, Powncer.connections.length
23
+ assert_not_nil Powncer.connections[0].options
24
+ Powncer.disconnect!
25
+ assert_equal [], Powncer.connections
26
+ end
27
+
28
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class BaseTest < Test::Unit::TestCase
4
+
5
+ def test_error_thrown
6
+ bad_url = '/note_lists/zzzzzzz.json?filter=public'
7
+ bad_url.mock_connection(example_error)
8
+ assert_raises Powncer::WebServiceError do
9
+ Base.request(bad_url)
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class ConnectionTest < Test::Unit::TestCase
4
+
5
+ def test_creating_a_connection
6
+ connection = Connection.new
7
+ assert_not_nil connection
8
+ assert_equal "http://api.pownce.com/2.0", connection.url
9
+ assert !connection.authenticated
10
+ end
11
+
12
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class EventTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ authorize
7
+ end
8
+
9
+ def test_no_requirements_throws_error
10
+ "/send/send_to.json".mock_auth_connection(auth_example_send_to_for)
11
+
12
+ assert_raises RequirementMissing do
13
+ Event.new
14
+ end
15
+ assert_nothing_raised do
16
+ Event.new(test_params)
17
+ end
18
+ end
19
+
20
+ def test_new_event_creation
21
+ event = Event.new(test_params.merge!({:to => :all}))
22
+ assert_equal test_params[:name], event.name
23
+ assert_equal :all, event.to
24
+ end
25
+
26
+ def test_event_create
27
+ "/send/send_to.json".mock_auth_connection(auth_example_send_to_for)
28
+ "/send/event.json".mock_post(example_post_event_response, test_params.merge!({:to => :public}))
29
+ event = Event.create(test_params)
30
+ assert_equal test_params[:name], event.name
31
+ assert_equal test_params[:location], event.location
32
+ assert_equal test_params[:date], event.date
33
+ assert_kind_of Powncer::Event, event
34
+ end
35
+
36
+ private
37
+
38
+ def authorize; Authentication::Basic.connect!; end
39
+
40
+ def test_params
41
+ {:name => "Foo", :location => "Bar", :date => "2008-01-16 21:00:00"}
42
+ end
43
+
44
+ end
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class LinkTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ authorize
7
+ end
8
+
9
+ def test_no_url_throws_error
10
+ "/send/send_to.json".mock_auth_connection(auth_example_send_to_for)
11
+
12
+ assert_raises RequirementMissing do
13
+ Link.new
14
+ end
15
+ assert_raises RequirementMissing do
16
+ Link.new({:url => "foo"})
17
+ end
18
+ assert_nothing_raised do
19
+ Link.new({:url => "http://test"})
20
+ end
21
+ end
22
+
23
+ def test_new_link_creation
24
+ lnk = Link.new(test_params.merge!({:to => :all}))
25
+ assert_equal test_params[:body], lnk.body
26
+ assert_equal test_params[:url], lnk.link
27
+ assert_equal :all, lnk.to
28
+ end
29
+
30
+ def test_link_create
31
+ "/users/powncertest.json".mock_auth_connection(example_profile_for_powncertest)
32
+ "/send/send_to.json".mock_auth_connection(auth_example_send_to_for)
33
+ "/send/link.json".mock_post(example_post_link_response, test_params.merge!({:to => "friend_171628"}))
34
+ lnk = Link.create(test_params)
35
+ assert_equal test_params[:body], lnk.body
36
+ assert_equal test_params[:url], lnk.link
37
+ assert_kind_of Powncer::Link, lnk
38
+ end
39
+
40
+ private
41
+
42
+ def authorize; Authentication::Basic.connect!; end
43
+
44
+ def test_params
45
+ {:url => "http://powncer.rubyforge.org", :body => "Foo", :to => "powncertest"}
46
+ end
47
+
48
+ end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class MediaTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ authorize
7
+ end
8
+
9
+ def test_new_file
10
+ file = Media.new({:to => "powncertest", :data => open(File.join(File.dirname(__FILE__), "1_1_TESTS")){|f| f.read}})
11
+ assert file.save
12
+ end
13
+
14
+ private
15
+
16
+ def authorize; Authentication::Basic.connect!; end
17
+
18
+ def test_params
19
+ {:name => "Foo", :location => "Bar", :date => "2008-01-16 21:00:00"}
20
+ end
21
+
22
+ end
@@ -0,0 +1,131 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ class NoteTest < Test::Unit::TestCase
3
+
4
+ def test_new_note_creation
5
+ note = Note.new({:body => "Foo", :to => :all})
6
+ assert_equal "Foo", note.body
7
+ assert_equal :all, note.to
8
+
9
+ authorize
10
+ "/send/send_to.json".mock_auth_connection(auth_example_send_to_for)
11
+ note = Note.new({:body => "Foo"})
12
+ assert_equal :public, note.to
13
+ end
14
+
15
+ def test_new_note_save_post
16
+ authorize
17
+ "/users/powncertest.json".mock_auth_connection(example_profile_for_powncertest)
18
+ "/users/davidbenedic.json".mock_auth_connection(example_profile_for_david)
19
+ "/send/send_to.json".mock_auth_connection(auth_example_send_to_for)
20
+ "/send/message.json".mock_post(example_post_note_response, {:body => "Foo", :to => "friend_171628"})
21
+ note = Note.new({:body => "Foo", :to => "powncertest"})
22
+ assert note.save
23
+ assert_equal "Foo", note.body
24
+ end
25
+
26
+ def test_note_create_to_public
27
+ authorize
28
+ "/users/powncertest.json".mock_auth_connection(example_profile_for_powncertest)
29
+ "/send/send_to.json".mock_auth_connection(auth_example_send_to_for)
30
+ "/send/message.json".mock_post(example_post_note_response, {:body => "Foo", :to => :public })
31
+ note = Note.create({:body => "Foo"})
32
+ assert_kind_of Powncer::Note, note
33
+ assert_equal "Foo", note.body
34
+ end
35
+
36
+ def test_note_throws_error_when_friends_are_invalid
37
+ authorize
38
+ "/users/leahculver.json".mock_auth_connection(example_profile_for_leah)
39
+ "/users/powncertest.json".mock_auth_connection(example_profile_for_powncertest)
40
+ "/send/send_to.json".mock_auth_connection(auth_example_send_to_for)
41
+ "/send/message.json".mock_post(example_post_note_response, {:body => "Foo", :to => "friend_171628"})
42
+ assert_raises Powncer::InvalidFriend do
43
+ Note.create({:body => "Foo", :to => "leahculver"})
44
+ end
45
+ assert_nothing_raised do
46
+ @note = Note.create({:body => "Foo", :to => "powncertest"})
47
+ end
48
+ end
49
+
50
+ def test_public_notes_list
51
+ '/note_lists.json'.mock_connection(example_public_notes)
52
+ @notes = Note.find(:public)
53
+ assert_not_nil @notes
54
+ assert_kind_of Array, @notes
55
+ assert_kind_of Powncer::Note, @notes.first
56
+ assert_equal 20, @notes.length
57
+ end
58
+
59
+ def test_public_notes_list_limit
60
+ limit = 50
61
+ "/note_lists.json?limit=#{limit}".mock_connection(example_public_notes(limit))
62
+ @notes = Note.find(:public, {:limit => limit})
63
+ assert_not_nil @notes
64
+ assert_equal limit, @notes.length
65
+ end
66
+
67
+ def test_public_notes_list_page
68
+ "/note_lists.json?page=1".mock_connection(example_public_notes(20, 1))
69
+ @notes = Note.find(:public, {:page => 1})
70
+ assert_not_nil @notes
71
+ assert_equal 20, @notes.length
72
+ end
73
+
74
+ def test_public_note_find
75
+ note = example_note
76
+ "/notes/#{note[:id]}.json".mock_connection(example_public_note_for)
77
+ @note = Note.find(note[:id])
78
+ assert_kind_of Powncer::Note, @note
79
+ assert_equal note[:body], @note.body
80
+ end
81
+
82
+ def test_public_note_sender_is_user
83
+ note = example_note
84
+ "/notes/#{note[:id]}.json".mock_connection(example_public_note_for)
85
+ @note = Note.find(note[:id])
86
+ assert_kind_of Powncer::User, @note.sender
87
+ end
88
+
89
+ def test_public_note_link_is_not_hash
90
+ "/users/jaehess.json".mock_connection(example_profile_for)
91
+ '/note_lists/jaehess.json?filter=public'.mock_connection(example_public_links_for)
92
+ user = User.find('jaehess')
93
+ assert_not_nil user
94
+ assert_not_nil user.notes
95
+ assert_equal "http://www.rubyforge.org/projects/powncer", user.notes.first.link
96
+ end
97
+
98
+ def test_chaining_notes_on_user_profile_find
99
+ "/users/jaehess.json".mock_connection(example_profile_for)
100
+ "/note_lists/jaehess.json?filter=public".mock_connection(example_public_notes_for)
101
+ @notes = User.find('jaehess').notes
102
+ assert_not_nil @notes
103
+ assert_kind_of Array, @notes
104
+ end
105
+
106
+ [:links, :messages, :events].each do |type|
107
+ class_eval(<<-EVAL, __FILE__, __LINE__)
108
+ def test_filter_public_#{type}
109
+ "/note_lists.json?type=#{type}".mock_connection(example_public_#{type})
110
+ #{type} = Note.find(:public, {:type => "#{type}"})
111
+ assert_not_nil #{type}
112
+ assert_kind_of Array, #{type}
113
+ assert_equal 20, #{type}.length
114
+ assert_kind_of Powncer::Note, #{type}.first
115
+ assert_equal "#{type}", #{type}.first.type + "s"
116
+ end
117
+ EVAL
118
+ end
119
+
120
+ private
121
+
122
+ def authorize; Authentication::Basic.connect!; end
123
+
124
+ def example_note
125
+ return {
126
+ :id => 1437687,
127
+ :body => "Powncer Ruby Gem released soon (with API 2.0 support)"
128
+ }
129
+ end
130
+
131
+ end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ class UserTest < Test::Unit::TestCase
3
+
4
+ def setup
5
+ @user = User.new('jaehess')
6
+ end
7
+
8
+ def test_user_has_profile_attributes
9
+ "/users/jaehess.json".mock_connection(example_profile_for)
10
+ profile = @user.profile
11
+ assert_equal "jaehess", profile.username
12
+ assert_equal false, profile.is_pro?
13
+ assert_equal 124992, profile.id
14
+ end
15
+
16
+ def test_user_friends_allocated_to_user_objects
17
+ "/users/jaehess/friends.json".mock_connection(example_friends_for)
18
+ assert_not_nil @user.friends
19
+ assert_kind_of Array, @user.friends
20
+ assert_kind_of Powncer::User, @user.friends[0]
21
+ end
22
+
23
+ def test_user_finder_and_load_profile
24
+ "/users/jaehess.json".mock_connection(example_profile_for)
25
+ user = User.find('jaehess')
26
+ assert_not_nil user
27
+ assert_equal "jaehess", user.username
28
+ assert_equal "Bloke", user.gender
29
+ end
30
+
31
+ def test_user_should_have_notes
32
+ '/note_lists/jaehess.json?filter=public'.mock_connection(example_public_notes_for)
33
+ assert_kind_of Array, @user.notes
34
+ assert_kind_of Powncer::Note, @user.notes.first
35
+ end
36
+
37
+ def test_user_has_send_to_list
38
+ Authentication::Basic.connect!
39
+ "/send/send_to.json".mock_auth_connection(auth_example_send_to_for)
40
+ assert_kind_of Hash, @user.send_to
41
+ assert_kind_of Hash, User.send_to
42
+ assert_equal @user.send_to, User.send_to
43
+ end
44
+
45
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: powncer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jae Hess
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-03-21 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description:
25
+ email: jae.hess@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - Rakefile
34
+ - lib/powncer/authentication.rb
35
+ - lib/powncer/base.rb
36
+ - lib/powncer/connection.rb
37
+ - lib/powncer/event.rb
38
+ - lib/powncer/ext.rb
39
+ - lib/powncer/link.rb
40
+ - lib/powncer/media.rb
41
+ - lib/powncer/note.rb
42
+ - lib/powncer/user.rb
43
+ - lib/powncer/version.rb
44
+ - lib/powncer.rb
45
+ has_rdoc: true
46
+ homepage: http://powncer.rubyforge.org
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project: powncer
67
+ rubygems_version: 1.0.1
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: Powncer is a Ruby library to the Pownce REST API
71
+ test_files:
72
+ - test/examples
73
+ - test/examples/authenticated_examples.rb
74
+ - test/examples/basic_examples.rb
75
+ - test/test_helper.rb
76
+ - test/unit
77
+ - test/unit/1_1_TESTS
78
+ - test/unit/authentication_test.rb
79
+ - test/unit/base_test.rb
80
+ - test/unit/connection_test.rb
81
+ - test/unit/event_test.rb
82
+ - test/unit/link_test.rb
83
+ - test/unit/media_test.rb
84
+ - test/unit/note_test.rb
85
+ - test/unit/user_test.rb