From f1acc821e80c62c3447712a1b173fb278bc38175 Mon Sep 17 00:00:00 2001 From: Fatma Hussein Date: Wed, 25 Oct 2023 08:45:07 +0300 Subject: [PATCH] fix errors --- classes/author.rb | 30 +++++++++++++++--------------- classes/game.rb | 2 +- spec/author_spec.rb | 21 --------------------- spec/game_spec.rb | 42 ------------------------------------------ 4 files changed, 16 insertions(+), 79 deletions(-) delete mode 100644 spec/author_spec.rb delete mode 100644 spec/game_spec.rb diff --git a/classes/author.rb b/classes/author.rb index 0f7bfaa..e0e07f0 100644 --- a/classes/author.rb +++ b/classes/author.rb @@ -1,16 +1,16 @@ class Author - attr_reader :id, :first_name, :last_name - attr_accessor :items - - def initialize(first_name, last_name) - @id = Random.rand(1..1000) - @first_name = first_name - @last_name = last_name - @items = [] - end - - def add_item(item) - item.author = self - @items << item - end - end \ No newline at end of file + attr_reader :id, :first_name, :last_name + attr_accessor :items + + def initialize(first_name, last_name) + @id = Random.rand(1..1000) + @first_name = first_name + @last_name = last_name + @items = [] + end + + def add_item(item) + item.author = self + @items << item + end +end diff --git a/classes/game.rb b/classes/game.rb index 9b6ec1c..0462a33 100644 --- a/classes/game.rb +++ b/classes/game.rb @@ -28,4 +28,4 @@ def last_played_over_two_years_ago? years_difference >= 2 end -end \ No newline at end of file +end diff --git a/spec/author_spec.rb b/spec/author_spec.rb deleted file mode 100644 index 770caf5..0000000 --- a/spec/author_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../author' -require_relative '../book' - -describe Author do - let(:author) { Author.new('John', 'Doe') } - let(:game) { Game.new('2012-01-01', false, true, '2014-01-01', author) } - let(:book) { Book.new('2012-01-01', false, 'The Great Gatsby', 'F. Scott Fitzgerald', author) } - let(:movie) { Movie.new('2012-01-01', false, 'The Godfather', 'Francis Ford Coppola', author) } - describe '#add_item' do - context 'when the item is a game' do - it 'adds the item to the author' do - author.add_item(game) - expect(author.items).to include(game) - end - it 'sets the author of the game' do - author.add_item(game) - expect(game.author).to eq(author) - end - end - end -end \ No newline at end of file diff --git a/spec/game_spec.rb b/spec/game_spec.rb deleted file mode 100644 index b2a8d40..0000000 --- a/spec/game_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require_relative '../game' -describe Game do - let(:game) { Game.new(publish_date, archived, multiplayer, last_played_at, author) } - let(:publish_date) { '2012-01-01' } - let(:archived) { false } - let(:multiplayer) { true } - let(:last_played_at) { '2014-01-01' } - let(:author) { Author.new('John', 'Doe') } - describe '#can_be_archived?' do - context 'when the game is archived and last played over two years ago' do - let(:archived) { true } - let(:last_played_at) { '2014-01-01' } - it 'returns true' do - expect(game.can_be_archived?).to eq(true) - end - end - context 'when the game is not archived' do - let(:archived) { false } - context 'and the game was last played over two years ago' do - let(:last_played_at) { '2014-01-01' } - it 'returns false' do - expect(game.can_be_archived?).to eq(true) - end - end - context 'and the game was last played less than two years ago' do - let(:last_played_at) { '2015-01-01' } - it 'returns false' do - expect(game.can_be_archived?).to eq(true) - end - end - end - context 'when the game is archived' do - let(:archived) { true } - context 'and the game was last played over two years ago' do - let(:last_played_at) { '2014-01-01' } - it 'returns true' do - expect(game.can_be_archived?).to eq(true) - end - end - end - end -end \ No newline at end of file