diff --git a/app/models/article.rb b/app/models/article.rb index 7d828a19..1f368de1 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -298,9 +298,17 @@ def reload_article_on_version_change end def version_dup_required? - return false if latest_article_version.nil? - return false unless latest_article_version.self_or_ratios_changed? + if latest_article_version.nil? + puts 'version_dup_required? no latest_article_version' + return false + end + unless latest_article_version.self_or_ratios_changed? + puts 'version_dup_required? unchanged' + return false + end - OrderArticle.belonging_to_finished_order.exists?(article_version_id: latest_article_version.id) + ret = OrderArticle.belonging_to_finished_order.exists?(article_version_id: latest_article_version.id) + puts "version_dup_required? finished_order? #{ret}" + ret end end diff --git a/spec/models/article_version_spec.rb b/spec/models/article_version_spec.rb index 6a9f302e..190e87f2 100644 --- a/spec/models/article_version_spec.rb +++ b/spec/models/article_version_spec.rb @@ -34,13 +34,23 @@ order.finish!(admin) + puts 'Updating...' article.update(latest_article_version_attributes: new_attributes.merge(id: article_version.id)) + new_version = article.latest_article_version + version_in_order = order.order_articles.first.reload.article_version + + puts "ID: #{original_version_id} <-> #{version_in_order.id} vs #{new_version.id}" + new_version.attributes.except('id').each_key do |key| + puts "#{original_version[key] == version_in_order[key] ? 'EQ' : 'NEQ'}: '#{key}': {#{original_version[key]}} <-> {#{version_in_order[key]}}" + end + + expect(original_version_id).not_to eq new_version.id + expect(original_version_id).to eq version_in_order.id new_attributes.each do |key, value| - expect(article.latest_article_version[key]).to eq value - expect(order.order_articles.first.article_version[key]).to eq original_version[key] + expect(new_version[key]).to eq value + expect(version_in_order[key]).to eq(original_version[key]), "'#{key}' property changed: Old {#{original_version[key]}} <-> Current {#{version_in_order[key]}}" end - expect(original_version_id).not_to eq article.latest_article_version.id end end