Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Test using sequel for sessions

  • Loading branch information...
commit 60460b2b9769bf92224a18849e702b9774bffca8 1 parent cce1be9
Lori Holden authored
View
4 merb_sequel/lib/merb/orms/sequel/connection.rb
@@ -42,8 +42,8 @@ def connect
else
copy_sample_config
Merb.logger.set_log(STDERR)
- Merb.logger.error! "No database.yml file found in #{Merb.root}/config."
- Merb.logger.error! "A sample file was created called config/database.yml.sample for you to copy and edit."
+ Merb.logger.error! "No database.yml file found at #{config_file}."
+ Merb.logger.error! "A sample file was created called #{sample_dest} for you to copy and edit."
exit(1)
end
end
View
1  merb_sequel/spec/.gitignore
@@ -0,0 +1 @@
+test.db
View
11 merb_sequel/spec/config/database.yml
@@ -0,0 +1,11 @@
+---
+development: &defaults
+ adapter: sqlite
+ encoding: utf8
+ database: spec/test.db
+
+test:
+ <<: *defaults
+
+production:
+ <<: *defaults
View
52 merb_sequel/spec/merb_sequel_session_spec.rb
@@ -1,31 +1,25 @@
require File.dirname(__FILE__) + "/spec_helper"
+require 'merb-core/dispatch/session/store_container'
+require File.join( File.dirname(__FILE__), "..", "lib", 'merb', 'session', 'sequel_session')
-# # Load up the shared specs from merb-core
-# if (gem_spec = Gem.source_index.search(Gem::Dependency.new('merb-core', '>=0.9.6')).last) &&
-# gem_spec.files.include?('spec/public/session/controllers/sessions.rb')
-# require gem_spec.full_gem_path / 'spec/public/session/controllers/sessions.rb'
-# require gem_spec.full_gem_path / 'spec/public/session/session_spec.rb'
-# end
-#
-# describe Merb::SequelSession do
-#
-# before do
-# @session_class = Merb::SequelSession
-# @session = @session_class.generate
-# end
-#
-# it_should_behave_like "All session-store backends"
-#
-# it "should have a session_store_type class attribute" do
-# @session.class.session_store_type.should == :sequel
-# end
-#
-# end
-#
-# describe Merb::SequelSession, "mixed into Merb::Controller" do
-#
-# before(:all) { @session_class = Merb::SequelSession }
-#
-# it_should_behave_like "All session-stores mixed into Merb::Controller"
-#
-# end
+describe Merb::SequelSession do
+
+ before(:each) do
+ @session_class = Merb::SequelSession
+ @session = @session_class.generate
+ end
+
+ it "should have a session_store_type class attribute" do
+ @session.class.session_store_type.should == :sequel
+ end
+
+ it "should persist values" do
+ response = request(url(:controller => :spec_controller, :action => :set))
+ response.should be_successful
+ response.body.should == 'value'
+ response = request(url(:controller => :spec_controller, :action => :get))
+ response.should be_successful
+ response.body.should == 'value'
+ end
+
+end
View
9 merb_sequel/spec/spec_controller.rb
@@ -0,0 +1,9 @@
+class SpecController < Merb::Controller
+ def set
+ session[:key] = 'value'
+ end
+
+ def get
+ session[:key]
+ end
+end
View
23 merb_sequel/spec/spec_helper.rb
@@ -1,31 +1,30 @@
-$:.push File.join(File.dirname(__FILE__), "..", "lib")
+$:.insert 0, File.join(File.dirname(__FILE__), "..", "lib")
require 'rubygems'
require 'spec'
+require 'spec/mocks'
require 'sequel'
require 'merb-core'
require 'merb-core/test'
require 'merb-core/test/helpers'
+
require File.join( File.dirname(__FILE__), "..", "lib", 'merb_sequel')
-module Merb
- module Orms
- module Sequel
- class << self
- def connect
- ::Sequel.connect(:adapter => 'sqlite')
- end
- end
- end
- end
+Merb::Config.use do |c|
+ c[:session_store] = 'sequel'
end
-Merb.start :environment => 'test', :adapter => 'runner', :session_store => 'session'
+Merb.start :environment => 'test', :adapter => 'runner', :session_store => 'sequel', :merb_root => File.dirname(__FILE__)
Spec::Runner.configure do |config|
config.include Merb::Test::RequestHelper
end
+Merb::Router.prepare do
+ default_routes
+end
+
require File.join( File.dirname(__FILE__), 'spec_model')
+require File.join( File.dirname(__FILE__), 'spec_controller')
View
25 merb_sequel/spec/spec_model.rb
@@ -0,0 +1,25 @@
+class SpecModel < Sequel::Model
+end
+
+class CreateSpecModel < Sequel::Migration
+ def up
+ create_table! :spec_models do
+ primary_key :id
+ text :name
+ end
+ end
+
+ def down
+ drop_table :spec_models
+ end
+end
+
+describe "it has a SpecModel", :shared => true do
+ before(:each) do
+ CreateSpecModel.apply(SpecModel.db, :up)
+ end
+
+ after(:each) do
+ CreateSpecModel.apply(SpecModel.db, :down)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.