Skip to content
Browse files

Merge branch '1-1-stable'

Conflicts:
	Gemfile
	Gemfile.lock
	README.md
	spec/models/taxon_spec.rb
	spec/requests/products_spec.rb
  • Loading branch information...
2 parents 83e67b0 + c4727a1 commit c2160729f44b6c78974fb2d5ff52daacaab33226 @sbounmy sbounmy committed
View
15 .travis.yml
@@ -0,0 +1,15 @@
+language: ruby
+rvm:
+ - 1.9.3
+
+before_script:
+ - "sh -e /etc/init.d/xvfb start"
+ - "bundle exec rake test_app"
+
+script:
+ - "DISPLAY=:99.0 bundle exec rspec spec"
+
+branches:
+ only:
+ - 1-0-stable
+ - 1-1-stable
View
9 Gemfile
@@ -4,13 +4,4 @@ group :test do
gem 'ffaker'
end
-if RUBY_VERSION < "1.9"
- gem "ruby-debug"
-else
- gem "ruby-debug19"
-end
-
-gem 'awesome_print'
-gem 'routing-filter', :git => "git://github.com/svenfuchs/routing-filter.git"
-
gemspec
View
9 README.md
@@ -1,4 +1,4 @@
-# SpreeMultiLingual
+# SpreeMultiLingual [![Build Status](https://secure.travis-ci.org/sbounmy/spree_multi_lingual.png?branch=1-0-stable)](http://travis-ci.org/sbounmy/spree_multi_lingual)
SpreeMultiLingual is originally a proof of concept for what could become a multi-lingual Spree plugin.
@@ -14,7 +14,6 @@ Add gem to your Gemfile:
```ruby
gem "spree_multi_lingual", :git => "git@github.com:jipiboily/spree_multi_lingual.git"
-gem 'routing-filter', :git => "git://github.com/MoritzMoritz/routing-filter.git", :branch => "locale-exclusion"
```
Run Bundler
@@ -34,7 +33,7 @@ For the moment, enable locale fallbacks for I18n (makes lookups for any locale f
```ruby
# config/application.rb
-config.I18.fallbacks = true
+config.I18n.fallbacks = true
```
Run spree_multi_lingual install:
@@ -100,6 +99,10 @@ SpreeMultiLingual depends on a fork of routing-filter because it supports :exclu
5. Fallback
6. Rake task for store that already have users
+## Contributors
+
+Special thanks to sbounmy for the amount of contributions he did. Thanks to Radar for merging spree_localize.
+
## Testing
Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.
View
16 app/controllers/admin/base_controller_decorator.rb
@@ -0,0 +1,16 @@
+Spree::Admin::BaseController.class_eval do
+ # removed link to /products
+ helper_method :locale_suffix
+
+ def locale_suffix(locale)
+ locale ||= I18n.locale
+ I18n.locale == locale.to_sym ? "".to_sym : "_"+ locale
+ end
+
+ private
+
+ def set_user_language
+ I18n.locale = Spree::Config[:default_locale].to_sym
+ end
+
+end
View
22 app/controllers/base_controller_decorator.rb → ...ntrollers/controller_helpers_decorator.rb
@@ -1,4 +1,4 @@
-Spree::BaseController.class_eval do
+Spree::Core::ControllerHelpers.module_eval do
private
# Internal : Set user I18n.locale
@@ -15,22 +15,4 @@ def set_user_language
locale = I18n.default_locale unless locale && I18n.available_locales.include?(locale.to_sym)
I18n.locale = locale.to_sym
end
-end
-
-
-Spree::Admin::BaseController.class_eval do
- # removed link to /products
- helper_method :locale_suffix
-
- def locale_suffix(locale)
- locale ||= I18n.locale
- I18n.locale == locale.to_sym ? "".to_sym : "_"+ locale
- end
-
- private
-
- def set_user_language
- I18n.locale = Spree::Config[:default_locale].to_sym
- end
-
-end
+end
View
20 app/mailers/spree/order_mailer_decorator.rb
@@ -0,0 +1,20 @@
+Spree::OrderMailer.class_eval do
+ # There might be a cleaner way to set locale instead of rewriting each method
+ def confirm_email(order, resend=false)
+ @order = order
+ I18n.locale = order.locale
+ subject = (resend ? "[#{t(:resend).upcase}] " : "")
+ subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{order.number}"
+ mail(:to => order.email,
+ :subject => subject)
+ end
+
+ def cancel_email(order, resend=false)
+ @order = order
+ I18n.locale = order.locale
+ subject = (resend ? "[#{t(:resend).upcase}] " : "")
+ subject += "#{Spree::Config[:site_name]} #{t('order_mailer.cancel_email.subject')} ##{order.number}"
+ mail(:to => order.email,
+ :subject => subject)
+ end
+end
View
12 app/mailers/spree/shipment_mailer_decorator.rb
@@ -0,0 +1,12 @@
+Spree::ShipmentMailer.class_eval do
+ helper 'spree/base'
+
+ def shipped_email(shipment, resend=false)
+ @shipment = shipment
+ I18n.locale = @shipment.order.locale
+ subject = (resend ? "[#{t(:resend).upcase}] " : "")
+ subject += "#{Spree::Config[:site_name]} #{t('shipment_mailer.shipped_email.subject')} ##{shipment.order.number}"
+ mail(:to => shipment.order.email,
+ :subject => subject)
+ end
+end
View
5 app/models/option_type_decorator.rb
@@ -0,0 +1,5 @@
+module Spree
+ OptionType.class_eval do
+ translates :presentation
+ end
+end
View
21 app/models/order_decorator.rb
@@ -0,0 +1,21 @@
+module Spree
+ Spree::Order.class_eval do
+ # Finalizes an in progress order after checkout is complete.
+ # Called after transition to complete state when payments will have been processed
+ def finalize!
+ update_attribute(:completed_at, Time.now)
+ update_attribute(:locale, I18n.locale)
+ InventoryUnit.assign_opening_inventory(self)
+ # lock any optional adjustments (coupon promotions, etc.)
+ adjustments.optional.each { |adjustment| adjustment.update_attribute('locked', true) }
+ deliver_order_confirmation_email
+
+ self.state_changes.create({
+ :previous_state => 'cart',
+ :next_state => 'complete',
+ :name => 'order' ,
+ :user_id => (User.respond_to?(:current) && User.current.try(:id)) || self.user_id
+ }, :without_protection => true)
+ end
+ end
+end
View
2 app/models/spree/product_decorator.rb
@@ -1,3 +1,3 @@
Spree::Product.class_eval do
translates :name, :description, :meta_description, :meta_keywords, :permalink
-end
+end
View
4 app/models/translation_decorator.rb
@@ -0,0 +1,4 @@
+# Tempory fix https://github.com/svenfuchs/globalize3/issues/128
+Globalize::ActiveRecord::Translation.class_eval do
+ attr_accessible :locale
+end
View
13 app/overrides/option_type_add_language_dropdown.rb
@@ -0,0 +1,13 @@
+Deface::Override.new(
+ :virtual_path => "spree/admin/option_types/index",
+ :insert_before => "div#new_option_type",
+ :text => '<%= render "spree/admin/shared/language_dropdown", :object => Spree::OptionType.new -%>',
+ :name => "option_type_add_language_dropdown"
+)
+
+Deface::Override.new(
+ :virtual_path => "spree/admin/option_types/edit",
+ :insert_before => "fieldset",
+ :text => '<%= render "spree/admin/shared/language_dropdown", :object => @option_type -%>',
+ :name => "option_type_add_language_dropdown"
+)
View
17 app/views/spree/order_mailer/cancel_email.fr.text.erb
@@ -0,0 +1,17 @@
+Cher client,
+
+Votre commande est annulee.
+Merci de conserver cet email pour un eventuel usage ulterieur.
+
+============================================================
+Commande [ANNULEE]
+============================================================
+<% @order.line_items.each do |item| %>
+<%= item.variant.sku %> <%= item.variant.product.name %> <%= variant_options(item.variant) %> (<%= item.quantity %>) @ <%= number_to_currency item.price %> = <%= number_to_currency(item.price * item.quantity) %>
+<% end %>
+============================================================
+Sous-Total: <%= number_to_currency @order.item_total %>
+<% @order.adjustments.each do |adjustment| %>
+<%= "#{adjustment.label}: #{number_to_currency adjustment.amount}"%>
+<% end %>
+Total TTC: <%= number_to_currency @order.total %>
View
20 app/views/spree/order_mailer/confirm_email.fr.text.erb
@@ -0,0 +1,20 @@
+Cher client,
+
+Votre commande est confirmee.
+Merci de conserver cet email pour un eventuel usage ulterieur.
+
+============================================================
+Commande
+============================================================
+<% @order.line_items.each do |item| %>
+<%=item.variant.sku %> <%=item.variant.product.name%> <%= item.variant.options_text -%> (<%=item.quantity%>) @ <%= number_to_currency item.price %> = <%= number_to_currency(item.price * item.quantity) %>
+<% end %>
+============================================================
+Sous-Total: <%= number_to_currency @order.item_total %>
+<% @order.adjustments.each do |adjustment| %>
+<%= "#{adjustment.label}: #{number_to_currency adjustment.amount}"%>
+<% end %>
+Total TTC: <%= number_to_currency @order.total %>
+
+
+Merci pour votre achat.
View
2 db/migrate/20120309094246_migrate_data_for_products.rb
@@ -2,7 +2,7 @@ class MigrateDataForProducts < ActiveRecord::Migration
def up
Spree::Product.transaction do
Spree::Product.find_each do |product|
- product.update_attributes! product.untranslated_attributes
+ product.update_attributes!(product.untranslated_attributes, :without_protection => true)
end
end
end
View
10 db/migrate/20120421183338_add_translations_to_option_types.rb
@@ -0,0 +1,10 @@
+class AddTranslationsToOptionTypes < ActiveRecord::Migration
+ def up
+ Spree::OptionType.create_translation_table!({:presentation => :string},
+ {:migrate_data => true})
+ end
+
+ def down
+ Spree::OptionType.drop_translation_table!
+ end
+end
View
5 db/migrate/20120426202113_add_locale_to_orders.rb
@@ -0,0 +1,5 @@
+class AddLocaleToOrders < ActiveRecord::Migration
+ def change
+ add_column :spree_orders, :locale, :string
+ end
+end
View
4 lib/spree_multi_lingual/engine.rb
@@ -21,10 +21,6 @@ def self.activate
Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
-
- Dir.glob(File.join(File.dirname(__FILE__), "../../app/overrides/*.rb")) do |c|
- Rails.configuration.cache_classes ? require(c) : load(c)
- end
end
# after rails config/initializers loading, setup spree_multi_lingual's language by getting
View
6 lib/spree_multi_lingual/translates_with_accessors.rb
@@ -41,6 +41,12 @@ def translates(*params)
super
+ params_with_locale = SpreeMultiLingual.languages.map do |locale|
+ params.map { |param| "#{param}_#{locale}".to_sym }
+ end
+
+ attr_accessible *(params_with_locale + params).flatten
+
globalize_accessors locales: SpreeMultiLingual.languages, attributes: params.to_a if accessors
end
end
View
13 spec/mailers/order_mailer_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+
+module Spree
+ describe OrderMailer do
+ let(:order) { FactoryGirl.create(:order, :locale => :fr) }
+ let(:mail) { ActionMailer::Base.deliveries.last }
+
+ it "should use i18n email template" do
+ OrderMailer.confirm_email(order, true).deliver
+ mail.encoded.should include("Merci")
+ end
+ end
+end
View
23 spec/models/order_spec.rb
@@ -0,0 +1,23 @@
+require 'spec_helper'
+
+module Spree
+ describe Order do
+ describe "#finalize!" do
+ it "sets order locale" do
+ I18n.locale = :fr
+ order = FactoryGirl.create(:order)
+ order.finalize!
+ order.locale.should == :fr
+ I18n.locale = nil
+ end
+ end
+
+ describe "#locale" do
+ it "should be stored as str" do
+ order = FactoryGirl.create(:order, :locale => :fr)
+ Order.find_by_locale("fr").should == order
+ end
+ end
+
+ end
+end
View
6 spec/models/taxon_spec.rb
@@ -1,8 +1,8 @@
require 'spec_helper'
describe Spree::Taxon do
- let(:taxon) { Factory(:taxon, :name => "Ruby on Rails") }
- let(:child) { Factory(:taxon, :name => "Sinatra", :parent => taxon) }
+ let(:taxon) { FactoryGirl.create(:taxon, :name => "Ruby on Rails") }
+ let(:child) { FactoryGirl.create(:taxon, :name => "Sinatra", :parent => taxon) }
describe "#set_permalink" do
it "should return default name if fallback is true and no parents" do
@@ -13,7 +13,7 @@
end
context "when child taxon" do
- before { taxon.update_attributes!(:permalink_en => "ruby-on-rails", :permalink_fr => "ruby-on-rails-fr", :permalink_es => "ruby-on-rails-es") }
+ before { taxon.update_attributes!(:permalink => "ruby-on-rails", :permalink_fr => "ruby-on-rails-fr", :permalink_es => "ruby-on-rails-es") }
it "returns translated parents permalink" do
child.permalink.should == "ruby-on-rails/sinatra"
View
2 spec/models/taxonomy_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe Spree::Taxonomy do
- let(:taxonomy) { Factory(:taxonomy, :name => "Man") }
+ let(:taxonomy) { FactoryGirl.create(:taxonomy, :name => "Man") }
let(:root) { taxonomy.root }
it "root taxon should set translated name" do
View
6 spec/requests/de/admin/products_spec.rb
@@ -1,10 +1,6 @@
require 'spec_helper'
describe "admin products" do
- before do
- sign_in_as!(Factory(:admin_user))
- end
-
- let!(:product) { Factory(:product) }
+ let!(:product) { FactoryGirl.create(:product) }
it "displays price in correct format" do
visit spree.edit_admin_product_path(product)
View
23 spec/requests/option_types_spec.rb
@@ -0,0 +1,23 @@
+require 'spec_helper'
+
+feature "OptionType multi lingual", :js => true do
+ background do
+ visit spree.admin_option_types_path
+ end
+
+ scenario "create successfully" do
+ click_link "new_option_type_link"
+ page.should have_button("Create")
+
+ select "fr", :from => "spree_multi_lingual_dropdown"
+
+ fill_in "option_type_name", :with => "size"
+ fill_in "option_type_presentation_fr", :with => "Taille"
+
+ select "en", :from => "spree_multi_lingual_dropdown"
+ fill_in "option_type_presentation", :with => "Size"
+
+ click_button "Create"
+ page.should have_content("successfully created!")
+ end
+end
View
4 spec/requests/products_spec.rb
@@ -2,7 +2,7 @@
feature "Products multi lingual", :js => true do
background do
- @product = Factory(:product, :name => "ror mug", :price => 30)
+ @product = FactoryGirl.create(:product, :name => "ror mug", :price => 30)
end
scenario "admin should be able to edit product page i18n" do
@@ -12,8 +12,6 @@
%w(fr en es).each do |locale|
select locale, :from => "spree_multi_lingual_dropdown"
# en is the default language so the selector doesnt apply
- save_and_open_page
- debugger
suffix = "#{locale.to_sym == I18n.locale ? "" : "_#{locale}"}"
fill_in "product_name#{suffix}", :with => "ror mug #{locale}"
View
100 spec/requests/taxons_spec.rb
@@ -30,49 +30,101 @@
page.should have_content("Hola")
end
- scenario "admin should be able to edit taxons" do
- visit spree.new_admin_taxonomy_path
+ context "edit taxons" do
- fill_in "Name", :with => "Hello"
- click_button "Create"
+ background do
+ visit spree.new_admin_taxonomy_path
+
+ fill_in "Name", :with => "Hello"
+ click_button "Create"
- taxonomy = Spree::Taxonomy.last
+ @taxonomy = Spree::Taxonomy.last
- visit spree.edit_admin_taxonomy_taxon_path(taxonomy, taxonomy.root)
+ visit spree.edit_admin_taxonomy_taxon_path(@taxonomy, @taxonomy.root)
- %w(fr en es).each do |locale|
- select locale, :from => "spree_multi_lingual_dropdown"
+ %w(fr en es).each do |locale|
+ select locale, :from => "spree_multi_lingual_dropdown"
- suffix = "#{locale.to_sym == I18n.locale ? "" : "_#{locale}"}"
+ suffix = "#{locale.to_sym == I18n.locale ? "" : "_#{locale}"}"
- fill_in "taxon_name#{suffix}", :with => "TAXON - #{locale}"
- fill_in "taxon_description#{suffix}", :with => "TAXON Description - #{locale * 20}"
- fill_in "taxon_permalink#{suffix}", :with => "taxon-#{locale}"
+ fill_in "taxon_name#{suffix}", :with => "TAXON - #{locale}"
+ fill_in "taxon_description#{suffix}", :with => "TAXON Description - #{locale * 20}"
+ fill_in "taxon_permalink#{suffix}", :with => "taxon-#{locale}"
+ end
+
+ click_button "Update"
end
- click_button "Update"
+ scenario "admin should be able to edit taxons" do
+ visit spree.edit_admin_taxonomy_taxon_path(@taxonomy, @taxonomy.root)
+
+ # verify if the form has correct values
+ %w(fr en es).each do |locale|
+ select locale, :from => "spree_multi_lingual_dropdown"
+ page.should have_content("TAXON - #{locale}")
+ page.should have_content("TAXON Description - #{locale * 20}")
+ end
+
+ # set local and ensure each page is visitable
+ %w(fr en es).each do |locale|
+ visit "/#{locale}/t/taxon-#{locale}"
+ page.should have_content "TAXON - #{locale}"
+ end
+ end
+
+ scenario "admin should be able to edit child taxons" do
+ @parent = Spree::Taxon.last
+ @child = FactoryGirl.create(:taxon, :name => "child", :parent => @parent, :taxonomy => @taxonomy)
+ visit spree.edit_admin_taxonomy_taxon_path(@taxonomy, @child)
- visit spree.edit_admin_taxonomy_taxon_path(taxonomy, taxonomy.root)
+ # verify if the form has correct values
+ %w(fr en es).each do |locale|
+ select locale, :from => "spree_multi_lingual_dropdown"
+ suffix = "#{locale.to_sym == I18n.locale ? "" : "_#{locale}"}"
- # verify if the form has correct values
- %w(fr en es).each do |locale|
- select locale, :from => "spree_multi_lingual_dropdown"
- page.should have_content("TAXON - #{locale}")
- page.should have_content("TAXON Description - #{locale * 20}")
+ fill_in "taxon_name#{suffix}", :with => "Child - #{locale}"
+ fill_in "taxon_description#{suffix}", :with => "Child : #{locale * 20}"
+ fill_in "taxon_permalink#{suffix}", :with => "child-#{locale}"
+ end
+
+ click_button "Update"
+
+ #ensure each child page is visitable
+ %w(fr en es).each do |locale|
+ visit "/#{locale}/t/taxon-#{locale}/child-#{locale}"
+ page.should have_content "Child - #{locale}"
+ end
end
- # set local and ensure each page is visitable
- %w(fr en es).each do |locale|
- visit "/#{locale}/t/taxon-#{locale}"
- page.should have_content "TAXON - #{locale}"
+ scenario "admin should be able to edit parent taxon permalink" do
+ @parent = Spree::Taxon.last
+ @child = FactoryGirl.create(:taxon, :name => "Sinatra En", :name_fr => "Sinatra Fr", :name_es => "Sinatra Es",
+ :permalink_fr => "sinatra-fr", :permalink => "sinatra-en", :permalink_es => "sinatra-es", :parent => @parent, :taxonomy => @taxonomy)
+ visit spree.edit_admin_taxonomy_taxon_path(@taxonomy, @parent)
+
+ %w(fr en es).each do |locale|
+ select locale, :from => "spree_multi_lingual_dropdown"
+ suffix = "#{locale.to_sym == I18n.locale ? "" : "_#{locale}"}"
+ fill_in "taxon_permalink#{suffix}", :with => "ruby-#{locale}"
+ end
+
+
+ click_button "Update"
+
+ %w(fr en es).each do |locale|
+ visit "/#{locale}/t/ruby-#{locale}/sinatra-#{locale}"
+ page.should have_content "Sinatra #{locale.capitalize}"
+ end
end
+
end
+
scenario "by explicitly setting their locale, user should be redirected to the viewed link with the setted locale", :js => false do
pending "TODO ! cf locale_controller_decorator#set"
- Factory(:taxon, :name => "Ruby on Rails", :permalink_fr => "ror-fr", :permalink_es => "ror-es", :permalink => "ror", :permalink_en => "ror")
+ FactoryGirl.create(:taxon, :name => "Ruby on Rails", :permalink_fr => "ror-fr", :permalink_es => "ror-es", :permalink => "ror", :permalink_en => "ror")
get "/en/t/ror"
get "/fr/locale/set", {}, {'HTTP_REFERER' => 'http://example.com/en/t/ror', 'HTTP_HOST' => 'example.com'} #manually set 'HTTP_REFERER' AND 'HTTP_HOST'
View
7 spec/spec_helper.rb
@@ -11,10 +11,8 @@
# Requires factories defined in spree_core
require 'spree/core/testing_support/factories'
-require 'spree/core/url_helpers'
RSpec.configure do |config|
- config.include Spree::Core::UrlHelpers
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
@@ -32,4 +30,7 @@
# instead of true.
config.use_transactional_fixtures = true
config.include Spree::UrlHelpers
-end
+ config.after(:each) do
+ I18n.locale = nil
+ end
+end
View
14 spec/support/authentication_helpers.rb
@@ -1,14 +0,0 @@
-module AuthenticationHelpers
- def sign_in_as!(user)
- visit '/login'
- fill_in I18n.t('email'), :with => user.email
- fill_in I18n.t('password'), :with => 'secret'
- click_button I18n.t('login')
- end
-
-end
-
-RSpec.configure do |c|
- c.include AuthenticationHelpers, :type => :request
-end
-
View
11 spree_multi_lingual.gemspec
@@ -16,22 +16,23 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'
- s.add_dependency 'spree_core', '~> 1.1.0beta'
+ s.add_dependency 'spree_core', '~> 1.1.0'
s.add_dependency 'i18n'
s.add_dependency 'globalize3', '~> 0.2.0.beta8'
s.add_dependency 'easy_globalize3_accessors'
- # s.add_dependency 'routing-filter'
+ s.add_dependency 'routing-filter', '~> 0.3.1'
s.add_dependency 'rack-contrib'
s.add_dependency 'coffee-rails'
s.add_development_dependency 'capybara', '1.0.1'
- s.add_development_dependency 'factory_girl'
+ s.add_development_dependency 'factory_girl_rails', '~> 1.7.0'
s.add_development_dependency 'ffaker'
- s.add_development_dependency 'rspec-rails', '~> 2.7'
+ s.add_development_dependency 'rspec-rails', '~> 2.9.0'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'mysql2'
s.add_development_dependency 'launchy', '2.0.5'
+ s.add_development_dependency 'awesome_print'
# Seems Spree doesn't require it correctly or there is a problem with extensions maybe? Still, it is needed to work with the dummy app!
- s.add_dependency 'sass'
+ s.add_development_dependency 'sass-rails'
end

0 comments on commit c216072

Please sign in to comment.
Something went wrong with that request. Please try again.