From efb9f511f426b9d6f3af63608e77f80c4b823fb0 Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 23 Jan 2013 15:52:38 +0100 Subject: added a small test for HostMetaPresenter and using links hash in xml view --- users/app/views/webfinger/host_meta.xml.erb | 10 ++++----- users/lib/webfinger/host_meta_presenter.rb | 22 +++++++++++-------- .../unit/webfinger/.user_presenter_test.rb.swp | Bin 12288 -> 0 bytes .../unit/webfinger/host_meta_presenter_test.rb | 24 +++++++++++++++++++++ 4 files changed, 42 insertions(+), 14 deletions(-) delete mode 100644 users/test/unit/webfinger/.user_presenter_test.rb.swp create mode 100644 users/test/unit/webfinger/host_meta_presenter_test.rb (limited to 'users') 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 @@ <%= @host_meta.subject %> - - - + <%- @host_meta.links.each do |rel, link| %> + + <%- end %> 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 Binary files a/users/test/unit/webfinger/.user_presenter_test.rb.swp and /dev/null 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 + + -- cgit v1.2.3