Skip to content

Commit

Permalink
Remove "create_default" option for i18n backend
Browse files Browse the repository at this point in the history
  • Loading branch information
miks committed Oct 11, 2016
1 parent b3c3b5d commit 18a063a
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 55 deletions.
2 changes: 1 addition & 1 deletion releaf-core/app/builders/releaf/builders/form_builder.rb
Expand Up @@ -100,7 +100,7 @@ def input_attributes(_name, attributes, _options)
end

def translate_attribute(attribute)
object.class.human_attribute_name(attribute, create_default: false)
object.class.human_attribute_name(attribute)
end

def association_collection(reflector)
Expand Down
Expand Up @@ -23,7 +23,7 @@ def restricted_relations
end

def relation_description(relation, key)
"#{resource.class.human_attribute_name(key, create_default: false)} (#{relation[:objects].count})"
"#{resource.class.human_attribute_name(key)} (#{relation[:objects].count})"
end

def relation_objects(relation)
Expand Down
2 changes: 1 addition & 1 deletion releaf-core/app/builders/releaf/builders/table_builder.rb
Expand Up @@ -73,7 +73,7 @@ def head_cell(column)
def head_cell_content(column)
unless column.to_sym == :toolbox
attribute = column.to_s.tr(".", "_")
resource_class.human_attribute_name(attribute, create_default: false)
resource_class.human_attribute_name(attribute)
end
end

Expand Down
Expand Up @@ -221,7 +221,7 @@ class FormBuilderTestHelper < ActionView::Base

describe "#translate_attribute" do
it "translates given attribute within object translation scope" do
allow(object.class).to receive(:human_attribute_name).with("x", create_default: false).and_return("z")
allow(object.class).to receive(:human_attribute_name).with("x").and_return("z")
expect(subject.translate_attribute("x")).to eq("z")
end
end
Expand Down
Expand Up @@ -196,12 +196,12 @@ def custom_title(resource); end

describe "#head_cell_content" do
it "returns translated column scoped to resource class attributes" do
allow(resource_class).to receive(:human_attribute_name).with("some_long_name", create_default: false).and_return("Taittls")
allow(resource_class).to receive(:human_attribute_name).with("some_long_name").and_return("Taittls")
expect(subject.head_cell_content("some_long_name")).to eq('Taittls')
end

it "casts given column to string" do
allow(resource_class).to receive(:human_attribute_name).with("title", create_default: false).and_return("Taittls")
allow(resource_class).to receive(:human_attribute_name).with("title",).and_return("Taittls")
expect(subject.head_cell_content(:title)).to eq('Taittls')
end

Expand Down
9 changes: 0 additions & 9 deletions releaf-i18n_database/lib/releaf/i18n_database/backend.rb
Expand Up @@ -64,15 +64,6 @@ def lookup(locale, key, scope = [], options = {})

result
end

def default(locale, object, subject, options = {})
if options[:create_default] == false
options = options.except(:create_default)
options[:create_missing] = false
end

super
end
end
end
end
16 changes: 0 additions & 16 deletions releaf-i18n_database/spec/features/translations_spec.rb
Expand Up @@ -258,22 +258,6 @@
end
end

context "when translation has default" do
context "when default creation is disabled" do
it "creates base translation" do
expect{ I18n.t("xxx.test.mest", default: :"xxx.mest", create_default: false) }.to change{ Releaf::I18nDatabase::I18nEntry.pluck(:key) }
.to(["xxx.test.mest"])
end
end

context "when default creation is not disabled" do
it "creates base and default translations" do
expect{ I18n.t("xxx.test.mest", default: :"xxx.mest") }.to change{ Releaf::I18nDatabase::I18nEntry.pluck(:key) }
.to(match_array(["xxx.mest", "xxx.test.mest"]))
end
end
end

context "in parent scope" do
context "nonexistent translation in given scope" do
it "uses parent scope" do
Expand Down
24 changes: 0 additions & 24 deletions releaf-i18n_database/spec/lib/releaf/i18n_database/backend_spec.rb
Expand Up @@ -60,30 +60,6 @@
end
end

describe "#default" do
context "when `create_default: false` option exists" do
it "adds `create_default: true` option and remove `create_default` option" do
expect(subject).to receive(:resolve).with("en", "aa", "bb", count: 1, fallback: true, create_missing: false)
subject.send(:default, "en", "aa", "bb", count:1, default: "xxx", fallback: true, create_default: false, create_missing: false)
end

it "does not change given options" do
options = {count:1, default: "xxx", fallback: true, create_default: false}
expect{ subject.send(:default, "en", "aa", "bb", options) }.to_not change{ options }
end
end

context "when `create_default: false` option does not exists" do
it "does not modify options" do
expect(subject).to receive(:resolve).with("en", "aa", "bb", count: 1, fallback: true)
subject.send(:default, "en", "aa", "bb", count:1, default: "xxx", fallback: true)

expect(subject).to receive(:resolve).with("en", "aa", "bb", count: 1, fallback: true, create_default: true)
subject.send(:default, "en", "aa", "bb", count:1, default: "xxx", fallback: true, create_default: true)
end
end
end

describe ".translations_updated_at" do
it "returns translations updated_at from cached settings" do
allow(Releaf::Settings).to receive(:[]).with(described_class::UPDATED_AT_KEY).and_return("x")
Expand Down

0 comments on commit 18a063a

Please sign in to comment.