Skip to content

Instantly share code, notes, and snippets.

View pascalesdedy's full-sized avatar

Pascales Kurniawan pascalesdedy

  • Not All Who Wander Are Lost - JRR Tolkien
  • Yogyakarta
View GitHub Profile
@pascalesdedy
pascalesdedy / response and exception_handler .rb
Created October 21, 2018 19:25
app/controller/concerns files - Simple Rails API server - TDD
#app/controller/concerns/response.rb
module Response
def json_response(object, status = :ok)
render json: object, status: status
end
end
#app/controller/concerns/exception_handler.rb
module ExceptionHandler
# provides the more graceful `included` method
@pascalesdedy
pascalesdedy / application_controller.rb
Created October 21, 2018 19:27
app/controller/application_controller.rb - Rails api server using TDD
class ApplicationController < ActionController::API
include Response
include ExceptionHandler
end
@pascalesdedy
pascalesdedy / rails_helper.rb
Last active October 21, 2018 20:18
spec/rails_helper.rb - used for creating simple CRUD TDD
# spec/rails_helper.rb
# [...]
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# [...]
RSpec.configuration do |config|
# [...]
config.include RequestSpecHelper, type: :request
# [...]
end
@pascalesdedy
pascalesdedy / request_spec_helper.rb
Last active October 21, 2018 20:20
spec/support/request_spec_helper.rb - used for creating simple CRUD TDD
module RequestSpecHelper
# Parse JSON response to ruby hash
def json
JSON.parse(response.body)
end
end
r = require('rethinkdb');
var connection = null;
r.connect( {host: 'localhost', port: 28015}, function(err, conn) {
if (err) throw err;
connection = conn;
r.db('test').tableCreate('authors').run(connection, function(err, result) {
if (err) throw err;
console.log(JSON.stringify(result, null, 2));