Created
August 23, 2013 10:32
-
-
Save Phazz/6317847 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
require 'spec_helper' | |
describe 'block example' do | |
let(:thing) { FactoryGirl.create :thing } | |
context 'without versioning' do | |
before do | |
thing.update_attributes name: 'a different name' | |
end | |
it 'does not create a version' do | |
thing.versions.should be_empty | |
end | |
end | |
context 'with versioning' do | |
before do | |
with_versioning do | |
PaperTrail.whodunnit = thing.owner | |
thing.update_attributes name: 'a different name' | |
end | |
end | |
it 'creates a version' do | |
thing.versions.should_not be_empty | |
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
require 'spec_helper' | |
describe 'metadata example' do | |
let(:thing) { FactoryGirl.create :thing } | |
context 'without versioning' do | |
before do | |
thing.update_attributes name: 'a different name' | |
end | |
it 'does not create a version' do | |
thing.versions.should be_empty | |
end | |
end | |
context 'with versioning', :versioning do | |
before do | |
PaperTrail.whodunnit = thing.owner | |
thing.update_attributes name: 'a different name' | |
end | |
it 'creates a version' do | |
thing.versions.should_not be_empty | |
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
# spec/support/ | |
def with_versioning | |
was_enabled = PaperTrail.enabled? | |
PaperTrail.enabled = true | |
begin | |
yield | |
ensure | |
PaperTrail.enabled = was_enabled | |
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
ENV['RAILS_ENV'] ||= 'test' | |
require 'rails/application' | |
require File.expand_path('../../config/environment', __FILE__) | |
require 'rspec/rails' | |
require 'capybara/rails' | |
require 'capybara/rspec' | |
Dir[Rails.root.join 'spec/support/**/*.rb'].each { |f| require f } | |
RSpec.configure do |config| | |
config.filter_run focus: true | |
config.mock_with :rspec | |
config.run_all_when_everything_filtered = true | |
config.treat_symbols_as_metadata_keys_with_true_values = true | |
config.use_transactional_fixtures = false | |
config.before :suite do | |
DatabaseCleaner.strategy = :truncation | |
end | |
config.before :each do | |
DatabaseCleaner.clean | |
PaperTrail.enabled = false | |
end | |
config.before :each, versioning: true do | |
PaperTrail.enabled = true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment