Permalink
Browse files

Add record.spotify_uri format validation

  • Loading branch information...
1 parent 0cdb3eb commit 5e4c29c13600c88956651fce10242d3fff168d4f @mllocs committed Dec 9, 2012
@@ -2,10 +2,10 @@
<a href="#" id="edit_record_<%= record.get('id') %>" class="edit">Edit</a> ·
<a href="#" id="delete_record_<%= record.get('id') %>" class="delete">Delete</a>
</div>
-<a class="cover" href="<%= record.get('spotify_uri') %>">
+<a class="cover" href="<%= record.get('spotify_uri') || "#" %>">
<img alt="" width="200px" height="200px" title="<%= record.get('title') %>" src="<%= record.get('cover_url') %>"></img>
</a>
-<a class="title" href="<%= record.get('spotify_uri') %>" title="<%= record.get('title') %>">
+<a class="title" href="<%= record.get('spotify_uri') || "#" %>" title="<%= record.get('title') %>">
<%= record.get('title').truncate(26) %>
</a>
<span class='artist' title="<%= record.get('artist') %>">
View
@@ -1,8 +1,14 @@
class Record < ActiveRecord::Base
attr_accessible :artist, :title, :cover_url, :spotify_uri
+
validates :artist, presence: true
validates :title, presence: true
+
validates_format_of :cover_url, with: %r{\.(gif|jpe?g|png)$}i,
message: "should be an image URL (jpg, gif or png)",
allow_blank: true
+
+ validates_format_of :spotify_uri, with: %r{spotify:(album|track):[a-zA-Z0-9]+},
+ message: "should be a correct album Spotify URI",
+ allow_blank: true
end
View
@@ -17,7 +17,7 @@
title: "The Heart Of Sunday Night",
artist: "Tom Waits",
cover_url: "http://ijustreadaboutthat.files.wordpress.com/2011/09/75112.jpg",
- spotify_uri: "spotify:track:23X3UiWmkM09Ug2heM6z38"
+ spotify_uri: "spotify:album:7MLzdbFViVmpQdnNmxQXoE"
)
Record.create!(
View
@@ -12,11 +12,11 @@ two:
title: The Heart Of Sunday Night
artist: Tom Waits
cover_url: http://ijustreadaboutthat.files.wordpress.com/2011/09/75112.jpg
- spotify_uri: spotify:track:23X3UiWmkM09Ug2heM6z38
+ spotify_uri: spotify:album:7MLzdbFViVmpQdnNmxQXoE
three:
id: 3
- title: "OH (Ohio)"
- artist: "Lambchop"
- cover_url: "http://expressmilwaukee.com/imgs/hed/art5489widea.jpg"
- spotify_uri: "spotify:album:4y9ebrmAx1TMyUlyCVJJL6"
+ title: OH (Ohio)
+ artist: Lambchop
+ cover_url: http://expressmilwaukee.com/imgs/hed/art5489widea.jpg
+ spotify_uri: spotify:album:4y9ebrmAx1TMyUlyCVJJL6
@@ -1,3 +1,4 @@
+# encoding: utf-8
require 'test_helper'
class RecordsPagesTest < ActionDispatch::IntegrationTest
@@ -9,7 +10,7 @@ class RecordsPagesTest < ActionDispatch::IntegrationTest
test "basic record elements exist" do
visit "/"
within("h1") do
- assert page.has_content?("Zoh My Records")
+ assert page.has_content?("ZOH·MY·RECORDS")
end
within("#container") do
assert page.has_selector?("ul#records")
@@ -32,7 +33,7 @@ class RecordsPagesTest < ActionDispatch::IntegrationTest
fill_in "title", :with => "The Harrow And The Harvest"
fill_in "artist", :with => "Gillian Welch"
fill_in "cover_url", :with => "http://upload.wikimedia.org/wikipedia/en/thumb/1/18/Theharrowandtheharvest.jpg"
- fill_in "spotify_uri", :with => "spotify:user:maxim.colls:playlist:0gxuTvV1XhCrnePamtPRrO"
+ fill_in "spotify_uri", :with => "spotify:album:7MLzdbFViVmpQdnNmxQXoE"
click_button "Add Record"
within("ul#records") do
View
@@ -17,4 +17,9 @@ class RecordTest < ActiveSupport::TestCase
assert !record.save
end
+ test "should not save record with an incorrect spotify_url" do
+ record = Record.new(title: "Take Five", artist: "Dave Brubeck", spotify_uri: "Not a valid spotify URI")
+ assert !record.save
+ end
+
end

0 comments on commit 5e4c29c

Please sign in to comment.