summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorpseudomuto <david.muto@gmail.com>2013-12-18 19:22:09 -0500
committerpseudomuto <david.muto@gmail.com>2013-12-18 19:22:09 -0500
commitfbc9497dbb8ece970f21bc67164557bba8db2db7 (patch)
treef2075e2e9ef9d3a191af10000ae1422f3f7e6cfe /test
parent0c1adbdb9fe428db1f4237e7bf021713b188f8f8 (diff)
moving app to it's own file under lib/dashing
Diffstat (limited to 'test')
-rw-r--r--test/app_test.rb307
1 files changed, 154 insertions, 153 deletions
diff --git a/test/app_test.rb b/test/app_test.rb
index bf3bbb1..dbb7cb5 100644
--- a/test/app_test.rb
+++ b/test/app_test.rb
@@ -1,153 +1,154 @@
-# require 'test_helper'
-# require 'haml'
-
-# class AppTest < Dashing::Test
-# def setup
-# @connection = []
-# Sinatra::Application.settings.history_file = File.join(Dir.tmpdir, 'history.yml')
-# Sinatra::Application.settings.connections = [@connection]
-# Sinatra::Application.settings.auth_token = nil
-# Sinatra::Application.settings.default_dashboard = nil
-# end
-
-# def test_post_widgets_without_auth_token
-# post '/widgets/some_widget', JSON.generate({value: 6})
-# assert_equal 204, last_response.status
-
-# assert_equal 1, @connection.length
-# data = parse_data @connection[0]
-# assert_equal 6, data['value']
-# assert_equal 'some_widget', data['id']
-# assert data['updatedAt']
-# end
-
-# def test_post_widgets_with_invalid_auth_token
-# Sinatra::Application.settings.auth_token = 'sekrit'
-# post '/widgets/some_widget', JSON.generate({value: 9})
-# assert_equal 401, last_response.status
-# end
-
-# def test_post_widgets_with_valid_auth_token
-# Sinatra::Application.settings.auth_token = 'sekrit'
-# post '/widgets/some_widget', JSON.generate({value: 9, auth_token: 'sekrit'})
-# assert_equal 204, last_response.status
-# end
-
-# def test_get_events
-# post '/widgets/some_widget', JSON.generate({value: 8})
-# assert_equal 204, last_response.status
-
-# get '/events'
-# assert_equal 200, last_response.status
-# assert_equal 8, parse_data(@connection[0])['value']
-# end
-
-# def test_dashboard_events
-# post '/dashboards/my_super_sweet_dashboard', JSON.generate({event: 'reload'})
-# assert_equal 204, last_response.status
-
-# get '/events'
-# assert_equal 200, last_response.status
-# assert_equal 'dashboards', parse_event(@connection[0])
-# assert_equal 'reload', parse_data(@connection[0])['event']
-# end
-
-# def test_redirect_to_default_dashboard
-# with_generated_project do
-# Sinatra::Application.settings.default_dashboard = 'test1'
-# get '/'
-# assert_equal 302, last_response.status
-# assert_equal 'http://example.org/test1', last_response.location
-# end
-# end
-
-# def test_redirect_to_first_dashboard
-# with_generated_project do
-# get '/'
-# assert_equal 302, last_response.status
-# assert_equal 'http://example.org/sample', last_response.location
-# end
-# end
-
-# def test_redirect_to_first_dashboard_without_erb
-# with_generated_project do |dir|
-# FileUtils.touch(File.join(dir, "dashboards/htmltest.html"))
-# get '/'
-# assert_equal 302, last_response.status
-# assert_equal 'http://example.org/htmltest', last_response.location
-# end
-# end
-
-# def test_get_dashboard
-# with_generated_project do
-# get '/sampletv'
-# assert_equal 200, last_response.status
-# assert_includes last_response.body, 'class="gridster"'
-# assert_includes last_response.body, "DOCTYPE"
-# end
-# end
-
-# def test_page_title_set_correctly
-# with_generated_project do
-# get '/sampletv'
-# assert_includes last_response.body, '<title>1080p dashboard</title>'
-# end
-# end
-
-# def test_get_haml_dashboard
-# with_generated_project do |dir|
-# File.write(File.join(dir, 'dashboards/hamltest.haml'), '.gridster')
-# get '/hamltest'
-# assert_equal 200, last_response.status
-# assert_includes last_response.body, "class='gridster'"
-# end
-# end
-
-# def test_get_haml_widget
-# with_generated_project do |dir|
-# File.write(File.join(dir, 'widgets/clock/clock.haml'), '%h1 haml')
-# File.unlink(File.join(dir, 'widgets/clock/clock.html'))
-# get '/views/clock.html'
-# assert_equal 200, last_response.status
-# assert_includes last_response.body, '<h1>haml</h1>'
-# end
-# end
-
-# def test_get_nonexistent_dashboard
-# with_generated_project do
-# get '/nodashboard'
-# assert_equal 404, last_response.status
-# end
-# end
-
-# def test_get_widget
-# with_generated_project do
-# get '/views/meter.html'
-# assert_equal 200, last_response.status
-# assert_includes last_response.body, 'class="meter"'
-# end
-# end
-
-# def with_generated_project
-# temp do |dir|
-# cli = Dashing::CLI.new
-# silent { cli.new 'new_project' }
-
-# Sinatra::Application.settings.views = File.join(dir, 'new_project/dashboards')
-# Sinatra::Application.settings.root = File.join(dir, 'new_project')
-# yield Sinatra::Application.settings.root
-# end
-# end
-
-# def app
-# Sinatra::Application
-# end
-
-# def parse_data(string)
-# JSON.parse string[/data: (.+)/, 1]
-# end
-
-# def parse_event(string)
-# string[/event: (.+)/, 1]
-# end
-# end
+require 'test_helper'
+require 'haml'
+
+class AppTest < Dashing::Test
+ def setup
+ @connection = []
+ Sinatra::Application.settings.history_file = File.join(Dir.tmpdir, 'history.yml')
+ Sinatra::Application.settings.connections = [@connection]
+ Sinatra::Application.settings.auth_token = nil
+ Sinatra::Application.settings.default_dashboard = nil
+ end
+
+ def test_post_widgets_without_auth_token
+ post '/widgets/some_widget', JSON.generate({value: 6})
+ assert_equal 204, last_response.status
+
+ assert_equal 1, @connection.length
+ data = parse_data @connection[0]
+ assert_equal 6, data['value']
+ assert_equal 'some_widget', data['id']
+ assert data['updatedAt']
+ end
+
+ def test_post_widgets_with_invalid_auth_token
+ Sinatra::Application.settings.auth_token = 'sekrit'
+ post '/widgets/some_widget', JSON.generate({value: 9})
+ assert_equal 401, last_response.status
+ end
+
+ def test_post_widgets_with_valid_auth_token
+ Sinatra::Application.settings.auth_token = 'sekrit'
+ post '/widgets/some_widget', JSON.generate({value: 9, auth_token: 'sekrit'})
+ assert_equal 204, last_response.status
+ end
+
+ def test_get_events
+ post '/widgets/some_widget', JSON.generate({value: 8})
+ assert_equal 204, last_response.status
+
+ get '/events'
+ assert_equal 200, last_response.status
+ assert_equal 8, parse_data(@connection[0])['value']
+ end
+
+ def test_dashboard_events
+ post '/dashboards/my_super_sweet_dashboard', JSON.generate({event: 'reload'})
+ assert_equal 204, last_response.status
+
+ get '/events'
+ assert_equal 200, last_response.status
+ assert_equal 'dashboards', parse_event(@connection[0])
+ assert_equal 'reload', parse_data(@connection[0])['event']
+ end
+
+ def test_redirect_to_default_dashboard
+ with_generated_project do
+ Sinatra::Application.settings.default_dashboard = 'test1'
+ get '/'
+ assert_equal 302, last_response.status
+ assert_equal 'http://example.org/test1', last_response.location
+ end
+ end
+
+ def test_redirect_to_first_dashboard
+ with_generated_project do
+ get '/'
+ assert_equal 302, last_response.status
+ assert_equal 'http://example.org/sample', last_response.location
+ end
+ end
+
+ def test_redirect_to_first_dashboard_without_erb
+ with_generated_project do |dir|
+ FileUtils.touch(File.join(dir, "dashboards/htmltest.html"))
+ get '/'
+ assert_equal 302, last_response.status
+ assert_equal 'http://example.org/htmltest', last_response.location
+ end
+ end
+
+ def test_get_dashboard
+ with_generated_project do
+ get '/sampletv'
+ assert_equal 200, last_response.status
+ assert_includes last_response.body, 'class="gridster"'
+ assert_includes last_response.body, "DOCTYPE"
+ end
+ end
+
+ def test_page_title_set_correctly
+ with_generated_project do
+ get '/sampletv'
+ assert_includes last_response.body, '<title>1080p dashboard</title>'
+ end
+ end
+
+ def test_get_haml_dashboard
+ with_generated_project do |dir|
+ File.write(File.join(dir, 'dashboards/hamltest.haml'), '.gridster')
+ get '/hamltest'
+ assert_equal 200, last_response.status
+ assert_includes last_response.body, "class='gridster'"
+ end
+ end
+
+ def test_get_haml_widget
+ with_generated_project do |dir|
+ File.write(File.join(dir, 'widgets/clock/clock.haml'), '%h1 haml')
+ File.unlink(File.join(dir, 'widgets/clock/clock.html'))
+ get '/views/clock.html'
+ assert_equal 200, last_response.status
+ assert_includes last_response.body, '<h1>haml</h1>'
+ end
+ end
+
+ def test_get_nonexistent_dashboard
+ with_generated_project do
+ get '/nodashboard'
+ assert_equal 404, last_response.status
+ end
+ end
+
+ def test_get_widget
+ with_generated_project do
+ get '/views/meter.html'
+ assert_equal 200, last_response.status
+ assert_includes last_response.body, 'class="meter"'
+ end
+ end
+
+ def with_generated_project
+ temp do |dir|
+ cli = Dashing::CLI.new
+ cli.stubs(:source_paths).returns([File.expand_path('../../templates', __FILE__)])
+ silent { cli.new 'new_project' }
+
+ Sinatra::Application.settings.views = File.join(dir, 'new_project/dashboards')
+ Sinatra::Application.settings.root = File.join(dir, 'new_project')
+ yield Sinatra::Application.settings.root
+ end
+ end
+
+ def app
+ Sinatra::Application
+ end
+
+ def parse_data(string)
+ JSON.parse string[/data: (.+)/, 1]
+ end
+
+ def parse_event(string)
+ string[/event: (.+)/, 1]
+ end
+end