Skip to content

Commit

Permalink
Remove "admin.global" scope
Browse files Browse the repository at this point in the history
  • Loading branch information
miks committed Aug 1, 2015
1 parent 29a6c3a commit 91d460a
Show file tree
Hide file tree
Showing 25 changed files with 50 additions and 58 deletions.
2 changes: 1 addition & 1 deletion lib/releaf/rspec/features_matchers.rb
Expand Up @@ -17,7 +17,7 @@ def has_header?(*args)
end

def has_number_of_resources?(count)
has_css?("#{primary_header_css_rule} .totals", text: "#{count} Resources found")
has_css?("#{primary_header_css_rule} .totals", text: "#{count} resources found")
end


Expand Down
Expand Up @@ -9,7 +9,7 @@ def footer_primary_tools
end

def cancel_button
button(t('Cancel', scope: 'admin.global'), "ban", class: "secondary", data: {type: 'cancel'}, href: url_for( action: 'index' ))
button(t('Cancel'), "ban", class: "secondary", data: {type: 'cancel'}, href: url_for( action: 'index' ))
end
end
end
Expand Up @@ -76,8 +76,8 @@ def item_position_options
end

def item_position_select_options
after_text = t('After', scope: 'admin.global')
list = [[t('First', scope: 'admin.global'), 0]]
after_text = t("After")
list = [[t("First"), 0]]
order_nodes.each do |node|
list.push [after_text + ' ' + node.name, node.lower_item ? node.lower_item.item_position : node.item_position + 1 ]
end
Expand Down
Expand Up @@ -18,7 +18,7 @@ def pagination?
end

def resource_creation_button
button(t('Create new resource', scope: 'admin.global'), "plus", class: %w(primary ajaxbox), href: url_for(controller: controller.controller_name, action: "content_type_dialog"))
button(t("Create new resource"), "plus", class: %w(primary ajaxbox), href: url_for(controller: controller.controller_name, action: "content_type_dialog"))
end
end
end
@@ -1,14 +1,14 @@
class Releaf::Builders::ConfirmDestroyDialogBuilder < Releaf::Builders::ConfirmDialogBuilder
def question_content
t('Do you want to delete the following object?', scope: 'admin.global')
t("Do you want to delete the following object?")
end

def description_content
resource_to_text(resource)
end

def section_header_text
t('Confirm deletion', scope: 'admin.global')
t("Confirm deletion")
end

def confirm_method
Expand Down
Expand Up @@ -41,14 +41,14 @@ def confirm_form_options
end

def confirm_button
button(t('Yes', scope: 'admin.global'), "check", class: "danger", type: 'submit')
button(t("Yes"), "check", class: "danger", type: 'submit')
end

def cancel_url
index_url
end

def cancel_button
button(t('No', scope: 'admin.global'), "ban", class: "secondary", data: {type: 'cancel'}, href: index_url)
button(t("No"), "ban", class: "secondary", data: {type: 'cancel'}, href: index_url)
end
end
6 changes: 3 additions & 3 deletions releaf-core/app/builders/releaf/builders/edit_builder.rb
Expand Up @@ -21,7 +21,7 @@ def index_url_preserver
end

def section_header_text
resource.new_record? ? t('Create new resource', scope: 'admin.global') : resource_to_text(resource)
resource.new_record? ? t("Create new resource") : resource_to_text(resource)
end

def section_header_extras
Expand Down Expand Up @@ -75,7 +75,7 @@ def footer_primary_tools
end

def save_button
button(t('Save', scope: "admin.global"), "check", class: "primary", data: { type: 'ok', disable: true }, type: "submit")
button(t("Save"), "check", class: "primary", data: { type: 'ok', disable: true }, type: "submit")
end

def footer_secondary_tools
Expand All @@ -89,7 +89,7 @@ def back_to_list?
end

def back_to_list_button
button(t('Back to list', scope: "admin.global"), "caret-left", class: "secondary", href: index_url)
button(t("Back to list"), "caret-left", class: "secondary", href: index_url)
end

end
Expand Up @@ -33,7 +33,7 @@ def body_content(&block)
end

def notifications
tag(:div, nil, class: "notifications", 'data-close-text' => t(:close, scope: "admin.global"))
tag(:div, nil, class: "notifications", 'data-close-text' => t("Close"))
end

def header
Expand Down
Expand Up @@ -5,7 +5,7 @@ def section_body
tag(:div, class: "body") do
[
icon("ban"),
tag(:div, t("Deletion of %{resource} was refused due to existing relations:", scope: "admin.global", default: "Deletion of %{resource} restricted, due to existing relations:", resource: resource_to_text(resource)), class: "description"),
tag(:div, t("Deletion of %{resource} was refused due to existing relations:", default: "Deletion of %{resource} restricted, due to existing relations:", resource: resource_to_text(resource)), class: "description"),
restricted_relations
]
end
Expand Down Expand Up @@ -58,11 +58,11 @@ def restricted_relation(relation, key)

def footer_primary_tools
[
button(t('Ok', scope: 'admin.global'), "check", href: index_url, data: {type: 'cancel'})
button(t("Ok"), "check", href: index_url, data: {type: 'cancel'})
]
end

def section_header_text
t('Deletion refused', scope: 'admin.global')
t("Deletion refused")
end
end
10 changes: 3 additions & 7 deletions releaf-core/app/builders/releaf/builders/table_builder.rb
Expand Up @@ -74,15 +74,15 @@ def head_cell(column)
def head_cell_content(column)
unless column.to_sym == :toolbox
attribute = column.to_s.gsub(".", "_")
I18n.t(attribute, scope: "activerecord.attributes.#{resource_class.name.underscore}")
t(attribute, scope: "activerecord.attributes.#{resource_class.name.underscore}")
end
end

def empty_body
tag(:tr) do
tag(:th) do
tag(:div, class: "nothing-found") do
I18n.t("nothing found", scope: translation_scope)
t("Nothing found")
end
end
end
Expand Down Expand Up @@ -147,7 +147,7 @@ def format_string_content(resource, column)
end

def format_boolean_content(resource, column)
I18n.t(column_value(resource, column) == true ? 'yes' : 'no', scope: translation_scope)
t(column_value(resource, column) == true ? "Yes" : "No")
end

def format_date_content(resource, column)
Expand Down Expand Up @@ -268,8 +268,4 @@ def cell(resource, column, options)
end
end
end

def translation_scope
"admin.global"
end
end
2 changes: 1 addition & 1 deletion releaf-core/app/builders/releaf/builders/toolbox.rb
Expand Up @@ -16,7 +16,7 @@ def toolbox_menu
end

def toolbox_button
tag(:button, disabled: "disabled", class: %w(button trigger only-icon), type: "button", title: t("Tools", scope: "admin.global")) do
tag(:button, disabled: "disabled", class: %w(button trigger only-icon), type: "button", title: t("Tools")) do
icon("cog lg")
end
end
Expand Down
Expand Up @@ -18,7 +18,7 @@ def items
end

def destroy_confirmation_link
button(t('Delete', scope: 'admin.global'), "trash-o lg", class: %w(ajaxbox danger),
button(t("Delete"), "trash-o lg", class: %w(ajaxbox danger),
href: destroy_confirmation_url, data: {modal: true})
end

Expand Down
4 changes: 2 additions & 2 deletions releaf-core/app/views/releaf/error_pages/_error.html.haml
Expand Up @@ -6,6 +6,6 @@
.body
- if defined? description
%div.description= description
%a.return{ :href => releaf_root_path }
= t('Go home', :scope => 'admin.global')
%a.return{href: releaf_root_path }
= t("Go home")
%i.fa.fa-chevron-right
@@ -1 +1 @@
= render 'releaf/error_pages/error', :message => t('You are not authorized to access %{controller}', :controller => controller_name, :scope => 'admin.global', :default => 'You are not authorized to access %{controller}')
= render 'releaf/error_pages/error', message: t('You are not authorized to access %{controller}', controller: controller_name, default: 'You are not authorized to access %{controller}', scope: controller_scope_name)
@@ -1 +1 @@
= render 'releaf/error_pages/error', :message => t('%{feature} feature disabled for %{controller}', feature: @feature, controller: controller_name, scope: 'admin.global', default: '%{feature} feature disabled for %{controller}')
= render 'releaf/error_pages/error', message: t('%{feature} feature disabled for %{controller}', feature: @feature, controller: controller_name, scope: controller_scope_name, default: '%{feature} feature disabled for %{controller}')
@@ -1,2 +1,2 @@
= render 'releaf/error_pages/error', :message => t('Page not found', :scope => 'admin.global'), :description => t('Something went wrong.', :scope => 'admin.global')
= render 'releaf/error_pages/error', message: t('Page not found', scope: controller_scope_name), description: t('Something went wrong.', scope: controller_scope_name)

Expand Up @@ -31,7 +31,7 @@ def request_forgery_protection_token

describe "#question_content" do
it "localized destroy question" do
allow(subject).to receive(:t).with("Do you want to delete the following object?", scope: "admin.global").and_return("xx")
allow(subject).to receive(:t).with("Do you want to delete the following object?").and_return("xx")
expect(subject.question_content).to eq("xx")
end
end
Expand Down
Expand Up @@ -82,7 +82,7 @@ def confirm_method; end

describe "#confirm_button" do
it "returns confirm button" do
allow(subject).to receive(:t).with("Yes", scope: "admin.global").and_return("Yess")
allow(subject).to receive(:t).with("Yes").and_return("Yess")
allow(subject).to receive(:button).with("Yess", "check", class: "danger", type: "submit").and_return("x")
expect(subject.confirm_button).to eq("x")
end
Expand All @@ -97,7 +97,7 @@ def confirm_method; end

describe "#cancel_button" do
it "returns cancel button" do
allow(subject).to receive(:t).with("No", scope: "admin.global").and_return("Noo")
allow(subject).to receive(:t).with("No").and_return("Noo")
allow(subject).to receive(:button).with("Noo", "ban", class: "secondary", data: {type: "cancel"}, href: "y").and_return("x")
expect(subject.cancel_button).to eq("x")
end
Expand Down
18 changes: 6 additions & 12 deletions releaf-core/spec/builders/builders/table_builder_spec.rb
Expand Up @@ -200,12 +200,12 @@ def custom_title(resource); end

describe "#head_cell_content" do
it "returns translated column scoped to resource class attributes" do
allow(I18n).to receive(:t).with("some_long_name", scope: "activerecord.attributes.book").and_return("Taittls")
allow(subject).to receive(:t).with("some_long_name", scope: "activerecord.attributes.book").and_return("Taittls")
expect(subject.head_cell_content("some_long_name")).to eq('Taittls')
end

it "casts given column to string" do
allow(I18n).to receive(:t).with("title", scope: "activerecord.attributes.book").and_return("Taittls")
allow(subject).to receive(:t).with("title", scope: "activerecord.attributes.book").and_return("Taittls")
expect(subject.head_cell_content(:title)).to eq('Taittls')
end

Expand All @@ -218,7 +218,8 @@ def custom_title(resource); end

describe "#empty_body" do
it "returns empty table body content" do
content = '<tr><th><div class="nothing-found">Nothing found</div></th></tr>'
allow(subject).to receive(:t).with("Nothing found").and_return("ntnn")
content = '<tr><th><div class="nothing-found">ntnn</div></th></tr>'
expect(subject.empty_body).to eq(content)
end
end
Expand Down Expand Up @@ -362,7 +363,7 @@ def custom_title(resource); end
describe "#format_boolean_content" do
context "when resource column value is 'true'" do
it "returns localized 'yes' value" do
allow(I18n).to receive(:t).with("yes", scope: "admin.global").and_return("Jā")
allow(subject).to receive(:t).with("Yes").and_return("Jā")
allow(subject).to receive(:column_value).with(resource, :active)
.and_return(true)

Expand All @@ -372,8 +373,7 @@ def custom_title(resource); end

context "when resource column value is other than 'true'" do
it "returns localized 'no' value" do
allow(I18n).to receive(:t).with("no", scope: "admin.global").and_return("Nē")

allow(subject).to receive(:t).with("No").and_return("Nē")
allow(subject).to receive(:column_value).with(resource, :active)
.and_return(false)
expect(subject.format_boolean_content(resource, :active)).to eq("Nē")
Expand Down Expand Up @@ -604,10 +604,4 @@ def custom_title(resource); end
end
end
end

describe "#translation_scope" do
it "returns 'admin.global'" do
expect(subject.translation_scope).to eq("admin.global")
end
end
end
3 changes: 2 additions & 1 deletion releaf-core/spec/builders/builders/toolbox_builder_spec.rb
Expand Up @@ -49,8 +49,9 @@ class ToolboxBuilderTestHelper < ActionView::Base

describe "#destroy_confirmation_link" do
it "returns destroy confirmation link" do
allow(subject).to receive(:t).with("Delete").and_return("dlt")
allow(subject).to receive(:destroy_confirmation_url).and_return("www.xxx")
content = '<a class="button with-icon ajaxbox danger" title="Delete" href="www.xxx" data-modal="true"><i class="fa fa-trash-o fa-lg"></i>Delete</a>'
content = '<a class="button with-icon ajaxbox danger" title="dlt" href="www.xxx" data-modal="true"><i class="fa fa-trash-o fa-lg"></i>dlt</a>'
expect(subject.destroy_confirmation_link).to eq(content)
end
end
Expand Down
3 changes: 2 additions & 1 deletion releaf-core/spec/builders/builders/toolbox_spec.rb
Expand Up @@ -25,12 +25,13 @@ class UnitTestToolboxBuilder
it "returns empty string" do
resource.id = 212
allow(resource).to receive(:new_record?).and_return(false)
allow(subject).to receive(:t).with("Tools").and_return("tls")
allow(subject).to receive(:icon).with("cog lg").and_return("cog_icon")
allow(subject).to receive(:icon).with("caret-up lg").and_return("caret_icon")
allow(subject).to receive(:action_name).and_return("edit")
allow(subject).to receive(:url_for).with({action: :toolbox, id: 212, context: "edit", some_param: 89}).and_return("/toolbox_action")

expect(subject.toolbox(resource, some_param: 89).gsub(/\s/,'')).to eq(%Q{<divclass=\"toolboxuninitialized\"data-url=\"/toolbox_action\"><buttondisabled=\"disabled\"class=\"buttontriggeronly-icon\"type=\"button\"title=\"Tools\">cog_icon</button><menuclass=\"blocktoolbox-items\"type=\"toolbar\">caret_icon<ulclass=\"block\"></ul></menu></div>}.gsub(/\s/,''))
expect(subject.toolbox(resource, some_param: 89).gsub(/\s/,'')).to eq(%Q{<divclass=\"toolboxuninitialized\"data-url=\"/toolbox_action\"><buttondisabled=\"disabled\"class=\"buttontriggeronly-icon\"type=\"button\"title=\"tls\">cog_icon</button><menuclass=\"blocktoolbox-items\"type=\"toolbar\">caret_icon<ulclass=\"block\"></ul></menu></div>}.gsub(/\s/,''))
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions releaf-core/spec/helpers/application_helper_spec.rb
Expand Up @@ -41,11 +41,11 @@

before do

translation = FactoryGirl.create(:translation, :key => "admin.global.colors-red")
translation = FactoryGirl.create(:translation, :key => "admin.xx.colors-red")
FactoryGirl.create(:translation_data, :lang => "en", :localization => "Color red", :translation => translation)
I18n.backend.reload_cache

allow(helper).to receive(:controller_scope_name).and_return("admin.global")
allow(helper).to receive(:controller_scope_name).and_return("admin.xx")
end

context "when array of string" do
Expand Down
Expand Up @@ -24,9 +24,9 @@ def import?

def save_button
if import?
button_text = t('Import')
button_text = t("Import")
else
button_text = t('Save', scope: "admin.global")
button_text = t("Save")
end

button(button_text, "check", class: "primary", data: { type: 'ok' }, type: "submit")
Expand All @@ -38,7 +38,7 @@ def footer_secondary_tools

def back_to_index_button
url = url_for( action: :index, search: params[:search])
button(t('Back to list', scope: 'admin.global'), "caret-left", class: "secondary", href: url)
button(t("Back to list"), "caret-left", class: "secondary", href: url)
end

def section_header; end
Expand Down
Expand Up @@ -34,7 +34,7 @@ def import_form

def edit_button
url = url_for(action: :edit, search: params[:search])
button(t('Edit', scope: 'admin.global'), "edit", class: "primary", href: url)
button(t("Edit"), "edit", class: "primary", href: url)
end
end
end
10 changes: 5 additions & 5 deletions releaf-i18n_database/spec/lib/i18n_database/backend_spec.rb
Expand Up @@ -75,14 +75,14 @@
end

it "loads all translated data to cache as hash" do
translation = FactoryGirl.create(:translation, key: "admin.global.save")
translation = FactoryGirl.create(:translation, key: "admin.xx.save")
FactoryGirl.create(:translation_data, translation: translation, localization: "saglabāt", lang: "lv")
FactoryGirl.create(:translation_data, translation: translation, localization: "save", lang: "en")

expect{ I18n.backend.reload_cache }.to change{ described_class::CACHE[:translations].blank? }.from(true).to(false)

expect(described_class::CACHE[:translations][:lv][:admin][:global][:save]).to eq("saglabāt")
expect(described_class::CACHE[:translations][:en][:admin][:global][:save]).to eq("save")
expect(described_class::CACHE[:translations][:lv][:admin][:xx][:save]).to eq("saglabāt")
expect(described_class::CACHE[:translations][:en][:admin][:xx][:save]).to eq("save")
end
end

Expand Down Expand Up @@ -222,9 +222,9 @@
context "nonexistent translation" do
context "loading multiple times" do
it "queries db only for the first time" do
I18n.t("save", scope: "admin.global")
I18n.t("save", scope: "admin.xx")
expect(Releaf::I18nDatabase::Translation).not_to receive(:where)
I18n.t("save", scope: "admin.global")
I18n.t("save", scope: "admin.xx")
end
end

Expand Down

0 comments on commit 91d460a

Please sign in to comment.