diff --git a/app.rb b/app.rb index 01ad886..f2e0983 100644 --- a/app.rb +++ b/app.rb @@ -113,6 +113,7 @@ def load_data end end + # save games to database def save_games update_games = [] @games.each do |game| @@ -123,6 +124,7 @@ def save_games File.write('json/games.json', JSON.generate(update_games)) end + # save authors to the database def save_authors authors_data = @authors.map do |author| { 'id' => author.id, 'first_name' => author.first_name, 'last_name' => author.last_name } diff --git a/spec/author_spec.rb b/spec/author_spec.rb new file mode 100644 index 0000000..2c4a947 --- /dev/null +++ b/spec/author_spec.rb @@ -0,0 +1,18 @@ +require_relative '../author' + +describe Author do + let(:author) { Author.new('John', 'Doe') } + + 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 diff --git a/spec/game_spec.rb b/spec/game_spec.rb new file mode 100644 index 0000000..bb71c1b --- /dev/null +++ b/spec/game_spec.rb @@ -0,0 +1,42 @@ +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