Skip to content

Commit

Permalink
fix: Ruby 3.0 keyword argument error when ICE is enabled (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilka2 committed May 21, 2024
1 parent 9ec6741 commit d0efad8
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/phraseapp-in-context-editor-ruby/backend_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def phraseapp_delegate_for(args)
key = given_key_from_args(args)
return nil unless present?(key)

options = args[1].nil? ? {} : args[1]
options = options_from_args(args)
PhraseApp::InContextEditor::Delegate::I18nDelegate.new(key, options, args)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module PhraseApp
module InContextEditor
module Delegate
class I18nDelegate < Base
attr_accessor :key, :display_key, :options, :api_client, :fallback_keys, :original_args
attr_accessor :key, :display_key

def initialize(key, options = {}, original_args = nil)
@key = key
Expand All @@ -24,7 +24,7 @@ def method_missing(*args, &block)
data.send(*args, &block)
else
self.class.log "You tried to execute the missing method ##{args.first} on key #{@key} which is not supported. Please make sure you treat your translations as strings only."
original_translation = ::I18n.translate_without_phraseapp(*@original_args)
original_translation = ::I18n.translate_without_phraseapp(*@original_args, **@options)
original_translation.send(*args, &block)
end
end
Expand Down
49 changes: 49 additions & 0 deletions spec/phraseapp-in-context-editor-ruby/backend_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,53 @@
it { is_expected.to eql "my.key" }
end
end

describe "delegation of methods on translatable values" do
let(:key) { "foo" }
let(:options) { {} }
let(:delegate) { phraseapp_service.translate(key, **options)}

before(:each) do
PhraseApp::InContextEditor.enabled = true
end

context "string method to decorated_key_name" do
subject { delegate.include? "phrase_foo" }
let(:method_return) { true }

before(:each) do
expect(I18n).not_to receive(:translate_without_phraseapp)
end

it { is_expected.to eql method_return }

context "with an option set" do
let(:options) { {locale: :en} }

it { is_expected.to eql method_return }
end
end

context "non-string method to original translation" do
subject { delegate.value? 3 }

let(:i18n_translation) { {baz: 3} }
let(:scoped) { "bar" }
let(:i18n_translation_scoped) { {baz: 5} }

before(:each) do
I18n.backend.store_translations(:en, {key => i18n_translation})
I18n.backend.store_translations(:en, {scoped => {key => i18n_translation_scoped}})
expect(I18n).to receive(:translate_without_phraseapp).and_call_original
end

it { is_expected.to eql true }

context "with an option set" do
let(:options) { {scope: scoped} }

it { is_expected.to eql false }
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
require "phraseapp-in-context-editor-ruby/delegate/i18n_delegate"

describe PhraseApp::InContextEditor::Delegate::I18nDelegate do
let(:key) { "foo.bar" }
let(:options) { {} }
let(:original_args) { double }
let(:delegate) { PhraseApp::InContextEditor::Delegate::I18nDelegate.new(key) }

subject { delegate }

describe "#to_s" do
let(:key) { "foo.bar" }
subject { delegate.to_s }
Expand All @@ -19,6 +14,7 @@
end

describe "#camelize" do
let(:key) { "foo.bar" }
subject { delegate.camelize }

it { is_expected.to be_a String }
Expand Down Expand Up @@ -58,6 +54,9 @@
end

describe "#decorated_key_name" do
let(:key) { "foo.bar" }
subject { delegate }

it "should include the phrase prefix" do
allow(PhraseApp::InContextEditor).to receive(:prefix).and_return("??")
expect(subject.send(:decorated_key_name).start_with?("??")).to be_truthy
Expand Down

0 comments on commit d0efad8

Please sign in to comment.