From fcd3b0363f4a1ecabeccd4b16e0191eee61044cd Mon Sep 17 00:00:00 2001 From: Patrick Reagan Date: Tue, 28 Dec 2010 21:34:43 -0700 Subject: [PATCH] Get include paths correct for Ruby 1.9 --- Rakefile | 2 +- .../fleakr/api/authentication_request_test.rb | 24 ++--- test/unit/fleakr/api/file_parameter_test.rb | 30 +++--- test/unit/fleakr/api/method_request_test.rb | 2 +- test/unit/fleakr/api/option_test.rb | 88 +++++++++--------- test/unit/fleakr/api/parameter_list_test.rb | 80 ++++++++-------- test/unit/fleakr/api/response_test.rb | 20 ++-- test/unit/fleakr/api/upload_request_test.rb | 56 +++++------ test/unit/fleakr/api/value_parameter_test.rb | 20 ++-- test/unit/fleakr/core_ext/false_class_test.rb | 10 +- test/unit/fleakr/core_ext/hash_test.rb | 18 ++-- test/unit/fleakr/core_ext/symbol_test.rb | 2 +- test/unit/fleakr/core_ext/true_class_test.rb | 10 +- .../objects/authentication_token_test.rb | 46 +++++----- test/unit/fleakr/objects/collection_test.rb | 42 ++++----- test/unit/fleakr/objects/comment_test.rb | 26 +++--- test/unit/fleakr/objects/contact_test.rb | 22 ++--- test/unit/fleakr/objects/error_test.rb | 16 ++-- test/unit/fleakr/objects/group_test.rb | 22 ++--- test/unit/fleakr/objects/image_test.rb | 6 +- .../objects/metadata_collection_test.rb | 2 +- test/unit/fleakr/objects/metadata_test.rb | 2 +- .../unit/fleakr/objects/photo_context_test.rb | 46 +++++----- test/unit/fleakr/objects/photo_test.rb | 2 +- test/unit/fleakr/objects/search_test.rb | 44 ++++----- test/unit/fleakr/objects/set_test.rb | 2 +- test/unit/fleakr/objects/tag_test.rb | 60 ++++++------ test/unit/fleakr/objects/url_test.rb | 92 +++++++++---------- test/unit/fleakr/objects/user_test.rb | 32 +++---- test/unit/fleakr/support/attribute_test.rb | 30 +++--- test/unit/fleakr/support/object_test.rb | 2 +- test/unit/fleakr/support/request_test.rb | 24 ++--- test/unit/fleakr_test.rb | 86 ++++++++--------- 33 files changed, 483 insertions(+), 483 deletions(-) diff --git a/Rakefile b/Rakefile index 7f6a5a8..b2d3278 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,7 @@ require 'rubygems' require 'rake/gempackagetask' require 'rake/testtask' -require 'lib/fleakr/version' +require File.expand_path('../lib/fleakr/version', __FILE__) spec = Gem::Specification.new do |s| s.name = 'fleakr' diff --git a/test/unit/fleakr/api/authentication_request_test.rb b/test/unit/fleakr/api/authentication_request_test.rb index 21500bb..01d18d7 100644 --- a/test/unit/fleakr/api/authentication_request_test.rb +++ b/test/unit/fleakr/api/authentication_request_test.rb @@ -1,37 +1,37 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Api class AuthenticationRequestTest < Test::Unit::TestCase - + context "An instance of AuthenticationRequest" do - + should "know the endpoint URL" do request = AuthenticationRequest.new request.endpoint_url.should == 'http://flickr.com/services/auth/' end - + should "be able to make a request" do endpoint_uri = stub() - + request = AuthenticationRequest.new request.stubs(:endpoint_uri).with().returns(endpoint_uri) - + Net::HTTP.expects(:get_response).with(endpoint_uri).returns('response') - + request.response.should == 'response' end - + should "know the authorization_url for the authentication request" do response_headers = {'Location' => 'http://example.com/auth'} response = stub() {|r| r.stubs(:header).with().returns(response_headers) } - + request = AuthenticationRequest.new request.stubs(:response).with().returns(response) - + request.authorization_url.should == 'http://example.com/auth' end - + end - + end end \ No newline at end of file diff --git a/test/unit/fleakr/api/file_parameter_test.rb b/test/unit/fleakr/api/file_parameter_test.rb index abd1d84..c8b3cd3 100644 --- a/test/unit/fleakr/api/file_parameter_test.rb +++ b/test/unit/fleakr/api/file_parameter_test.rb @@ -1,40 +1,40 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Api class FileParameterTest < Test::Unit::TestCase - + context "An instance of the FileParameter class" do - + setup do @temp_dir = File.expand_path(create_temp_directory) @filename = "#{@temp_dir}/image.jpg" end - + teardown do FileUtils.rm_rf(@temp_dir) end - + {'jpg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif'}.each do |ext, mime_type| should "know the correct MIME type for an extension of #{ext}" do parameter = FileParameter.new('photo', "#{@temp_dir}/image.#{ext}") parameter.mime_type.should == mime_type end end - + should "retrieve the contents of the file when accessing the value" do File.expects(:read).with(@filename).returns('bopbip') - + parameter = FileParameter.new('photo', @filename) parameter.value.should == 'bopbip' end - + should "cache the file contents after retrieving them" do File.expects(:read).with(@filename).once.returns('bopbip') - + parameter = FileParameter.new('photo', @filename) 2.times { parameter.value } end - + should "know how to generate a form representation of itself" do filename = 'image.jpg' mime_type = 'image/jpeg' @@ -42,17 +42,17 @@ class FileParameterTest < Test::Unit::TestCase parameter = FileParameter.new('photo', filename) parameter.stubs(:mime_type).with().returns(mime_type) parameter.stubs(:value).with().returns('data') - - expected = + + expected = "Content-Disposition: form-data; name=\"photo\"; filename=\"#{filename}\"\r\n" + "Content-Type: image/jpeg\r\n" + "\r\n" + "data\r\n" - + parameter.to_form.should == expected end - + end - + end end \ No newline at end of file diff --git a/test/unit/fleakr/api/method_request_test.rb b/test/unit/fleakr/api/method_request_test.rb index d7ed4f0..9d0003f 100644 --- a/test/unit/fleakr/api/method_request_test.rb +++ b/test/unit/fleakr/api/method_request_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Api class MethodRequestTest < Test::Unit::TestCase diff --git a/test/unit/fleakr/api/option_test.rb b/test/unit/fleakr/api/option_test.rb index f2e1e14..74d80ec 100644 --- a/test/unit/fleakr/api/option_test.rb +++ b/test/unit/fleakr/api/option_test.rb @@ -1,15 +1,15 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Api - + class OptionTest < Test::Unit::TestCase - + def self.should_know_the_class_for(type, options) should "know the class for the :#{type} type" do Option.class_for(type).should == options[:is] end end - + context "The Option class" do should_know_the_class_for :title, :is => Fleakr::Api::SimpleOption should_know_the_class_for :description, :is => Fleakr::Api::SimpleOption @@ -18,64 +18,64 @@ def self.should_know_the_class_for(type, options) should_know_the_class_for :level, :is => Fleakr::Api::LevelOption should_know_the_class_for :type, :is => Fleakr::Api::TypeOption should_know_the_class_for :hide?, :is => Fleakr::Api::HiddenOption - + should "be able to create an option for a type" do option = stub() - + Option.expects(:class_for).with(:title).returns(Fleakr::Api::SimpleOption) Fleakr::Api::SimpleOption.expects(:new).with(:title, 'blip').returns(option) - + Option.for(:title, 'blip').should == option end end - + end - + class SimpleOptionTest < Test::Unit::TestCase - + context "An instance of the SimpleOption class" do should "have a type" do so = SimpleOption.new(:title, 'blip') so.type.should == :title end - + should "have a value" do so = SimpleOption.new(:title, 'blip') so.value.should == 'blip' end - + should "be able to generate a hash representation of itself" do so = SimpleOption.new(:title, 'blip') so.to_hash.should == {:title => 'blip'} end end - + end class TagOptionTest < Test::Unit::TestCase - + context "An instance of the TagOption class" do - + should "normalize the input value to an array" do to = TagOption.new(:tags, 'blip') to.value.should == ['blip'] end - + should "be able to generate a hash representation of itself with tags joined on spaces" do to = TagOption.new(:tags, %w(bop bip)) to.to_hash.should == {:tags => '"bop" "bip"'} end - + should "quote tag values with spaces" do to = TagOption.new(:tags, ['tag', 'one with spaces']) to.to_hash.should == {:tags => '"tag" "one with spaces"'} end end - + end - + class ViewOptionTest < Test::Unit::TestCase - + context "An instance of the ViewOption class" do should "be able to generate a hash representation for viewing by :everyone" do vo = ViewOption.new(:viewable_by, :everyone) @@ -86,94 +86,94 @@ class ViewOptionTest < Test::Unit::TestCase vo = ViewOption.new(:viewable_by, :family) vo.to_hash.should == {:is_public => 0, :is_family => 1, :is_friend => 0} end - + should "be able to generate a hash representation for viewing by :friends" do vo = ViewOption.new(:viewable_by, :friends) vo.to_hash.should == {:is_public => 0, :is_family => 0, :is_friend => 1} end - + should "know the visibility is public if value is set to :everyone" do vo = ViewOption.new(:viewable_by, :everyone) vo.public?.should be(true) end - + should "know the visibility is not public if :everyone is not the only value" do vo = ViewOption.new(:viewable_by, [:everyone, :family]) vo.public?.should be(false) end - + should "know that its visible to friends and family if specified as such" do vo = ViewOption.new(:viewable_by, [:friends, :family]) vo.friends?.should be(true) vo.family?.should be(true) end - + end - + end class LevelOptionTest < Test::Unit::TestCase - + context "An instance of the LevelOption class" do - + should "be able to generate a hash representation for the :safe level" do lo = LevelOption.new(:level, :safe) lo.to_hash.should == {:safety_level => 1} end - + should "be able to generate a hash representation for the :moderate level" do lo = LevelOption.new(:level, :moderate) lo.to_hash.should == {:safety_level => 2} end - + should "be able to generate a hash representation for the :restricted level" do lo = LevelOption.new(:level, :restricted) lo.to_hash.should == {:safety_level => 3} end - + end - + end class TypeOptionTest < Test::Unit::TestCase - + context "An instance of the TypeOption class" do - + should "be able to generate a hash representation for the :photo type" do to = TypeOption.new(:type, :photo) to.to_hash.should == {:content_type => 1} end - + should "be able to generate a hash representation for the :screenshot type" do to = TypeOption.new(:type, :screenshot) to.to_hash.should == {:content_type => 2} end - + should "be able to generate a hash representation for the :other type" do to = TypeOption.new(:type, :other) to.to_hash.should == {:content_type => 3} end - + end - + end - + class HiddenOptionTest < Test::Unit::TestCase - + context "An instance of the HiddenOption class" do - + should "be able to generate a hash representation when set to true" do ho = HiddenOption.new(:hide?, true) ho.to_hash.should == {:hidden => 2} end - + should "be able to generate a hash representation when set to false" do ho = HiddenOption.new(:hide?, false) ho.to_hash.should == {:hidden => 1} end - + end - + end end \ No newline at end of file diff --git a/test/unit/fleakr/api/parameter_list_test.rb b/test/unit/fleakr/api/parameter_list_test.rb index 0990c2f..336f066 100644 --- a/test/unit/fleakr/api/parameter_list_test.rb +++ b/test/unit/fleakr/api/parameter_list_test.rb @@ -1,13 +1,13 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Api class ParameterListTest < Test::Unit::TestCase - + context "An instance of the ParameterList class with an available API key" do setup do @api_key_value = 'api_key_value' Fleakr.stubs(:api_key).with().returns(@api_key_value) - + @parameter_list = ParameterList.new end @@ -15,146 +15,146 @@ class ParameterListTest < Test::Unit::TestCase @parameter_list.stubs(:authentication_token).with().returns('toke') @parameter_list.send_authentication_token?.should be(true) end - + should "know not to send the authentication token" do pl = ParameterList.new({}, false) pl.stubs(:authentication_token).with().returns('toke') - + pl.send_authentication_token?.should be(false) end - + should "know not to send the authentication token if it's not available from the global value" do @parameter_list.stubs(:authentication_token).with().returns(nil) @parameter_list.send_authentication_token?.should be(false) end - + should "have a default list of options" do @parameter_list.default_options.should == {:api_key => @api_key_value} end - + should "use the authentication_token in the options if we're to authenticate" do @parameter_list.stubs(:send_authentication_token?).with().returns(true) @parameter_list.stubs(:authentication_token).with().returns('toke') @parameter_list.stubs(:default_options).with().returns({}) - + @parameter_list.options.should == {:auth_token => 'toke'} end - + should "add additional options from the constructor" do pl = ParameterList.new(:foo => 'bar') pl.options.should == {:foo => 'bar', :api_key => @api_key_value} end - + should "know that it doesn't need to sign the request by default" do @parameter_list.sign?.should be(false) end - + should "know that it needs to sign the request when a shared secret is available" do Fleakr.expects(:shared_secret).with().returns('secrit') @parameter_list.sign?.should be(true) end - + should "be able to add an option to the list" do @parameter_list.stubs(:default_options).with().returns({}) - + @parameter_list.add_option(:foo, 'bar') @parameter_list.options.should == {:foo => 'bar'} end - + should "have an empty list of upload options by default" do @parameter_list.upload_options.should == {} end - + should "be able to add an upload option to the list" do @parameter_list.add_upload_option(:file, '/path/to/foo') @parameter_list.upload_options.should == {:file => '/path/to/foo'} end - + should "be able to generate the list of parameters without a signature" do @parameter_list.stubs(:options).with().returns({:foo => 'bar', :api_sig => '1234'}) @parameter_list.options_without_signature.should == {:foo => 'bar'} end - + should "be able to calculate the signature of the parameters" do Fleakr.stubs(:shared_secret).with().returns('sekrit') - + options = {:api_key => @api_key_value, :foo => 'bar', :blip => 'zeeez'} @parameter_list.stubs(:options_without_signature).with().returns(options) @parameter_list.signature.should == Digest::MD5.hexdigest("sekritapi_key#{@api_key_value}blipzeeezfoobar") end - + should "be able to generate a list of options with a signature" do parameters = [ValueParameter.new('foo', 'bar')] - + @parameter_list.stubs(:options_without_signature).with().returns(:foo => 'bar') @parameter_list.stubs(:signature).with().returns('sig') - + @parameter_list.options_with_signature.should == {:foo => 'bar', :api_sig => 'sig'} end - + should "know the auth token when provided to the constructor" do pl = ParameterList.new(:auth_token => 'toke') pl.authentication_token.should == 'toke' end - + should "know the auth token when available as a global value" do Fleakr.stubs(:auth_token).with().returns('toke') - + pl = ParameterList.new pl.authentication_token.should == 'toke' end - + should "know that there is no authentication token if it is not available as a param or global value" do Fleakr.stubs(:auth_token).with().returns(nil) - + pl = ParameterList.new pl.authentication_token.should be_nil end should "be able to generate a boundary for post data" do rand = '0.123' - + @parameter_list.stubs(:rand).with().returns(stub(:to_s => rand)) @parameter_list.boundary.should == Digest::MD5.hexdigest(rand) end should "be able to generate a list of parameters without a signature" do parameter = stub() - + @parameter_list.stubs(:sign?).with().returns(false) @parameter_list.expects(:options_without_signature).with().returns(:foo => 'bar') ValueParameter.expects(:new).with(:foo, 'bar').returns(parameter) - + @parameter_list.list.should == [parameter] end - + should "be able to generate a list of parameters with a signature" do parameter = stub() - + @parameter_list.stubs(:sign?).with().returns(true) @parameter_list.expects(:options_with_signature).with().returns(:foo => 'bar') ValueParameter.expects(:new).with(:foo, 'bar').returns(parameter) - + @parameter_list.list.should == [parameter] end - + should "be able to generate a list of parameters with upload parameters if available" do value_parameter = stub() file_parameter = stub() - + @parameter_list.stubs(:sign?).with().returns(true) @parameter_list.expects(:options_with_signature).with().returns(:foo => 'bar') @parameter_list.expects(:upload_options).with().returns(:file => 'path') - + ValueParameter.expects(:new).with(:foo, 'bar').returns(value_parameter) FileParameter.expects(:new).with(:file, 'path').returns(file_parameter) - + @parameter_list.list.should == [value_parameter, file_parameter] end - + context "with associated parameters" do setup do @@ -177,7 +177,7 @@ class ParameterListTest < Test::Unit::TestCase should "be able to represent a form representation of itself" do @parameter_list.stubs(:boundary).returns('bound') - expected = + expected = "--bound\r\n" + "f1" + "--bound\r\n" + @@ -190,6 +190,6 @@ class ParameterListTest < Test::Unit::TestCase end end - + end end \ No newline at end of file diff --git a/test/unit/fleakr/api/response_test.rb b/test/unit/fleakr/api/response_test.rb index b7e0c7d..a5136b9 100644 --- a/test/unit/fleakr/api/response_test.rb +++ b/test/unit/fleakr/api/response_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Api class ResponseTest < Test::Unit::TestCase @@ -10,35 +10,35 @@ class ResponseTest < Test::Unit::TestCase hpricot_stub = stub() Hpricot.expects(:XML).with(response_xml).returns(hpricot_stub) - + response = Response.new(response_xml) response.body.should == hpricot_stub end - + should "memoize the Hpricot document" do response = Response.new('') - + Hpricot.expects(:XML).with(kind_of(String)).once.returns(stub()) - + 2.times { response.body } end - + should "know if there are errors in the response" do response_xml = "\n\n\t\n\n" response = Response.new(response_xml) - + response.error?.should be(true) end - + should "not have an error if there are no errors in the XML" do response = Response.new(read_fixture('people.findByUsername')) response.error.should be(nil) end - + should "have an error if there is an error in the response" do response_xml = "\n\n\t\n\n" response = Response.new(response_xml) - + response.error.code.should == '1' response.error.message.should == 'User not found' end diff --git a/test/unit/fleakr/api/upload_request_test.rb b/test/unit/fleakr/api/upload_request_test.rb index 5044739..581b9c4 100644 --- a/test/unit/fleakr/api/upload_request_test.rb +++ b/test/unit/fleakr/api/upload_request_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Api class UploadRequestTest < Test::Unit::TestCase @@ -7,32 +7,32 @@ class UploadRequestTest < Test::Unit::TestCase should "have a collection of upload_options" do request = UploadRequest.new('foo', :create, {:title => 'foo', :tags => %w(a b)}) - + option_1, option_2 = [stub(:to_hash => {:one => 'value_1'}), stub(:to_hash => {:two => 'value_2'})] - + Option.expects(:for).with(:title, 'foo').returns(option_1) Option.expects(:for).with(:tags, %w(a b)).returns(option_2) - + request.upload_options.should == {:one => 'value_1', :two => 'value_2'} end - + should "create a file parameter on initialization" do filename = '/path/to/image.jpg' - + parameter_list = mock() {|p| p.expects(:add_upload_option).with(:photo, filename) } UploadRequest.any_instance.stubs(:parameters).with().returns(parameter_list) - + UploadRequest.new(filename) end - + should "allow setting options on initialization" do option = stub() option.stubs(:to_hash).with().returns({:title => 'foo'}) - + Option.expects(:for).with(:title, 'foo').returns(option) - + ParameterList.expects(:new).with({:title => 'foo'}).returns(stub(:add_upload_option)) - + UploadRequest.new('filename', :create, {:title => 'foo'}) end @@ -44,7 +44,7 @@ class UploadRequestTest < Test::Unit::TestCase request = UploadRequest.new('file') request.type.should == :create end - + should "allow setting the type to :update" do request = UploadRequest.new('file', :update) request.type.should == :update @@ -54,16 +54,16 @@ class UploadRequestTest < Test::Unit::TestCase request = UploadRequest.new('filename') request.__send__(:endpoint_uri).should == URI.parse('http://api.flickr.com/services/upload/') end - + should "know the endpoint_uri for an :update request" do request = UploadRequest.new('filename', :update) request.__send__(:endpoint_uri).should == URI.parse('http://api.flickr.com/services/replace/') end - + should "only parse the endpoint URI once" do request = UploadRequest.new('filename') URI.expects(:parse).with(kind_of(String)).once.returns('uri') - + 2.times { request.__send__(:endpoint_uri) } end @@ -83,14 +83,14 @@ class UploadRequestTest < Test::Unit::TestCase should "be able to send a POST request to the API service" do request = UploadRequest.new('filename') - + uri = stub() uri.stubs(:host).with().returns('host') uri.stubs(:path).with().returns('path') uri.stubs(:port).with().returns(80) - + request.stubs(:endpoint_uri).with().returns(uri) - + request.stubs(:headers).with().returns('header' => 'value') request.parameters.stubs(:to_form).with().returns('form') @@ -98,39 +98,39 @@ class UploadRequestTest < Test::Unit::TestCase http.expects(:post).with('path', 'form', {'header' => 'value'}) Net::HTTP.expects(:start).with('host', 80).yields(http).returns(stub(:body)) - + request.send end - + should "get back a response from a POST operation" do response = stub() - + Net::HTTP.expects(:start).with(kind_of(String), kind_of(Fixnum)).returns(stub(:body => '')) Response.expects(:new).with('').returns(response) - + request = UploadRequest.new('filename') request.send.should == response end - + should "be able to make a full request and response cycle" do filename = 'filename' response = stub(:error? => false) - + UploadRequest.expects(:new).with(filename, :create, {}).returns(stub(:send => response)) UploadRequest.with_response!(filename).should == response end - + should "raise an exception when the full request / response cycle has errors" do filename = 'filename' response = stub(:error? => true, :error => stub(:code => '1', :message => 'User not found')) - + UploadRequest.expects(:new).with(filename, :create, {}).returns(stub(:send => response)) - + lambda do UploadRequest.with_response!(filename) end.should raise_error(Fleakr::ApiError) end - + end end diff --git a/test/unit/fleakr/api/value_parameter_test.rb b/test/unit/fleakr/api/value_parameter_test.rb index d9df8d7..e8dd3c4 100644 --- a/test/unit/fleakr/api/value_parameter_test.rb +++ b/test/unit/fleakr/api/value_parameter_test.rb @@ -1,41 +1,41 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Api class ValueParameterTest < Test::Unit::TestCase context "An instance of the ValueParameter class" do - + should "have a value" do parameter = ValueParameter.new('foo', 'bar') parameter.value.should == 'bar' end - + should "know how to generate the query representation of itself" do parameter = ValueParameter.new('foo', 'bar') parameter.to_query.should == 'foo=bar' end - + should "escape the value when generating the query representation" do parameter = ValueParameter.new('foo', 'Mr. Crystal?') parameter.to_query.should == 'foo=Mr.+Crystal%3F' end - + should "use an empty string when generating a query if the parameter value is nil" do parameter = ValueParameter.new('foo', nil) parameter.to_query.should == 'foo=' end - + should "know how to generate the form representation of itself" do parameter = ValueParameter.new('foo', 'bar') - expected = + expected = 'Content-Disposition: form-data; name="foo"' + "\r\n" + "\r\n" + "bar\r\n" - + parameter.to_form.should == expected end - + end - + end end \ No newline at end of file diff --git a/test/unit/fleakr/core_ext/false_class_test.rb b/test/unit/fleakr/core_ext/false_class_test.rb index bce4d8f..816c7df 100644 --- a/test/unit/fleakr/core_ext/false_class_test.rb +++ b/test/unit/fleakr/core_ext/false_class_test.rb @@ -1,13 +1,13 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) class FalseClassTest < Test::Unit::TestCase - + context "An instance of the FalseClass class" do - + should "have 0 as its integer value" do false.to_i.should == 0 end - + end - + end diff --git a/test/unit/fleakr/core_ext/hash_test.rb b/test/unit/fleakr/core_ext/hash_test.rb index 59e3616..25603fb 100644 --- a/test/unit/fleakr/core_ext/hash_test.rb +++ b/test/unit/fleakr/core_ext/hash_test.rb @@ -1,32 +1,32 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) class HashTest < Test::Unit::TestCase - + context "An instance of Hash" do context "when extracting key/value pairs" do - + setup do @hash = {:one => 'two', :three => 'four'} end - + should "return a hash with the matching key/value pairs" do @hash.extract!(:one).should == {:one => 'two'} end - + should "return an empty hash if the key isn't found" do @hash.extract!(:foo).should == {} end - + should "alter the original hash when a value is extracted" do @hash.extract!(:one) @hash.should == {:three => 'four'} end - + should "be able to extract multiple keys" do @hash.extract!(:one, :three, :missing).should == {:one => 'two', :three => 'four'} end - + end end - + end \ No newline at end of file diff --git a/test/unit/fleakr/core_ext/symbol_test.rb b/test/unit/fleakr/core_ext/symbol_test.rb index 286ad7d..852622c 100644 --- a/test/unit/fleakr/core_ext/symbol_test.rb +++ b/test/unit/fleakr/core_ext/symbol_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) class SymbolTest < Test::Unit::TestCase diff --git a/test/unit/fleakr/core_ext/true_class_test.rb b/test/unit/fleakr/core_ext/true_class_test.rb index cd301a2..9fb07b2 100644 --- a/test/unit/fleakr/core_ext/true_class_test.rb +++ b/test/unit/fleakr/core_ext/true_class_test.rb @@ -1,13 +1,13 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) class TrueClassTest < Test::Unit::TestCase - + context "An instance of the TrueClass class" do - + should "have 1 as its integer value" do true.to_i.should == 1 end - + end - + end diff --git a/test/unit/fleakr/objects/authentication_token_test.rb b/test/unit/fleakr/objects/authentication_token_test.rb index 47ae08d..a3b1ccf 100644 --- a/test/unit/fleakr/objects/authentication_token_test.rb +++ b/test/unit/fleakr/objects/authentication_token_test.rb @@ -1,70 +1,70 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Objects class AuthenticationTokenTest < Test::Unit::TestCase - + context "The AuthenticationToken class" do - + should "be able to create an instance from a mini_token" do token = '123-123-123' auth_token = stub() - + response = mock_request_cycle :for => 'auth.getFullToken', :with => {:mini_token => token, :authenticate? => false} - + AuthenticationToken.expects(:new).with(response.body).returns(auth_token) - + AuthenticationToken.from_mini_token(token).should == auth_token end - + should "be able to create an instance from an auth_token" do token = 'abc123' auth_token = stub() response = mock_request_cycle :for => 'auth.checkToken', :with => {:auth_token => token, :authenticate? => false} - + AuthenticationToken.expects(:new).with(response.body).returns(auth_token) AuthenticationToken.from_auth_token(token).should == auth_token end - - + + should "be able to create an instance from a frob" do frob = '12345678901234567-abcde89012fg3456-7890123' auth_token = stub() - + response = mock_request_cycle :for => 'auth.getToken', :with => {:frob => frob, :authenticate? => false} - + AuthenticationToken.expects(:new).with(response.body).returns(auth_token) AuthenticationToken.from_frob(frob).should == auth_token end - + end - + context "An instance of the AuthenticationToken class" do - + should "have an associated user" do token = AuthenticationToken.new token.stubs(:user_id).with().returns('1') - + User.expects(:find_by_id).with('1').returns('user') - + token.user.should == 'user' end - + context "when populating from an XML document" do - + setup do @object = AuthenticationToken.new(Hpricot.XML(read_fixture('auth.getFullToken'))) end - + should_have_a_value_for :value => 'abc-123' should_have_a_value_for :permissions => 'delete' should_have_a_value_for :user_id => '31066442@N69' should_have_a_value_for :full_name => 'Sir Froot Pants' should_have_a_value_for :user_name => 'frootpantz' - + end - + end - + end end \ No newline at end of file diff --git a/test/unit/fleakr/objects/collection_test.rb b/test/unit/fleakr/objects/collection_test.rb index efe68a0..cfc28a5 100644 --- a/test/unit/fleakr/objects/collection_test.rb +++ b/test/unit/fleakr/objects/collection_test.rb @@ -1,23 +1,23 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Objects class CollectionTest < Test::Unit::TestCase context "The Collection class" do - + should_find_one :collections, :by => :id, :call => 'collections.getInfo', :path => 'rsp/collection' should_find_all :collections, :by => :user_id, :call => 'collections.getTree', :path => 'rsp/collections/collection' - + end context "An instance of the Collection class" do - + context "when populating from a call to collections.getInfo" do setup do document = Hpricot.XML(read_fixture('collections.getInfo')).at('rsp/collection') @object = Collection.new(document) end - + should_have_a_value_for :id => '34762917-72157619347181335' should_have_a_value_for :title => 'Work' should_have_a_value_for :description => 'Sample Collection' @@ -26,46 +26,46 @@ class CollectionTest < Test::Unit::TestCase should_have_a_value_for :created => '1244460707' end - + context "when populating from a call to collections.getTree" do setup do document = Hpricot.XML(read_fixture('collections.getTree')).at('rsp/collections/collection') @object = Collection.new(document) end - + should_have_a_value_for :id => '123-456' should_have_a_value_for :title => 'Top-Level Collection 1' should_have_a_value_for :description => 'Description 1' should_have_a_value_for :large_icon_url => 'http://farm4.static.flickr.com/3573/cols/72157617429277370_1691956f71_l.jpg' should_have_a_value_for :small_icon_url => 'http://farm4.static.flickr.com/3573/cols/72157617429277370_1691956f71_s.jpg' - + end - + context "that contains collections" do setup do document = Hpricot.XML(read_fixture('collections.getTree')).at('rsp/collections/collection') @collection = Collection.new(document) end - + should "have a set of collections" do collection_titles = @collection.collections.map {|c| c.title } collection_titles.should == ['Second-Level Collection 1'] end - + should "not have any associated sets" do @collection.sets.should == [] end end - + context "that contains sets" do setup do xml = <<-XML - - - + + + XML - + document = Hpricot.XML(xml).at('collection') @collection = Collection.new(document) end @@ -73,25 +73,25 @@ class CollectionTest < Test::Unit::TestCase should "not have any associated collections" do @collection.collections.should == [] end - + should "have associated sets" do set_titles = @collection.sets.map {|s| s.title } set_titles.should == ['Set 5', 'Set 6'] end - + end - + context "in general" do setup do @collection = Collection.new @time = Time.parse('2008-08-01 00:00:00') end - + should "have a value for :created_at" do @collection.expects(:created).with().returns("#{@time.to_i}") @collection.created_at.to_s.should == @time.to_s end - + end end diff --git a/test/unit/fleakr/objects/comment_test.rb b/test/unit/fleakr/objects/comment_test.rb index 31ddf80..45b65d6 100644 --- a/test/unit/fleakr/objects/comment_test.rb +++ b/test/unit/fleakr/objects/comment_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Objects class CommentTest < Test::Unit::TestCase @@ -22,17 +22,17 @@ class CommentTest < Test::Unit::TestCase should_have_a_value_for :created => '1239217523' should_have_a_value_for :url => 'http://www.flickr.com/photos/frootpantz/3422268412/#comment72157616515348062' should_have_a_value_for :body => 'comment one' - + end - + context "in general" do - + setup { @comment = Comment.new } should "have a value for :created_at" do @comment.expects(:created).with().returns('1239217523') Time.expects(:at).with(1239217523).returns('time') - + @comment.created_at.should == 'time' end @@ -40,25 +40,25 @@ class CommentTest < Test::Unit::TestCase @comment.expects(:body).with().returns('bod') @comment.to_s.should == 'bod' end - + should "be able to find the author of the comment" do author = stub() - - + + @comment.stubs(:author_id).with().returns('1') User.expects(:find_by_id).with('1').returns(author) - + @comment.author.should == author end - + should "memoize the owner information" do @comment.stubs(:author_id).with().returns('1') - + User.expects(:find_by_id).with('1').once.returns(stub()) - + 2.times { @comment.author } end - + end end diff --git a/test/unit/fleakr/objects/contact_test.rb b/test/unit/fleakr/objects/contact_test.rb index 656db21..209ff92 100644 --- a/test/unit/fleakr/objects/contact_test.rb +++ b/test/unit/fleakr/objects/contact_test.rb @@ -1,10 +1,10 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Objects class ContactTest < Test::Unit::TestCase context "The Contact class" do - + should "return a list of users for a specified user's contacts" do user_1, user_2 = stub(), stub() @@ -19,7 +19,7 @@ class ContactTest < Test::Unit::TestCase Contact.find_all_by_user_id('1').should == [user_1, user_2] end - + should "return a list of users for an authenticated user" do response = mock_request_cycle :for => 'contacts.getList', :with => {} contact_1, contact_2 = [stub("contact"), stub('contact')] @@ -29,7 +29,7 @@ class ContactTest < Test::Unit::TestCase Contact.stubs(:new).with(contact_2_doc).returns(@contact_2) Contact.find_all.should == [@user_1, @user_2] end - + end context "An instance of the Contact class" do @@ -44,7 +44,7 @@ class ContactTest < Test::Unit::TestCase should_have_a_value_for :icon_farm => '3' end - + context "when populating from an XML document with authenticated user's contacts" do setup do @object = Contact.new(Hpricot.XML(read_fixture('contacts.getList')).at('contacts/contact')) @@ -61,24 +61,24 @@ class ContactTest < Test::Unit::TestCase context "in general" do - + should "be able to convert to a user" do contact = Contact.new user = mock() - + User.stubs(:new).returns(user) - + [:id, :username, :icon_server, :icon_farm, :name, :location].each do |method| contact.stubs(method).with().returns(method.to_s) user.expects("#{method}=".to_sym).with(method.to_s) end - + contact.to_user.should == user end - + end end - + end end \ No newline at end of file diff --git a/test/unit/fleakr/objects/error_test.rb b/test/unit/fleakr/objects/error_test.rb index 1b9d1c0..84e0c32 100644 --- a/test/unit/fleakr/objects/error_test.rb +++ b/test/unit/fleakr/objects/error_test.rb @@ -1,21 +1,21 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Objects class ErrorTest < Test::Unit::TestCase - + context "An instance of the Error class" do - + should "have a code and a message" do response_xml = "\n\n\t\n\n" - + error = Error.new(Hpricot.XML(response_xml)) - + error.code.should == '1' error.message.should == 'User not found' end - + end - - + + end end \ No newline at end of file diff --git a/test/unit/fleakr/objects/group_test.rb b/test/unit/fleakr/objects/group_test.rb index 5aadc88..4aa9dfd 100644 --- a/test/unit/fleakr/objects/group_test.rb +++ b/test/unit/fleakr/objects/group_test.rb @@ -1,30 +1,30 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Objects class GroupTest < Test::Unit::TestCase should_have_many :photos - + should_search_by :group_id context "The Group class" do - + should_find_all :groups, :by => :user_id, :call => 'people.getPublicGroups', :path => 'rsp/groups/group' - + end - + context "An instance of the Group class" do context "when initializing from an Hpricot document" do - + setup do doc = Hpricot.XML(read_fixture('people.getPublicGroups')).at('rsp/groups/group') @object = Group.new(doc) end - + should_have_a_value_for :id => '13378274@N00' should_have_a_value_for :name => 'Group #1' should_have_a_value_for :adult_flag => '1' - + end should "know that the group is adult-only" do @@ -32,15 +32,15 @@ class GroupTest < Test::Unit::TestCase group.stubs(:adult_flag).with().returns('1') group.adult?.should be(true) end - + should "know that the group is not adult-only" do group = Group.new group.stubs(:adult_flag).with().returns('0') group.adult?.should be(false) end - + end - + end end diff --git a/test/unit/fleakr/objects/image_test.rb b/test/unit/fleakr/objects/image_test.rb index e7fc297..1b4f8d6 100644 --- a/test/unit/fleakr/objects/image_test.rb +++ b/test/unit/fleakr/objects/image_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Objects class ImageTest < Test::Unit::TestCase @@ -45,7 +45,7 @@ class ImageTest < Test::Unit::TestCase @image = Image.new @image.stubs(:url).with().returns(@url) @image.stubs(:filename).with().returns(@image_filename) - + @image_data = 'image_data' Net::HTTP.expects(:get).with(URI.parse(@url)).returns(@image_data) end @@ -67,7 +67,7 @@ class ImageTest < Test::Unit::TestCase @image.save_to(existing_file) File.read(existing_file).should == @image_data end - + should "be able to save the file using a specified prefix" do @image.save_to(@tmp_dir, '001_') File.read("#{@tmp_dir}/001_image.jpg").should == @image_data diff --git a/test/unit/fleakr/objects/metadata_collection_test.rb b/test/unit/fleakr/objects/metadata_collection_test.rb index 71acfa7..b25a6e6 100644 --- a/test/unit/fleakr/objects/metadata_collection_test.rb +++ b/test/unit/fleakr/objects/metadata_collection_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Objects class MetadataCollectionTest < Test::Unit::TestCase diff --git a/test/unit/fleakr/objects/metadata_test.rb b/test/unit/fleakr/objects/metadata_test.rb index 78c6a35..03436ae 100644 --- a/test/unit/fleakr/objects/metadata_test.rb +++ b/test/unit/fleakr/objects/metadata_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Objects class MetadataTest < Test::Unit::TestCase diff --git a/test/unit/fleakr/objects/photo_context_test.rb b/test/unit/fleakr/objects/photo_context_test.rb index 5ad6cdf..626769b 100644 --- a/test/unit/fleakr/objects/photo_context_test.rb +++ b/test/unit/fleakr/objects/photo_context_test.rb @@ -1,80 +1,80 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Objects class PhotoContextTest < Test::Unit::TestCase - + context "An instance of the PhotoContext class" do - + setup { @context = PhotoContext.new } - + context "when populating from the photos_getContext XML data" do setup do @object = PhotoContext.new(Hpricot.XML(read_fixture('photos.getContext'))) end - + should_have_a_value_for :count => '5584' should_have_a_value_for :next_id => '12343' should_have_a_value_for :previous_id => '12345' end - + should "know that there is a previous photo" do @context.expects(:previous_id).with().returns('1') @context.previous?.should be(true) end - + should "know that there isn't a previous photo" do @context.expects(:previous_id).with().returns('0') @context.previous?.should be(false) end - + should "know that there is a next photo" do @context.expects(:next_id).with().returns('1') @context.next?.should be(true) end - + should "know that there isn't a next photo" do @context.expects(:next_id).with().returns('0') @context.next?.should be(false) end - + should "find the previous photo" do photo = stub() - + @context.expects(:previous_id).with().returns('1') @context.expects(:previous?).with().returns(true) - + Photo.expects(:find_by_id).with('1').returns(photo) - + @context.previous.should == photo end - + should "not try to find the previous photo if it doesn't exist" do @context.expects(:previous?).with().returns(false) Photo.expects(:find_by_id).never - + @context.previous.should be(nil) end - + should "find the next photo" do photo = stub() @context.expects(:next_id).with().returns('1') @context.expects(:next?).with().returns(true) - + Photo.expects(:find_by_id).with('1').returns(photo) - + @context.next.should == photo end - + should "not try to find the next photo if it doesn't exist" do @context.expects(:next?).with().returns(false) Photo.expects(:find_by_id).never - + @context.next.should be(nil) end - - + + end - + end end \ No newline at end of file diff --git a/test/unit/fleakr/objects/photo_test.rb b/test/unit/fleakr/objects/photo_test.rb index ee6be8b..b2b19c0 100644 --- a/test/unit/fleakr/objects/photo_test.rb +++ b/test/unit/fleakr/objects/photo_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Objects class PhotoTest < Test::Unit::TestCase diff --git a/test/unit/fleakr/objects/search_test.rb b/test/unit/fleakr/objects/search_test.rb index 49b2386..a3dd5ab 100644 --- a/test/unit/fleakr/objects/search_test.rb +++ b/test/unit/fleakr/objects/search_test.rb @@ -1,15 +1,15 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Objects class SearchTest < Test::Unit::TestCase - + context "An instance of the Search class" do should "have a list of tags" do search = Search.new(:tags => %w(a b c)) search.tags.should == %w(a b c) end - + should "have convert tags into an array" do search = Search.new(:tags => 'a') search.tags.should == ['a'] @@ -19,76 +19,76 @@ class SearchTest < Test::Unit::TestCase search = Search.new(:tags => 'foo') search.send(:tag_list).should == 'foo' end - + should "be able to generate a list of tags from multi-valued parameters" do search = Search.new(:tags => %w(foo bar)) search.send(:tag_list).should == 'foo,bar' end - + should "be able to create parameters for the search" do search = Search.new(:tags => %w(foo bar)) search.send(:parameters).should == {:tags => 'foo,bar'} end - + should "preserve the original :tags parameter if it is a comma-separated string" do search = Search.new(:tags => 'one,two') search.send(:parameters).should == {:tags => 'one,two'} end - + should "not have any :tags parameters if none are supplied" do search = Search.new({}) search.send(:parameters).should == {} end - + should "convert the search term into the appropriate parameter" do search = Search.new(:text => 'foo') search.send(:parameters).should == {:text => 'foo'} end - + should "convert a single string parameter into a text search" do search = Search.new('term') search.send(:parameters).should == {:text => 'term'} end - + should "be able to handle a combination of text and options" do search = Search.new('term', :tags => %w(a b)) search.send(:parameters).should == {:text => 'term', :tags => 'a,b'} end - + should "be able to search photos based on text" do response = mock_request_cycle :for => 'photos.search', :with => {:text => 'foo'} search = Search.new(:text => 'foo') search.results end - + should "be able to search photos based on tags" do response = mock_request_cycle :for => 'photos.search', :with => {:tags => 'one,two'} - + photo_1, photo_2 = [stub(), stub()] photo_1_doc, photo_2_doc = (response.body/'rsp/photos/photo').map {|doc| doc } - + Photo.expects(:new).with(photo_1_doc).returns(photo_1) Photo.expects(:new).with(photo_2_doc).returns(photo_2) - + search = Search.new(:tags => %w(one two)) search.results.should == [photo_1, photo_2] end - + should "memoize the search results" do response = stub(:body => Hpricot.XML(read_fixture('photos.search'))) Fleakr::Api::MethodRequest.expects(:with_response!).with(kind_of(String), kind_of(Hash)).once.returns(response) - + (response.body/'rsp/photos/photo').each do |doc| Photo.expects(:new).with(doc).once end - + search = Search.new(:tags => %w(foo)) - + 2.times { search.results } end - - + + end - + end end \ No newline at end of file diff --git a/test/unit/fleakr/objects/set_test.rb b/test/unit/fleakr/objects/set_test.rb index c497318..c6a2175 100644 --- a/test/unit/fleakr/objects/set_test.rb +++ b/test/unit/fleakr/objects/set_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Objects class SetTest < Test::Unit::TestCase diff --git a/test/unit/fleakr/objects/tag_test.rb b/test/unit/fleakr/objects/tag_test.rb index 5ed679d..2eab3ae 100644 --- a/test/unit/fleakr/objects/tag_test.rb +++ b/test/unit/fleakr/objects/tag_test.rb @@ -1,98 +1,98 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Objects class TagTest < Test::Unit::TestCase context "The Tag class" do - + should_find_all :tags, :by => :photo_id, :call => 'tags.getListPhoto', :path => 'rsp/photo/tags/tag' - should_find_all :tags, :by => :user_id, :call => 'tags.getListUser', :path => 'rsp/who/tags/tag' + should_find_all :tags, :by => :user_id, :call => 'tags.getListUser', :path => 'rsp/who/tags/tag' end - + context "An instance of the Tag class" do - + setup { @tag = Tag.new } - + context "when populating from the tags_getListPhoto XML data" do setup do @object = Tag.new(Hpricot.XML(read_fixture('tags.getListPhoto')).at('rsp/photo/tags/tag')) end - + should_have_a_value_for :id => '1' should_have_a_value_for :author_id => '15498419@N05' should_have_a_value_for :value => 'stu72' should_have_a_value_for :raw => 'stu 72' should_have_a_value_for :machine_flag => '0' - + end - + should "have an author" do user = stub() - + @tag.expects(:author_id).at_least_once.with().returns('1') - - + + User.expects(:find_by_id).with('1').returns(user) - + @tag.author.should == user end - + should "memoize the author data" do @tag.expects(:author_id).at_least_once.with().returns('1') - + User.expects(:find_by_id).with('1').once.returns(stub()) - + 2.times { @tag.author } end - + should "return nil for author if author_id is not present" do @tag.expects(:author_id).with().returns(nil) - + @tag.author.should be(nil) end - + should "have related tags" do @tag.expects(:value).with().returns('foo') - + response = mock_request_cycle :for => 'tags.getRelated', :with => {:tag => 'foo'} stubs = [] elements = (response.body/'rsp/tags/tag').map - + elements.each do |element| stub = stub() stubs << stub Tag.expects(:new).with(element).returns(stub) end - + @tag.related.should == stubs end - + should "memoize the data for related tags" do @tag.expects(:value).with().returns('foo') - + mock_request_cycle :for => 'tags.getRelated', :with => {:tag => 'foo'} - + 2.times { @tag.related } end - + should "be able to generate a string representation of itself" do @tag.expects(:value).with().returns('foo') @tag.to_s.should == 'foo' end - + should "know that it is not a machine tag" do @tag.expects(:machine_flag).with().returns('0') @tag.machine?.should be(false) end - + should "know that it is a machine tag" do @tag.expects(:machine_flag).with().returns('1') @tag.machine?.should be(true) end - + end - + end end \ No newline at end of file diff --git a/test/unit/fleakr/objects/url_test.rb b/test/unit/fleakr/objects/url_test.rb index 1c6d0f5..562b11f 100644 --- a/test/unit/fleakr/objects/url_test.rb +++ b/test/unit/fleakr/objects/url_test.rb @@ -1,171 +1,171 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Objects class UrlTest < Test::Unit::TestCase - + context "An instance of the Url class" do - + should "know the path" do u = Url.new('http://www.flickr.com/photos/reagent/4041660453/') u.path.should == '/photos/reagent/4041660453/' end - + should "know the path when there is no hostname" do u = Url.new('http://flickr.com/photos/reagent/4041660453/') u.path.should == '/photos/reagent/4041660453/' end - + should "know the path when using the shortened URL" do u = Url.new('http://flic.kr/p/7a9yQV') u.path.should == '/p/7a9yQV' end - + should "be able to retrieve a user" do u = Url.new('') u.stubs(:user_identifier).with().returns('reagent') - + User.expects(:find_by_identifier).with('reagent').returns('user') - + u.user.should == 'user' end - + should "memoize the user" do u = Url.new('') u.stubs(:user_identifier).with().returns('reagent') - + User.expects(:find_by_identifier).with('reagent').once.returns('user') - + 2.times { u.user } end - + context "when provided a single photo URL" do subject { Url.new('http://flickr.com/photos/reagent/4041660453/') } - + should "know that it's retrieving a photo resource" do subject.resource_type.should == Photo end - + should "know the :user_identifier" do subject.user_identifier.should == 'reagent' end - + should "know the :resource_identifier" do subject.resource_identifier.should == '4041660453' end - + should "know that it's not retrieving a collection of resources" do subject.collection?.should be(false) end - + should "return the resource" do Fleakr::Objects::Photo.expects(:find_by_id).with('4041660453').returns('photo') subject.resource.should == 'photo' end end - + context "when provided with a photoset URL" do subject { @subject ||= Url.new('http://www.flickr.com/photos/reagent/') } - + should "know that it's retrieving a Photo resource" do subject.resource_type.should == Photo end - + should "know the :user_identifier" do subject.user_identifier.should == 'reagent' end - + should "not have a :resource_identifier" do subject.resource_identifier.should be_nil end - + should "know that it's retrieving a collection of resources" do subject.collection?.should be(true) end - + should "return the resource" do subject.stubs(:user).with().returns(stub(:id => '1')) - + Fleakr::Objects::Photo.expects(:find_all_by_user_id).with('1').returns('photos') subject.resource.should == 'photos' end - + end - + context "when provided with a profile URL" do subject { @subject ||= Url.new('http://www.flickr.com/people/reagent/') } - + should "know that it's retrieving a user resource" do subject.resource_type.should == User end - + should "know the :user_identifier" do subject.user_identifier.should == 'reagent' end - + should "not have a :resource_identifier" do subject.resource_identifier.should be_nil end - + should "return the resource" do subject.expects(:user).with().returns('user') subject.resource.should == 'user' end end - + context "when provided a profile URL with a user ID" do subject { Url.new('http://www.flickr.com/people/43955217@N05/') } - + should "know the :user_identifier" do subject.user_identifier.should == '43955217@N05' end - + end - + context "when provided with a single set URL" do subject { Url.new('http://www.flickr.com/photos/reagent/sets/72157622660138146/') } - + should "know that it's retrieving a set resource" do subject.resource_type.should == Set end - + should "know the :user_identifier" do subject.user_identifier.should == 'reagent' end - + should "know the :resource_identifier" do subject.resource_identifier.should == '72157622660138146' end - + should "return the resource" do Fleakr::Objects::Set.expects(:find_by_id).with('72157622660138146').returns('set') subject.resource.should == 'set' end end - + context "when provided a set listing URL" do subject { @subject ||= Url.new('http://www.flickr.com/photos/reagent/sets/') } - + should "know that it's retrieving a set resource" do subject.resource_type.should == Set end - + should "know the :user_identifier" do subject.user_identifier.should == 'reagent' end - + should "not have a :resource_identifier" do subject.resource_identifier.should be_nil end - + should "return the resource" do subject.stubs(:user).with().returns(stub(:id => '1')) - + Fleakr::Objects::Set.expects(:find_all_by_user_id).with('1').returns('sets') subject.resource.should == 'sets' end end - + end - + end end diff --git a/test/unit/fleakr/objects/user_test.rb b/test/unit/fleakr/objects/user_test.rb index d6d85fa..32f077e 100644 --- a/test/unit/fleakr/objects/user_test.rb +++ b/test/unit/fleakr/objects/user_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Objects class UserTest < Test::Unit::TestCase @@ -6,7 +6,7 @@ class UserTest < Test::Unit::TestCase should_search_by :user_id should_have_many :photos, :groups, :sets, :contacts, :tags, :collections - + should_autoload_when_accessing :name, :photos_url, :profile_url, :photos_count, :location, :with => :load_info should_autoload_when_accessing :icon_server, :icon_farm, :pro, :admin, :icon_url, :with => :load_info @@ -20,22 +20,22 @@ class UserTest < Test::Unit::TestCase should "recognize a string as not being a Flickr user ID" do User.user_id?('reagent').should be(false) end - + should "recognize a string as being a Flickr user ID" do User.user_id?('43955217@N05').should be(true) end - + should "be able to find a user by ID when supplied with an identifier" do id = '43955217@N05' User.expects(:find_by_id).with(id).returns('user') - + User.find_by_identifier(id).should == 'user' end - + should "be able to find a user by username when supplied with an identifier" do username = 'reagent' User.expects(:find_by_username).with(username).returns('user') - + User.find_by_identifier(username).should == 'user' end @@ -59,18 +59,18 @@ class UserTest < Test::Unit::TestCase should_have_a_value_for :icon_farm => '1' should_have_a_value_for :pro => '1' should_have_a_value_for :admin => '0' - + end - + context "when populating an object from the urls.lookupUser API call" do setup do document = Hpricot.XML(read_fixture('urls.lookupUser')) @object = User.new(document) end - + should_have_a_value_for :id => '123456' should_have_a_value_for :username => 'frootpantz' - + end context "in general" do @@ -101,23 +101,23 @@ class UserTest < Test::Unit::TestCase @user.stubs(:icon_server).with().returns(nil) @user.icon_url.should == 'http://www.flickr.com/images/buddyicon.jpg' end - + should "return a boolean value for :pro?" do @user.stubs(:pro).with().returns('0') @user.pro?.should be(false) - + @user.stubs(:pro).with().returns('1') @user.pro?.should be(true) end - + should "return a boolean value for :admin?" do @user.stubs(:admin).with().returns('0') @user.admin?.should be(false) - + @user.stubs(:admin).with().returns('1') @user.admin?.should be(true) end - + end end diff --git a/test/unit/fleakr/support/attribute_test.rb b/test/unit/fleakr/support/attribute_test.rb index 7b21683..69a92ca 100644 --- a/test/unit/fleakr/support/attribute_test.rb +++ b/test/unit/fleakr/support/attribute_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) module Fleakr::Support class AttributeTest < Test::Unit::TestCase @@ -13,7 +13,7 @@ class AttributeTest < Test::Unit::TestCase attr = Attribute.new(:foo) attr.sources.should == ['foo'] end - + should "be able to assign multiple sources" do attr = Attribute.new(:foo, ['foo1', 'foo2']) attr.sources.should == ['foo1', 'foo2'] @@ -23,32 +23,32 @@ class AttributeTest < Test::Unit::TestCase attr = Attribute.new('foo') attr.location('foo').should == 'foo' end - + should "return the location when splitting" do attr = Attribute.new('foo') attr.split('foo').should == ['foo', nil] end - + should "return the name for the location when splitting if the location isn't specified" do attr = Attribute.new('foo') attr.split('@bar').should == ['foo', 'bar'] end - + should "allow the setting of the location information" do attr = Attribute.new('foo', 'bar') attr.sources.should == ['bar'] end - + should "allow the setting of the attribute value" do attr = Attribute.new('foo') attr.attribute('@bogon').should == 'bogon' end - + should "use the location as the attribute" do attr = Attribute.new('foo') attr.attribute('foo').should == 'foo' end - + should "use the attribute for the attribute if specified" do attr = Attribute.new(:id, '@nsid') attr.attribute('@nsid').should == 'nsid' @@ -57,15 +57,15 @@ class AttributeTest < Test::Unit::TestCase should "be able to retrieve the node from the path" do document = Hpricot.XML('Bassdrive') expected = document.at('name') - + attr = Attribute.new(:name) attr.node_for(document, 'name').should == expected end - + should "be able to retrieve the node that contains the specified attribute" do document = Hpricot.XML('') expected = document.at('user') - + attr = Attribute.new(:id) attr.node_for(document, '@id').should == expected end @@ -73,11 +73,11 @@ class AttributeTest < Test::Unit::TestCase should "be able to retrieve the node for the specified attribute" do document = Hpricot.XML('') expected = document.at('user') - + attr = Attribute.new(:id, '@nsid') attr.node_for(document, '@nsid').should == expected end - + should "be able to pull simple values from an XML document" do document = Hpricot.XML('Bassdrive') attr = Attribute.new(:name) @@ -89,7 +89,7 @@ class AttributeTest < Test::Unit::TestCase attr = Attribute.new(:id) attr.value_from(document).should == '1337' end - + should "be able to pull a specific attribute value from the current XML node" do document = Hpricot.XML('') attr = Attribute.new(:id, '@nsid') @@ -101,7 +101,7 @@ class AttributeTest < Test::Unit::TestCase attr = Attribute.new(:slug, 'station/genre@slug') attr.value_from(document).should == 'dnb' end - + should "be able to pull a value from a nested XML node" do document = Hpricot.XML('blip') attr = Attribute.new(:user) diff --git a/test/unit/fleakr/support/object_test.rb b/test/unit/fleakr/support/object_test.rb index 30f3e89..cb47630 100644 --- a/test/unit/fleakr/support/object_test.rb +++ b/test/unit/fleakr/support/object_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) class EmptyObject include Fleakr::Support::Object diff --git a/test/unit/fleakr/support/request_test.rb b/test/unit/fleakr/support/request_test.rb index 07c1f4e..03f538e 100644 --- a/test/unit/fleakr/support/request_test.rb +++ b/test/unit/fleakr/support/request_test.rb @@ -1,42 +1,42 @@ -require File.dirname(__FILE__) + '/../../../test_helper' +require File.expand_path('../../../../test_helper', __FILE__) class BasicRequest include Fleakr::Support::Request - + def endpoint_url 'http://example.com' end - + end module Fleakr class RequestTest < Test::Unit::TestCase - + context "An instance of the BasicRequest class with the Request mix-in" do - + should "have a collection of parameters" do params = {:perms => 'read'} Fleakr::Api::ParameterList.expects(:new).with(params, true).returns('params') - + request = BasicRequest.new(params) request.parameters.should == 'params' end - + should "know not to authenticate the request if asked not to" do Fleakr::Api::ParameterList.expects(:new).with({:perms => 'read'}, false).returns('params') - + request = BasicRequest.new(:perms => 'read', :authenticate? => false) request.parameters.should == 'params' end - + should "know the endpoint with full URL parameters" do request = BasicRequest.new request.parameters.stubs(:to_query).with().returns('query') - + request.endpoint_uri.to_s.should == 'http://example.com?query' end - + end - + end end diff --git a/test/unit/fleakr_test.rb b/test/unit/fleakr_test.rb index 38075e6..8690818 100644 --- a/test/unit/fleakr_test.rb +++ b/test/unit/fleakr_test.rb @@ -1,160 +1,160 @@ -require File.dirname(__FILE__) + '/../test_helper' +require File.expand_path('../../test_helper', __FILE__) class FleakrTest < Test::Unit::TestCase - + context "The Fleakr module" do - + [:api_key, :shared_secret, :auth_token].each do |attribute| should "be able to set a value for :#{attribute}" do value = 'value' - + Fleakr.send("#{attribute}=".to_sym, value) Fleakr.send(attribute).should == value end end - + should "provide a means to find a user by his username" do user = stub() Fleakr::Objects::User.expects(:find_by_username).with('username', {}).returns(user) Fleakr.user('username').should == user end - + should "fall back to finding a user by email if finding by username fails" do user = stub() email = 'user@host.com' - + Fleakr::Objects::User.stubs(:find_by_username).with(email, {}).raises(Fleakr::ApiError) Fleakr::Objects::User.expects(:find_by_email).with(email, {}).returns(user) - + Fleakr.user(email).should == user end - + should "fall back to finding a user by URL if username and email both fail" do user = stub() url = 'http://flickr.com/photos/user' - + Fleakr::Objects::User.stubs(:find_by_username).with(url, {}).raises(Fleakr::ApiError) Fleakr::Objects::User.stubs(:find_by_email).with(url, {}).raises(Fleakr::ApiError) Fleakr::Objects::User.expects(:find_by_url).with(url, {}).returns(user) - + Fleakr.user(url).should == user end should "not return nil if a user cannot be found" do data = 'data' - + Fleakr::Objects::User.stubs(:find_by_username).with(data, {}).raises(Fleakr::ApiError) Fleakr::Objects::User.stubs(:find_by_email).with(data, {}).raises(Fleakr::ApiError) Fleakr::Objects::User.stubs(:find_by_url).with(data, {}).raises(Fleakr::ApiError) - + Fleakr.user(data).should be_nil end - + should "provide additional options to the finder call if supplied" do user = stub() Fleakr::Objects::User.expects(:find_by_username).with('username', :auth_token => 'toke').returns(user) Fleakr.user('username', :auth_token => 'toke').should == user end - + should "find all contacts for the authenticated user" do Fleakr::Objects::Contact.expects(:find_all).with({}).returns('contacts') Fleakr.contacts.should == 'contacts' end - + should "allow filtering when finding contacts for the authenticated user" do Fleakr::Objects::Contact.expects(:find_all).with(:filter => :friends).returns('contacts') Fleakr.contacts(:friends).should == 'contacts' end - + should "allow passing of additional parameters when finding contacts for the authenticated user" do Fleakr::Objects::Contact.expects(:find_all).with(:filter => :friends, :page => 1).returns('contacts') Fleakr.contacts(:friends, :page => 1).should == 'contacts' end - + should "be able to perform text searches" do photos = [stub()] - + Fleakr::Objects::Search.expects(:new).with(:text => 'foo').returns(stub(:results => photos)) Fleakr.search('foo').should == photos end - + should "be able to perform searches based on tags" do Fleakr::Objects::Search.expects(:new).with(:tags => %w(one two)).returns(stub(:results => [])) Fleakr.search(:tags => %w(one two)) end - + # TODO: refactor uploading tests? should "be able to upload a collection of images" do glob = '*.jpg' filenames = %w(one.jpg two.jpg) - + Dir.expects(:[]).with(glob).returns(filenames) - + Fleakr::Objects::Photo.expects(:upload).with('one.jpg', {}) Fleakr::Objects::Photo.expects(:upload).with('two.jpg', {}) - + Fleakr.upload(glob) end - + should "return recently uploaded photos" do filename = '/path/to/image.jpg' new_image = stub() - + Dir.expects(:[]).with(filename).returns([filename]) Fleakr::Objects::Photo.expects(:upload).with(filename, {}).returns(new_image) - + Fleakr.upload(filename).should == [new_image] end - + should "be able to pass options for the uploaded files" do filename = '/path/to/image.jpg' new_image = stub() - + Dir.expects(:[]).with(filename).returns([filename]) Fleakr::Objects::Photo.expects(:upload).with(filename, :title => 'bop bip').returns(new_image) - + Fleakr.upload(filename, :title => 'bop bip').should == [new_image] end - + should "be able to generate the authorization_url with default permissions" do request = stub() {|r| r.stubs(:authorization_url).with().returns('auth_url') } Fleakr::Api::AuthenticationRequest.expects(:new).with(:perms => :read).returns(request) - + Fleakr.authorization_url.should == 'auth_url' end - + should "be able to specify different permissions when generating the authorization_url" do request = stub() {|r| r.stubs(:authorization_url).with().returns('auth_url') } Fleakr::Api::AuthenticationRequest.expects(:new).with(:perms => :delete).returns(request) - + Fleakr.authorization_url(:delete).should == 'auth_url' end - + should "be able to retrieve a token from the provided frob" do Fleakr::Objects::AuthenticationToken.expects(:from_frob).with('frob').returns('toke') Fleakr.token_from_frob('frob').should == 'toke' end - + should "be able to retrieve a token from the provided mini-token" do Fleakr::Objects::AuthenticationToken.expects(:from_mini_token).with('mini_token').returns('toke') Fleakr.token_from_mini_token('mini_token').should == 'toke' end - + should "be able to get the user for the provided auth token" do token = stub() {|t| t.stubs(:user).with().returns('user') } - + Fleakr::Objects::AuthenticationToken.expects(:from_auth_token).with('toke').returns(token) - + Fleakr.user_for_token('toke').should == 'user' end - + should "be able to find the correct resource for a URL" do url = stub() {|u| u.stubs(:resource).with().returns('resource') } Fleakr::Objects::Url.expects(:new).with('url').returns(url) - + Fleakr.resource_from_url('url').should == 'resource' end - + end - + end \ No newline at end of file