Skip to content

Instantly share code, notes, and snippets.

View theCrab's full-sized avatar
💭
What happens when you take a long holiday from work? Shit happens

The Crab theCrab

💭
What happens when you take a long holiday from work? Shit happens
View GitHub Profile
@theCrab
theCrab / authenticication_helpers.rb
Created March 14, 2013 15:03
Spree RSpec sign_in_as!(user) helper method undefined spec/spec_helper.rb spec/support/authenticication_helpers.rb
module AuthenticationHelpers
def sign_in_as!(user)
visit '/login'
fill_in 'Email', :with => user.email
fill_in 'Password', :with => "secret"
click_button 'Login'
end
end
RSpec.configure do |config|
@theCrab
theCrab / SKU.rb
Last active December 14, 2015 14:18
Auto generating an SKU and appending it to the Master product
# I have a product with a master_SKU = 'BBLZ-A0-00000'
# auto generate a variant SKU for each product variant
# @return variant_SKU = 'BBLZ-A0-00001' OR 'BBLZ-A0-00020'
variants = Product.variants
variants_len = variants.length
i = 0
master_SKU = 'BBLZ-A0-'
v_sku = '00000'
while i < variants_len
class Friendship < ActiveRecord::Base
attr_accessible :friend_id, :user_id, :status
belongs_to :user
belongs_to :friend, :class_name => 'User', :counter_cache => :friends_count
def self.request(user, friend)
unless user == friend or Friendship.where(:user_id => user, :friend_id => friend).exists?
transaction do
create({:user => user, :friend => friend, :status => 'pending'}, :without_protection => true)
create({:user => friend, :friend => user, :status => 'requested'}, :without_protection => true)
@theCrab
theCrab / variants.md
Created February 26, 2013 22:23
This graphic shows what am trying to achieve. Any ideas

admin_product_path

How do i deal with the update method accepting variant_ids? Is it the same way the create method creates each variant from the array of prototypes?

ProductVarintsManagement

@theCrab
theCrab / property.rb
Created February 19, 2013 15:38
Decipher this
class Property
include DataMapper::Resource
property :id, Serial
property :name, String, required: true
property :price, Integer, required: true
property :description, Text
has 1, :address
has n, :rooms