Sha256: d69463ddcad27b87e6f6dbb340f593ba194c2ff9217015d55cd69183f14025e8

Contents?: true

Size: 1.1 KB

Versions: 12

Compression:

Stored size: 1.1 KB

Contents

require 'spec_helper'
require 'copy_tuner_client/helper_extension'
require 'copy_tuner_client/copyray'

describe CopyTunerClient::HelperExtension do
  # rails <= 6.0.x
  module HashArgumentHelper
    def translate(key, options = {})
      "Hello, #{options[:name]}"
    end
  end

  # rails >= 6.1.x
  module KeywordArgumentsHelper
    def translate(key, **options)
      "Hello, #{options[:name]}"
    end
  end

  class HashArgumentView
    include HashArgumentHelper
  end

  class KeywordArgumentsView
    include KeywordArgumentsHelper
  end

  CopyTunerClient::HelperExtension.hook_translation_helper(HashArgumentHelper, middleware_enabled: true)
  CopyTunerClient::HelperExtension.hook_translation_helper(KeywordArgumentsHelper, middleware_enabled: true)

  it 'works with hash argument method' do
    view = HashArgumentView.new
    expect(view.translate('some.key', name: 'World')).to eq '<!--COPYRAY some.key-->Hello, World'
  end

  it 'works with keyword argument method' do
    view = KeywordArgumentsView.new
    expect(view.translate('some.key', name: 'World')).to eq '<!--COPYRAY some.key-->Hello, World'
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
copy_tuner_client-0.15.0 spec/copy_tuner_client/helper_extension_spec.rb
copy_tuner_client-0.14.2 spec/copy_tuner_client/helper_extension_spec.rb
copy_tuner_client-0.14.1 spec/copy_tuner_client/helper_extension_spec.rb
copy_tuner_client-0.14.0 spec/copy_tuner_client/helper_extension_spec.rb
copy_tuner_client-0.13.6 spec/copy_tuner_client/helper_extension_spec.rb
copy_tuner_client-0.13.5 spec/copy_tuner_client/helper_extension_spec.rb
copy_tuner_client-0.13.3 spec/copy_tuner_client/helper_extension_spec.rb
copy_tuner_client-0.13.2 spec/copy_tuner_client/helper_extension_spec.rb
copy_tuner_client-0.13.1 spec/copy_tuner_client/helper_extension_spec.rb
copy_tuner_client-0.13.0 spec/copy_tuner_client/helper_extension_spec.rb
copy_tuner_client-0.12.0 spec/copy_tuner_client/helper_extension_spec.rb
copy_tuner_client-0.11.0 spec/copy_tuner_client/helper_extension_spec.rb