Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove testing_support/i18n #2340

Merged
merged 1 commit into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 0 additions & 97 deletions core/lib/spree/testing_support/i18n.rb

This file was deleted.

73 changes: 4 additions & 69 deletions core/spec/lib/i18n_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'spec_helper'
require 'spree/i18n'
require 'spree/testing_support/i18n'

RSpec.describe "i18n" do
before do
Expand All @@ -20,20 +19,20 @@
end

it "translates within the spree scope" do
expect(Spree.normal_t(:foo)).to eql("bar")
expect(Spree.t(:foo)).to eql("bar")
expect(Spree.translate(:foo)).to eql("bar")
end

it "prepends a string scope" do
expect(Spree.normal_t(:foo, scope: "bar")).to eql("bar within bar scope")
expect(Spree.t(:foo, scope: "bar")).to eql("bar within bar scope")
end

it "prepends to an array scope" do
expect(Spree.normal_t(:foo, scope: ["bar"])).to eql("bar within bar scope")
expect(Spree.t(:foo, scope: ["bar"])).to eql("bar within bar scope")
end

it "returns two translations" do
expect(Spree.normal_t([:foo, 'bar.foo'])).to eql(["bar", "bar within bar scope"])
expect(Spree.t([:foo, 'bar.foo'])).to eql(["bar", "bar within bar scope"])
end

it "returns reasonable string for missing translations" do
Expand All @@ -43,68 +42,4 @@
it "should have a Spree::I18N_GENERIC_PLURAL constant" do
expect(Spree::I18N_GENERIC_PLURAL).to eq 2.1
end

context "missed + unused translations" do
def key_with_locale(key)
"#{key} (#{I18n.locale})"
end

before do
Spree.used_translations = []
end

context "missed translations" do
def assert_missing_translation(key)
key = key_with_locale(key)
message = Spree.missing_translation_messages.detect { |m| m == key }
expect(message).not_to(be_nil, "expected '#{key}' to be missing, but it wasn't.")
end

it "logs missing translations" do
Spree.t(:missing, scope: [:else, :where])
Spree.check_missing_translations
assert_missing_translation("else")
assert_missing_translation("else.where")
assert_missing_translation("else.where.missing")
end

it "does not log present translations" do
Spree.t(:foo)
Spree.check_missing_translations
expect(Spree.missing_translation_messages).to be_empty
end

it "does not break when asked for multiple translations" do
Spree.t [:foo, 'bar.foo']
Spree.check_missing_translations
expect(Spree.missing_translation_messages).to be_empty
end
end

context "unused translations" do
def assert_unused_translation(key)
key = key_with_locale(key)
message = Spree.unused_translation_messages.detect { |m| m == key }
expect(message).not_to(be_nil, "expected '#{key}' to be unused, but it was used.")
end

def assert_used_translation(key)
key = key_with_locale(key)
message = Spree.unused_translation_messages.detect { |m| m == key }
expect(message).to(be_nil, "expected '#{key}' to be used, but it wasn't.")
end

it "logs translations that aren't used" do
Spree.check_unused_translations
assert_unused_translation("bar.legacy_translation")
assert_unused_translation("legacy_translation")
end

it "does not log used translations" do
Spree.t(:foo)
Spree.check_unused_translations
assert_used_translation("foo")
end
end
end
end
4 changes: 0 additions & 4 deletions core/spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@

Dir["./spec/support/**/*.rb"].sort.each { |f| require f }

if ENV["CHECK_TRANSLATIONS"]
require "spree/testing_support/i18n"
end

require 'spree/testing_support/factories'
require 'spree/testing_support/preferences'
require 'cancan/matchers'
Expand Down
4 changes: 0 additions & 4 deletions frontend/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@

require 'database_cleaner'

if ENV["CHECK_TRANSLATIONS"]
require "spree/testing_support/i18n"
end

require 'spree/testing_support/authorization_helpers'
require 'spree/testing_support/capybara_ext'
require 'spree/testing_support/factories'
Expand Down