Skip to content

Commit

Permalink
Client#follow applies expand_with variables to link if supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekelly committed Jan 26, 2013
1 parent db7cf6d commit 2027ab5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
7 changes: 5 additions & 2 deletions lib/hactor/http/client.rb
Expand Up @@ -13,10 +13,13 @@ def initialize(options={})
end

def follow(link, options = {})
actor = options[:actor] || Hactor::NullActor.new
context_url = options.fetch(:context_url)
actor = options[:actor] || Hactor::NullActor.new
variables = options[:expand_with]

href = variables ? link.expand_with(variables) : link.href
url = context_url.merge(href)

url = context_url.merge(link.href)
get(url: url, actor: actor)
end

Expand Down
24 changes: 20 additions & 4 deletions spec/hactor/http/client_spec.rb
Expand Up @@ -36,16 +36,32 @@
let(:context_url) { mock }
let(:resolved_uri) { stub }

it "should use the context url to resolve link href" do
before :each do
Delegator.class_eval { include RSpec::Mocks::Methods }
client.stub!(:get).with(url: resolved_uri, actor: actor)
link.should_receive(:href)
end

context "plain url (no expand_with in option)" do
it "should use the context url to resolve link href" do
link.should_receive(:href)
.and_return(uri)
context_url.should_receive(:merge)
context_url.should_receive(:merge)
.with(uri)
.and_return(resolved_uri)

client.follow(link, context_url: context_url, actor: actor)
client.follow(link, context_url: context_url, actor: actor)
end
end

context "URI template (expand_with in option)" do
it "should apply the variables to the template and follow resulting URI" do
variables = stub

link.should_receive(:expand_with).with(variables).and_return(uri)
context_url.should_receive(:merge).with(uri).and_return(resolved_uri)

client.follow(link, context_url: context_url, actor: actor, expand_with: variables)
end
end
end
end
Expand Down

0 comments on commit 2027ab5

Please sign in to comment.