Skip to content

Instantly share code, notes, and snippets.

View jasononaquest's full-sized avatar

Jason Harrison jasononaquest

View GitHub Profile
params.each_key do |key|
if RESERVED_KEYS.include?(key)
params.delete(key)
end
end
@jasononaquest
jasononaquest / gist:df6a11aaab327cd7795e
Created April 6, 2015 17:17
The old List model (Rails 1.2.6 version)
class List < ActiveRecord::Base
acts_as_paranoid
has_many :categories,
:dependent=>:destroy,
:order => "categories.position"
has_many :items,
:order => "items.position"
belongs_to :user
@jasononaquest
jasononaquest / copy_list_spec.rb
Last active August 29, 2015 14:18
copy_list_spec.rb
require 'rails_helper'
require './app/services/copy_list'
describe CopyList, type: :service do
describe 'given an existing list and a list name' do
let(:list) { list = List.create(name: 'my list') }
let(:category) { Category.create(name: 'my category', list: list) }
let!(:item) { Item.create(name: 'my item', category: category)
let(:new_name) { 'my new list' }
@jasononaquest
jasononaquest / list.rb
Created April 6, 2015 23:49
List#copy
def self.copy(lists, new_list_name, current_user)
new_list = current_user.lists.create(:name => new_list_name)
lists.each do |list|
list.categories.find(:all, :conditions=>["categories.deleted_at is null or categories.deleted_at > '#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}'"]).each do |category|
new_category = new_list.categories.create(:name => category.name,
:user_id => category.user_id,
:position => category.position)
category.items.find(:all, :conditions=>["items.deleted_at is null or items.deleted_at > '#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}'"]).each do |item|
new_category.items.create(:name => item.name,
@jasononaquest
jasononaquest / copy_list_spec.rb
Created April 6, 2015 23:52
copy_list_spec.rb
require 'spec_helper'
require './app/services/copy_list'
describe CopyList, type: :service do
it 'responds to #call' do
expect(described_class).to respond_to(:call)
end
end
@jasononaquest
jasononaquest / copy_list.rb
Last active August 29, 2015 14:18
copy_list.rb
class CopyList
attr_reader :list, :new_name
def initialize(list, new_name)
@list = list
@new_name = new_name
end
def call
@jasononaquest
jasononaquest / copy_list.rb
Created April 6, 2015 23:54
copy_list.rb
class CopyList
class << self
def call(list, name, user)
end
end
end
@jasononaquest
jasononaquest / copy_list.rb
Created April 7, 2015 16:51
copy_list.rb
class CopyList
class << self
def call(list, name, user)
if list.user_id = user.id
new_list = list.dup
new_list.name = name
new_list.save
new_list
end
@jasononaquest
jasononaquest / copy_list_spec.rb
Last active August 29, 2015 14:18
copy_list_spec.rb
require 'rails_helper'
require './app/services/copy_list'
describe CopyList, type: :service do
describe 'given an existing list and a name' do
let(:list) { list = List.create(name: 'my list') }
let(:category) { Category.create(name: 'my category', list: list) }
let!(:item) { Item.create(name: 'my item', category: category) }
let(:new_name) { 'my new list' }
@jasononaquest
jasononaquest / copy_list.rb
Last active August 29, 2015 14:18
copy_list.rb
class CopyList
attr_reader :list, :new_name
def initialize(list, new_name)
@list = list
@new_name = new_name
end
def call