commit 92c4913a6cb82da1ae32af141c5ac024c8291e23 Author: Tarmo Tänav Date: Wed Jul 16 02:35:10 2008 +0300 Replaced tabs with spaces in indentation diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 4818ac7..63b9229 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -842,10 +842,10 @@ module ActiveResource # # => [...] def encode(options={}) case self.class.format - when ActiveResource::Formats[:xml] - self.class.format.encode(attributes, {:root => self.class.element_name}.merge(options)) - else - self.class.format.encode(attributes, options) + when ActiveResource::Formats[:xml] + self.class.format.encode(attributes, {:root => self.class.element_name}.merge(options)) + else + self.class.format.encode(attributes, options) end end diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index 13f923c..2a14118 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -146,7 +146,7 @@ module ActiveResource def request(method, path, *arguments) logger.info "#{method.to_s.upcase} #{site.scheme}://#{site.host}:#{site.port}#{path}" if logger result = nil - time = Benchmark.realtime { result = http.send(method, path, *arguments) } + time = Benchmark.realtime { result = http.send(method, path, *arguments) } logger.info "--> #{result.code} #{result.message} (#{result.body ? result.body.length : 0}b %.2fs)" % time if logger handle_response(result) rescue Timeout::Error => e @@ -206,7 +206,7 @@ module ActiveResource def authorization_header (@user || @password ? { 'Authorization' => 'Basic ' + ["#{@user}:#{ @password}"].pack('m').delete("\r\n") } : {}) end - + def http_format_header(http_method) {HTTP_FORMAT_HEADER_NAMES[http_method] => format.mime_type} end diff --git a/activeresource/lib/active_resource/custom_methods.rb b/activeresource/lib/active_resource/custom_methods.rb index a441ef1..e0b96c6 100644 --- a/activeresource/lib/active_resource/custom_methods.rb +++ b/activeresource/lib/active_resource/custom_methods.rb @@ -90,10 +90,10 @@ module ActiveResource end def post(method_name, options = {}, body = nil) - request_body = body.nil? ? encode : body - if new? + request_body = body.nil? ? encode : body + if new? connection.post(custom_method_new_element_url(method_name, options), request_body, self.class.headers) - else + else connection.post(custom_method_element_url(method_name, options), request_body, self.class.headers) end end diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb index 05b389e..b1047c7 100644 --- a/activeresource/lib/active_resource/http_mock.rb +++ b/activeresource/lib/active_resource/http_mock.rb @@ -151,7 +151,7 @@ module ActiveResource def ==(other_request) if !other_request.body.nil? and !body.nil? - other_request.hash_with_body == hash_with_body + other_request.hash_with_body == hash_with_body else other_request.hash == hash end diff --git a/activeresource/test/format_test.rb b/activeresource/test/format_test.rb index 6cc4102..c718ce5 100644 --- a/activeresource/test/format_test.rb +++ b/activeresource/test/format_test.rb @@ -12,11 +12,11 @@ class FormatTest < Test::Unit::TestCase def test_http_format_header_name header_name = ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[:get] assert_equal 'Accept', header_name - + headers_names = [ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[:put], ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[:post]] headers_names.each{|header_name| assert_equal 'Content-Type', header_name} end - + def test_formats_on_single_element for format in [ :json, :xml ] using_format(Person, format) do @@ -66,17 +66,17 @@ class FormatTest < Test::Unit::TestCase ryan = ActiveResource::Formats[format].encode({ :name => 'Ryan' }, {:root=>'person'}) post_format_header = {'Content-Type' => ActiveResource::Formats[format].mime_type} using_format(Person, format) do - remote_ryan = Person.new(:name => 'Ryan') - ActiveResource::HttpMock.respond_to.post "/people.#{format}", post_format_header, '', 201, {'Location' => "/people/5.#{format}"}, ryan - remote_ryan.save + remote_ryan = Person.new(:name => 'Ryan') + ActiveResource::HttpMock.respond_to.post "/people.#{format}", post_format_header, '', 201, {'Location' => "/people/5.#{format}"}, ryan + remote_ryan.save - remote_ryan = Person.new(:name => 'Ryan') - ActiveResource::HttpMock.respond_to.post "/people/new/register.#{format}", post_format_header, '', 201, {'Location' => "/people/5.#{format}"}, ryan - assert_equal ActiveResource::Response.new('', 201, {'Location' => "/people/5.#{format}"}), remote_ryan.post(:register) + remote_ryan = Person.new(:name => 'Ryan') + ActiveResource::HttpMock.respond_to.post "/people/new/register.#{format}", post_format_header, '', 201, {'Location' => "/people/5.#{format}"}, ryan + assert_equal ActiveResource::Response.new('', 201, {'Location' => "/people/5.#{format}"}), remote_ryan.post(:register) end end end - + def test_parse_errors error_bodies = {} error_bodies[:xml] = "Age can't be blankName can't be blankName must start with a letterPerson quota full for today." @@ -84,12 +84,12 @@ class FormatTest < Test::Unit::TestCase for format in [ :json, :xml ] post_format_header = {'Content-Type' => ActiveResource::Formats[format].mime_type} using_format(Person, format) do - person = Person.new(:name => '', :age => '') - ActiveResource::HttpMock.respond_to.post "/people.#{format}", post_format_header, error_bodies[format], 422 + person = Person.new(:name => '', :age => '') + ActiveResource::HttpMock.respond_to.post "/people.#{format}", post_format_header, error_bodies[format], 422 assert_equal person.save, false - assert !person.valid? - assert_kind_of ActiveResource::Errors, person.errors - assert_equal 4, person.errors.size + assert !person.valid? + assert_kind_of ActiveResource::Errors, person.errors + assert_equal 4, person.errors.size end end end