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
params.each_key do |key| | |
if RESERVED_KEYS.include?(key) | |
params.delete(key) | |
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 List < ActiveRecord::Base | |
acts_as_paranoid | |
has_many :categories, | |
:dependent=>:destroy, | |
:order => "categories.position" | |
has_many :items, | |
:order => "items.position" | |
belongs_to :user |
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 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' } |
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
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, |
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 |
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
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 | |
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
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 | |
attr_reader :list, :new_name | |
def initialize(list, new_name) | |
@list = list | |
@new_name = new_name | |
end | |
def call |
OlderNewer