Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
rshewitt committed Apr 24, 2024
1 parent 5b9e32a commit 55a8fe3
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 85 deletions.
65 changes: 38 additions & 27 deletions app/controllers/translates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,33 @@ def create
reader_name = params[:reader]
writer_name = params[:writer]

@md_return = ADIWG::Mdtranslator.translate(
file: file_obj, reader: reader_name, writer: writer_name
)
@md_return =
ADIWG::Mdtranslator.translate(
file: file_obj,
reader: reader_name,
writer: writer_name
)

@response_info = {}
@response_info[:success] = true
@response_info[:readerStructureStatus] = 'OK'
@response_info[:readerStructureMessages] = @md_return[:readerStructureMessages]
@response_info[:readerValidationStatus] = 'OK'
@response_info[:readerValidationMessages] = @md_return[:readerValidationMessages]
@response_info[:readerExecutionStatus] = 'OK'
@response_info[:readerExecutionMessages] = @md_return[:readerExecutionMessages]
@response_info[:writerStatus] = 'OK'
@response_info[:readerStructureStatus] = "OK"
@response_info[:readerStructureMessages] = @md_return[
:readerStructureMessages
]
@response_info[:readerValidationStatus] = "OK"
@response_info[:readerValidationMessages] = @md_return[
:readerValidationMessages
]
@response_info[:readerExecutionStatus] = "OK"
@response_info[:readerExecutionMessages] = @md_return[
:readerExecutionMessages
]
@response_info[:writerStatus] = "OK"
@response_info[:writerMessages] = @md_return[:writerMessages]
@response_info[:readerRequested] = @md_return[:readerRequested]
@response_info[:readerVersionRequested] = @md_return[:readerVersionRequested]
@response_info[:readerVersionRequested] = @md_return[
:readerVersionRequested
]
@response_info[:readerVersionUsed] = @md_return[:readerVersionUsed]
@response_info[:writerRequested] = @md_return[:writerRequested]
@response_info[:writerVersion] = @md_return[:writerVersion]
Expand All @@ -40,28 +51,28 @@ def create
a_e_mess = @response_info[:readerExecutionMessages]
a_w_mess = @response_info[:writerMessages]

status = 'OK'
status = 'NOTICE' if a_s_mess.any? { |s| s.include?('NOTICE') }
status = 'WARNING' if a_s_mess.any? { |s| s.include?('WARNING') }
status = 'ERROR' if a_s_mess.any? { |s| s.include?('ERROR') }
status = "OK"
status = "NOTICE" if a_s_mess.any? { |s| s.include?("NOTICE") }
status = "WARNING" if a_s_mess.any? { |s| s.include?("WARNING") }
status = "ERROR" if a_s_mess.any? { |s| s.include?("ERROR") }
@response_info[:readerStructureStatus] = status

status = 'OK'
status = 'NOTICE' if a_v_mess.any? { |s| s.include?('NOTICE') }
status = 'WARNING' if a_v_mess.any? { |s| s.include?('WARNING') }
status = 'ERROR' if a_v_mess.any? { |s| s.include?('ERROR') }
status = "OK"
status = "NOTICE" if a_v_mess.any? { |s| s.include?("NOTICE") }
status = "WARNING" if a_v_mess.any? { |s| s.include?("WARNING") }
status = "ERROR" if a_v_mess.any? { |s| s.include?("ERROR") }
@response_info[:readerValidationStatus] = status

status = 'OK'
status = 'NOTICE' if a_e_mess.any? { |s| s.include?('NOTICE') }
status = 'WARNING' if a_e_mess.any? { |s| s.include?('WARNING') }
status = 'ERROR' if a_e_mess.any? { |s| s.include?('ERROR') }
status = "OK"
status = "NOTICE" if a_e_mess.any? { |s| s.include?("NOTICE") }
status = "WARNING" if a_e_mess.any? { |s| s.include?("WARNING") }
status = "ERROR" if a_e_mess.any? { |s| s.include?("ERROR") }
@response_info[:readerExecutionStatus] = status

status = 'OK'
status = 'NOTICE' if a_w_mess.any? { |s| s.include?('NOTICE') }
status = 'WARNING' if a_w_mess.any? { |s| s.include?('WARNING') }
status = 'ERROR' if a_w_mess.any? { |s| s.include?('ERROR') }
status = "OK"
status = "NOTICE" if a_w_mess.any? { |s| s.include?("NOTICE") }
status = "WARNING" if a_w_mess.any? { |s| s.include?("WARNING") }
status = "ERROR" if a_w_mess.any? { |s| s.include?("ERROR") }
@response_info[:writerStatus] = status

# check for errors returned by parser, validator, reader, and writer
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class ApplicationMailer < ActionMailer::Base
default from: '[email protected]'
layout 'mailer'
default from: "[email protected]"
layout "mailer"
end
26 changes: 13 additions & 13 deletions config/application.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# frozen_string_literal: true

require_relative 'boot'
require_relative "boot"

require 'rails'
require "rails"
# Pick the frameworks you want:
require 'active_model/railtie'
require 'active_job/railtie'
require 'active_record/railtie'
require 'active_storage/engine'
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'action_mailbox/engine'
require 'action_text/engine'
require 'action_view/railtie'
require 'action_cable/engine'
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_mailbox/engine"
require "action_text/engine"
require "action_view/railtie"
require "action_cable/engine"
# require "sprockets/railtie"
require 'rails/test_unit/railtie'
require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Expand Down
6 changes: 3 additions & 3 deletions config/boot.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

require 'bundler/setup' # Set up gems listed in the Gemfile.
require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
require "bundler/setup" # Set up gems listed in the Gemfile.
require "bootsnap/setup" # Speed up boot time by caching expensive operations.
2 changes: 1 addition & 1 deletion config/environment.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Load the Rails application.
require_relative 'application'
require_relative "application"

# Initialize the Rails application.
Rails.application.initialize!
4 changes: 2 additions & 2 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
if Rails.root.join('tmp/caching-dev.txt').exist?
if Rails.root.join("tmp/caching-dev.txt").exist?
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{2.days.to_i}"
"Cache-Control" => "public, max-age=#{2.days.to_i}"
}
else
config.action_controller.perform_caching = false
Expand Down
8 changes: 4 additions & 4 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
Expand Down Expand Up @@ -75,10 +75,10 @@
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new($stdout)
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new($stdout)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
config.logger = ActiveSupport::TaggedLogging.new(logger)
end

# Do not dump schema after migrations.
Expand Down
4 changes: 2 additions & 2 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
# Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{1.hour.to_i}"
"Cache-Control" => "public, max-age=#{1.hour.to_i}"
}

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.cache_store = :null_store

Expand Down
4 changes: 1 addition & 3 deletions config/initializers/wrap_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
# is enabled by default.

# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json]
end
ActiveSupport.on_load(:action_controller) { wrap_parameters format: [:json] }

# To enable root element in JSON for ActiveRecord objects.
# ActiveSupport.on_load(:active_record) do
Expand Down
10 changes: 5 additions & 5 deletions config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)
min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5)
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch('PORT', 3000)
port ENV.fetch("PORT", 3000)

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch('RAILS_ENV', 'development')
environment ENV.fetch("RAILS_ENV", "development")

# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid')
pidfile ENV.fetch("PIDFILE", "tmp/pids/server.pid")

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked web server processes. If using threads and workers together
Expand Down
8 changes: 4 additions & 4 deletions config/spring.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

Spring.watch(
'.ruby-version',
'.rbenv-vars',
'tmp/restart.txt',
'tmp/caching-dev.txt'
".ruby-version",
".rbenv-vars",
"tmp/restart.txt",
"tmp/caching-dev.txt"
)
2 changes: 0 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_12_26_174535) do

create_table "translates", force: :cascade do |t|
t.binary "file"
t.string "reader"
t.string "writer"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

end
2 changes: 1 addition & 1 deletion test/channels/application_cable/connection_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'test_helper'
require "test_helper"

module ApplicationCable
class ConnectionTest < ActionCable::Connection::TestCase
Expand Down
32 changes: 25 additions & 7 deletions test/controllers/translates_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
# frozen_string_literal: true

require 'test_helper'
require "test_helper"

class TranslatesControllerTest < ActionDispatch::IntegrationTest
test 'post valid transformation of sbJson to mdJson' do
test "post valid transformation of sbJson to mdJson" do
@translate = translates(:sbjson_to_mdjson)
@file = File.read(File.join(File.dirname(__FILE__), "../fixtures/#{@translate.file}"))
post '/translates', params: { file: @file, reader: @translate.reader, writer: @translate.writer }, as: :json
@file =
File.read(
File.join(File.dirname(__FILE__), "../fixtures/#{@translate.file}")
)
post "/translates",
params: {
file: @file,
reader: @translate.reader,
writer: @translate.writer
},
as: :json
assert_response 200
end

test 'post invalid transformation of fgdc to iso19115_3' do
test "post invalid transformation of fgdc to iso19115_3" do
@translate = translates(:fgdc_to_iso)
@file = File.read(File.join(File.dirname(__FILE__), "../fixtures/#{@translate.file}"))
post '/translates', params: { file: @file, reader: @translate.reader, writer: @translate.writer }, as: :json
@file =
File.read(
File.join(File.dirname(__FILE__), "../fixtures/#{@translate.file}")
)
post "/translates",
params: {
file: @file,
reader: @translate.reader,
writer: @translate.writer
},
as: :json
assert_response 422
end
end
16 changes: 10 additions & 6 deletions test/models/translate_test.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# frozen_string_literal: true

require 'test_helper'
require "test_helper"

class TranslateTest < ActiveSupport::TestCase
test 'convert fgdc to iso19115_3' do
test "convert fgdc to iso19115_3" do
@translate = translates(:fgdc_to_iso)
@file = File.read(File.expand_path("../../fixtures/#{@translate.file}", __FILE__))
@file =
File.read(File.expand_path("../../fixtures/#{@translate.file}", __FILE__))
@reader = @translate.reader
@writer = @translate.writer

@md_return = ADIWG::Mdtranslator.translate(
file: @file, reader: @reader, writer: @writer
)
@md_return =
ADIWG::Mdtranslator.translate(
file: @file,
reader: @reader,
writer: @writer
)

assert_not_nil(@md_return[:writerOutput])
end
Expand Down
6 changes: 3 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
require 'rails/test_help'
ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
require "rails/test_help"

module ActiveSupport
class TestCase
Expand Down

0 comments on commit 55a8fe3

Please sign in to comment.