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 solidus deprecations #120

Merged
13 changes: 11 additions & 2 deletions app/decorators/models/solidus_globalize/spree/product_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,26 @@ def self.prepended(base)

include SolidusGlobalize::Translatable

after_discard do
translations.discard_all
end

translation_class.class_eval do
# Paranoia soft-deletes the associated records only if they are paranoid themselves.
acts_as_paranoid
include ::Spree::ParanoiaDeprecations

include Discard::Model
self.discard_column = :deleted_at

# Paranoid sets the default scope and Globalize rewrites all query methods.
# Therefore we prefer to unset the default_scopes over injecting 'unscope'
# in every Globalize query method.
self.default_scopes = []

# Punch slug on every translation to allow reuse of original
after_destroy :punch_slug
after_discard do
punch_slug
end

def punch_slug
update(slug: "#{Time.now.to_i}_#{slug}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!-- insert_bottom '[data-hook="localization_settings_body"]' -->
<div class="form-group">
<label for="supported_locales_">
<%= Spree.t(:'i18n.supported_locales') %>
<%= t(:'spree.i18n.supported_locales') %>
</label>
<%= select_supported_locales %>
<p class="help-block">
<%= Spree.t(:'globalize.locales_displayed_on_translation_forms') %>
<%= t(:'spree.globalize.locales_displayed_on_translation_forms') %>
</p>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- insert_bottom 'td.actions' -->
<% if f.object.persisted? %>
<%= link_to_with_icon 'globe', nil, spree.admin_translations_path('option_values', f.object.id), title: Spree.t(:'i18n.translations'), no_text: true %>
<%= link_to_with_icon 'globe', nil, spree.admin_translations_path('option_values', f.object.id), title: t(:'spree.i18n.translations'), no_text: true %>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!-- insert_bottom 'td.actions' -->
<%= link_to_with_icon 'globe', nil, spree.admin_translations_path('option_types', option_type.id), title: Spree.t(:'i18n.translations'), no_text: true %>
<%= link_to_with_icon 'globe', nil, spree.admin_translations_path('option_types', option_type.id), title: t(:'spree.i18n.translations'), no_text: true %>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- insert_bottom 'td.actions' -->
<% if f.object.persisted? %>
<%= link_to_with_icon 'globe', nil, spree.admin_translations_path('product_property', f.object.id), title: Spree.t(:'i18n.translations'), no_text: true %>
<%= link_to_with_icon 'globe', nil, spree.admin_translations_path('product_property', f.object.id), title: t(:'spree.i18n.translations'), no_text: true %>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!-- insert_bottom 'td.actions' -->
<%= link_to_with_icon 'globe', nil, spree.admin_translations_path('promotions', promotion.id), title: Spree.t(:'i18n.translations'), no_text: true %>
<%= link_to_with_icon 'globe', nil, spree.admin_translations_path('promotions', promotion.id), title: t(:'spree.i18n.translations'), no_text: true %>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!-- insert_bottom 'td.actions' -->
<%= link_to_with_icon 'globe', nil, spree.admin_translations_path('properties', property.id), title: Spree.t(:'i18n.translations'), no_text: true %>
<%= link_to_with_icon 'globe', nil, spree.admin_translations_path('properties', property.id), title: t(:'spree.i18n.translations'), no_text: true %>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- insert_bottom "[data-hook='admin_product_tabs']" -->
<li<%== ' class="active"' if current == 'Translations' %>>
<%= link_to_with_icon 'globe', Spree.t(:'i18n.translations'), spree.admin_translations_url('products', @product.slug), title: Spree.t(:'i18n.translations') %>
<%= link_to t(:'spree.i18n.translations'), spree.admin_translations_url('products', @product.slug) %>
</li>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!-- insert_bottom 'script' -->
$.extend(Spree.translations, { translations: "<%= strip_tags(Spree.t(:'i18n.translations')) %>" })
$.extend(Spree.translations, { translations: "<%= strip_tags(t(:'spree.i18n.translations')) %>" })
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!-- insert_bottom "[data-hook='admin_configurations_sidebar_menu']" -->
<%= configurations_sidebar_menu_item Spree.t(:'globalize.store_translations'), spree.admin_translations_path('stores', current_store.id) if can? :manage, Spree::Store %>
<%= configurations_sidebar_menu_item t(:'spree.globalize.store_translations'), spree.admin_translations_path('stores', current_store.id) if can? :manage, Spree::Store %>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!-- insert_bottom 'td.actions' -->
<%= link_to_with_icon 'globe', nil, spree.admin_translations_path('shipping_methods', shipping_method.id), title: Spree.t(:'i18n.translations'), no_text: true %>
<%= link_to_with_icon 'globe', nil, spree.admin_translations_path('shipping_methods', shipping_method.id), title: t(:'spree.i18n.translations'), no_text: true %>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!-- insert_bottom 'td.actions' -->
<%= link_to_with_icon 'globe', nil, spree.admin_translations_path('taxonomies', taxonomy.id), title: Spree.t(:'i18n.translations'), no_text: true %>
<%= link_to_with_icon 'globe', nil, spree.admin_translations_path('taxonomies', taxonomy.id), title: t(:'spree.i18n.translations'), no_text: true %>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!-- insert_top 'li' -->
<%= button_link_to Spree.t(:'i18n.translations'), spree.admin_translations_path('taxons', @taxon.id), no_text: true, icon: 'globe' %>
<%= link_to t(:'spree.i18n.translations'), spree.admin_translations_path('taxons', @taxon.id), class: 'btn btn-default' %>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<%= form_tag spree.set_locale_path, no_text: truenavbar-form' do %>
<div class="form-group">
<label for="switch_to_locale" class="sr-only">
<%= Spree.t(:'i18n.language') %>
<%= t(:'spree.i18n.language') %>
</label>
<%= select_tag(:switch_to_locale, options_for_select(supported_locales_options, I18n.locale), no_text: trueform-control') %>
<noscript><%= submit_tag %></noscript>
Expand Down
2 changes: 1 addition & 1 deletion app/views/spree/admin/translations/_fields.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="panel panel-default fields">
<div class="panel-heading">
<%= Spree.t(:'i18n.fields') %>
<%= t(:'spree.i18n.fields') %>
</div>
<div class="list-group" id="attr_list">
<% @resource.class.translated_attribute_names.each_with_index do |attr, i| %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/spree/admin/translations/_form_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<%= @resource.class.human_attribute_name(attr) %>

<div class="pull-right text-muted">
<small><i><%= Spree.t(:'i18n.this_file_language') %></i></small>
<small><i><%= t(:'spree.i18n.this_file_language') %></i></small>
</div>
<% end %>
</div>
Expand All @@ -26,7 +26,7 @@
<% end %>

<p class="no-translations" style="display: none">
<%= Spree.t(:'globalize.no_translations_for_criteria') %>
<%= t(:'spree.globalize.no_translations_for_criteria') %>
</p>
</div>

Expand Down
10 changes: 5 additions & 5 deletions app/views/spree/admin/translations/_settings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
<div class="row no-padding-bottom">
<div class="col-md-4">
<div class="form-group no-margin-bottom">
<label><%= Spree.t(:show) %></label>
<label><%= t(:'spree.show') %></label>
<select class="form-control" name="show-only">
<option value="all"><%= Spree.t(:all) %></option>
<option value="incomplete"><%= Spree.t(:'i18n.only_incomplete') %></option>
<option value="complete"><%= Spree.t(:'i18n.only_complete') %></option>
<option value="all"><%= t(:'spree.all') %></option>
<option value="incomplete"><%= t(:'spree.i18n.only_incomplete') %></option>
<option value="complete"><%= t(:'spree.i18n.only_complete') %></option>
</select>
</div>
</div>

<div class="col-md-8">
<div class="form-group no-margin-bottom">
<label>
<%= Spree.t(:'i18n.select_locale') %>
<%= t(:'spree.i18n.select_locale') %>
<%= select_available_locales_fields %>
</label>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/spree/admin/translations/option_type.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<% content_for :page_title do %>
<%= Spree.t(:editing_resource, resource: Spree::OptionType.model_name.human) %> <span class="green">"<%= @option_type.name %>"</span>
<%= t(:'spree.editing_resource', resource: Spree::OptionType.model_name.human) %> <span class="green">"<%= @option_type.name %>"</span>
<% end %>

<% content_for :page_actions do %>
<%= button_link_to Spree.t(:back_to_resource_list, resource: Spree::OptionType.model_name.human), spree.admin_option_types_path, class: 'btn-primary', icon: 'arrow-left' %>
<%= link_to t(:'spree.back_to_resource_list', resource: Spree::OptionType.model_name.human), spree.admin_option_types_path, class: 'btn btn-primary' %>
<% end %>

<%= render 'form' %>
12 changes: 6 additions & 6 deletions app/views/spree/admin/translations/option_value.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<% content_for :page_title do %>
<%= Spree.t(:editing_resource, resource: Spree::OptionValue.model_name.human) %> <span class="green">"<%= @option_value.name %>"</span>
<%= t(:'spree.editing_resource', resource: Spree::OptionValue.model_name.human) %> <span class="green">"<%= @option_value.name %>"</span>
<% end %>

<% content_for :page_actions do %>
<%= button_link_to Spree.t(:back_to_resource_list, resource: Spree::OptionValue.model_name.human), spree.edit_admin_option_type_path(@option_value.option_type), class: 'btn-primary', icon: 'arrow-left' %>
<%= link_to t(:'spree.back_to_resource_list', resource: Spree::OptionValue.model_name.human), spree.edit_admin_option_type_path(@option_value.option_type), class: 'btn btn-primary' %>
<% end %>

<%= render 'settings' %>
Expand All @@ -15,10 +15,10 @@
<div class="col-md-8">
<%= form_for [:admin, :option_type, @resource] do |f| %>
<%= render 'form_fields', f: f %>
<div class="form-actions" data-hook="buttons">
<%= button Spree.t(:update), 'update' %>
<span class="or"><%= Spree.t(:or) %></span>
<%= button_link_to Spree.t(:cancel), spree.edit_admin_option_type_path(@option_value.option_type), icon: 'remove' %>

<div class="form-buttons filter-actions actions" data-hook="buttons">
<%= button_tag t('spree.actions.update'), class: 'btn btn-primary' %>
<%= link_to t('spree.actions.cancel'), spree.edit_admin_option_type_path(@option_value.option_type), class: 'button' %>
</div>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/spree/admin/translations/product.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= render 'spree/admin/shared/product_tabs', current: 'Translations' %>

<% content_for :page_actions do %>
<%= button_link_to Spree.t(:back_to_resource_list, resource: Spree::Product.model_name.human), spree.admin_products_path, class: 'btn-primary', icon: 'arrow-left' %>
<%= link_to t(:'spree.back_to_resource_list', resource: Spree::Product.model_name.human), spree.admin_products_path, class: 'btn btn-primary' %>
<% end %>

<%= render 'form' %>
12 changes: 6 additions & 6 deletions app/views/spree/admin/translations/product_property.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<% content_for :page_title do %>
<%= Spree.t(:editing_resource, resource: Spree::ProductProperty.model_name.human) %> <span class="green">"<%= @product_property.property.presentation %>"</span>
<%= t(:'spree.editing_resource', resource: Spree::ProductProperty.model_name.human) %> <span class="green">"<%= @product_property.property.presentation %>"</span>
<% end %>

<% content_for :page_actions do %>
<%= button_link_to Spree.t(:back_to_resource_list, resource: Spree::ProductProperty.model_name.human), spree.admin_product_product_properties_path(@product_property.product), class: 'btn-primary', icon: 'icon-arrow-left' %>
<%= link_to t(:'spree.back_to_resource_list', resource: Spree::ProductProperty.model_name.human), spree.admin_product_product_properties_path(@product_property.product), class: 'btn btn-primary' %>
<% end %>

<%= render 'settings' %>
Expand All @@ -15,10 +15,10 @@
<div class="col-md-8">
<%= form_for [:admin, @resource.product, @resource], method: :patch do |f| %>
<%= render 'form_fields', f: f %>
<div class="form-actions" data-hook="buttons">
<%= button Spree.t(:update), 'update' %>
<span class="or"><%= Spree.t(:or) %></span>
<%= button_link_to Spree.t(:cancel), spree.admin_product_product_properties_path(@product_property.product), icon: 'remove' %>

<div class="form-buttons filter-actions actions" data-hook="buttons">
<%= button_tag t('spree.actions.update'), class: 'btn btn-primary' %>
<%= link_to t('spree.actions.cancel'), spree.admin_product_product_properties_path(@product_property.product), class: 'button' %>
</div>
<% end %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/spree/admin/translations/promotion.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<% content_for :page_title do %>
<%= Spree.t(:editing_resource, resource: Spree::Promotion.model_name.human) %>
<%= t(:'spree.editing_resource', resource: Spree::Promotion.model_name.human) %>
<% end %>

<% content_for :page_actions do %>
<%= button_link_to Spree.t(:back_to_resource_list, resource: Spree::Promotion.model_name.human), spree.admin_promotions_path, class: 'btn-primary', icon: 'arrow-left' %>
<%= link_to t(:'spree.back_to_resource_list', resource: Spree::Promotion.model_name.human), spree.admin_promotions_path, class: 'btn btn-primary' %>
<% end %>

<%= render 'form' %>
4 changes: 2 additions & 2 deletions app/views/spree/admin/translations/property.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<% content_for :page_title do %>
<%= Spree.t(:editing_resource, resource: Spree::Property.model_name.human) %>
<%= t(:'spree.editing_resource', resource: Spree::Property.model_name.human) %>
<% end %>

<% content_for :page_actions do %>
<%= button_link_to Spree.t(:back_to_resource_list, resource: Spree::Property.model_name.human), spree.admin_properties_path, class: 'btn-primary', icon: 'arrow-left' %>
<%= link_to t(:'spree.back_to_resource_list', resource: Spree::Property.model_name.human), spree.admin_properties_path, class: 'btn btn-primary' %>
<% end %>

<%= render 'form' %>
4 changes: 2 additions & 2 deletions app/views/spree/admin/translations/shipping_method.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<% content_for :page_title do %>
<%= Spree.t(:editing_resource, resource: Spree::ShippingMethod.model_name.human) %>
<%= t(:'spree.editing_resource', resource: Spree::ShippingMethod.model_name.human) %>
<% end %>

<% content_for :page_actions do %>
<%= button_link_to Spree.t(:back_to_resource_list, resource: Spree::ShippingMethod.model_name.human), spree.admin_shipping_methods_path, class: 'btn-primary', :icon => 'arrow-left' %>
<%= link_to t(:'spree.back_to_resource_list', resource: Spree::ShippingMethod.model_name.human), spree.admin_shipping_methods_path, class: 'btn btn-primary' %>
<% end %>

<%= render 'form' %>
10 changes: 5 additions & 5 deletions app/views/spree/admin/translations/store.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% content_for :page_title do %>
<%= Spree.t(:editing_resource, resource: Spree::Store.model_name.human) %>
<%= t(:'spree.editing_resource', resource: Spree::Store.model_name.human) %>
<% end %>

<%= render 'settings' %>
Expand All @@ -11,10 +11,10 @@
<div class="col-md-8">
<%= form_for [:admin, @resource], url: spree.admin_general_settings_path do |f| %>
<%= render 'form_fields', f: f %>
<div class="form-actions" data-hook="buttons">
<%= button Spree.t('actions.update'), 'refresh', 'submit', {class: 'btn-success'} %>
<span class="or"><%= Spree.t(:or) %></span>
<%= button_link_to Spree.t('actions.cancel'), spree.edit_admin_general_settings_path, icon: 'delete' %>

<div class="form-buttons filter-actions actions" data-hook="buttons">
<%= button_tag t('spree.actions.update'), class: 'btn btn-primary' %>
<%= link_to t('spree.actions.cancel'), spree.edit_admin_general_settings_path, class: 'button' %>
</div>
<% end %>
</div>
Expand Down
12 changes: 6 additions & 6 deletions app/views/spree/admin/translations/taxon.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<% content_for :page_title do %>
<%= Spree.t(:editing_resource, resource: Spree::Taxon.model_name.human) %>
<%= t(:'spree.editing_resource', resource: Spree::Taxon.model_name.human) %>
<% end %>

<% content_for :page_actions do %>
<%= button_link_to Spree.t(:back_to_resource_list, resource: Spree::Taxonomy.model_name.human), spree.admin_taxonomies_path, class: 'btn-primary', icon: 'arrow-left' %>
<%= link_to t(:'spree.back_to_resource_list', resource: Spree::Taxonomy.model_name.human), spree.admin_taxonomies_path, class: 'btn btn-primary' %>
<% end %>

<%= render 'settings' %>
Expand All @@ -15,10 +15,10 @@
<div class="col-md-8">
<%= form_for [:admin, @resource.taxonomy, @resource], url: spree.admin_taxonomy_taxon_path(@taxon.taxonomy, @taxon.id) do |f| %>
<%= render 'form_fields', f: f %>
<div class="form-actions" data-hook="buttons">
<%= button Spree.t(:update), 'update' %>
<span class="or"><%= Spree.t(:or) %></span>
<%= button_link_to Spree.t(:cancel), spree.edit_admin_taxonomy_url(@taxon.taxonomy), icon: 'remove' %>

<div class="form-buttons filter-actions actions" data-hook="buttons">
<%= button_tag t('spree.actions.update'), class: 'btn btn-primary' %>
<%= link_to t('spree.actions.cancel'), spree.edit_admin_taxonomy_url(@taxon.taxonomy), class: 'button' %>
</div>
<% end %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/spree/admin/translations/taxonomy.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<% content_for :page_title do %>
<%= Spree.t(:editing_resource, resource: Spree::Taxonomy.model_name.human) %>
<%= t(:'spree.editing_resource', resource: Spree::Taxonomy.model_name.human) %>
<% end %>

<% content_for :page_actions do %>
<%= button_link_to Spree.t(:back_to_resource_list, resource: Spree::Taxonomy.model_name.human), spree.admin_taxonomies_path, class: 'btn-primary', icon: 'arrow-left' %>
<%= link_to t(:'spree.back_to_resource_list', resource: Spree::Taxonomy.model_name.human), spree.admin_taxonomies_path, class: 'btn btn-primary' %>
<% end %>

<%= render 'form' %>
15 changes: 9 additions & 6 deletions spec/features/admin/translations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
stub_authorization!
include_context 'with pt-BR locale file in place'

let(:language) { Spree.t(:this_file_language, scope: 'i18n', locale: 'pt-BR') }
let(:language) { I18n.t(:this_file_language, scope: 'spree.i18n', locale: 'pt-BR') }
let!(:store) { create(:store, available_locales: available_locales) }
let(:available_locales) { [:en, :'pt-BR'] }

before do
create(:store, available_locales: available_locales)
reset_spree_preferences
SolidusGlobalize::Config.supported_locales = [:en, :'pt-BR']
end

after do
SolidusGlobalize::Config.supported_locales = [:en]
end

context "products" do
let(:product) { create(:product) }

Expand Down Expand Up @@ -225,8 +228,8 @@
context "store" do
pending 'saves translated attributes properly' do
visit spree.edit_admin_general_settings_path
click_link Spree.t(:configurations)
click_link Spree.t(:'globalize.store_translations')
click_link I18n.t(:configurations)
click_link I18n.t(:'spree.globalize.store_translations')

within("#attr_fields .name.pt-BR") { fill_in_name "nome store" }
click_on "Update"
Expand Down Expand Up @@ -267,7 +270,7 @@
end

context "localization settings" do
let(:language) { Spree.t(:this_file_language, scope: 'i18n', locale: 'pt-BR') }
let(:language) { I18n.t(:this_file_language, scope: 'spree.i18n', locale: 'pt-BR') }

before do
create(:store, available_locales: [:en])
Expand All @@ -283,7 +286,7 @@
end

context "permalink routing" do
let(:language) { Spree.t(:this_file_language, scope: 'i18n', locale: 'pt-BR') }
let(:language) { I18n.t(:this_file_language, scope: 'spree.i18n', locale: 'pt-BR') }
let(:product) { create(:product) }
let(:available_locales) { [:en, :'pt-BR'] }

Expand Down
Loading