Skip to content

Instantly share code, notes, and snippets.

View dbarrionuevo's full-sized avatar

Darío Barrionuevo dbarrionuevo

  • San Miguel de Tucumán
View GitHub Profile
@dbarrionuevo
dbarrionuevo / rspec_model_testing_template.rb
Last active July 27, 2017 16:38 — forked from SabretWoW/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails.
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
describe Model do
# Lazily loaded to ensure it's only used when it's needed
# Try to avoid @instance_variables if possible. They're slow.
let(:factory_instance) { build(:some_factory) }
describe 'ActiveRecord validations' do
{
"ensure_newline_at_eof_on_save": true,
"file_exclude_patterns":
[
".DS_Store",
".tags*",
"*.pyc",
"*.pyo",
"*.exe",
"*.dll",
// Update subtotal and total amounts on checkout, considering fees
GrowDough.Behaviors.UpdateTotal = Essential.Behavior.extend({
init: function() {},
events: {
'keyup': 'updateSubtotal'
},
updateSubtotal: function(e, force) {
// Keys and events on which the behavior has to update totals
<img
alt=""
class="producto-imagen"
src="productos/obtenerimagen/?id=5&amp;useDensity=true&amp;width=640&amp;height=360&amp;tipoEscala=contain"
data-bind="ghostTo: agregandoACarrito, ghostToTarget: $('.cartCount'), attr:{width: width, ___height: height}, src:imagenes.representativa &amp;&amp; imagenes.representativa() &amp;&amp; imagenes.representativa().get &amp;&amp; imagenes.representativa().get({width: width, height: height, tipoEscala: 'contain', useDensity: true}) || '/img/px.gif'"
width="640"
___height="360"
>
# app/controllers/sessions_controller.rb
class SessionsController < ApplicationController
def login
if current_user
redirect_to root_path
return
end
@redirect_path = { path: "/auth/facebook", message: { notice: "Logged in successfully" } }
parse_to_path if params[:to]
redirect_to @redirect_path[:path], @redirect_path[:message]
# app/controllers/sessions_controllers.rb
def login
url = "/auth/facebook"
url += "?" + params.try(:to_param) if params
session[:from] = params[:to] if params.any?
redirect_to url #unless user_signed_in?
end
# app/controllers/videos_controller.rb
def destroy
video = Video.find params[:id]
video.destroy if video
render :nothing => true
end
# config/routes.rb
resources :photos, only: [:create]
resources :videos, only: [:create]
# app/controllers/photos_controller.rb
@file = params[:file] || params[:facebook_image_url]
if params[:facebook_image_url] && params[:access_token]
@photo.image = open(@file + "?access_token=" + params[:access_token])
else …
@dbarrionuevo
dbarrionuevo / omniauth.rb
Created August 7, 2013 14:35
Workflow to ensure correct catch of Omniauth login failure. Specs included.
OmniAuth.config.on_failure = Proc.new { |env|
OmniAuth::FailureEndpoint.new(env).redirect_to_failure
}