Move setting availability to sync method
This commit is contained in:
parent
cd164bc3eb
commit
25deefced1
3 changed files with 25 additions and 9 deletions
|
@ -181,13 +181,9 @@ class ArticlesController < ApplicationController
|
||||||
has_error = true
|
has_error = true
|
||||||
end
|
end
|
||||||
# Update articles
|
# Update articles
|
||||||
@updated_articles.map{|a| a.save or has_error=true }
|
@updated_articles.each {|a| a.save or has_error=true }
|
||||||
# Add new articles
|
# Add new articles
|
||||||
@new_articles.each do |article|
|
@new_articles.each {|a| a.save or has_error=true }
|
||||||
article.availability = true if @supplier.shared_sync_method == 'all_available'
|
|
||||||
article.availability = false if @supplier.shared_sync_method == 'all_unavailable'
|
|
||||||
article.save or has_error=true
|
|
||||||
end
|
|
||||||
|
|
||||||
raise ActiveRecord::Rollback if has_error
|
raise ActiveRecord::Rollback if has_error
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,11 +52,16 @@ class Supplier < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# Find any new articles, unless the import is manual
|
# Find any new articles, unless the import is manual
|
||||||
unless shared_sync_method == 'import'
|
if ['all_available', 'all_unavailable'].include?(shared_sync_method)
|
||||||
|
# build new articles
|
||||||
shared_supplier
|
shared_supplier
|
||||||
.shared_articles
|
.shared_articles
|
||||||
.where.not(id: existing_articles.to_a)
|
.where.not(id: existing_articles.to_a)
|
||||||
.find_each { |new_shared_article| new_articles << new_shared_article.build_new_article(self) }
|
.find_each { |new_shared_article| new_articles << new_shared_article.build_new_article(self) }
|
||||||
|
# make them unavailable when desired
|
||||||
|
if shared_sync_method == 'all_unavailable'
|
||||||
|
new_articles.each {|new_article| new_article.availability = false }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return [updated_article_pairs, outlisted_articles, new_articles]
|
return [updated_article_pairs, outlisted_articles, new_articles]
|
||||||
end
|
end
|
||||||
|
|
|
@ -73,8 +73,23 @@ describe Supplier do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Setting articles to unavailable with sync method all_unavailable
|
context 'with sync method all_unavailable' do
|
||||||
# is handled in the articles controller, so no need to test it here.
|
let(:shared_sync_method) { 'all_unavailable' }
|
||||||
|
|
||||||
|
it 'returns the expected articles' do
|
||||||
|
updated_article_pairs, outlisted_articles, new_articles = supplier.sync_all
|
||||||
|
|
||||||
|
expect(updated_article_pairs).to_not be_empty
|
||||||
|
expect(updated_article_pairs[0][0].id).to eq updated_article.id
|
||||||
|
expect(updated_article_pairs[0][1].keys).to include :origin
|
||||||
|
|
||||||
|
expect(outlisted_articles).to eq [removed_article]
|
||||||
|
|
||||||
|
expect(new_articles).to_not be_empty
|
||||||
|
expect(new_articles[0].order_number).to eq new_shared_article.number
|
||||||
|
expect(new_articles[0].availability?).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue