Skip to content

Instantly share code, notes, and snippets.

View mbj's full-sized avatar

Markus Schirp mbj

View GitHub Profile
@mbj
mbj / uncovered_spec.rb
Created November 7, 2012 17:51
incomplete specs that trigger uncovered mutations
require 'spec_helper'
describe AliasSet, '#initialize' do
let(:prefix) { :songs }
let(:attributes) { Mapper::AttributeSet.new << attribute }
let(:attribute) { Mapper::Attribute.build(:id, :type => Integer) }
let(:excluded) { [ :id ] }
context 'with prefix passed to #initialize' do
subject { described_class.new(prefix) }
@mbj
mbj / pricingResCookie.parts.js
Created November 8, 2012 21:05
Why does sixt.de hide they are stealing my history?
// http://www.sixt.de/static/oi/js/pricingResCookie.js | 2012-11-08 21:56 UTC+2
// Loaded when visiting http://www.sixt.de Line 1178.
// Lines: 821-853 with decoded base64 in comments.
// checkHistory() does CSS :visited based history stealing.
// The privacy policy does not reflect they are hitting my privacy with this. Somewhere deeper in the code they are
// checking for: something-even-more-private.com? I dislike such stuff, how far do they want to go?
// German privacy policy under: http://www.sixt.de/informationen/datenschutz/
// I'm not a so happy customer anymore.
var ep = [
@mbj
mbj / method_object.rb
Created November 14, 2012 18:01
Service object simplifications
class MethodObject < Module
def initialize(output_name)
@output_name = output_name
end
module InstanceMethods
attr_reader :input
def initialize(input)
@input = input
@mbj
mbj / does-not-explode-anymore.rb
Created November 21, 2012 15:10
Fixed custom property for MarcWeber
# encoding: UTF-8
require "rubygems"
require "bundler/setup"
require 'json'
# File.delete "/tmp/sqlite-bug-report-test"
require 'dm-core'
@mbj
mbj / some_rails_controllre.rb
Created November 22, 2012 15:32
Example on how a service object can be used within a rails controller
# In reference to my discussion with shingara and http://stackoverflow.com/questions/13294788/how-can-i-have-a-datamapper-callback-happen-in-a-transaction/13444988#13444988
class SomeRailsController
def update
comment = Comment.get(params[:id])
return not_found unless comment
text = params[:text]
update = CommentUpdater.run(comment, text)
if update.successful?
@mbj
mbj / blow.rb
Created November 22, 2012 18:03
# Scenario when Classes and Modules are duped in memoizers!
class A
include Adamantium::Flat
def foo
:foo
end
memoize :foo
end
@mbj
mbj / design.md
Created November 22, 2012 22:28
dm-session mapper interface

Mapper interfaces as used by dm-session

Mapper#loader(body)   => [Loader]      # Loader for specific body
Mapper#dumper(object) => [Dumper]      # Dumper for object
Mapper#execute(command)                # command is an instance of DataMapper::Session::Command::{Insert,Update,Delete}

Loader#identity       => [Identity]    # Any mapper specific object that implements#hash
Loader#object         => [Object]      # The loaded domain object
describe User, '.with_first_name' do
let(:object) { described_class }
subject { object.with_first_name(name) }
let(:result) { mock('Result') }
let(:name) { mock('Name') }
before do
User.stub(:all => result)
@mbj
mbj / components.md
Created November 23, 2012 15:43
list of dm-2 components, to be outdated soon

This list is not official, definitive or in some other kind authoritative or ordered by importance / priority.

Support libraries

Testing

@mbj
mbj / rspec-reset.rb
Created November 25, 2012 00:14
rspec-2 memory leak
# Solves the leak by nuking dynamically generated subclasses from vm
def clean
RSpec::Core::ExampleGroup.children.clear
RSpec::Core::ExampleGroup.constants.each do |name|
if name =~ /^Nested/
RSpec::Core::ExampleGroup.send(:remove_const, name)
end
end
end