Skip to content

Commit

Permalink
Add option to export all user updates.
Browse files Browse the repository at this point in the history
Implements issue 653
  • Loading branch information
tlatsas committed Oct 28, 2012
1 parent d187bd9 commit aac25a4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/controllers/updates_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UpdatesController < ApplicationController
before_filter :process_params
before_filter :require_user, :only => [:timeline, :replies]
before_filter :require_user, :only => [:timeline, :replies, :export]

def index
@title = "updates"
Expand All @@ -27,6 +27,14 @@ def replies
render_index(current_user.at_replies(params))
end

def export
updates = Update.where :author_id => current_user.author.id
json_updates = updates.to_json(:only => [:created_at, :text])
send_data(json_updates,
:filename => "#{current_user.username}-updates.json",
:type => "application/json")
end

def show
@update = Update.first(:id => params[:id])
if @update
Expand Down
2 changes: 2 additions & 0 deletions app/views/users/show.haml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
- if @author.user == current_user
.edit
%a{:href => edit_user_path(@author.username)} Edit
.export
%a= link_to "Export all updates", export_path

- unless @author.website.blank? or @author.bio.blank?
.info
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
resources :updates, :only => [:index, :show, :create, :destroy]
match "/timeline", :to => "updates#timeline"
match "/replies", :to => "updates#replies"
match "/export", :to => "updates#export", :via => :get

# Search
resource :search, :only => :show
Expand Down
34 changes: 34 additions & 0 deletions test/acceptance/export_updates_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'require_relative' if RUBY_VERSION[0,3] == '1.8'
require_relative 'acceptance_helper'

describe "export updates" do
include AcceptanceHelper

describe "logged in" do
before do
log_in_as_some_user
update = Fabricate(:update, :author => @u.author)
end

it "has a link to export all updates" do
visit "/users/#{@u.username}"
assert has_link? "Export all updates"
end

it "exports all updates in json format" do
visit "/users/#{@u.username}"
click_link "Export all updates"
assert_equal "application/json", page.response_headers['Content-Type']
assert_match /#{@u.username}-updates.json/, page.response_headers['Content-Disposition']
end

end

describe "unauthorized" do
before { visit "/export" }
it "should redirect to root page" do
assert page.has_selector? 'div#signup'
end
end

end

0 comments on commit aac25a4

Please sign in to comment.