Skip to content

Instantly share code, notes, and snippets.

View elliotlarson's full-sized avatar

Elliot Larson elliotlarson

View GitHub Profile
require 'test_helper'
class FoosControllerTest < ActionDispatch::IntegrationTest
setup do
@foo = foos(:one)
end
test "should get index" do
get foos_url
assert_response :success
import uuid from "uuid/v4";
import { combineReducers } from "redux";
export const types = {
CREATE: "CHARACTERS_CREATE",
UPDATE: "CHARACTERS_UPDATE",
DELETE: "CHARACTERS_DELETE"
};
const byId = (state = {}, action) => {
import { combineReducers } from "redux";
const byId = (state = {}, action) => {
switch (action.type) {
case types.CREATE:
case types.UPDATE:
// Note: create and update are the same now so we can let the case for
// create fall through to the case for update
const characterData = action.payload;
return { ...state, [id]: characterData };
// `src/store/characters.js`
import uuid from "uuid/v4";
export const types = {
CREATE: "CHARACTERS_CREATE",
UPDATE: "CHARACTERS_UPDATE",
DELETE: "CHARACTERS_DELETE"
};
import omit from "lodash/omit";
const newCharacters = omit(characters, deleteId);
const newCharacters = Object.keys(characters).reduce((obj, id) => {
if (id !== `${deleteId}`) {
return { ...obj, [id]: characters[id] };
}
return obj;
}, {});
// You don't need to type cast the integer `deleteId` to a string in the
// browser, but when running Jest specs, I found that I had to cast to a
// string. Maybe this is a difference between browser JS and Node, which
// the tests run in?
const { [`${deleteId}`]: deleted, ...newCharacters } = characters;
const deleteId = 3;
const newCharacters = characters.filter(c => c !== characterToRemove);
const newCharacters = [
...characters.slice(0, index),
...characters.slice(index + 1)
];