Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

60 lines (46 sloc) 1.547 kb
require './server'
require 'rack/test'
require 'test/unit'
ENV['RACK_ENV'] = 'test'
class ServerTest < Test::Unit::TestCase
include Rack::Test::Methods
def app
Sinatra::Application
end
def setup
REDIS.hmset 'key.asdfxxx', :staff, false, :room, 'test-1'
end
def test_api_key_required
get '/messages'
assert ! last_response.ok? # 401
end
def test_index
Message.clear "test-1"
get "/messages?key=asdfxxx&callback=callme"
assert last_response.ok?
assert_equal "callme({\"results\":[]})", last_response.body
end
def test_makes_message
Message.clear "test-1"
post "/messages", { :key => "asdfxxx", :name => "joe", :message => "test" }
assert last_response.redirect?
results = Message.all("test-1", false)
assert_equal 1, results.size
assert_equal 'joe', results[0]['name']
assert_equal 'test', results[0]['text']
end
def test_ignores_internal
Message.clear "test-1"
post "/messages", { :key => "asdfxxx", :name => "joe", :message => "test", :internal => "0" }
assert last_response.redirect?
post "/messages", { :key => "asdfxxx", :name => "admin", :message => "test2", :internal => "1" }
assert last_response.redirect?
results = Message.all("test-1", false)
assert_equal 1, results.size
assert_equal 'joe', results[0]['name']
assert_equal 'test', results[0]['text']
results = Message.all("test-1", true)
assert_equal 2, results.size
assert_equal 'admin', results[1]['name']
end
end
Jump to Line
Something went wrong with that request. Please try again.