lib/flextures/rspec_flextures_support.rb in flextures-3.0.1 vs lib/flextures/rspec_flextures_support.rb in flextures-3.1.0
- old
+ new
@@ -1,36 +1,66 @@
# encoding: utf-8
+
+module RSpec
+ module Rails
+ module SetupAndTeardownAdapter
+ extend ActiveSupport::Concern
+
+ module ClassMethods
+ def flextures_prepend_before(&block)
+ prepend_before(&block)
+ end
+
+ def flextures_before(&block)
+ before(&block)
+ end
+ end
+ end
+ end
+end
+
# flextures function use like fixtures method in RSpec
module RSpec
module Core
module Hooks
# load fixtture data
# @params [Array] _ fixture file names
- def flextures *_
- before { Flextures::Loader::flextures *_ }
+ def flextures( *_ )
+ flextures_loader = create_or_get_flextures_loader(__method__)
+ flextures_before do
+ flextures_loader.loads( *_ )
+ end
end
+ # flexturesの読み出し
+ def create_or_get_flextures_loader(*_)
+ @@flextures_loader ||= Flextures::Loader.new(*_)
+ end
+
+ def flextures_get_options
+ @@flextures_loader
+ end
+
# delete table data
# @params [Array] _ table names
- def flextures_delete *_
- before {
+ def flextures_delete( *_ )
+ flextures_loader = create_or_get_flextures_loader(__method__)
+ flextures_before do
if _.empty?
Flextures::init_tables
else
- Flextures::delete_tables *_
+ Flextures::delete_tables( *_ )
end
- }
+ end
end
- def flextures_set_options options
- before do
- Flextures::Loader::set_options options
+ def flextures_set_options( options )
+ flextures_loader = create_or_get_flextures_loader(__method__)
+ flextures_prepend_before do
+ flextures_loader.set_options( options )
end
- after do
- Flextures::Loader::delete_options
- end
end
end
end
module Rails
@@ -51,14 +81,20 @@
module TestFixtures
alias :setup_fixtures_bkup :setup_fixtures
def setup_fixtures
Flextures::init_load
setup_fixtures_bkup
+ set_transactional_filter_params
end
+ # nilで無い時は値をtransactional_filterが有効
+ def set_transactional_filter_params
+ return if Flextures::Config.use_transactional_fixtures.nil?
+ self.use_transactional_fixtures = Flextures::Config.use_transactional_fixtures
+ end
+
alias :teardown_fixtures_bkup :teardown_fixtures
def teardown_fixtures
teardown_fixtures_bkup
end
end
end
-