Sha256: 78a16f9cc26a2fac64dda0b07657a0b44a4218aa8535a1d6ae69b9ec9e248e7b

Contents?: true

Size: 1.36 KB

Versions: 7

Compression:

Stored size: 1.36 KB

Contents

module FixtureBackground
  module ActiveSupport
    module TestCase
      extend ::ActiveSupport::Concern
  
      included do
        class_inheritable_accessor :background_ivars
        class_inheritable_accessor :active_record_fixture_cache_resetted

        set_callback(:setup, :before, :reset_active_record_fixture_cache, {:prepend => true})
        set_callback(:setup, :before, :setup_background_ivars)
      end

      module ClassMethods
        def parent_fixture_background
          nil
        end
        
        def fixture_background
          @fixture_background
        end
        
        def background(&blk)
          @fixture_background = FixtureBackground::Background.new(name, self, nil, blk) 
        end
      end
  
      module InstanceMethods
        def setup_background_ivars
          self.background_ivars ||= IVars.deserialize((YAML.load_file("#{fixture_path}/ivars.dump") rescue {})) 

          deep_copy = Marshal.load(Marshal.dump(self.background_ivars))

          deep_copy.each do |ivar, record|
            instance_variable_set(ivar,record)
          end
        end
    
        def reset_active_record_fixture_cache
          return if active_record_fixture_cache_resetted
      
          Fixtures.class_variable_set(:@@all_cached_fixtures, {})
          self.active_record_fixture_cache_resetted = true
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fixture_background-0.9.7 lib/fixture_background/active_support/test_case.rb
fixture_background-0.9.6 lib/fixture_background/active_support/test_case.rb
fixture_background-0.9.5 lib/fixture_background/active_support/test_case.rb
fixture_background-0.9.4 lib/fixture_background/active_support/test_case.rb
fixture_background-0.9.3 lib/fixture_background/active_support/test_case.rb
fixture_background-0.9.2 lib/fixture_background/active_support/test_case.rb
fixture_background-0.9.1 lib/fixture_background/active_support/test_case.rb