Skip to content

Instantly share code, notes, and snippets.

View mazikwyry's full-sized avatar
🍔

Adam Mazur mazikwyry

🍔
  • Global App Testing
  • Wyry
View GitHub Profile
@mazikwyry
mazikwyry / gist:c5db71fcd9afca9c80fbe40b459f0082
Created September 30, 2019 14:03
React Testing Library - Given, When, Then
describe("when user inputs more characters ", () => {
const { getByLabelText, getByText } = render(<Component />);
const input = getByLabelText("label", { selector: "input" });
beforeEach(() => {
fireEvent.change(input, { target: { value: "new value" } });
});
it("displays suggestions", () => {
expect(getByText("new value")).toBeInTheDocument();
require 'rails_helper'
RSpec.describe 'POST /signup', type: :request do
let(:url) { '/signup' }
let(:params) do
{
user: {
email: '[email protected]',
password: 'password'
}
require 'rails_helper'
RSpec.describe 'POST /login', type: :request do
let(:user) { Fabricate(:user) }
let(:url) { '/login' }
let(:params) do
{
user: {
email: user.email,
password: user.password
class ApplicationController < ActionController::API
def render_resource(resource)
if resource.errors.empty?
render json: resource
else
validation_error(resource)
end
end
def validation_error(resource)
class RegistrationsController < Devise::RegistrationsController
respond_to :json
def create
build_resource(sign_up_params)
resource.save
render_resource(resource)
end
end
devise_for :users,
path: '',
path_names: {
sign_in: 'login',
sign_out: 'logout',
registration: 'signup'
},
controllers: {
sessions: 'sessions',
registrations: 'registrations'
class SessionsController < Devise::SessionsController
respond_to :json
private
def respond_with(resource, _opts = {})
render json: resource
end
def respond_to_on_destroy
config.jwt do |jwt|
jwt.secret = ENV['DEVISE_JWT_SECRET_KEY']
jwt.dispatch_requests = [
['POST', %r{^/login$}]
]
jwt.revocation_requests = [
['DELETE', %r{^/logout$}]
]
jwt.expiration_time = 1.day.to_i
end
class JWTBlacklist < ApplicationRecord
include Devise::JWT::RevocationStrategies::Blacklist
self.table_name = 'jwt_blacklist'
end
class CreateJwtBlacklist < ActiveRecord::Migration[5.0]
def change
create_table :jwt_blacklist do |t|
t.string :jti, null: false
end
add_index :jwt_blacklist, :jti
end
end