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

Add formatter #2

Merged
merged 4 commits into from
Jun 14, 2024
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ group :development do
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'syntax_tree', '~>6.2.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ GEM
parser (3.2.2.4)
ast (~> 2.4.1)
racc
prettier_print (1.2.1)
psych (3.3.4)
public_suffix (5.0.4)
puma (4.3.12)
Expand Down Expand Up @@ -206,6 +207,8 @@ GEM
sprockets (>= 3.0.0)
sqlite3 (1.6.9-arm64-darwin)
sqlite3 (1.6.9-x86_64-linux)
syntax_tree (6.2.0)
prettier_print (>= 1.2.0)
thor (0.20.3)
thread_safe (0.3.6)
timeout (0.4.1)
Expand Down Expand Up @@ -234,6 +237,7 @@ DEPENDENCIES
spring
spring-watcher-listen (~> 2.0.0)
sqlite3 (~> 1.4)
syntax_tree (~> 6.2.0)
tzinfo-data

RUBY VERSION
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ lint:

.PHONY: test
test:
rails test
rails test

# recursively finds all .rb files in the current dir and formats them using stree
format:
find . -type f -name "*.rb" | xargs -L1 bundle exec stree write --plugins=plugin/single_quotes
25 changes: 18 additions & 7 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[:readerStructureMessages] = @md_return[
:readerStructureMessages
]
@response_info[:readerValidationStatus] = 'OK'
@response_info[:readerValidationMessages] = @md_return[:readerValidationMessages]
@response_info[:readerValidationMessages] = @md_return[
:readerValidationMessages
]
@response_info[:readerExecutionStatus] = 'OK'
@response_info[:readerExecutionMessages] = @md_return[:readerExecutionMessages]
@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 Down
4 changes: 2 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new($stdout)
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
2 changes: 1 addition & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}

# 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
2 changes: 1 addition & 1 deletion config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# 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.
#
Expand Down
14 changes: 6 additions & 8 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
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
26 changes: 22 additions & 4 deletions test/controllers/translates_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,33 @@
class TranslatesControllerTest < ActionDispatch::IntegrationTest
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
@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
12 changes: 8 additions & 4 deletions test/models/translate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
class TranslateTest < ActiveSupport::TestCase
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
Loading