Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started writing tests, added mpd library and sample music, moved arou…
…nd configs a bit
- Loading branch information
Jonathan Hoyt
committed
Jan 19, 2010
1 parent
d4888b1
commit d377be9
Showing
12 changed files
with
202 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'librmpd' | ||
|
||
class Player | ||
|
||
def self.play | ||
with_mpd do |mpd| | ||
mpd.play | ||
end | ||
end | ||
|
||
def self.next_song | ||
with_mpd do |mpd| | ||
mpd.next | ||
end | ||
end | ||
|
||
def self.previous_song | ||
with_mpd do |mpd| | ||
mpd.previous | ||
end | ||
end | ||
|
||
def self.stop | ||
with_mpd do |mpd| | ||
mpd.stop | ||
end | ||
end | ||
|
||
def self.clear | ||
with_mpd do |mpd| | ||
mpd.clear | ||
end | ||
end | ||
|
||
def self.with_mpd(&block) | ||
mpd = MPD.new 'localhost', APP_CONFIG[:mpd_port] | ||
mpd.connect | ||
if mpd.connected? | ||
yield(mpd) | ||
end | ||
ensure | ||
mpd.disconnect | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,24 @@ | ||
require 'librmpd' | ||
|
||
class Playlist | ||
include MongoMapper::Document | ||
key :name, String, :require => true, :unique => true | ||
key :songs, Array | ||
key :songs, Array | ||
|
||
def load | ||
with_mpd do |mpd| | ||
songs.each { |id| mpd.add "http://localhost:3333/gridfs/#{Song.find(id).mp3_path}" } | ||
end | ||
end | ||
|
||
def with_mpd(&block) | ||
mpd = MPD.new 'localhost', APP_CONFIG[:mpd_port] | ||
mpd.connect | ||
if mpd.connected? | ||
yield(mpd) | ||
end | ||
ensure | ||
mpd.disconnect | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# mongomapper connection | ||
require 'mongo/gridfs' | ||
MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017, :logger => Rails.logger, :slave_ok => true) | ||
MongoMapper.database = "jukeman-#{RAILS_ENV}" | ||
Dir[Rails.root + 'app/models/**/*.rb'].each do |model_path| | ||
File.basename(model_path, '.rb').classify.constantize | ||
end | ||
MongoMapper.ensure_indexes! |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,20 @@ | ||
ENV["RAILS_ENV"] = "test" | ||
require File.expand_path(File.dirname(__FILE__) + "/../config/environment") | ||
require 'test_help' | ||
require 'librmpd' | ||
require 'mpdserver' | ||
|
||
class ActiveSupport::TestCase | ||
# Transactional fixtures accelerate your tests by wrapping each test method | ||
# in a transaction that's rolled back on completion. This ensures that the | ||
# test database remains unchanged so your fixtures don't have to be reloaded | ||
# between every test method. Fewer database queries means faster tests. | ||
# | ||
# Read Mike Clark's excellent walkthrough at | ||
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting | ||
# | ||
# Every Active Record database supports transactions except MyISAM tables | ||
# in MySQL. Turn off transactional fixtures in this case; however, if you | ||
# don't care one way or the other, switching from MyISAM to InnoDB tables | ||
# is recommended. | ||
# | ||
# The only drawback to using transactional fixtures is when you actually | ||
# need to test transactions. Since your test is bracketed by a transaction, | ||
# any transactions started in your code will be automatically rolled back. | ||
self.use_transactional_fixtures = true | ||
|
||
# Instantiated fixtures are slow, but give you @david where otherwise you | ||
# would need people(:david). If you don't want to migrate your existing | ||
# test cases which use the @david style and don't mind the speed hit (each | ||
# instantiated fixtures translates to a database query per test method), | ||
# then set this back to true. | ||
self.use_instantiated_fixtures = false | ||
|
||
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. | ||
# | ||
# Note: You'll currently still have to declare fixtures explicitly in integration tests | ||
# -- they do not yet inherit this setting | ||
fixtures :all | ||
|
||
# Add more helper methods to be used by all tests here... | ||
def setup | ||
# clear database | ||
MongoMapper.database.collections.map(&:remove) | ||
# setup test mpd server | ||
@server = MPDTestServer.new APP_CONFIG[:mpd_port] | ||
@server.start | ||
@server.audit = true | ||
end | ||
|
||
def teardown | ||
@server.stop | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require File.dirname(__FILE__) + '/../test_helper' | ||
require 'librmpd' | ||
require 'mpdserver' | ||
|
||
class PlayerTest < ActiveSupport::TestCase | ||
context "when controlling mpd it" do | ||
|
||
should "play" do | ||
assert Player.play | ||
end | ||
|
||
should "next_song" do | ||
assert Player.next_song | ||
end | ||
|
||
should "previous_song" do | ||
assert Player.previous_song | ||
end | ||
|
||
should "stop" do | ||
assert Player.stop | ||
end | ||
|
||
should "clear" do | ||
assert Player.clear | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require File.dirname(__FILE__) + '/../test_helper' | ||
|
||
|
||
class PlaylistTest < ActiveSupport::TestCase | ||
context "playlists" do | ||
setup do | ||
Song.import_from_folder | ||
end | ||
|
||
should "store song ids" do | ||
playlist = Playlist.new(:name => "Test Playlist") | ||
playlist.songs = Song.all.collect { |s| s.id } | ||
playlist.save | ||
assert_equal 2, playlist.songs.length | ||
end | ||
end | ||
|
||
# context "when loading a playlist it" do | ||
# def setup | ||
# Song.import_from_folder | ||
# @playlist = Playlist.new(:name => "Test Playlist") | ||
# @playlist.songs = Song.all.collect { |s| s.id } | ||
# @playlist.save | ||
# end | ||
# | ||
# should "load the playlist to mpd" do | ||
# @playlist.load | ||
# assert @mpd.playlist | ||
# end | ||
# end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require File.dirname(__FILE__) + '/../test_helper' | ||
|
||
class SongTest < ActiveSupport::TestCase | ||
context "during song creation it" do | ||
should "read the id3 tags" do | ||
tags = Song.read_id3_tags("#{RAILS_ROOT}/music/song.mp3") | ||
assert_equal 15, tags["duration"].to_i | ||
assert_equal "Idol, Billy", tags["artist"] | ||
assert_equal "White Wedding", tags["title"] | ||
assert_nil tags["album"] | ||
assert_equal "Rock", tags["genre"] | ||
end | ||
|
||
should "fail gracefully if id3 tags aren't present" do | ||
tags = Song.read_id3_tags("#{RAILS_ROOT}/music/Caught Up.mp3") | ||
assert_equal 15, tags["duration"].to_i | ||
assert_nil tags["artist"] | ||
assert_equal "Caught Up.mp3", tags["title"] | ||
assert_nil tags["album"] | ||
assert_nil tags["genre"] | ||
end | ||
|
||
should "create new song in database" do | ||
assert Song.import_song("#{RAILS_ROOT}/music/song.mp3") | ||
assert_equal Song.count, 1 | ||
end | ||
end | ||
|
||
context "when importing from a folder" do | ||
setup do | ||
Song.import_from_folder | ||
end | ||
|
||
should "import all songs in the folder" do | ||
assert_equal Song.count, 2 | ||
end | ||
end | ||
|
||
|
||
end |