From 69ed82efa8319e7fbde9df95a4fad4ee96aa5074 Mon Sep 17 00:00:00 2001 From: pseudomuto Date: Wed, 18 Dec 2013 15:49:32 -0500 Subject: adding haml to dev dependencies so all tests run --- test/app_test.rb | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'test/app_test.rb') diff --git a/test/app_test.rb b/test/app_test.rb index 0032165..0547eb8 100644 --- a/test/app_test.rb +++ b/test/app_test.rb @@ -1,5 +1,6 @@ require 'test_helper' -require File.expand_path('../../lib/dashing', __FILE__) +require 'haml' + Sinatra::Application.settings.history_file = File.join(Dir.tmpdir, 'history.yml') class AppTest < Dashing::Test @@ -94,29 +95,23 @@ class AppTest < Dashing::Test end end - begin - require 'haml' - - 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_include last_response.body, "class='gridster'" - 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_include 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_include last_response.body, '

haml

' - 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_include last_response.body, '

haml

' end - rescue LoadError - puts "[skipping haml tests because haml isn't installed]" end def test_get_nonexistent_dashboard -- cgit v1.2.3 From c3a72795ecab47f94527e079b60549051843caa4 Mon Sep 17 00:00:00 2001 From: pseudomuto Date: Wed, 18 Dec 2013 15:55:46 -0500 Subject: switching from test unit to minitest --- test/app_test.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'test/app_test.rb') diff --git a/test/app_test.rb b/test/app_test.rb index 0547eb8..a176d2e 100644 --- a/test/app_test.rb +++ b/test/app_test.rb @@ -1,11 +1,10 @@ require 'test_helper' require 'haml' -Sinatra::Application.settings.history_file = File.join(Dir.tmpdir, 'history.yml') - 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 @@ -83,15 +82,15 @@ class AppTest < Dashing::Test with_generated_project do get '/sampletv' assert_equal 200, last_response.status - assert_include last_response.body, 'class="gridster"' - assert_include last_response.body, "DOCTYPE" + 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_include last_response.body, '1080p dashboard' + assert_includes last_response.body, '1080p dashboard' end end @@ -100,7 +99,7 @@ class AppTest < Dashing::Test File.write(File.join(dir, 'dashboards/hamltest.haml'), '.gridster') get '/hamltest' assert_equal 200, last_response.status - assert_include last_response.body, "class='gridster'" + assert_includes last_response.body, "class='gridster'" end end @@ -110,7 +109,7 @@ class AppTest < Dashing::Test File.unlink(File.join(dir, 'widgets/clock/clock.html')) get '/views/clock.html' assert_equal 200, last_response.status - assert_include last_response.body, '

haml

' + assert_includes last_response.body, '

haml

' end end @@ -125,7 +124,7 @@ class AppTest < Dashing::Test with_generated_project do get '/views/meter.html' assert_equal 200, last_response.status - assert_include last_response.body, 'class="meter"' + assert_includes last_response.body, 'class="meter"' end end -- cgit v1.2.3 From d0eef2dbe9d1178111cd768116a66b32a3a4b2b5 Mon Sep 17 00:00:00 2001 From: pseudomuto Date: Wed, 18 Dec 2013 19:12:43 -0500 Subject: moving cli to lib and updating bin file --- test/app_test.rb | 306 +++++++++++++++++++++++++++---------------------------- 1 file changed, 153 insertions(+), 153 deletions(-) (limited to 'test/app_test.rb') diff --git a/test/app_test.rb b/test/app_test.rb index a176d2e..bf3bbb1 100644 --- a/test/app_test.rb +++ b/test/app_test.rb @@ -1,153 +1,153 @@ -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, '1080p dashboard' - 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, '

haml

' - 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, '1080p dashboard' +# 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, '

haml

' +# 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 -- cgit v1.2.3 From fbc9497dbb8ece970f21bc67164557bba8db2db7 Mon Sep 17 00:00:00 2001 From: pseudomuto Date: Wed, 18 Dec 2013 19:22:09 -0500 Subject: moving app to it's own file under lib/dashing --- test/app_test.rb | 307 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 154 insertions(+), 153 deletions(-) (limited to 'test/app_test.rb') 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, '1080p dashboard' -# 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, '

haml

' -# 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, '1080p dashboard' + 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, '

haml

' + 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 -- cgit v1.2.3 From e975ce77408f5995213cc1b85f61e806152ba3a2 Mon Sep 17 00:00:00 2001 From: pseudomuto Date: Thu, 19 Dec 2013 12:08:07 -0500 Subject: light refactoring for better test coverage --- test/app_test.rb | 83 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 36 deletions(-) (limited to 'test/app_test.rb') diff --git a/test/app_test.rb b/test/app_test.rb index dbb7cb5..4101e91 100644 --- a/test/app_test.rb +++ b/test/app_test.rb @@ -4,10 +4,45 @@ 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 + app.settings.connections = [@connection] + app.settings.auth_token = nil + app.settings.default_dashboard = nil + app.settings.history_file = File.join(Dir.tmpdir, 'history.yml') + 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_redirect_to_default_dashboard + with_generated_project do + app.settings.default_dashboard = 'test1' + get '/' + assert_equal 302, last_response.status + assert_equal 'http://example.org/test1', last_response.location + end + end + + def test_errors_out_when_no_dashboards_available + with_generated_project do + app.settings.views = File.join(app.settings.root, 'lib') + + get '/' + assert_equal 500, last_response.status + end end def test_post_widgets_without_auth_token @@ -22,13 +57,13 @@ class AppTest < Dashing::Test end def test_post_widgets_with_invalid_auth_token - Sinatra::Application.settings.auth_token = 'sekrit' + app.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' + app.settings.auth_token = 'sekrit' post '/widgets/some_widget', JSON.generate({value: 9, auth_token: 'sekrit'}) assert_equal 204, last_response.status end @@ -52,32 +87,6 @@ class AppTest < Dashing::Test 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' @@ -129,14 +138,16 @@ class AppTest < Dashing::Test end def with_generated_project + source_path = File.expand_path('../../templates', __FILE__) + temp do |dir| cli = Dashing::CLI.new - cli.stubs(:source_paths).returns([File.expand_path('../../templates', __FILE__)]) + cli.stubs(:source_paths).returns([source_path]) 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 + app.settings.views = File.join(dir, 'new_project/dashboards') + app.settings.root = File.join(dir, 'new_project') + yield app.settings.root end end -- cgit v1.2.3