Skip to content

Instantly share code, notes, and snippets.

View huoxito's full-sized avatar
🏊‍♂️

Washington L Braga Jr huoxito

🏊‍♂️
View GitHub Profile
@huoxito
huoxito / rollback_infinite_loop.rb
Created August 25, 2014 22:07
Rollback infinite loop
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', path: '../rails'
gem 'arel', '~> 5.0.0'
gem 'rack', '~> 1.5.2'
gem 'i18n', github: 'svenfuchs/i18n'
gem 'sqlite3'
gem 'rspec-rails', '~> 2.14.0'
GEMFILE
@huoxito
huoxito / rollback_test.rb
Created August 25, 2014 21:50
Rollback loop
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', path: '../rails'
gem 'arel', '~> 5.0.0'
gem 'rack', '~> 1.5.2'
gem 'i18n', github: 'svenfuchs/i18n'
gem 'sqlite3'
GEMFILE
@huoxito
huoxito / loop.log.sql
Last active August 29, 2015 14:05
Stack level too deep <3 callbacks
Running #persist_invalid:
(0.1ms) begin transaction
(0.0ms) SAVEPOINT active_record_1
Spree::Order Exists (0.1ms) SELECT 1 AS one FROM "spree_orders" WHERE "spree_orders"."number" = 'R287523099' LIMIT 1
(0.1ms) SELECT COUNT(*) FROM "spree_orders" WHERE (spree_orders.number LIKE 'R287523099%')
Spree::Order Exists (0.1ms) SELECT 1 AS one FROM "spree_orders" WHERE "spree_orders"."number" = 'R287523099' LIMIT 1
Running #confirmation_required?
Spree::Order Exists (0.1ms) SELECT 1 AS one FROM "spree_orders" WHERE "spree_orders"."guest_token" = 'Z_tTol42m1nKm4Ghfwm8YA' LIMIT 1
SQL (0.8ms) INSERT INTO "spree_orders" ("created_at", "currency", "guest_token", "number", "state", "updated_at") VALUES (?, ?, ?, ?, ?,
?) [["created_at", "2014-08-25 17:36:26.478451"], ["currency", "USD"], ["guest_token", "Z_tTol42m1nKm4Ghfwm8YA"], ["number", "R287523099"],
@huoxito
huoxito / product.destroy.sql
Created August 6, 2014 03:27
A `product.destroy` query in spree
FriendlyId::Slug Load (0.8ms) SELECT "friendly_id_slugs".* FROM "friendly_id_slugs" WHERE "friendly_id_slugs"."sluggable_id" = $1 AND "friendly_id_slugs"."sluggable_type" = $2 ORDER BY "friendly_id_slugs".id DESC [["sluggable_id", 1], ["sluggable_type", "Spree::Product"]]
(0.1ms) BEGIN
SQL (0.2ms) DELETE FROM "friendly_id_slugs" WHERE "friendly_id_slugs"."id" = $1 [["id", 17]]
SQL (0.2ms) DELETE FROM "friendly_id_slugs" WHERE "friendly_id_slugs"."id" = $1 [["id", 1]]
(0.4ms) COMMIT
Spree::ProductOptionType Load (0.6ms) SELECT "spree_product_option_types".* FROM "spree_product_option_types" WHERE "spree_product_option_types"."product_id" = $1 [["product_id", 1]]
Spree::ProductProperty Load (0.6ms) SELECT "spree_product_properties".* FROM "spree_product_properties" WHERE "spree_product_properties"."product_id" = $1 ORDER BY spree_product_properties.position [["product_id", 1]]
(0.1ms) BEGIN
SQL (0.2ms) DELETE FROM "spree_product_properties" WHERE "spree_product_properties
@huoxito
huoxito / order.json
Created August 3, 2014 07:22
Example order to be imported in spree
{
"order": {
"number": "REREGEGERGRRG",
"state": "complete",
"channel": "spree",
"email": "[email protected]",
"currency": "USD",
"completed_at": "2014-08-03T09:08:57Z",
"adjustments_attributes": [
{
@huoxito
huoxito / json_validator.json
Created July 8, 2014 16:57
JSON schema validator
{
"title": "Product Schema",
"type": "object",
"required": [
"sku",
"description",
"price",
"cost_price"
],
"properties": {
@huoxito
huoxito / checkout_flow.md
Last active August 29, 2015 14:02
Hey yo make this clean consice intuitive c'mon

Create order

Users should be able to set things like email, currency or any Order value not dependent on other objects.

curl -H 'X-Spree-Token: 123' -X POST http://localhost:9292/api/orders.json

api/orders.json should be the root path for creating the orders.

module Spree
Gateway::AdyenPaymentEncrypted.class_eval do
def require_3d_secure?(payment)
if payment.order && payment.order.bill_address.city == "Bethesda"
false
else
true
end
end
module Spree
Order.class_eval do
# NOTE Overriden spree core
def confirmation_required?
false
end
# NOTE Overriden spree core
#
# Currently Spree 2-2-stable raises an error any time Order#process_payments!
require 'httparty'
Spree::CheckoutController.class_eval do
include Spree::Adyen::CheckoutRescue
Spree::Payment.send :attr_accessor, :request_env
Spree::PermittedAttributes.payment_attributes.push request_env: ['HTTP_USER_AGENT', 'HTTP_ACCEPT']
Spree::PermittedAttributes.source_attributes.push :customer_enabled
before_filter :set_payment_request_env, only: :update