Permalink
Browse files

test examples with the new helpers

  • Loading branch information...
1 parent ace64f8 commit 8f1fd9bc008db0dcc90b4cf87302c64c749e0c5e @NoamB committed Apr 30, 2011
Showing with 68 additions and 8 deletions.
  1. +4 −0 .gitignore
  2. +5 −1 Gemfile
  3. +9 −7 Gemfile.lock
  4. +50 −0 my_test.rb
View
@@ -1 +1,5 @@
dummy
+
+.idea
+
+.bundle
View
@@ -2,4 +2,8 @@ source 'http://rubygems.org'
gem 'sinatra', '>= 1.2.0'
gem 'sqlite3-ruby', :require => 'sqlite3'
-gem "sorcery", '0.4.1'
+gem "sorcery", '0.4.2'
+
+group :development do
+ gem "test-unit"
+end
View
@@ -40,18 +40,18 @@ GEM
rack (< 2, >= 1.1.0)
i18n (0.5.0)
json (1.5.1)
- mail (2.2.17)
+ mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
- multi_json (0.0.5)
+ multi_json (1.0.0)
multipart-post (1.1.0)
oauth (0.4.4)
- oauth2 (0.4.0)
- faraday (~> 0.6.0)
- multi_json (~> 0.0.4)
+ oauth2 (0.4.1)
+ faraday (~> 0.6.1)
+ multi_json (>= 0.0.5)
polyglot (0.3.1)
rack (1.2.2)
rack-mount (0.6.14)
@@ -75,7 +75,7 @@ GEM
sinatra (1.2.3)
rack (~> 1.1)
tilt (< 2.0, >= 1.2.2)
- sorcery (0.3.1)
+ sorcery (0.4.2)
bcrypt-ruby (~> 2.1.4)
json (>= 1.5.1)
oauth (>= 0.4.4)
@@ -86,6 +86,7 @@ GEM
sqlite3 (1.3.3)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
+ test-unit (2.3.0)
thor (0.14.6)
tilt (1.2.2)
treetop (1.4.9)
@@ -97,5 +98,6 @@ PLATFORMS
DEPENDENCIES
sinatra (>= 1.2.0)
- sorcery (= 0.3.1)
+ sorcery (= 0.4.2)
sqlite3-ruby
+ test-unit
View
@@ -0,0 +1,50 @@
+require_relative 'myapp'
+require "test/unit"
+require 'rack/test'
+
+ENV['RACK_ENV'] = 'test'
+
+ActionMailer::Base.delivery_method = :test
+
+class MyTest < Test::Unit::TestCase
+ include Rack::Test::Methods
+ include Sorcery::TestHelpers::Sinatra
+
+ def app
+ ::Sinatra::Application.new
+ end
+
+ # Called before every test method runs. Can be used
+ # to set up fixture information.
+ def setup
+ ::Sinatra::Application.rack_test_session = rack_test_session
+
+ @user = User.create!(:email => "bla@bla.com", :password => 'secret')
+ @user.activate!
+ p @user
+ end
+
+ # Called after every test method runs. Can be used to tear
+ # down fixture information.
+
+ def teardown
+ User.delete_all
+ end
+
+ def test_root_url
+ get '/'
+ assert last_response.ok?
+ assert last_response.body.include?('Login')
+ end
+
+ def test_login
+ post '/login', :email => 'bla@bla.com', :password => 'secret'
+ assert_equal 302, last_response.status
+ end
+
+ def test_logout
+ login_user
+ get '/logout'
+ assert_equal 302, last_response.status
+ end
+end

0 comments on commit 8f1fd9b

Please sign in to comment.