From 067669d62bc42c8ccb5d4e98de376ce9c75b4759 Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Thu, 17 Oct 2013 11:24:58 +0100 Subject: [PATCH] Add song class. --- models/song.rb | 15 +++++++++++++++ spec/models/song_spec.rb | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 models/song.rb create mode 100644 spec/models/song_spec.rb diff --git a/models/song.rb b/models/song.rb new file mode 100644 index 0000000..b1e1195 --- /dev/null +++ b/models/song.rb @@ -0,0 +1,15 @@ +require './models/mpd_connection' + +class Song < Struct.new(:artist, :album, :title) + + def initialize(song) + @song = song + self.artist = song.artist + self.album = song.album + self.title = song.title + end + + def self.queue + MPDConnection.mpd.queue.map { |song| self.new(song) } + end +end diff --git a/spec/models/song_spec.rb b/spec/models/song_spec.rb new file mode 100644 index 0000000..93f3430 --- /dev/null +++ b/spec/models/song_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe Song do + + let(:song1) { MPD::Song.new({ title: 'Back in Black', album: 'Back in Black', genre: 'Rock', date: '1980' }) } + let(:song2) { MPD::Song.new({ title: 'Highway to Hell', album: 'Highway to Hell', genre: 'Rock', date: '1979' }) } + + before do + MPDConnection.mpd.stub(:queue).and_return([song1, song2]) + end + + it 'returns the queue of songs' do + queue = Song.queue + expect(queue).to have(2).items + end +end