Skip to content

Instantly share code, notes, and snippets.

View Electron-libre's full-sized avatar

Cedric Brancourt Electron-libre

View GitHub Profile
@Electron-libre
Electron-libre / funny_to_read_spec.rb
Created February 17, 2014 14:03
This Rspec Test is funny daer, hem .. read
describe "link_with" do
let (:mirror) {create(:relation_kind, label: 'mirror')}
let (:rorrim) {create(:relation_kind, label: 'rorrim')}
it 'link relation kind both ways' do
mirror.link_with(rorrim)
expect(mirror.mirror_relation_kind).to eql rorrim
expect(rorrim.mirror_relation_kind).to eql mirror
end
end
@Electron-libre
Electron-libre / partner.rb
Created June 19, 2014 09:11
Bintje model example
class OpenObject::Partner
include OpenObjectModel
set_open_object_model 'res.partner'
## Where user context is the trinity : {uid: Int , dbname: String , pwd: String}
def my_custom_method(user_context)
OpenObject.rescue_xmlrpc_fault do
response = self.class.connection(user_context).execute(self.class.open_object_model, 'remoteOpenObjectMethod', self.id.to_i)
OpenObject::BackendResponse.new(success: true, content: response)
end
@Electron-libre
Electron-libre / any_spec.rb
Last active August 29, 2015 14:05
How to chain message expectation ?
require 'spec_helper'
describe Documents::PaymentSummaryPresenter do
describe 'deal_paid_deposits' do
let(:deal) {double()}
let(:deposit) {double()}
let(:presenter) { Documents::PaymentSummaryPresenter.new(deal) }
before(:each) do
deal.stub_chain(:deposits, :paid) {[deposit]}
end
"#top-menu ul li a".on('click', function(e){
e.preventDefault();
$('content').load(e.target.pathname);
e.target.parent().radioClass('active');
});
".opacify".on({
mouseover: function(e){
e.target.morph({opacity: '1'})
},
mouseout: function(e){
e.target.morph({opacity: '0.7'})
}
});
def integrity
if time_credit?
errors.add(:base, I18n.t(:establishment_cost_empty, :scope => [:models, :destinations, :integrity])) unless establishment_cost?
elsif establishment_cost?
errors.add(:base, I18n.t(:time_credit_empty, :scope => [:models, :destinations, :integrity])) unless time_credit?
end
end
def integrity
dependent_attributes = %w(time_credit establishment_cost)
nullity_proc = lambda{|attr| send(attr.to_sym).nil? || send(attr.to_sym).zero?}
dependent_attributes.each_index do |i|
if nullity_proc.call(dependent_attributes[i]) && !nullity_proc.call(dependent_attributes[i-1])
errors.add(dependent_attributes[i].to_sym, I18n.t("#{dependent_attributes[i]}_empty", :scope => [:models, :destinations, :integrity]))
end
end
end
@Electron-libre
Electron-libre / destination_prefixes.rb
Created February 16, 2011 15:08
to get ["1", "12", "123", "1234", "12345", "123456", "1234567", "12345678", "123456789", "1234567890"] with "123456789"
destination_number = cdr.called_number
prefixes_array = Array.new
destination_number.each_char do |char|
prefixes_array << (destination_number[-1] or '' ) + char
end
@files = ARGV
@files.each_with_index do |file, index|
pid = fork {
require 'stomp'
client = Stomp::Client.open("", "", "localhost", 61613)
def send_message(server, message, queue)
server.send("/cdr/cdr#{queue}", message, {})
end
def self.resolve(cdr)
prefixes_array = Array.new
cdr.called_number.each_char do |char|
prefixes_array << (prefixes_array[-1] or '') + char
end
prefixes_array.reverse!
best_match = Proc.new do |destinations, prefixes|