Skip to content

Commit

Permalink
On #8: Adapted article version unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed Apr 19, 2024
1 parent b4a9624 commit 331cbe0
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions spec/models/article_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,36 @@
let(:article_version) { order.order_articles.first.article_version }
let(:article) { article_version.article }

it 'updates the name of articles in open orders in place' do
article.update(latest_article_version_attributes: { name: 'new name', id: article_version.id })
it 'updates the properties of article versions in open orders in place' do
original_version_id = article_version.id

expect(order.order_articles.first.article_version.name).to eq 'new name'
new_version = create(:article_version)
new_attributes = new_version.attributes.except('updated_at', 'created_at', 'id', 'article_id')

article.update(latest_article_version_attributes: new_attributes.merge(id: article_version.id))

new_attributes.each do |key, value|
expect(order.order_articles.first.article_version[key]).to eq value
end
expect(original_version_id).to eq article.latest_article_version.id
end

it 'keeps the names of articles in closed orders' do
original_name = article_version.name
it 'keeps the properties of article versions in closed orders' do
original_version_id = article_version.id
original_version = article_version.dup

new_version = create(:article_version)
new_attributes = new_version.attributes.except('updated_at', 'created_at', 'id', 'article_id')

order.finish!(admin)

article.update(latest_article_version_attributes: { name: 'new name', id: article_version.id })
article.update(latest_article_version_attributes: new_attributes.merge(id: article_version.id))

expect(article.latest_article_version.name).to eq 'new name'
expect(order.order_articles.first.article_version.name).to eq original_name
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]
end
expect(original_version_id).not_to eq article.latest_article_version.id
end
end

Expand Down

0 comments on commit 331cbe0

Please sign in to comment.