diff --git a/ruby/gilded_rose.rb b/ruby/gilded_rose.rb index 01261571..622ae121 100644 --- a/ruby/gilded_rose.rb +++ b/ruby/gilded_rose.rb @@ -7,6 +7,8 @@ class GildedRose def update_quality @items.each do |item| case item.name + when 'Aged Brie' + update_aged_brie_quality(item) when 'Sulfuras, Hand of Ragnaros' update_sulfuras_quality(item) else @@ -51,6 +53,14 @@ class GildedRose end end + def update_aged_brie_quality(item) + item.sell_in -= 1 + + item.quality += 1 + item.quality += 1 if item.sell_in.negative? + item.quality = 50 if item.quality > 50 + end + def update_sulfuras_quality(item); end end diff --git a/ruby/specs/gilded_rose_spec.rb b/ruby/specs/gilded_rose_spec.rb index 77e994c0..e1213d7c 100644 --- a/ruby/specs/gilded_rose_spec.rb +++ b/ruby/specs/gilded_rose_spec.rb @@ -37,6 +37,20 @@ describe GildedRose do end end + context 'when 1 day left' do + let(:sell_in) { 1 } + + it 'lowers quality by 1' do + subject.update_quality + expect(items[0].quality).to eq 2 + end + + it 'lowers sell_in by 1' do + subject.update_quality + expect(items[0].sell_in).to eq 0 + end + end + it 'does never lower the quality below 0' do items = [Item.new(item_name, sell_in, 0)] subject.update_quality @@ -60,6 +74,20 @@ describe GildedRose do end end + context 'when 1 day left' do + let(:sell_in) { 1 } + + it 'does not lower quality by 1' do + subject.update_quality + expect(items[0].quality).to eq 80 + end + + it 'does not lower sell_in' do + subject.update_quality + expect(items[0].sell_in).to eq 1 + end + end + context 'when sell by date has passed' do let(:sell_in) { 0 } @@ -104,9 +132,23 @@ describe GildedRose do end end + context 'when 1 day left' do + let(:sell_in) { 1 } + + it 'increases quality by 1' do + subject.update_quality + expect(items[0].quality).to eq 4 + end + + it 'lowers sell_in by 1' do + subject.update_quality + expect(items[0].sell_in).to eq 0 + end + end + it 'does never raise the quality above 50' do items = [Item.new(item_name, sell_in, 50)] - subject.update_quality + GildedRose.new(items).update_quality expect(items[0].quality).to eq 50 end end @@ -143,6 +185,20 @@ describe GildedRose do end end + context 'when 1 day left' do + let(:sell_in) { 1 } + + it 'increases quality by 1' do + subject.update_quality + expect(items[0].quality).to eq 6 + end + + it 'lowers sell_in by 1' do + subject.update_quality + expect(items[0].sell_in).to eq 0 + end + end + context 'when sell by date has passed' do let(:sell_in) { 0 } @@ -159,7 +215,7 @@ describe GildedRose do it 'does never raise the quality above 50' do items = [Item.new(item_name, sell_in, 50)] - subject.update_quality + GildedRose.new(items).update_quality expect(items[0].quality).to eq 50 end end @@ -179,6 +235,20 @@ describe GildedRose do end end + context 'when 1 day left' do + let(:sell_in) { 1 } + + it 'lowers quality by 2' do + subject.update_quality + expect(items[0].quality).to eq 1 + end + + it 'lowers sell_in by 1' do + subject.update_quality + expect(items[0].sell_in).to eq 2 + end + end + context 'when sell by date has passed' do let(:sell_in) { 0 } let(:quality) { 6 } @@ -196,7 +266,7 @@ describe GildedRose do it 'does never lower the quality below 0' do items = [Item.new(item_name, sell_in, 0)] - subject.update_quality + GildedRose.new(items).update_quality expect(items[0].quality).to eq 0 end end