summaryrefslogtreecommitdiff
path: root/users/lib
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-01-23 13:13:41 +0100
committerAzul <azul@leap.se>2013-01-23 13:13:41 +0100
commit30f406de954bac1da5fef7cdd753c0af16f11051 (patch)
treed22dab24afa09e3949d0babcaa2d773ee03c1827 /users/lib
parentb530279a144ad5fb35070952898c8e6ae3ba68ea (diff)
added unit tests for user presenter
changed the way the presenter works. Will need functional testing
Diffstat (limited to 'users/lib')
-rw-r--r--users/lib/webfinger/host_meta_presenter.rb2
-rw-r--r--users/lib/webfinger/user_presenter.rb36
2 files changed, 22 insertions, 16 deletions
diff --git a/users/lib/webfinger/host_meta_presenter.rb b/users/lib/webfinger/host_meta_presenter.rb
index b48729c..6a6235f 100644
--- a/users/lib/webfinger/host_meta_presenter.rb
+++ b/users/lib/webfinger/host_meta_presenter.rb
@@ -15,7 +15,7 @@ class Webfinger::HostMetaPresenter
"#{subject}/#{path}?#{query_param}={uri}"
end
- def to_json(options)
+ def to_json(options = {})
{
subject: subject,
links: {
diff --git a/users/lib/webfinger/user_presenter.rb b/users/lib/webfinger/user_presenter.rb
index 8288bff..41153a8 100644
--- a/users/lib/webfinger/user_presenter.rb
+++ b/users/lib/webfinger/user_presenter.rb
@@ -1,20 +1,26 @@
class Webfinger::UserPresenter
include Rails.application.routes.url_helpers
- attr_accessor :subject
+ attr_accessor :user
- def initialize(subject, request)
- @subject = subject
+ def initialize(user, request)
+ @user = user
@request = request
end
- def email_identifier
- "#{@subject.username}@#{@request.host}"
+ def to_json(options = {})
+ {
+ subject: subject,
+ aliases: aliases,
+ links: links
+ }.to_json(options)
end
- def key
- if @subject.public_key.present?
- Base64.encode64(@subject.public_key.to_s)
- end
+ def subject
+ "acct:#{@user.email_address}"
+ end
+
+ def aliases
+ [ user_url(@user, :host => @request.host) ]
end
def links
@@ -23,12 +29,12 @@ class Webfinger::UserPresenter
return links
end
- def to_json(options)
- {
- subject: "acct:#{email_identifier}",
- aliases: [ user_url(@subject, :host => @request.host) ],
- links: links
- }.to_json(options)
+ protected
+
+ def key
+ if @user.public_key.present?
+ Base64.encode64(@user.public_key.to_s)
+ end
end
end