On 11/11/2010 12:36 PM, [email protected] wrote:
> From: Ladislav Martincik<[email protected]>
>
> - Better than default Rails transactional fixtures
> - Good fit when mixing fixtures with factories
> - No need to turn transactional fixtures when using transactions
> ---
>   src/spec/services/registration_service_spec.rb |   12 +-----------
>   src/spec/spec_helper.rb                        |   16 +++++++++++++++-
>   2 files changed, 16 insertions(+), 12 deletions(-)
>
> diff --git a/src/spec/services/registration_service_spec.rb 
> b/src/spec/services/registration_service_spec.rb
> index 6764715..7b26c63 100644
> --- a/src/spec/services/registration_service_spec.rb
> +++ b/src/spec/services/registration_service_spec.rb
> @@ -2,9 +2,7 @@ require 'spec_helper'
>
>   describe RegistrationService do
>
> -  before(:all) do
> -    MetadataObject.delete_all
> -    Role.delete_all
> +  before(:each) do
>       Factory.create(:default_quota_metadata)
>       Factory.create(:default_role_metadata)
>       Factory.create(:default_pool_metadata)
> @@ -48,14 +46,6 @@ describe RegistrationService do
>
>     describe "with transaction" do
>
> -    before(:all) do
> -      ActiveSupport::TestCase.use_transactional_fixtures = false
> -    end
> -
> -    after(:all) do
> -      ActiveSupport::TestCase.use_transactional_fixtures = true
> -    end
> -
>       it "doesn't save user if quota save! raise error and return false if 
> validation failed" do
>         user_attributes = Factory.attributes_for(:user)
>         user = User.new(user_attributes)
> diff --git a/src/spec/spec_helper.rb b/src/spec/spec_helper.rb
> index 52e5de0..12727d8 100644
> --- a/src/spec/spec_helper.rb
> +++ b/src/spec/spec_helper.rb
> @@ -6,6 +6,7 @@ require 'spec/autorun'
>   require 'spec/rails'
>   require 'authlogic/test_case'
>   require 'timecop'
> +require 'database_cleaner'
>
>   # Uncomment the next line to use webrat's matchers
>   #require 'webrat/integrations/rspec-rails'
> @@ -18,7 +19,7 @@ Spec::Runner.configure do |config|
>     # If you're not using ActiveRecord you should remove these
>     # lines, delete config/database.yml and disable :active_record
>     # in your config/boot.rb
> -  config.use_transactional_fixtures = true
> +  config.use_transactional_fixtures = false
>     config.use_instantiated_fixtures  = false
>     config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
>
> @@ -60,4 +61,17 @@ Spec::Runner.configure do |config|
>     config.after(:each, :type =>  :controller) do
>       #current_user_session.destroy
>     end
> +
> +  # Database cleaner
> +  config.before(:suite) do
> +    DatabaseCleaner.strategy = :truncation
> +    DatabaseCleaner.clean_with(:truncation)
> +  end
> +  config.before(:each) do
> +    DatabaseCleaner.start
> +  end
> +
> +  config.after(:each) do
> +    DatabaseCleaner.clean
> +  end
>   end

ACK, looks good (though running tests takes 2.5 times more time now, but 
it's not important)
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to