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
class Database | |
def initialize | |
@count = Hash.new(0) | |
@db = Hash.new() | |
end | |
# CRUD COMMANDS | |
def set(key, value) | |
@db[key] = value |
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
class User < ApplicationRecord | |
# Include default devise modules. Others available are: | |
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable | |
... | |
def active_for_authentication? | |
super && approved? | |
end | |
def inactive_message |
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_relative "database" | |
require "test/unit" | |
class TestDatabase < Test::Unit::TestCase | |
... | |
def test_commit_with_transaction | |
db = Database.new |
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
... | |
def test_rollback_with_transaction | |
db = Database.new | |
db.set "Bald", "Eagle" | |
assert_equal(1, db.count("Eagle")) | |
db.begin | |
db.set "Golden", "Eagle" |
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
class Database | |
def initialize | |
@count_versions = [Hash.new(0)] | |
@db_versions = [Hash.new()] | |
end | |
# CRUD COMMANDS | |
def set(key, value) | |
@db_versions[-1][key] = value |
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
class Database | |
def initialize | |
@count_versions = [Hash.new(0)] | |
@db_versions = [Hash.new()] | |
end | |
# CRUD COMMANDS | |
def set(key, value) | |
@db_versions[-1][key] = value |
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
class Database | |
def initialize | |
@count_versions = [Hash.new(0)] | |
@db_versions = [Hash.new()] | |
@tier = 0 | |
end | |
# CRUD COMMANDS | |
def set(key, value) |
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
... | |
def test_nested_transaction | |
db = Database.new | |
db.set "Pacific", "Baza" | |
assert_equal(1, db.count("Baza")) | |
db.begin | |
db.set "Black", "Baza" |
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
... | |
def test_transaction_with_deletion | |
db = Database.new | |
db.set "Homing", "Pigeon" | |
db.set "Fantail", "Pigeon" | |
assert_equal(2, db.count("Pigeon")) |
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
class Database | |
def initialize | |
@count_versions = [Hash.new(0)] | |
@db_versions = [Hash.new()] | |
@deletion_keys = [[]] | |
@tier = 0 | |
end | |
# CRUD COMMANDS |