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
const outer = () => { | |
let outerData = "This is outer"; | |
return () => { | |
let innerData = " and this is inner"; | |
return outerData + innerData; | |
}; | |
}; |
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
const outer = (x) => { | |
return (y) => { | |
return x*y; | |
}; | |
}; | |
outer(5)(5) // 25 | |
let store = outer(5) | |
store(4) // 20 |
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
const counter = () => { | |
let count = 0; | |
return () => { | |
return (count = count + 1); | |
}; | |
}; | |
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
const shoppingList = () => { | |
let buyList = ["Milk", "Bread", "Eggs"]; | |
return { | |
getList: () => { | |
return buyList; | |
}, | |
addToList: (item) => { | |
buyList.push(item); | |
return buyList; | |
}, |
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
yarn add cypress axios --dev |
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
{ | |
"name": "Rails_cypress", | |
"private": true, | |
"dependencies": { | |
"@rails/actioncable": "^6.0.0", | |
"@rails/activestorage": "^6.0.0", | |
"@rails/ujs": "^6.0.0", | |
"@rails/webpacker": "4.2.2", | |
"turbolinks": "^5.2.0" | |
}, |
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
if Rails.env.test? | |
Place.create!([ | |
{ "name": 'Mount Rushmore', "latitude": '43.87910249999999', "longitude": '-103.4590667' }, | |
{ "name": 'Hiroshima', "latitude": '34.3852894', "longitude": '132.4553055' }, | |
{ "name": 'Dubai', "latitude": '25.2048493', "longitude": '55.2707828' } | |
]) | |
end |
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
Rails.application.routes.draw do | |
resources :places | |
if Rails.env.test? | |
namespace :test do | |
post 'reset_database', to: 'databases#reset_database' | |
end | |
end | |
end |
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
class Test::DatabasesController < ApplicationController | |
def reset_database | |
tables = ActiveRecord::Base.connection.tables | |
tables.delete 'schema.migrations' | |
tables.each do |table| | |
ActiveRecord::Base.connection.execute("DELETE FROM #{table}") | |
ActiveRecord::Base.connection.execute("DELETE FROM sqlite_sequence where name='#{table}'") | |
end | |
Rails.application.load_seed if params['seed'] == true | |
end |
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
import axios from "axios"; | |
Cypress.Commands.add("deleteAndSeedDatabase", async () => { | |
return await axios.post("http://localhost:3000/test/delete_database", { | |
seed: true, | |
}); | |
}); | |
Cypress.Commands.add("deleteDatabase", async () => { | |
return await axios.post("http://localhost:3000/test/delete_database", { |
OlderNewer