mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 16:01:42 +00:00
update_normal_item method updates items without quality allowances if quality > 0
This commit is contained in:
parent
2b410aa50b
commit
27860ced34
@ -7,11 +7,11 @@ class GildedRose
|
|||||||
def self.update_quality(items)
|
def self.update_quality(items)
|
||||||
items.map do |item|
|
items.map do |item|
|
||||||
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert"
|
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert"
|
||||||
if item.quality > 0
|
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros"
|
if item.name != "Sulfuras, Hand of Ragnaros"
|
||||||
item.quality = item.quality - 1
|
update_normal_quality(item)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
else
|
else
|
||||||
if item.quality < 50
|
if item.quality < 50
|
||||||
item.quality = item.quality + 1
|
item.quality = item.quality + 1
|
||||||
@ -52,6 +52,10 @@ class GildedRose
|
|||||||
end
|
end
|
||||||
items
|
items
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.update_normal_quality(item)
|
||||||
|
item.quality -= 1 unless item.quality.zero?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Item
|
class Item
|
||||||
|
|||||||
@ -2,6 +2,7 @@ require 'gilded_rose'
|
|||||||
|
|
||||||
describe GildedRose do
|
describe GildedRose do
|
||||||
let(:potato) { Item.new('potato', 15, 2)}
|
let(:potato) { Item.new('potato', 15, 2)}
|
||||||
|
#let(:grain) {instance_double("item", name: "potato", :quality => 5)}
|
||||||
let(:sulfarus) { Item.new('Sulfuras, Hand of Ragnaros', 50, 80) }
|
let(:sulfarus) { Item.new('Sulfuras, Hand of Ragnaros', 50, 80) }
|
||||||
|
|
||||||
describe "#update_quality" do
|
describe "#update_quality" do
|
||||||
@ -84,10 +85,23 @@ let(:sulfarus) { Item.new('Sulfuras, Hand of Ragnaros', 50, 80) }
|
|||||||
expect(items.first.quality).to eq 0
|
expect(items.first.quality).to eq 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
describe '#update_normal_quality' do
|
||||||
|
it 'updates the quality of a normal item' do
|
||||||
|
item_double = double :item, name: "potato", sellIn: 1, quality: 3
|
||||||
|
expect(item_double).to receive(:quality=).with(2)
|
||||||
|
GildedRose.update_normal_quality(item_double)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not update quality if quality == 0' do
|
||||||
|
item_double = double :item, name: "potato", sellIn: 1, quality: 0
|
||||||
|
expect(item_double).not_to receive(:quality=).with(-1)
|
||||||
|
GildedRose.update_normal_quality(item_double)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user