diff options
author | Marius Mathiesen <marius@shortcut.no> | 2010-01-26 13:00:28 +0100 |
---|---|---|
committer | Marius Mathiesen <marius@shortcut.no> | 2010-01-26 13:00:28 +0100 |
commit | 408f6ddeb70d7d34cec7fd31f1aa0e0534bc387f (patch) | |
tree | a02208f98c8c2930aca8c71b251f348685d0ecd9 | |
parent | 628ed4e05cfe77e08d1e56f600a871e553f559ea (diff) | |
download | gitorious-mainline-outdated-408f6ddeb70d7d34cec7fd31f1aa0e0534bc387f.zip gitorious-mainline-outdated-408f6ddeb70d7d34cec7fd31f1aa0e0534bc387f.tar.gz gitorious-mainline-outdated-408f6ddeb70d7d34cec7fd31f1aa0e0534bc387f.tar.bz2 |
Adding JSON support to Blobs#history
This was requested on IRC the other day, to check for updates to a Greasemonkey script
-rw-r--r-- | app/controllers/blobs_controller.rb | 12 | ||||
-rw-r--r-- | test/functional/blobs_controller_test.rb | 8 |
2 files changed, 19 insertions, 1 deletions
diff --git a/app/controllers/blobs_controller.rb b/app/controllers/blobs_controller.rb index c2240c1..25e98d5 100644 --- a/app/controllers/blobs_controller.rb +++ b/app/controllers/blobs_controller.rb @@ -87,7 +87,17 @@ class BlobsController < ApplicationController :name => @blob.basename }) @commits = @git.log(@ref, desplat_path(@path)) - expires_in 30.minutes + expires_in 30.minutes + respond_to do |wants| + wants.html + wants.json {render :json => + @commits.map{|c|{ + :author => c.author.name, + :sha => c.id, + :message => c.short_message, + :committed_date => c.committed_date} + }.to_json} + end end protected diff --git a/test/functional/blobs_controller_test.rb b/test/functional/blobs_controller_test.rb index c624309..8900eb3 100644 --- a/test/functional/blobs_controller_test.rb +++ b/test/functional/blobs_controller_test.rb @@ -146,6 +146,14 @@ class BlobsControllerTest < ActionController::TestCase assert_equal 5, assigns(:commits).size assert_match(/max-age=\d+, private/, @response.headers['Cache-Control']) end + + should "get the history as json" do + get :history, :project_id => @project.to_param, :repository_id => @repository.to_param, + :branch_and_path => ["master","README.txt"], :format => "json" + assert_response :success + json_body = JSON.parse(@response.body) + assert_equal 5, json_body.size + end end end end |