Skip to content

Instantly share code, notes, and snippets.

View SweeD's full-sized avatar

Markus Schwed SweeD

View GitHub Profile
require 'rspec/mocks'
class ClassForMocking
end
RSpec::Mocks::setup(ClassForMocking)
# 1. ================
# Could work (never tried)
Rails.application.routes.draw do
load 'routes/admin' # file includes just the routes
load 'routes/crm' # file includes just the routes
resources :customer
@SweeD
SweeD / get_posts_example
Created April 27, 2011 15:12
GET /posts response example
<posts>
<post>
<attr></attr>
<comments>
<comment> ... </comment>
...
</comments>
</post>
</posts>
@SweeD
SweeD / gist:948896
Created April 29, 2011 19:41
Ugly arrayify
class Object
def arrayify
[*self]
end
end
@SweeD
SweeD / new_trophy_route.rb
Created February 7, 2012 16:13
Routing with constraints
class NewTrohpyRoute
def self.matches?(request)
trophy_id = request.params[:trophy_id] # Not sure if you can get the params this way
return NewTrophy.where(:id => trophy_id).count > 1
end
end
@SweeD
SweeD / store.js.coffee
Created January 16, 2013 14:17
Sad try to to use a DS.Model and DS.Store up and running.
When I try to find a model in the console, i get an error.
MyApp.User.find(98)
> TypeError: Object Ember has no method 'merge'
@SweeD
SweeD / models.coffee
Created January 30, 2013 09:04
I try to load hasMany associations embedded...what am I doing wrong?!
App.User = DS.Model.extend
#...
addresses: DS.hasMany(GleichklangWeb.Address, { embedded: true })
App.Address = DS.Model.extend
#...
user: DS.belongsTo(GleichklangWeb.User)
App.Router.map ->
@resource 'portal', ->
@route 'dashboard'
@resource 'developers', ->
@resource 'messages', ->
@route 'inbox'
@route 'hidden'
@resource 'sysops', ->
locationToUse = if window.history.replaceState then 'history' else 'hash'
App.Router.reopen
location: locationToUse
@SweeD
SweeD / rest_adapter_config.coffee
Last active December 17, 2015 18:40
DS.RESTAdapter plurals configuration (Ember-Data)
DS.RESTAdapter.configure("plurals",
galleries: "galleries" # If your model is called App.Galleries
gallery: "galleries" # If your model is called App.Gallery
)