Skip to content

Instantly share code, notes, and snippets.

@tobyhede
Forked from coreyhaines/.rspec
Created June 10, 2012 00:40
Show Gist options
  • Select an option

  • Save tobyhede/2903242 to your computer and use it in GitHub Desktop.

Select an option

Save tobyhede/2903242 to your computer and use it in GitHub Desktop.

Revisions

  1. @coreyhaines coreyhaines revised this gist Mar 18, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions .rspec
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    --colour
    -I app
  2. @coreyhaines coreyhaines revised this gist Mar 18, 2012. 2 changed files with 21 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions coderetreat.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    class Coderetreat < ActiveRecord::Base
    def self.running_today
    where(scheduled_on: Date.today)
    end
    end
    16 changes: 16 additions & 0 deletions coderetreat_spec.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    require 'active_record_spec_helper'
    require 'models/coderetreat'

    describe Coderetreat do
    describe ".running_today" do
    it "returns a coderetreat scheduled for today" do
    coderetreat = Coderetreat.create! city: "Chicago", scheduled_on: Date.today
    Coderetreat.running_today.all.should =~ [coderetreat]
    end

    it "does not return a coderetreat not scheduled for today" do
    coderetreat = Coderetreat.create! city: "Chicago", scheduled_on: Date.today.advance(:days => -1)
    Coderetreat.running_today.should be_empty
    end
    end
    end
  3. @coreyhaines coreyhaines created this gist Mar 18, 2012.
    18 changes: 18 additions & 0 deletions active_record_spec_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    require 'active_record'
    require 'database_cleaner'

    connection_info = YAML.load(File.open("config/database.yml"))["test"]
    ActiveRecord::Base.establish_connection(connection_info)

    RSpec.configure do |config|
    config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:truncation)
    end
    config.before(:each) do
    DatabaseCleaner.start
    end
    config.after(:each) do
    DatabaseCleaner.clean
    end
    end