Skip to content

Instantly share code, notes, and snippets.

@cupakromer
Forked from coreyhaines/.rspec
Created June 10, 2012 13:16
Show Gist options
  • Save cupakromer/2905524 to your computer and use it in GitHub Desktop.
Save cupakromer/2905524 to your computer and use it in GitHub Desktop.
Loading just active record
--colour
-I app
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
class Coderetreat < ActiveRecord::Base
def self.running_today
where(scheduled_on: Date.today)
end
end
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment