Sha256: b69c88667dbd7b9be9101e493b827ad7572bb5c8c5b9b87a5140f452e65cbee8

Contents?: true

Size: 870 Bytes

Versions: 11

Compression:

Stored size: 870 Bytes

Contents

# encoding: utf-8
require 'i18n'

module Link2
  module SubstitutionsHelper

    # Execute the block setting the given values and restoring old values after
    # the block is executed.
    def swap(object, new_values)
      old_values = {}
      new_values.each do |key, value|
        old_values[key] = object.send key
        object.send :"#{key}=", value
      end
      yield
    ensure
      old_values.each do |key, value|
        object.send :"#{key}=", value
      end
    end

    def store_translations(locale, translations, &block)
      current_translations = ::I18n.backend.send(:translations).send(:[], locale.to_sym)

      begin
        ::I18n.backend.store_translations locale, translations
        yield
      ensure
        # ::I18n.reload!
      end
    end

  end
end

ActiveSupport::TestCase.class_eval do
  include Link2::SubstitutionsHelper
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
link2-0.1.11 test/support/substitutions_helper.rb
link2-0.1.10 test/support/substitutions_helper.rb
link2-0.1.9 test/support/substitutions_helper.rb
link2-0.1.8 test/support/substitutions_helper.rb
link2-0.1.7 test/support/substitutions_helper.rb
link2-0.1.6 test/support/substitutions_helper.rb
link2-0.1.5 test/support/substitutions_helper.rb
link2-0.1.4 test/support/substitutions_helper.rb
link2-0.1.3 test/support/substitutions_helper.rb
link2-0.1.1 test/support/substitutions_helper.rb
link2-0.1.0 test/support/substitutions_helper.rb