This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
commit 6152a11a3a30570bc5f42a350d82976f37fc5664
tree 0f02e0161c96b4b5d90af716f35ce79df3ea336e
parent f78c0c9eaf7cd8b8ecee21782be1b13dd60d5865
tree 0f02e0161c96b4b5d90af716f35ce79df3ea336e
parent f78c0c9eaf7cd8b8ecee21782be1b13dd60d5865
| 7eb8c9e0 » | jnunemaker | 2007-10-06 | 1 | require File.dirname(__FILE__) + '/test_helper.rb' | |
| 2 | |||||
| 3 | class TestPost < Test::Unit::TestCase | ||||
| 4 | |||||
| 5 | def setup | ||||
| 6 | Mirrored::Base.establish_connection(:magnolia, 'jnunemaker', 'password') | ||||
| 7 | end | ||||
| 8 | |||||
| 9 | test 'should get posts' do | ||||
| 10 | data = open(File.join(File.dirname(__FILE__), 'fixtures/xml/posts.xml')).read | ||||
| 11 | FakeWeb.register_uri(URI.join(Mirrored::Base.api_url, 'posts/get'), :string => data) | ||||
| 12 | posts = Mirrored::Post.find(:get) | ||||
| 13 | assert_equal 3, posts.size | ||||
| 14 | first = posts.first | ||||
| 15 | assert_equal 'http://codersifu.blogspot.com/2007/10/restful-pdf-on-rails-20.html', first.href | ||||
| 16 | assert_equal 'CoderSifu: RESTful PDF on Rails 2.0', first.description | ||||
| 17 | assert_equal 'A nice simple example of responding to the pdf format using rails rest-fulness.', first.extended | ||||
| 18 | assert_equal '580485cf09ea39f3cb4a1182390a6dfb', first.hash | ||||
| 19 | assert_equal '1', first.others | ||||
| 20 | assert_equal ['ruby on rails', 'rest', 'pdf', 'plugins', 'railstips'], first.tags | ||||
| 21 | assert_equal Time.utc(2007, 10, 05, 14, 59, 02), first.time | ||||
| 22 | end | ||||
| 23 | |||||
| 24 | test 'should get posts by tag' do | ||||
| 25 | data = open(File.join(File.dirname(__FILE__), 'fixtures/xml/posts_by_tag.xml')).read | ||||
| 26 | FakeWeb.register_uri(URI.join(Mirrored::Base.api_url, 'posts/get?tag=ruby'), :string => data) | ||||
| 27 | posts = Mirrored::Post.find(:get, :tag => 'ruby') | ||||
| 28 | assert_equal 1, posts.size | ||||
| 29 | end | ||||
| 30 | |||||
| 31 | test 'should get posts by date' do | ||||
| 32 | data = open(File.join(File.dirname(__FILE__), 'fixtures/xml/posts_by_date.xml')).read | ||||
| 33 | FakeWeb.register_uri(URI.join(Mirrored::Base.api_url, 'posts/get?dt=2007-10-05'), :string => data) | ||||
| 34 | posts = Mirrored::Post.find(:get, :dt => '2007-10-05') | ||||
| 35 | assert_equal 2, posts.size | ||||
| 36 | end | ||||
| 37 | |||||
| 38 | test 'should get posts by url' do | ||||
| 39 | data = open(File.join(File.dirname(__FILE__), 'fixtures/xml/posts_by_url.xml')).read | ||||
| 40 | FakeWeb.register_uri(URI.join(Mirrored::Base.api_url, 'posts/get?url=http://www.railsontherun.com/2007/10/4/sexy-charts-in-less-than-5-minutes'), :string => data) | ||||
| 41 | posts = Mirrored::Post.find(:get, :url => 'http://www.railsontherun.com/2007/10/4/sexy-charts-in-less-than-5-minutes') | ||||
| 42 | assert_equal 1, posts.size | ||||
| 43 | end | ||||
| 44 | |||||
| 45 | test 'should filter by recent posts' do | ||||
| 46 | data = open(File.join(File.dirname(__FILE__), 'fixtures/xml/recent_posts.xml')).read | ||||
| 47 | FakeWeb.register_uri(URI.join(Mirrored::Base.api_url, 'posts/recent'), :string => data) | ||||
| 48 | posts = Mirrored::Post.find(:recent) | ||||
| 49 | assert_equal 15, posts.size | ||||
| 50 | end | ||||
| 51 | |||||
| 52 | test 'should filter recent posts by tag' do | ||||
| 53 | data = open(File.join(File.dirname(__FILE__), 'fixtures/xml/recent_posts_by_tag.xml')).read | ||||
| 54 | FakeWeb.register_uri(URI.join(Mirrored::Base.api_url, 'posts/recent?tag=ruby'), :string => data) | ||||
| 55 | posts = Mirrored::Post.find(:recent, :tag => 'ruby') | ||||
| 56 | assert_equal 15, posts.size | ||||
| 57 | end | ||||
| 58 | |||||
| 59 | test 'should filter recent posts by tag and count' do | ||||
| 60 | data = open(File.join(File.dirname(__FILE__), 'fixtures/xml/recent_posts_by_tag_and_count.xml')).read | ||||
| 61 | # TODO: make fake web realize that tag=ruby&count=5 is the same as count=5&tag=ruby | ||||
| 62 | FakeWeb.register_uri(URI.join(Mirrored::Base.api_url, 'posts/recent?tag=ruby&count=5'), :string => data) | ||||
| 63 | FakeWeb.register_uri(URI.join(Mirrored::Base.api_url, 'posts/recent?count=5&tag=ruby'), :string => data) | ||||
| 64 | posts = Mirrored::Post.find(:recent, :tag => 'ruby', :count => 5) | ||||
| 65 | assert_equal 5, posts.size | ||||
| 66 | end | ||||
| 67 | |||||
| 68 | test 'should get all posts' do | ||||
| 69 | data = open(File.join(File.dirname(__FILE__), 'fixtures/xml/all_posts.xml')).read | ||||
| 70 | FakeWeb.register_uri(URI.join(Mirrored::Base.api_url, 'posts/all'), :string => data) | ||||
| 71 | posts = Mirrored::Post.find(:all) | ||||
| 72 | assert_equal 2607, posts.size | ||||
| 73 | end | ||||
| 74 | |||||
| 75 | test 'should get all posts for tag' do | ||||
| 76 | data = open(File.join(File.dirname(__FILE__), 'fixtures/xml/all_posts_by_tag.xml')).read | ||||
| 77 | FakeWeb.register_uri(URI.join(Mirrored::Base.api_url, 'posts/all?tag=actionscript'), :string => data) | ||||
| 78 | posts = Mirrored::Post.find(:all, :tag => 'actionscript') | ||||
| 79 | assert_equal 24, posts.size | ||||
| 80 | end | ||||
| 81 | |||||
| 82 | test 'should be able to convert post to hash' do | ||||
| 83 | data = open(File.join(File.dirname(__FILE__), 'fixtures/xml/posts_by_url.xml')).read | ||||
| 84 | FakeWeb.register_uri(URI.join(Mirrored::Base.api_url, 'posts/get?url=http://www.railsontherun.com/2007/10/4/sexy-charts-in-less-than-5-minutes'), :string => data) | ||||
| 85 | posts = Mirrored::Post.find(:get, :url => 'http://www.railsontherun.com/2007/10/4/sexy-charts-in-less-than-5-minutes') | ||||
| 86 | post = posts.first | ||||
| 87 | post_hash = { | ||||
| 88 | :description => 'Easy charting with amcharts and ruby on rails.', | ||||
| 89 | :extended => 'Rails on the Run - Sexy charts in less than 5 minutes', | ||||
| 90 | :tags => 'charts ruby_on_rails railstips', | ||||
| 91 | :url => 'http://www.railsontherun.com/2007/10/4/sexy-charts-in-less-than-5-minutes', | ||||
| 92 | :share => 'yes' | ||||
| 93 | } | ||||
| 94 | assert_equal post_hash.keys.map { |k| k.to_s }.sort, post.to_h.keys.map { |k| k.to_s }.sort | ||||
| 95 | assert_equal post_hash.values.sort, post.to_h.values.sort | ||||
| 96 | end | ||||
| 97 | |||||
| 98 | # TODO: Figure out best way to test this. Fakeweb craps out because of hash keys not being ordered correctly in url. I don't feel like thinking about it now. | ||||
| 99 | # test 'should be able to add post' do | ||||
| 100 | # data = open(File.join(File.dirname(__FILE__), 'fixtures/xml/add_post_done.xml')).read | ||||
| 101 | # FakeWeb.register_uri(URI.join(Mirrored::Base.api_url, 'posts/add?'), :string => data) | ||||
| 102 | # p = Mirrored::Post.new | ||||
| 103 | # p.url = 'http://addictedtonew.com' | ||||
| 104 | # p.description = 'Addicted to New by John Nuneamker' | ||||
| 105 | # p.dt = Time.now.utc | ||||
| 106 | # p.extended = 'Really cool dude' | ||||
| 107 | # p.tags = %w(cool dude ruby) | ||||
| 108 | # p.save(false) | ||||
| 109 | # end | ||||
| 110 | |||||
| 111 | test 'should know if destroy succeeded' do | ||||
| 112 | data = open(File.join(File.dirname(__FILE__), 'fixtures/xml/delete_post.xml')).read | ||||
| 113 | FakeWeb.register_uri(URI.join(Mirrored::Base.api_url, 'posts/delete?url=http://www.railsontherun.com/2007/10/4/sexy-charts-in-less-than-5-minutes'), :string => data) | ||||
| 114 | assert Mirrored::Post.destroy('http://www.railsontherun.com/2007/10/4/sexy-charts-in-less-than-5-minutes') | ||||
| 115 | end | ||||
| 116 | |||||
| 117 | test 'should also know if aliased delete succeeded' do | ||||
| 118 | data = open(File.join(File.dirname(__FILE__), 'fixtures/xml/delete_post.xml')).read | ||||
| 119 | FakeWeb.register_uri(URI.join(Mirrored::Base.api_url, 'posts/delete?url=http://www.railsontherun.com/2007/10/4/sexy-charts-in-less-than-5-minutes'), :string => data) | ||||
| 120 | assert Mirrored::Post.delete('http://www.railsontherun.com/2007/10/4/sexy-charts-in-less-than-5-minutes') | ||||
| 121 | end | ||||
| 122 | |||||
| 123 | test 'should know if destroy failed' do | ||||
| 124 | data = open(File.join(File.dirname(__FILE__), 'fixtures/xml/delete_post_failed.xml')).read | ||||
| 125 | FakeWeb.register_uri(URI.join(Mirrored::Base.api_url, 'posts/delete?url=http://www.railsontherun.com/2007/10/4/sexy-charts-in-less-than-5-minutes'), :string => data) | ||||
| 126 | assert ! Mirrored::Post.destroy('http://www.railsontherun.com/2007/10/4/sexy-charts-in-less-than-5-minutes') | ||||
| 127 | end | ||||
| 128 | |||||
| 129 | test 'should also know if aliased delete failed' do | ||||
| 130 | data = open(File.join(File.dirname(__FILE__), 'fixtures/xml/delete_post_failed.xml')).read | ||||
| 131 | FakeWeb.register_uri(URI.join(Mirrored::Base.api_url, 'posts/delete?url=http://www.railsontherun.com/2007/10/4/sexy-charts-in-less-than-5-minutes'), :string => data) | ||||
| 132 | assert ! Mirrored::Post.delete('http://www.railsontherun.com/2007/10/4/sexy-charts-in-less-than-5-minutes') | ||||
| 133 | end | ||||
| 134 | |||||
| 135 | end | ||||








