Permalink
Browse files

Tests for slug enforcement

  • Loading branch information...
1 parent 3fb315b commit 95657c6ae571d60751056fdc5ed64a92b2efe7e7 @sgtFloyd sgtFloyd committed Dec 22, 2011
Showing with 10 additions and 0 deletions.
  1. +1 −0 lib/dashboard.rb
  2. +9 −0 test/lib/test_dashboard.rb
View
@@ -6,6 +6,7 @@ class Dashboard
def self.save(slug = nil, json)
slug ||= json[:slug]
slug = "#{Time.now.to_f}".delete('.') if slug.nil? || slug.empty?
+ json[:slug] = slug
key = "dashboards:#{slug}"
redis.hset key, "title", json[:title]
redis.hset key, "slug", slug
@@ -40,6 +40,15 @@ def test_saving_dashboard
assert_equal @dash_json, dash
end
+ def test_saving_dashboard_without_slug
+ dash = Dashboard.save({title: "dash without slug"})
+ assert dash[:slug]
+ dash = Dashboard.save({title: "dash with empty slug", slug: ''})
+ assert dash[:slug]
+ dash = Dashboard.save({title: "dash with nil slug", slug: nil})
+ assert dash[:slug]
+ end
+
def test_find_dashboard_with_graphs
assert Dashboard.save(@dash_json)
assert Dashboard.add_graph(@dash_json[:slug], @graph_uuid)

0 comments on commit 95657c6

Please sign in to comment.