Skip to content

Instantly share code, notes, and snippets.

@groyoh
Created January 13, 2017 18:17
Show Gist options
  • Save groyoh/97438d130f4c27e227969f9747740054 to your computer and use it in GitHub Desktop.
Save groyoh/97438d130f4c27e227969f9747740054 to your computer and use it in GitHub Desktop.
AMS #2025
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '4.2.6'
gem 'active_model_serializers', "0.10.3"
end
require 'action_controller/railtie'
class TestApp < Rails::Application
config.root = File.dirname(__FILE__)
config.session_store :cookie_store, key: 'cookie_store_key'
secrets.secret_token = 'secret_token'
secrets.secret_key_base = 'secret_key_base'
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.logger = Logger.new($stdout)
Rails.logger = config.logger
end
TestApp.initialize!
TestApp.routes.draw do
get 'users/:id', to: 'test#user', as: 'user'
end
TestApp.routes.default_url_options = {
host: 'www.example.com'
}
class User < ActiveModelSerializers::Model
attr_accessor :id, :name
end
class UserSerializer < ActiveModel::Serializer
attributes :id, :name
end
require 'rack/test'
class TestController < ActionController::Base
def user
user = User.new(id: 1, name: "John")
render json: user, adapter: :json, meta: { foo: 1 }, meta_key: 'user_meta'
end
end
require 'minitest/autorun'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_user
get '/users/1'
expected_result = {
user: {
id: 1,
name: "John"
},
user_meta: {
foo: 1
}
}
assert_equal(expected_result, JSON.parse(last_response.body, symbolize_names: true))
end
private
def app
Rails.application
end
end
__END__
Fetching gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 12.0.0
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.10.1
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.1.0
Using rack 1.6.5
Using mime-types-data 3.2016.0521
Using arel 6.0.4
Using bundler 1.13.7
Using concurrent-ruby 1.0.4
Using thor 0.19.4
Using jsonapi 0.1.1.beta2
Using tzinfo 1.2.2
Using nokogiri 1.7.0.1
Using rack-test 0.6.3
Using mime-types 3.1
Using sprockets 3.7.1
Using activesupport 4.2.6
Using loofah 2.0.3
Using mail 2.6.4
Using rails-deprecated_sanitizer 1.0.3
Using globalid 0.3.7
Using activemodel 4.2.6
Using rails-html-sanitizer 1.0.3
Using rails-dom-testing 1.0.8
Using activejob 4.2.6
Using activerecord 4.2.6
Using actionview 4.2.6
Using actionpack 4.2.6
Using actionmailer 4.2.6
Using active_model_serializers 0.10.3
Using railties 4.2.6
Using sprockets-rails 3.2.0
Using rails 4.2.6
config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
* development - set it to false
* test - set it to false (unless you use a tool that preloads your test environment)
* production - set it to true
Run options: --seed 47903
# Running:
D, [2017-01-07T14:21:50.084815 #5791] DEBUG -- :
D, [2017-01-07T14:21:50.084862 #5791] DEBUG -- :
I, [2017-01-07T14:21:50.085175 #5791] INFO -- : Started GET "/users/1" for 127.0.0.1 at 2017-01-07 14:21:50 +0100
I, [2017-01-07T14:21:50.087008 #5791] INFO -- : Processing by TestController#user as HTML
I, [2017-01-07T14:21:50.087055 #5791] INFO -- : Parameters: {"id"=>"1"}
UserSerializer
I, [2017-01-07T14:21:50.088679 #5791] INFO -- : Rendered UserSerializer with User (0.12ms)
I, [2017-01-07T14:21:50.088829 #5791] INFO -- : Completed 200 OK in 2ms (Views: 0.5ms)
.
Finished in 0.011775s, 84.9248 runs/s, 84.9248 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment