summaryrefslogtreecommitdiff
path: root/users
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-01-23 15:52:38 +0100
committerAzul <azul@leap.se>2013-01-23 16:17:51 +0100
commitefb9f511f426b9d6f3af63608e77f80c4b823fb0 (patch)
tree20329dfae6e6182ded56174c2bad21e114ae4583 /users
parent30f406de954bac1da5fef7cdd753c0af16f11051 (diff)
added a small test for HostMetaPresenter and using links hash in xml view
Diffstat (limited to 'users')
-rw-r--r--users/app/views/webfinger/host_meta.xml.erb10
-rw-r--r--users/lib/webfinger/host_meta_presenter.rb22
-rw-r--r--users/test/unit/webfinger/.user_presenter_test.rb.swpbin12288 -> 0 bytes
-rw-r--r--users/test/unit/webfinger/host_meta_presenter_test.rb24
4 files changed, 42 insertions, 14 deletions
diff --git a/users/app/views/webfinger/host_meta.xml.erb b/users/app/views/webfinger/host_meta.xml.erb
index 37c9d1e..cfcbcc0 100644
--- a/users/app/views/webfinger/host_meta.xml.erb
+++ b/users/app/views/webfinger/host_meta.xml.erb
@@ -3,9 +3,9 @@
<Subject><%= @host_meta.subject %></Subject>
-
- <Link rel='lrdd'
- type='application/xrd+xml'
- template='<%= @host_meta.webfinger_template %>' />
-
+ <%- @host_meta.links.each do |rel, link| %>
+ <Link rel='<%= rel %>'
+ type='<%= link[:type] %>'
+ template='<%= link[:template] %>' />
+ <%- end %>
</XRD>
diff --git a/users/lib/webfinger/host_meta_presenter.rb b/users/lib/webfinger/host_meta_presenter.rb
index 6a6235f..84ab7a9 100644
--- a/users/lib/webfinger/host_meta_presenter.rb
+++ b/users/lib/webfinger/host_meta_presenter.rb
@@ -5,22 +5,26 @@ class Webfinger::HostMetaPresenter
@request = request
end
+ def to_json(options = {})
+ {
+ subject: subject,
+ links: links
+ }.to_json(options)
+ end
+
def subject
url = URI.parse(@request.url)
url.path = ''
url.to_s
end
- def webfinger_template(path = 'webfinger', query_param='q')
- "#{subject}/#{path}?#{query_param}={uri}"
+ def links
+ { lrdd: { type: 'application/xrd+xml', template: webfinger_template } }
end
- def to_json(options = {})
- {
- subject: subject,
- links: {
- lrdd: { type: 'application/xrd+xml', template: webfinger_template }
- }
- }.to_json(options)
+ protected
+
+ def webfinger_template(path = 'webfinger', query_param='q')
+ "#{subject}/#{path}?#{query_param}={uri}"
end
end
diff --git a/users/test/unit/webfinger/.user_presenter_test.rb.swp b/users/test/unit/webfinger/.user_presenter_test.rb.swp
deleted file mode 100644
index 5b92867..0000000
--- a/users/test/unit/webfinger/.user_presenter_test.rb.swp
+++ /dev/null
Binary files differ
diff --git a/users/test/unit/webfinger/host_meta_presenter_test.rb b/users/test/unit/webfinger/host_meta_presenter_test.rb
new file mode 100644
index 0000000..af86404
--- /dev/null
+++ b/users/test/unit/webfinger/host_meta_presenter_test.rb
@@ -0,0 +1,24 @@
+require 'test_helper'
+require 'webfinger'
+require 'json'
+
+class Webfinger::HostMetaPresenterTest < ActiveSupport::TestCase
+
+ setup do
+ @request = stub(
+ url: "https://#{APP_CONFIG[:domain]}/.well-known/host-meta"
+ )
+ @meta = Webfinger::HostMetaPresenter.new(@request)
+ end
+
+ test "creates proper json" do
+ hash = JSON.parse @meta.to_json
+ assert_equal ["subject", "links"].sort, hash.keys.sort
+ hash.each do |key, value|
+ assert_equal @meta.send(key.to_sym).to_json, value.to_json
+ end
+ end
+
+end
+
+