Skip to content

Commit

Permalink
Set up testing Rails db stuff (shamelessly stolen from Object Daddy) …
Browse files Browse the repository at this point in the history
…and started on spec.
  • Loading branch information
ymendel committed Feb 8, 2008
1 parent befdce2 commit fec6987
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/autochronic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'chronic'
25 changes: 25 additions & 0 deletions spec/autochronic_spec.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
require File.dirname(__FILE__) + '/spec_helper'
require 'autochronic'
require 'activerecord'

setup_rails_database

class SpaceCowboy < ActiveRecord::Base
end

describe SpaceCowboy do
before :each do
@toker = SpaceCowboy.new
end

describe "'some_date' field" do
it 'should accept a date object' do
date = Date.civil(2008, 2, 7)
date_input = date
@toker.some_date = date_input
@toker.some_date.should == date
end

it 'should accept a date string'
it 'should accept a natural language date string'
it 'should be nil on unusable input'
end
end
3 changes: 3 additions & 0 deletions spec/resources/config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sqlite3:
:adapter: sqlite3
:dbfile: vendor/plugins/autochronic/spec/tmp/autochronic.db
5 changes: 5 additions & 0 deletions spec/resources/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ActiveRecord::Schema.define(:version => 0) do
create_table :space_cowboys, :force => true do |t|
t.date :some_date
end
end
15 changes: 15 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,18 @@
Spec::Runner.configure do |config|
config.mock_with :mocha
end

def setup_rails_database
dir = File.dirname(__FILE__)

ENV['RAILS_ENV'] ||= 'test'
require "#{dir}/../../../../config/environment"

db = YAML.load(IO.read("#{dir}/resources/config/database.yml"))
ActiveRecord::Base.configurations = {'test' => db[ENV['DB'] || 'sqlite3']}
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
ActiveRecord::Migration.verbose = false
load "#{dir}/resources/schema.rb"

require "#{dir}/../init.rb"
end
Empty file added spec/tmp/.git_sucks
Empty file.

0 comments on commit fec6987

Please sign in to comment.