Skip to content

Commit

Permalink
show action returns current version
Browse files Browse the repository at this point in the history
  • Loading branch information
ndushay committed Aug 24, 2017
1 parent a854245 commit beb3779
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/controllers/moab_storage_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ def index
end
end

def show
version_metadata_file = Stanford::StorageServices.version_metadata(params['id'])
vm = Moab::VersionMetadata.parse(version_metadata_file.read)
# FIXME: moab gem likely has a better way to get the latest version (github issue #24)
@output = { current_version: vm.versions.last.version_id }
respond_to do |format|
format.xml { render xml: @output }
format.all { render json: @output, content_type: 'application/json' }
end
end

private

def druids_from_storage_root
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Rails.application.routes.draw do
get 'moab_storage/index'

get 'moab_storage/show/:id', to: 'moab_storage#show'

# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
30 changes: 30 additions & 0 deletions spec/controllers/moab_storage_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,34 @@
expect(response.content_type).to eq "application/xml"
end
end

describe "GET #show" do
let(:fixture_druid) { 'ct764fs4485' }
it "returns http success status code" do
get :show, params: { id: fixture_druid }
expect(response).to have_http_status(:success)
end
context 'assigns @output correctly' do
it 'Hash' do
get :show, params: { id: fixture_druid }
expect(assigns(:output)).to be_an_instance_of Hash
end
it 'current_version' do
get :show, params: { id: fixture_druid }
expect(assigns(:output)[:current_version]).to eq 10
end
end
it 'returns json by default' do
get :show, params: { id: fixture_druid }
expect(response.content_type).to eq "application/json"
end
it 'returns json when requested' do
get :show, params: { id: fixture_druid, format: :json }
expect(response.content_type).to eq "application/json"
end
it 'returns xml when requested' do
get :show, params: { id: fixture_druid, format: :xml }
expect(response.content_type).to eq "application/xml"
end
end
end

0 comments on commit beb3779

Please sign in to comment.