Skip to content

Instantly share code, notes, and snippets.

View aldesantis's full-sized avatar

Alessandro Desantis aldesantis

View GitHub Profile
require 'active_support/concern'
module Processable
extend ActiveSupport::Concern
included do
scope :processed, ->{ where processed: true }
scope :unprocessed, ->{ where processed: false }
end
class Task < ActiveRecord::Base
include Processable
end
require 'rails_helper'
RSpec.describe Processable do
before(:all) do
Temping.create :processable_model do
include Processable
with_columns do |t|
t.boolean :processable, default: false
end
require 'rails_helper'
RSpec.describe Processable do
# ...
describe '#mark_as_processed!' do
it 'updates the processed column to true' do
subject
.expects(:update_column)
.with(:processed, true)
@aldesantis
aldesantis / sidekiq.rb
Created September 13, 2014 19:06
Executing Sidekiq Jobs Immediately
if ENV['DISABLE_ASYNC']
require 'sidekiq/testing'
Sidekiq::Testing.inline!
end
version: 8.4.3 (api:1/proto:86-101)
srcversion: F97798065516C94BE0F27DC
0: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate C r-----
ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
angular.module('controllers', []).controller('SessionsController', ['$scope', '$translate',
($scope, $translate)->
$scope.labels = []
$translate(['models.user.labels.email', 'models.user.labels.password']).then(
(translations)->
$scope.foo = 'bar'
$scope.labels = translations['models.user.labels.email']
console.log 'promise resolved'
)
class TranslationsController < ApplicationController
respond_to :json
def show
@locale = params[:id].to_sym
@translations = I18n.with_locale(@locale) do
I18n.backend.send(:translations)[@locale]
end
app = angular.module('app', [
'pascalprecht.translate'
]);
app.config(['$translateProvider', function($translateProvider) {
$translateProvider.useStaticFilesLoader({
prefix: 'translations/',
suffix: '.json'
});
Rails.application.routes.draw do
resources :translations, only: :show
end