Permalink
Browse files

Using in-memory sqlite for testing activerecord-based features

  • Loading branch information...
1 parent 57c5e07 commit 8075548255050724b4ccc4ec8985a4b73c9e8915 @alno committed Mar 22, 2012
Showing with 26 additions and 3 deletions.
  1. +6 −1 spec/extensions/models/wiki_page_spec.rb
  2. +3 −2 spec/helpers/wiki_pages_helper_spec.rb
  3. +17 −0 spec/spec_helper.rb
@@ -6,7 +6,6 @@
class AbstractPage < ActiveRecord::Base
-
def self.columns
c = ActiveRecord::ConnectionAdapters::Column
@@ -25,6 +24,9 @@ def self.columns
Irwi::config.page_attachment_class_name = nil
@cls = Class.new AbstractPage do
+
+ self.table_name = 'pages'
+
include Irwi::Extensions::Models::WikiPage
end
end
@@ -60,6 +62,9 @@ def self.columns
Irwi::config.page_attachment_class_name = 'WikiPageAttachment'
@cls = Class.new AbstractPage do
+
+ self.table_name = 'pages'
+
include Irwi::Extensions::Models::WikiPage
end
end
@@ -8,11 +8,12 @@
before(:each) do
@m = Object.new
+ @m.send :extend, ERB::Util
@m.send :extend, Irwi::Helpers::WikiPagesHelper
end
it { @m.should respond_to(:wiki_page_form) }
-
+
it { @m.should respond_to(:wiki_page_new_path) }
it { @m.should respond_to(:wiki_page_edit_path) }
it { @m.should respond_to(:wiki_page_history_path) }
@@ -25,7 +26,7 @@
@m.wiki_page_new_path.should == 'newpath'
end
-
+
specify "should form url_for by wiki_page_new_path if path left blank" do
@m.stub(:params).and_return(nil)
@m.should_receive(:url_for).with(:action => :new).and_return('blank_path')
View
@@ -1,13 +1,30 @@
require 'rubygems'
require 'active_support/test_case'
+require 'active_record'
require 'irwi'
require 'irwi/config'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:"
+
+begin
+ ActiveRecord::Schema.drop_table('pages')
+rescue
+ nil
+end
+
+ActiveRecord::Schema.define do
+ create_table "pages", :force => true do |t|
+ t.column "title", :string, :limit => 255, :null => false
+ t.column "path", :string, :limit => 255, :null => false
+ t.column "content", :text , :null => false
+ end
+end
+
RSpec.configure do |config|
end

0 comments on commit 8075548

Please sign in to comment.