This file contains hidden or 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
require 'test_helper' | |
class FoosControllerTest < ActionDispatch::IntegrationTest | |
setup do | |
@foo = foos(:one) | |
end | |
test "should get index" do | |
get foos_url | |
assert_response :success |
This file contains hidden or 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
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) => { |
This file contains hidden or 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
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 }; |
This file contains hidden or 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
// `src/store/characters.js` | |
import uuid from "uuid/v4"; | |
export const types = { | |
CREATE: "CHARACTERS_CREATE", | |
UPDATE: "CHARACTERS_UPDATE", | |
DELETE: "CHARACTERS_DELETE" | |
}; |
This file contains hidden or 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
import omit from "lodash/omit"; | |
const newCharacters = omit(characters, deleteId); |
This file contains hidden or 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
const newCharacters = Object.keys(characters).reduce((obj, id) => { | |
if (id !== `${deleteId}`) { | |
return { ...obj, [id]: characters[id] }; | |
} | |
return obj; | |
}, {}); |
This file contains hidden or 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
// 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; |
This file contains hidden or 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
const deleteId = 3; |
This file contains hidden or 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
const newCharacters = characters.filter(c => c !== characterToRemove); |
This file contains hidden or 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
const newCharacters = [ | |
...characters.slice(0, index), | |
...characters.slice(index + 1) | |
]; |
NewerOlder