Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show action initial implementation #25

Merged
merged 4 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
/yarn-error.log

.byebug_history
.pry_history

coverage/*

config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml
config/environments/*.local.yml
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ git_source(:github) do |repo_name|
"https://github.com/#{repo_name}.git"
end

# work with Moab Objects
gem 'moab-versioning'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.3'
Expand Down Expand Up @@ -36,6 +38,8 @@ gem 'jbuilder', '~> 2.5'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
# Call 'binding.pry' anywhere in the code to stop execution and get a pry console
gem 'pry-byebug', require: false
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
Expand Down
23 changes: 23 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ GEM
xpath (~> 2.0)
childprocess (0.7.1)
ffi (~> 1.0, >= 1.0.11)
coderay (1.1.1)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
railties (>= 4.0.0)
Expand All @@ -61,6 +62,8 @@ GEM
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.0.5)
confstruct (1.0.2)
hashie (~> 3.3)
coveralls (0.7.1)
multi_json (~> 1.3)
rest-client
Expand All @@ -76,6 +79,7 @@ GEM
ffi (1.9.18)
globalid (0.4.0)
activesupport (>= 4.2.0)
hashie (3.5.6)
http-cookie (1.0.3)
domain_name (~> 0.5)
i18n (0.8.6)
Expand All @@ -98,11 +102,26 @@ GEM
mini_mime (0.1.4)
mini_portile2 (2.2.0)
minitest (5.10.3)
moab-versioning (2.0.0)
confstruct
json
nokogiri
nokogiri-happymapper
systemu
multi_json (1.12.1)
netrc (0.11.0)
nio4r (2.1.0)
nokogiri (1.8.0)
mini_portile2 (~> 2.2.0)
nokogiri-happymapper (0.5.9)
nokogiri (~> 1.5)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-byebug (3.4.2)
byebug (~> 9.0)
pry (~> 0.10)
public_suffix (2.0.5)
puma (3.9.1)
rack (2.0.3)
Expand Down Expand Up @@ -181,6 +200,7 @@ GEM
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
slop (3.6.0)
spring (2.0.2)
activesupport (>= 4.2)
spring-watcher-listen (2.0.1)
Expand All @@ -194,6 +214,7 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
systemu (2.6.5)
term-ansicolor (1.6.0)
tins (~> 1.0)
thor (0.20.0)
Expand Down Expand Up @@ -231,6 +252,8 @@ DEPENDENCIES
coveralls
jbuilder (~> 2.5)
listen (>= 3.0.5, < 3.2)
moab-versioning
pry-byebug
puma (~> 3.7)
rails (~> 5.1.3)
rails-controller-testing
Expand Down
27 changes: 24 additions & 3 deletions app/controllers/moab_storage_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
require 'moab/stanford'

# API to retrieve data from Moab Object Store
class MoabStorageController < ApplicationController

def index
storage_root = 'spec/fixtures/moab_storage_root'
@stored_druids = Dir.glob("#{storage_root}/**/[a-z][a-z]*[0-9]").map {|d| d.split("/").last}
@stored_druids = druids_from_storage_root
respond_to do |format|
format.xml { render xml: @stored_druids }
format.all { render json: @stored_druids, content_type: 'application/json' }
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
druids ||= begin
@storage_root ||= "#{Moab::Config.storage_roots}/#{Moab::Config.storage_trunk}"
Dir.glob("#{@storage_root}/**/[a-z][a-z]*[0-9]").map {|d| d.split("/").last}
end
end

end
7 changes: 7 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ class Application < Rails::Application
# -- all .rb files in that directory are automatically loaded.
end
end

require 'moab'
Moab::Config.configure do
# FIXME: put this hardcoded dir in settings.yml file (github issue #21)
storage_roots File.join(File.dirname(__FILE__), '..', 'spec','fixtures')
storage_trunk 'moab_storage_root'
end
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
34 changes: 34 additions & 0 deletions spec/controllers/moab_storage_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
expect(assigns(:stored_druids).first).to be_an_instance_of String
end
end
it 'assigns @storage_root correctly' do
get :index
expect(assigns(:storage_root)).to eq "#{Moab::Config.storage_roots}/#{Moab::Config.storage_trunk}"
end
it 'returns json by default' do
get :index
expect(response.content_type).to eq "application/json"
Expand All @@ -35,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