Skip to content

Instantly share code, notes, and snippets.

View chelseatroy's full-sized avatar

Chelsea Troy chelseatroy

View GitHub Profile
@chelseatroy
chelseatroy / registrations_controller.rb
Created April 8, 2019 19:17
Devise Generated Custom Controller Example
# frozen_string_literal: true
class Users::RegistrationsController < Devise::RegistrationsController
# before_action :configure_sign_up_params, only: [:create]
# before_action :configure_account_update_params, only: [:update]
# GET /resource/sign_up
# def new
# super
# end
@chelseatroy
chelseatroy / registrations_controller.rb
Last active April 8, 2019 19:33
Modifying Create Method
class RegistrationsController < Devise::RegistrationsController
# before_action :configure_sign_up_params, only: [:create]
# before_action :configure_account_update_params, only: [:update]
# GET /resource/sign_up
# def new
# super
# end
@chelseatroy
chelseatroy / registrations_controller.rb
Created April 8, 2019 20:16
Adding Notes to Permitted Params
class RegistrationsController < Devise::RegistrationsController
# before_action :configure_sign_up_params, only: [:create]
# before_action :configure_account_update_params, only: [:update]
# GET /resource/sign_up
# def new
# super
# end
@chelseatroy
chelseatroy / new.html.erb
Created April 8, 2019 20:24
Devise Registration form
<h2>Sign up</h2>
<%= simple_form_for(resource, as: resource_name, url: user_registration_path) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email,
required: true,
autofocus: true,
input_html: { autocomplete: "email" }%>
@chelseatroy
chelseatroy / new.html.erb
Created April 8, 2019 20:29
Devise Registration with Notes Added
<h2>Sign up</h2>
<%= simple_form_for(resource, as: resource_name, url: user_registration_path) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email,
required: true,
autofocus: true,
input_html: { autocomplete: "email" }%>
@chelseatroy
chelseatroy / test_database.rb
Created May 23, 2019 03:58
Testing Crud Commands
require_relative "database"
require "test/unit"
require 'objspace'
class TestDatabase < Test::Unit::TestCase
def test_get_set_happy_path
#These two methods are tested together because isolating them would require opening direct access to database objects.
db = Database.new
@chelseatroy
chelseatroy / database.rb
Created May 23, 2019 04:11
Initial Database
class Database
def initialize
@db = Hash.new()
end
# CRUD COMMANDS
def set(key, value)
@db[key] = value
...
def test_count_happy_path
db = Database.new
db.set "Snowy", "Owl"
assert_equal(1, db.count("Owl"))
db.set "GreatHorned", "Owl"
assert_equal(2, db.count("Owl"))
end
@chelseatroy
chelseatroy / database.rb
Created May 23, 2019 04:26
Count Implementation
class Database
def initialize
@count = Hash.new(0)
@db = Hash.new()
end
# CRUD COMMANDS
def set(key, value)
@db[key] = value
...
def test_delete_happy_path
db = Database.new
db.set "Tufted", "Titmouse"
assert_equal("Titmouse", db.get("Tufted"))
db.delete "Tufted"
assert_equal("NULL", db.get("Tufted"))