This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CopyList | |
attr_reader :list, :new_name | |
def initialize(list, new_name) | |
@list = list | |
@new_name = new_name | |
end | |
def call |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CopyList | |
attr_reader :list, :new_name | |
def initialize(list, new_name) | |
@list = list | |
@new_name = new_name | |
end | |
def call |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CopyList | |
class << self | |
def call(list, name, user) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CopyList | |
attr_reader :list, :new_name | |
def initialize(list, new_name) | |
@list = list | |
@new_name = new_name | |
end | |
def call |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder