Skip to content

Commit

Permalink
Merge fd14654 into 416f7c8
Browse files Browse the repository at this point in the history
  • Loading branch information
atz committed Oct 2, 2018
2 parents 416f7c8 + fd14654 commit bdda82a
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 31 deletions.
7 changes: 6 additions & 1 deletion app/controllers/bundle_contexts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ def new
def create
@bundle_context = BundleContext.new(bundle_contexts_params)
if @bundle_context.save
redirect_to controller: 'job_runs', created: 1
flash[:success] = 'Success! Your job is queued. A link to your validation report will be emailed to you when it is ready.'
redirect_to controller: 'job_runs'
else
render :new
end
end

def show
@bundle_context = BundleContext.find(params[:id])
end

private

def bundle_contexts_params
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/job_runs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class JobRunsController < ApplicationController
def index
flash[:notice] = 'Success! Your job is queued. A link to your validation report will be emailed to you when it is ready.' if params[:created]
@job_runs = JobRun.order('created_at desc').page params[:page]
end

Expand All @@ -13,7 +12,7 @@ def download
if @job_run.output_location
send_file @job_run.output_location
else
flash[:notice] = 'Job is not complete. Please check back later.'
flash[:warning] = 'Job is not complete. Please check back later.'
render 'show'
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/bundle_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def verify_output_dir

def verify_bundle_directory
return if errors.key?(:bundle_dir)
errors.add(:bundle_dir, "Bundle directory: #{bundle_dir} not found.") unless File.directory?(bundle_dir)
errors.add(:bundle_dir, "'#{bundle_dir}' not found.") unless File.directory?(bundle_dir)
end

def verify_content_metadata_creation
Expand Down
24 changes: 24 additions & 0 deletions app/views/bundle_contexts/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="container mt-5">
<dl class="dl row">
<dt class="col-sm-3">Project Name</dt>
<dd class="col-sm-9"><%= @bundle_context.project_name %></dd>
<dt class="col-sm-3">User</dt>
<dd class="col-sm-9"><%= @bundle_context.user.email %></dd>
<dt class="col-sm-3">Content Structure</dt>
<dd class="col-sm-9"><%= @bundle_context.content_structure %></dd>
<dt class="col-sm-3">Bundle Directory</dt>
<dd class="col-sm-9"><%= @bundle_context.bundle_dir %></dd>
<dt class="col-sm-3">Staging Style Symlink?</dt>
<dd class="col-sm-9">
<% if @bundle_context.staging_style_symlink %>
<i class="fas fa-check"></i>
<% else %>
<i class="far fa-times-circle"></i>
<% end %>
</dd>
<dt class="col-sm-3">Content Metadata Creation</dt>
<dd class="col-sm-9"><%= @bundle_context.content_metadata_creation %></dd>
<dt class="col-sm-3">Created At</dt>
<dd class="col-sm-9"><%= @bundle_context.created_at %></dd>
</dl>
</div>
6 changes: 1 addition & 5 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
<title>Pre-Assembly</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>

<body>
<%= render "shared/header" %>
<div class="container mx-auto mt-5" style="width: 50em">
<p class="notice alert-info" role="alert"><%= notice %></p>
<p class="alert" role="alert"><%= alert %></p>
</div>
<%= yield %>
</body>
</html>
10 changes: 9 additions & 1 deletion app/views/shared/_header.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<nav class="navbar">
<a class="navbar-brand" href="#"><%= image_tag('sul-logo.png', height: '30') %></a>
<a class="navbar-brand" href="#"><%= image_tag('sul-logo.png', height: '30') %></a>
</nav>
<div style="background-color: #8c1515; color: white; font-family: serif">
<h1 class="p-4">Accessioning</h1>
<%= image_tag("bookheader.png", width: "100%", height: "75") %>
</div>
<% flash.each do |key, value| %>
<div class="container">
<div class="alert alert-<%= key %> alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><i class="fas fa-times"></i></button>
<%= value %>
</div>
</div>
<% end %>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
devise_for :users, skip: :all
root to: 'bundle_contexts#new'
resources :bundle_contexts, only: [:new, :create]
resources :bundle_contexts, only: [:create, :new, :show]
resources :job_runs, only: [:show, :index]
get 'job_runs/:id/download', to: 'job_runs#download', as: 'download'
mount Resque::Server.new, at: '/resque'
Expand Down
24 changes: 7 additions & 17 deletions spec/controllers/bundle_contexts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
post :create, params: params
expect(assigns(:bundle_context)).to be_a(BundleContext).and be_persisted
expect(response).to have_http_status(302) # HTTP code for found
expect(response).to redirect_to(job_runs_path(created: 1))
expect(response).to redirect_to(job_runs_path)
expect(flash[:success]).to start_with('Success! Your job is queued.')
end
it 'has the correct attributes' do
post :create, params: params
Expand All @@ -67,25 +68,14 @@
end

context 'Invalid Parameters' do
let(:bc_params) { { project_name: '', content_structure: '', content_metadata_creation: '', bundle_dir: '' } }

it 'do not create objects' do
params[:bundle_context][:project_name] = nil
expect { post :create, params: params }.not_to change(BundleContext, :count)
expect do
post :create, params: { bundle_context: {
project_name: '',
content_structure: '',
content_metadata_creation: '',
bundle_dir: ''
} }
end .not_to change(BundleContext, :count)
expect do
post :create, params: { bundle_context: {
project_name: "SMPL's folly",
content_structure: '',
content_metadata_creation: '',
bundle_dir: ''
} }
end .not_to change(BundleContext, :count)
expect { post :create, params: { bundle_context: bc_params } }.not_to change(BundleContext, :count)
bc_params[:project_name] = "SMPL's folly"
expect { post :create, params: { bundle_context: bc_params } }.not_to change(BundleContext, :count)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/job_runs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
it 'before job is complete, renders page with flash' do
allow(JobRun).to receive(:find).with('123').and_return(instance_double(JobRun, output_location: nil))
get :download, params: { id: 123 }
expect(flash[:notice]).to eq('Job is not complete. Please check back later.')
expect(flash[:warning]).to eq('Job is not complete. Please check back later.')
end
it 'when job is complete, returns file attachment' do
job_run_double = instance_double(JobRun, output_location: 'spec/test_data/input/mock_progress_log.yaml')
Expand All @@ -42,7 +42,7 @@
'Content-Type' => 'application/x-yaml',
'Content-Disposition' => 'attachment; filename="mock_progress_log.yaml"'
)
expect(flash[:notice]).to be_nil
expect(flash[:warning]).to be_nil
end
it 'requires ID param' do
expect { get :download }.to raise_error(ActionController::UrlGenerationError)
Expand Down
2 changes: 1 addition & 1 deletion spec/views/bundle_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
bc = build(:bundle_context, bundle_dir: 'bad path').tap(&:valid?)
assign(:bundle_context, bc)
render
expect(render).to match(/Bundle dir Bundle directory: bad path not found./)
expect(render).to match(/Bundle dir &#39;bad path&#39; not found./)
end
end
10 changes: 10 additions & 0 deletions spec/views/bundle_contexts/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RSpec.describe 'bundle_contexts/show.html.erb', type: :view do
let(:bc) { create(:bundle_context) }

it 'diplays BundleContext info' do
assign(:bundle_context, bc)
render
expect(rendered).to include("<dd class=\"col-sm-9\">#{bc.project_name}</dd>")
expect(rendered).to include('<i class="far fa-times-circle"></i>') # icon for symlink="false"
end
end

0 comments on commit bdda82a

Please sign in to comment.