Skip to content

Instantly share code, notes, and snippets.

@felixflores
felixflores / gist:2ce479ae9f0b6e90a913
Last active August 29, 2015 14:15
Clojure Database Manipulation and Migration with Drift and SQLingvo

Overview

To create any non-trivial application, you need some way of persisting data. While there are a lot solutions available, Datomic, Neo4j, Samza, just to name a few, but for various reasons, a lot of us still use relational databases. One reason might be because there is a pre-existing Rails application that still needs to interoperate with the Clojure application you are building. Another reason could be because of the exisiting deployment environment requires you to use a certain type of database (I encountered this first hand while working for a large client).

+--------------+          +---------------+
|              |          |               |
|     Ruby     |          |               |
|      on      |          |   Compojure   |
|     Rails    |          | (Clojure app) |
ActiveRecord::AssociationTypeMismatch in UsersController#update
Photo(#2175010700) expected, got HashWithIndifferentAccess(#2158250880)
RAILS_ROOT: /Users/felixflores86/Sites/veritas
Application Trace | Framework Trace | Full Trace
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/associations/association_proxy.rb:263:in `raise_on_type_mismatch'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/associations/has_one_association.rb:52:in `replace'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/associations.rb:1278:in `photo='
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:2744:in `send'
Feature: User profiles
In order to have users profiles
for the website
I want to be able to view and edit users
Background: Set up user
Scenario: Edit profile
Given a user is logged in as "foobar@example.com"
Feature: Managing movies
In order manage movies
As an authorized user
I want to be able to manage movies
Background: Only authenticated users can add movies
Given a user is logged in as "foobar@example.com"
Given /^a user is logged in as "(.*)"$/ do |email|
named_scope :coming_soon,
:joins => :showtimes,
:having => 'showtimes.day > CURRENT_DATE'
# WHAT!!!!
(rdb:27) @movies_for_the_week[1][:items].size
2
(rdb:27) @movies_for_the_week[1][:items]
[]
(rdb:27) @movies_for_the_week[1][:items].size
0
>> m = Movie.for_the_week
class MoviesController < ApplicationController
def index
if params[:filter] == "coming_soon"
@movies = Movie.coming_soon
else
@movies_for_the_week = Movie.for_the_week
end
@view = params[:filter]
end
// Assuming you have underscore and jQuery as a project dependency.
// You can use this to include individual files on your jasmine specs.
// Sample Usage
requireJS('myJSfile', 'myOtherJsFile');
describe("My stuff", function() {
it("rocks", function() {
// your spec
@felixflores
felixflores / UIViewController+Segue.h
Last active December 9, 2015 22:08
A convenient category to make segue preparation a little nicer.
//
// UIViewController+Segue.h
// TimeCapsule
//
// Created by Felix Flores on 12/19/12.
// Copyright (c) 2012 felixflor.es. All rights reserved.
//
#import <UIKit/UIKit.h>
@felixflores
felixflores / UIViewController+ActionSheet.h
Last active December 10, 2015 00:48
Make Action Sheet a little bit more sane
//
// UIViewController+ActionSheet.h
// Tweaks
//
// Created by Felix Flores on 12/21/12.
// Copyright (c) 2012 felixflor.es. All rights reserved.
//
#import <UIKit/UIKit.h>