Skip to content

Instantly share code, notes, and snippets.

View JasonSpatial's full-sized avatar

Jason Harrison JasonSpatial

View GitHub Profile
# index on spotify_id in Track, Artist, and Album tables?
class SaveTracksWorker
include Sidekiq::Worker
def perform(user_id, tracks_with_date, kind = 'added')
# Find user these tracks are associated with, if a user_id is passed
# index on user_id?
@JasonSpatial
JasonSpatial / copy_list_controller_example.rb
Last active August 29, 2015 14:18
CopyList controller example
if !params[:new_list_name].present?
# make sure we're scoping to the logged in user
@list = current_user.lists.find(params[:id])
@new_list_name = params[:new_list_name]
if @new_list = CopyList.call(@list, @new_list_name)
redirect_to lists_path, notice: "#{@new_list_name} created from your selected list"
else
redirect_to :back, alert: "We were unable to copy your selected list"
end
@JasonSpatial
JasonSpatial / 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
@JasonSpatial
JasonSpatial / 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) do
list = List.create(name: 'my list')
category = list.categories.create(name: 'my category')
category.items.create(name: 'my item')
@JasonSpatial
JasonSpatial / 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
@JasonSpatial
JasonSpatial / 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' }
@JasonSpatial
JasonSpatial / 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
@JasonSpatial
JasonSpatial / copy_list.rb
Created April 6, 2015 23:54
copy_list.rb
class CopyList
class << self
def call(list, name, user)
end
end
end
@JasonSpatial
JasonSpatial / 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
@JasonSpatial
JasonSpatial / 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