Skip to content

Instantly share code, notes, and snippets.

class ProductImageCollection
def initialize(images)
self.images = load_images(images)
end
def images_for(group: nil, color: nil, size: nil)
processor = ProductImageCollectionProcessor.new(images.clone)
processor.filter(group, color)
processor.resize(size) if size.present?
before(:each) { Rails.cache.clear }
let(:magento_response) { "file in VCR"}
subject(:inventory} {...]
specify {expect(inventory.results).to eq magento_response }
filename = ARVG[0]
content = File.read(filename)
snippets = content.split("\n\n\n")
snippets.each_with_index do |snippet, index|
f = File.new("snippet_#{index}.js")
f.write(snippet)
end
module Apibase
class User
def self.find_by_api_token(token)
if token.present?
users.find { |u| u['api_key'] == token }
else
nil
end
end
@dangalipo
dangalipo / order.rb
Last active December 30, 2015 18:19
RSpec::Matchers.define :match_unordered_json_string do |json_string|
match do |actual|
sort_hash(JSON.parse(actual)).to_json == sort_hash(JSON.parse(json_string)).to_json
end
description do
"be in the correct order"
end
class JsonTarget
attr_accessor :votes_count, :votes_percentage, :position, :type, :media, :post
def factory_hash
{
position: position,
type: type,
media: media,
post: post
}
@dangalipo
dangalipo / gist:7637497
Last active December 29, 2015 07:39
hash sort
def sort_hash(hash)
sorted_hash = {}
hash.keys.sort.each do |k|
if hash[k].is_a?(Hash)
sorted_hash[k] = sort_hash(hash[k])
elsif hash[k].is_a?(Array) && hash[k].first.is_a?(Hash)
sorted_hash[k] = hash[k].collect{ |h| sort_hash(h) }
else
sorted_hash[k] = hash[k]
end
def pending_subscription_creation_required?
updated_pending_subscription_required? || new_pending_subscription_required?
end
def updated_pending_subscription_required?
@account.pending_subscription.present?
end
def new_pending_subscription_required?
def recordings
super do |recordings|
recordings = recordings.with_rejected_readings if self.with_rejected_readings.present?
recordings
end
end
def accepted_rejected_pie_chart_data
readings = FoodReadings.where(food_recording_id: recordings.collect(&:id))
accepted = FoodReadings.where(food_recording_id: recordings.collect(&:id)).with_section(self.section_id).accepted.count }
require 'spec_helper'
describe GSTCalculator do
describe '#ex_gst_amount' do
end
describe '#gst_amount' do