Last active
August 29, 2015 14:06
-
-
Save bcardarella/bcfde93a2171a331cd7d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| if Rails.env.test? | |
| require 'active_record/fixtures' | |
| require File.expand_path('../../test/config/geocoder.rb', __FILE__) | |
| DatabaseCleaner.strategy = :transaction | |
| class DatabaseResetter | |
| def self.start | |
| DatabaseCleaner.start | |
| # Reload the fixtures | |
| fixtures_path = File.join Rails.root, 'test', 'fixtures' | |
| ActiveRecord::FixtureSet.reset_cache | |
| Dir["#{fixtures_path}/**/*.yml"].map {|f| f[(fixtures_path.size + 1)..-5] }.each { |f_name| ActiveRecord::FixtureSet.create_fixtures(fixtures_path, f_name) } | |
| end | |
| def self.stop(controller) | |
| controller.session.delete :identity_id | |
| DatabaseCleaner.clean | |
| end | |
| end | |
| end |
This file contains hidden or 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
| namespace :api do | |
| if Rails.env.test? | |
| post '/tests' => 'tests#create' | |
| delete '/tests' => 'tests#destroy' | |
| end | |
| end |
This file contains hidden or 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 'database_resetter' | |
| class Api::TestsController < ApplicationController | |
| before_action :ensure_test | |
| layout false | |
| def create | |
| DatabaseResetter.start | |
| head(:ok) | |
| end | |
| def destroy | |
| DatabaseResetter.stop(self) | |
| head(:ok) | |
| end | |
| private | |
| def ensure_test | |
| raise unless Rails.env.test? | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment