Created
June 17, 2020 15:05
-
-
Save Edouard-chin/f5eb1bcac9d1f982d8e4d9bf54d1af3f to your computer and use it in GitHub Desktop.
RouteSet generate extras for json requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem "rails", github: 'rails/rails' | |
end | |
require "rack/test" | |
require "action_controller/railtie" | |
class TestApp < Rails::Application | |
config.root = __dir__ | |
config.hosts << "example.org" | |
config.session_store :cookie_store, key: "cookie_store_key" | |
secrets.secret_key_base = "secret_key_base" | |
config.logger = Logger.new($stdout) | |
Rails.logger = config.logger | |
routes.draw do | |
resources :customers | |
end | |
end | |
class CustomersController < ActionController::Base | |
include Rails.application.routes.url_helpers | |
def update | |
puts params[:customer][:tax_exemptions] | |
head(:ok) | |
end | |
end | |
require "minitest/autorun" | |
require "action_controller/test_case" | |
class BugTest < ActionController::TestCase | |
tests CustomersController | |
setup do | |
@routes = Rails.application.routes | |
request.headers['CONTENT_TYPE'] = "application/json" | |
end | |
def test_returns_success | |
put(:update, params: { id: 1, customer: { tax_exemptions: [] }, format: 'json' }) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment