Created
August 13, 2010 17:07
-
-
Save JoshCheek/523209 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # for http://groups.google.com/group/sinatrarb/browse_thread/thread/f076b033cf87efd3/c5dd8f47c87e798f | |
| # an example of my spec_helper.rb, which put Warden into the middleware, which fixed the problem | |
| require 'rack/test' | |
| ENV['RACK_ENV'] = 'test' | |
| ENV["RAILS_ENV"] ||= 'test' # don't know if we need this or not | |
| # This file is copied to ~/spec when you run 'ruby script/generate rspec' | |
| # from the project root directory. | |
| require File.expand_path(File.join(File.dirname(__FILE__),'..','environment')) | |
| require 'spec/autorun' | |
| # Uncomment the next line to use webrat's matchers | |
| #require 'webrat/integrations/rspec-rails' | |
| # Requires supporting files with custom matchers and macros, etc, | |
| # in ./support/ and its subdirectories. | |
| Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f} | |
| Spec::Runner.configure do |config| | |
| # If you're not using ActiveRecord you should remove these | |
| # lines, delete config/database.yml and disable :active_record | |
| # in your config/boot.rb | |
| # config.use_transactional_fixtures = true | |
| # config.use_instantiated_fixtures = false | |
| # config.fixture_path = RAILS_ROOT + '/spec/fixtures/' | |
| def app | |
| @app ||= begin | |
| Rack::Builder.app do | |
| use Rack::Session::Cookie | |
| use Warden::Manager do |manager| | |
| manager.default_strategies :password | |
| manager.failure_app = Sinatra::Application | |
| end | |
| Warden::Manager.serialize_into_session do |user| | |
| user.wsuid | |
| end | |
| Warden::Manager.serialize_from_session do |wsuid| | |
| User.get(wsuid) | |
| end | |
| Warden::Strategies.add(:password) do | |
| def valid? | |
| params["wsuid"] || params["password"] | |
| end | |
| def authenticate! | |
| u = User.authenticate(params["wsuid"], params["password"]) | |
| u.nil? ? fail!("Could not log in") : success!(u) | |
| end | |
| end | |
| use Rack::Flash | |
| run Sinatra::Application | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment