-
-
Save justinko/5174949 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--colour | |
-I app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record' | |
require 'database_cleaner' | |
connection_info = YAML.load_file("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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Coderetreat < ActiveRecord::Base | |
def self.running_today | |
where(scheduled_on: Date.today) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record_spec_helper' | |
require 'models/coderetreat' | |
describe Coderetreat do | |
describe ".running_today" do | |
def coderetreat_on(date) | |
Coderetreat.create! city: "Chicago", scheduled_on: date | |
end | |
context 'with a coderetreat scheduled for today' do | |
specify do | |
coderetreat = coderetreat_on Date.today | |
Coderetreat.running_today.should include coderetreat | |
end | |
end | |
context 'with a coderetreat not scheduled for today' do | |
example do | |
coderetreat = coderetreat_on Date.today.advance(:days => -1) | |
Coderetreat.running_today.should_not include coderetreat | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Some databases get upset if you try to start a new transaction while a transaction is already in play, so running the whole spec suite chokes when rspec is trying to start a transaction. You need to update your spec_helper to rely on active_record_spec_helper to do this for you. | |
#Replace this line | |
config.use_transactional_fixtures = true | |
#With this | |
require 'active_record_spec_helper' | |
#TADA |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment