Skip to content
Permalink
Browse files

Fixes Issue #536: ALPS microblogging API - only unauthenticated read …

…messages (statuses)
  • Loading branch information...
carols10cents committed Apr 28, 2012
1 parent 468e962 commit 4e234556c73426dc16526883661b3feb1e2f7d9f
@@ -1,5 +1,6 @@
class StaticController < ApplicationController
def homepage
@list_class = "all"
render :layout => false
end

@@ -4,14 +4,17 @@ class UpdatesController < ApplicationController

def index
@title = "updates"
@list_class = "all"
render_index(Update)
end

def timeline
@list_class = "friends"
render_index(current_user.timeline(params))
end

def replies
@list_class = "mentions"
render_index(current_user.at_replies(params))
end

@@ -29,6 +29,12 @@ def show
@updates = @user.updates
@updates = @updates.paginate(:page => params[:page], :per_page => params[:per_page])

if @user == current_user
@list_class = "me"
else
@list_class = "single-user"
end

set_pagination_buttons(@updates)

headers['Link'] = "<#{user_xrd_path(@user.author)}>; rel=\"lrdd\"; type=\"application/xrd+xml\""
@@ -6,7 +6,7 @@ class AuthorDecorator < ApplicationDecorator
def avatar
h.content_tag "div", :class => "avatar" do
h.link_to(
h.image_tag(avatar_src, :class => "photo", :alt => "avatar"),
h.image_tag(avatar_src, :class => "photo user-image", :alt => "avatar"),
author.url
)
end
@@ -8,5 +8,5 @@
%input#search-input{:name => "q", :type => "text", :value => params[:q]}
%input#search-button.button{:type => "submit", :value => "Search"}

= render :partial => "updates/list", :locals => {:updates => @updates, :tagline => "No statuses match your search."}
= render :partial => "updates/list", :locals => {:updates => @updates, :tagline => "No statuses match your search.", :list_class => "search"}

@@ -51,7 +51,7 @@
%p What people are talking about right now
#content
.updates
!= render :partial => "updates/list", :locals => {:updates => Update.hot_updates}
!= render :partial => "updates/list", :locals => {:updates => Update.hot_updates, :list_class => @list_class}
#bottom
.login
%a{:href => "/login"}
@@ -1,25 +1,28 @@
- reply ||= false
.update
.byline
= AuthorDecorator.decorate(update.author).avatar
%a{:href => "/users/#{update.author.username}"}
= update.author.username
.update-text
.content
!= update.to_html
.update-date
- if reply
%a.timeago{:href => "/updates/#{update.id}", :title => update.created_at.getutc.iso8601}
- else
%abbr.timeago{:title => update.created_at.getutc.iso8601}
#messages
%ul.single
%li.message
.update
.byline
= AuthorDecorator.decorate(update.author).avatar
%a{:href => "/users/#{update.author.username}"}
= update.author.username
.update-text
.content
!= update.to_html
.update-date
- if reply
%a.timeago{:href => "/updates/#{update.id}", :title => update.created_at.getutc.iso8601}
- else
%abbr.timeago{:title => update.created_at.getutc.iso8601}

.actions
-unless current_user.nil? or (current_user.author.id == update.author.id)
%a.share{:href => "/?share=#{update.id}"} share
|
%a.reply{:href => "/?reply=#{update.id}"} reply
.actions
-unless current_user.nil? or (current_user.author.id == update.author.id)
%a.share{:href => "/?share=#{update.id}"} share
|
%a.reply{:href => "/?reply=#{update.id}"} reply

- if current_user and update.author.id == current_user.author.id
= form_tag "/updates/#{update.id}" do
%input{:type => "hidden", :name => "_method", :value => "delete"}
= submit_tag "I Regret This", :class => "remove-update", :confirm => t(:remove_update, :scope => :confirms)
- if current_user and update.author.id == current_user.author.id
= form_tag "/updates/#{update.id}" do
%input{:type => "hidden", :name => "_method", :value => "delete"}
= submit_tag "I Regret This", :class => "remove-update", :confirm => t(:remove_update, :scope => :confirms)
@@ -1,47 +1,50 @@
- unless defined?(id)
- id = (request.path_info.gsub("/", "_")[1..-1])
#messages
%ul.updates{:class => "#{list_class}#{(controller.controller_name == "updates" ? " has-update-form" : "")}", :id => id}
- updates.each do |update|
- unless defined?(no_highlight) and no_highlight
- mine = current_user.nil? ? false : (update.author.user == current_user)
- mentioned = current_user.nil? ? false : update.mentioned?(current_user.username)
%li.update.hentry.message{:class => (mentioned ? "mention " : "") + (mine ? "mine " : ""), :id => "update-#{update.id}", "data-id" => update.id, "data-name" => update.author.username}
.author.vcard
%a.url{:href => update.author.url, :rel => "user"}
= AuthorDecorator.decorate(update.author).avatar
%span.fn
%a.url{:href => update.author.url}
= update.author.display_name
(<span class="nickname user-text">#{update.author.username}</span>)
.entry-content
%span.message-text
!= update.to_html

%ul.updates{:class => (controller.controller_name == "updates" ? "has-update-form" : ""), :id => id}
- updates.each do |update|
- unless defined?(no_highlight) and no_highlight
- mine = current_user.nil? ? false : (update.author.user == current_user)
- mentioned = current_user.nil? ? false : update.mentioned?(current_user.username)
%li.update.hentry{:class => (mentioned ? "mention " : "") + (mine ? "mine " : ""), :id => "update-#{update.id}", "data-id" => update.id, "data-name" => update.author.username}
.author.vcard
%a.url{:href => update.author.url}
= AuthorDecorator.decorate(update.author).avatar
%span.fn
%a.url{:href => update.author.url}
= update.author.display_name
(<span class="nickname">#{update.author.username}</span>)
.entry-content
!= update.to_html
.info
%time.published{:pubdate => "pubdate", :datetime => update.created_at.iso8601}
%a.timeago{:href => update.url, :rel => "bookmark message", :title => update.created_at.getutc.iso8601}
%span.date-time
= update.created_at.strftime("%FT%T")

.info
%time.published{:pubdate => "pubdate", :datetime => update.created_at.iso8601}
%a.timeago{:href => update.url, :rel => "bookmark", :title => update.created_at.getutc.iso8601}
- if !update.referral.nil?
%span.in-reply
%a{:href => "/updates/#{update.referral.id}"}
in reply to
%span.name= update.referral.author.username
- elsif !update.referral_url.nil?
%span.in-reply
%a{:href => update.referral_url}
in reply to

- if !update.referral.nil?
%span.in-reply
%a{:href => "/updates/#{update.referral.id}"}
in reply to
%span.name= update.referral.author.username
- elsif !update.referral_url.nil?
%span.in-reply
%a{:href => update.referral_url}
in reply to
.actions
-# when @timeline is true, this is a list on the user's page
-unless current_user.nil? or (current_user.author.id == update.author.id)
%a.share{:href => (controller.controller_name == "updates" ? "" : "/") + "?share=#{update.id}"} share
|
%a.reply{:href => (controller.controller_name == "updates" ? "" : "/") + "?reply=#{update.id}"} reply

.actions
-# when @timeline is true, this is a list on the user's page
-unless current_user.nil? or (current_user.author.id == update.author.id)
%a.share{:href => (controller.controller_name == "updates" ? "" : "/") + "?share=#{update.id}"} share
|
%a.reply{:href => (controller.controller_name == "updates" ? "" : "/") + "?reply=#{update.id}"} reply

- if current_user and update.author.id == current_user.author.id
= form_tag "/updates/#{update.id}" do
%input{:type => "hidden", :name => "_method", :value => "delete"}
= submit_tag "I Regret This", :class => "remove-update", :confirm => t(:remove_update, :scope => :confirms)
- if current_user and update.author.id == current_user.author.id
= form_tag "/updates/#{update.id}" do
%input{:type => "hidden", :name => "_method", :value => "delete"}
= submit_tag "I Regret This", :class => "remove-update", :confirm => t(:remove_update, :scope => :confirms)

!= render :partial => "shared/pagination"

@@ -8,4 +8,4 @@
#updates-menu-background
!= render :partial => "shared/menu/updates"

!= render :partial => "updates/list", :locals => {:updates => @updates}
!= render :partial => "updates/list", :locals => {:updates => @updates, :list_class => @list_class}
@@ -50,4 +50,4 @@
%a{ :href => "/users/#{@author.username}/followers"}= @author.user.followers.length
Followers

= render :partial => "updates/list", :locals => {:updates => @updates, :id => "profile_updates", :no_highlight => true}
= render :partial => "updates/list", :locals => {:updates => @updates, :id => "profile_updates", :no_highlight => true, :list_class => @list_class}
@@ -0,0 +1,122 @@
require 'require_relative' if RUBY_VERSION[0,3] == '1.8'
require_relative 'acceptance_helper'

# This file tests our compatibility with the ALPS microblogging profile
# defined at http://amundsen.com/hypermedia/profiles/

describe "ALPS microblogging spec" do
include AcceptanceHelper

describe "messages" do
describe "ALPS all, rstat.us homepage (logged out /)" do
it "has an individual status in an li with class message" do
@u2 = Fabricate(:user)
@update = Fabricate(:update)
@u2.feed.updates << @update

visit "/"

within "div#messages ul.all li.message" do
assert has_content? @update.text
end
end
end

describe "ALPS all, rstat.us world (/updates)" do
it "has an individual status in an li with class message" do
@u2 = Fabricate(:user)
@update = Fabricate(:update)
@u2.feed.updates << @update

visit "/updates"

within "div#messages ul.all li.message" do
assert has_content? @update.text
end
end
end

describe "Unspecified in ALPS: a user's profile other than currently logged in user ('not me')" do
# Addition not specified in official ALPS spec!!!
it "has a user's updates in a ul with class single-user" do
@u2 = Fabricate(:user)
@update = Fabricate(:update, :author => @u2.author)
@u2.feed.updates << @update

visit "/users/#{@u2.username}"

within "div#messages ul.single-user li.message" do
assert has_content? @update.text
end
end
end

describe "ALPS single, rstat.us update show" do
it "shows the status in a ul with class single" do
update = Fabricate(:update)

visit "/updates/#{update.id}"

within "div#messages ul.single li.message" do
assert has_content? update.text
end
end
end

describe "ALPS li.message descendants" do
before do
@a_user = Fabricate(:user)
@an_update = Fabricate(:update, :author => @a_user.author)
@a_user.feed.updates << @an_update

visit "/"
end

it "has the user nickname in span.user-text" do
within "li.message span.user-text" do
assert has_content? @a_user.username
end
end

it "has a link to the user's profile page in a.rel=user" do
within "li.message" do
assert has_selector?(
:xpath,
".//a[contains(@rel, 'user') and @href='#{@a_user.url}']"
)
end
end

it "has the text of the status in span.message-text" do
within "li.message span.message-text" do
assert has_content? @an_update.text
end
end

it "has the permalink to the update in a.rel=message" do
within "li.message" do
assert has_selector?(
:xpath,
"//a[contains(@rel, 'message') and @href='#{@an_update.url}']"
)
end
end

it "has a gravatar in img.user-image" do
within "li.message" do
assert has_selector?(
:xpath,
"//img[contains(@class, 'user-image') and @src='#{@a_user.author.avatar_url}']"
)
end
end

it "has the update time in span.date-time" do
# valid per RFC3339
within "li.message" do
assert has_selector?("span.date-time")
end
end
end
end
end

0 comments on commit 4e23455

Please sign in to comment.
You can’t perform that action at this time.