diff --git a/ruby/gilded_rose.rb b/ruby/gilded_rose.rb index 0e50f84a..d6f5c52c 100644 --- a/ruby/gilded_rose.rb +++ b/ruby/gilded_rose.rb @@ -37,6 +37,15 @@ class GildedRose quality: self.regular_quality_limit(next_quality) } end, + "Conjured Mana Cake" => Proc.new do |sell_in:, quality:| + next_sell_in = sell_in -1 + { + sell_in: next_sell_in, + quality: self.regular_quality_limit( + quality + (next_sell_in < 0 ? -4 : -2) + ) + } + end, } def self.regular_quality_limit(unsanitized_quality) diff --git a/ruby/gilded_rose_spec.rb b/ruby/gilded_rose_spec.rb index 7c0303f8..4ba4af08 100644 --- a/ruby/gilded_rose_spec.rb +++ b/ruby/gilded_rose_spec.rb @@ -122,6 +122,30 @@ describe GildedRose do expect(items[0].sell_in).to eq 1 # does not change expect(items[0].quality).to eq 80 # always 80 end + + it "degrades conjured cake quickly" do + items = [Item.new("Conjured Mana Cake", 2, 9)] + updater = GildedRose.new(items) + updater.update_quality() + + expect(items[0].sell_in).to eq 1 + expect(items[0].quality).to eq 7 # degrades twice as fast + + updater.update_quality() + + expect(items[0].sell_in).to eq 0 + expect(items[0].quality).to eq 5 # still above zero + + updater.update_quality() + + expect(items[0].sell_in).to eq -1 + expect(items[0].quality).to eq 1 # still above zero + + updater.update_quality() + + expect(items[0].sell_in).to eq -2 + expect(items[0].quality).to eq 0 # does not go below zero + end end end