Skip to content

Instantly share code, notes, and snippets.


Jon Kern JonKernPA

View GitHub Profile
JonKernPA / list_movies_spec.rb
Created Aug 5, 2014
spec helper and test for flix project
View list_movies_spec.rb
require 'spec_helper'
describe "Viewing the list of movies" do
it "shows the movies" do
movie1 = Movie.create(title: "Iron Man",
rating: "PG-13",
total_gross: 318412101.00,
description: "Tony Stark builds an armored suit to fight the throes of evil",
released_on: "2008-05-02",
JonKernPA / state_spec.rb
Created Apr 14, 2014
I spent 15 minutes creating a quick example...
View state_spec.rb
require 'spec_helper'
# I spent 15 minutes creating a quick example for an email list...
describe "State" do
it 'has a list of states' do
expect(State.states).to have_key('AK')
JonKernPA / dragonfly.rb
Created Mar 13, 2014
Dragonfly and MongoMapper and Heroku
View dragonfly.rb
require 'dragonfly'
require 'dragonfly/mongo_data_store'
require 'mongo'
require 'uri'
# From
def get_connection
return @db_connection if @db_connection
db = URI.parse(ENV['MONGOHQ_URL'])
JonKernPA / embedded_delete_sample.rb
Created Jul 5, 2012
Deleting an embedded document
View embedded_delete_sample.rb
class Period
include MongoMapper::EmbeddedDocument
key :text, String
embedded_in :schedule
def to_s
View admin_smoke_test.feature
Feature: Quickly exercise the primary ADMIN UIs just to make sure nothing blows up
Background: We need to pre-populate the database with the simulator results, and be logged in as admin
Given I login as "admin"
And we have the following Patients:
| Johnson |
| Henry |
| Walters |
| Glanzmann |
| Franklin |
JonKernPA / extending_user.rb
Created Mar 2, 2012
Demonstrating opening a mongomapper class and extending
View extending_user.rb
# Run this in mmconsole
class User
include MongoMapper::Document
key :name
key :role
def admin?
JonKernPA / Node.rb
Created Feb 16, 2012
Tree example in MongoMapper
View Node.rb
class Node
include MongoMapper::Document
key :name
belongs_to :parent, :class_name => 'Node'
many :children, :class_name => 'Node'
def root?
JonKernPA / resource_log_spec.rb
Created Dec 28, 2011
Sample RSpec for MongoMapper showing data cleanup
View resource_log_spec.rb
require File.dirname(__FILE__) + '/../spec_helper'
describe "ResourceLog" do
@@debug = false
before :all do
puts "--------------------"
ResourceLog.count().should == 0
JonKernPA / sample_index.log
Created Nov 26, 2011
Examining Effect of MongoDB index using explain
View sample_index.log
without a compound index
> db.accounts.find({state: "active"}).limit(15).sort({email: 1}).explain();
"cursor" : "BasicCursor",
"nscanned" : 11002,
"nscannedObjects" : 11002,
"n" : 15,
"scanAndOrder" : true,
"millis" : 44,
"nYields" : 0,
JonKernPA / show_model_keys.rb
Created May 18, 2011
Model keys with MongoMapper
View show_model_keys.rb
class User
include MongoMapper::Document
key :name, String, :required => true
text = []
text << "After model with key :name, String"
text << User.keys.keys.inspect