Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

renamed #http_transport to #transport_engine. also, you can now set t…

…his switch per-instance.
  • Loading branch information...
commit 58c5b08b5d32ba194d10a689ef247e2db3bd9bab 1 parent 27ab621
@apotonick authored
View
11 lib/roar/representer/feature/http_verbs.rb
@@ -8,13 +8,13 @@ module Feature
module HttpVerbs
class << self
- attr_accessor :http_transport
+ attr_accessor :transport_engine
def included(base)
base.extend ClassMethods
end
end
- self.http_transport = ::Roar::Representer::Transport::NetHTTP
+ self.transport_engine = ::Roar::Representer::Transport::NetHTTP
module ClassMethods
@@ -25,6 +25,11 @@ def get(*args)
end
+ attr_writer :transport_engine
+ def transport_engine
+ @transport_engine || HttpVerbs.transport_engine
+ end
+
# Serializes the object, POSTs it to +url+ with +format+, deserializes the returned document
# and updates properties accordingly.
def post(url, format)
@@ -64,7 +69,7 @@ def handle_response(response)
end
def http
- Roar::Representer::Feature::HttpVerbs.http_transport.new
+ transport_engine.new
end
end
end
View
43 test/http_verbs_feature_test.rb
@@ -23,35 +23,44 @@ class Band
@band.extend(Roar::Representer::Feature::HttpVerbs)
end
- describe "HttpVerbs.get" do
+ describe "transport_engine" do
before do
- # let's pretend the user wants Roar class methods.
- @Band = Class.new do
- include Roar::Representer::JSON
- include BandRepresenter
- include Roar::Representer::Feature::HttpVerbs
- attr_accessor :name, :label
- end
+ @http_verbs = Roar::Representer::Feature::HttpVerbs
+ @net_http = Roar::Representer::Transport::NetHTTP
end
-
+
+ it "has a default set in the transport module level" do
+ assert_equal @net_http, @band.transport_engine
+ end
+
+ it "allows changing on instance level" do
+ @band.transport_engine = :soap
+ assert_equal @net_http, @http_verbs.transport_engine
+ assert_equal :soap, @band.transport_engine
+ end
+ end
+
+
+ describe "HttpVerbs.get" do
it "returns instance from incoming representation" do
- @band = @Band.get("http://roar.example.com/bands/slayer", "application/json")
- assert_equal "Slayer", @band.name
- assert_equal "Canadian Maple", @band.label
+ band = @band.get("http://roar.example.com/bands/slayer", "application/json")
+ assert_equal "Slayer", band.name
+ assert_equal "Canadian Maple", band.label
end
+ # FIXME: move to faraday test.
describe 'a non-existent resource' do
it 'handles HTTP errors and raises a ResourceNotFound error with FaradayHttpTransport' do
- Roar::Representer::Feature::HttpVerbs.http_transport = Roar::Representer::Transport::Faraday
+ @band.transport_engine = Roar::Representer::Transport::Faraday
assert_raises(::Faraday::Error::ResourceNotFound) do
- @Band.get('http://roar.example.com/bands/anthrax', "application/json")
+ @band.get('http://roar.example.com/bands/anthrax', "application/json")
end
end
- it 'performs no HTTP error handling with BasicHttpTransport' do
- Roar::Representer::Feature::HttpVerbs.http_transport = Roar::Representer::Transport::NetHTTP
+ it 'performs no HTTP error handling with NetHttpTransport' do
+ @band.transport_engine = Roar::Representer::Transport::NetHTTP
assert_raises(JSON::ParserError) do
- @Band.get('http://roar.example.com/bands/anthrax', "application/json")
+ @band.get('http://roar.example.com/bands/anthrax', "application/json")
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.