subdomain_locale 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5da9fa1546e807d5b21bf511496257ef32741596
4
- data.tar.gz: e15c64020a71c4dee2f4a001a1c90b5f25735f51
3
+ metadata.gz: 58e47382709b64c4b6cad31a6b18ed1aecb877cd
4
+ data.tar.gz: aab6515f887fd395b12fcc0f92f5b9f880194206
5
5
  SHA512:
6
- metadata.gz: 22ae781fa5583463102c0b25f942a65f9c5ebcae46409e8ed281efef0640394ca972bb8eadb76926df0f29e08825f3c380233d575e17c6122f46516cdea13528
7
- data.tar.gz: 42a64ecad75d68ba195b611c82e74493f1b96e9622dcb40e9ccf270a26a3be23bd3a42f35af769ec589c36b271bcb4cc1f21b3bc27df39f96adbc01cc6d024d6
6
+ metadata.gz: 389de7c0409e09ced5edfd2677a14c2367fa4cc0e789a8f2764783c80d421659feecf2f6b0f06e00556b4a437cb10c3158e5f7a755e090e1fd42836793fa1b88
7
+ data.tar.gz: 7a20a72a24742d04ecb3a81dcaf7c487a446bf9b090a8d1a23ba6040e7b8b2dc132231ea7a4de4476c41492b28cc05472c97a696001ff8f4efebae902126197b
data/Isolate CHANGED
@@ -4,16 +4,22 @@ gem 'bundler', '~> 1.5.0'
4
4
  gem 'i18n', '~> 0.6.9'
5
5
 
6
6
  case ENV['RAILS']
7
- when '3'
7
+ when '3.2'
8
8
  version = '~> 3.2.16'
9
9
  gem 'actionpack', version
10
10
  gem 'actionmailer', version
11
11
  gem 'railties', version
12
- when nil
12
+ gem 'minitest', '~> 4.2'
13
+ when '4.0'
13
14
  version = '~> 4.0.0'
14
15
  gem 'actionpack', version
15
16
  gem 'actionmailer', version
16
17
  gem 'railties', version
18
+ when nil
19
+ version = '~> 4.1.0'
20
+ gem 'actionpack', version
21
+ gem 'actionmailer', version
22
+ gem 'railties', version
17
23
  else
18
24
  raise "Unrecognized Rails version: #{ENV['RAILS']}"
19
25
  end
data/Rakefile CHANGED
@@ -3,15 +3,20 @@ require "isolate/now"
3
3
  require "bundler/gem_tasks"
4
4
 
5
5
  Rake::TestTask.new do |t|
6
- t.libs << "test"
7
6
  t.test_files = Dir['test/**/*_test.rb']
8
7
  t.verbose = true
8
+
9
+ # The default rake test loader is messing up $LOAD_PATH
10
+ t.loader = :direct
11
+ t.libs << '.'
9
12
  end
10
13
 
11
14
  task "test:all" do
12
15
  sh "rake test"
13
16
  puts
14
- sh "rake test RAILS=3"
17
+ sh "rake test RAILS=4.0"
18
+ puts
19
+ sh "rake test RAILS=3.2"
15
20
  end
16
21
 
17
22
  task :default => :test
data/Readme.md CHANGED
@@ -75,7 +75,7 @@ end
75
75
 
76
76
  ## Testing
77
77
 
78
- This gem is tested against Rails 3.2 and 4.0.
78
+ This gem is tested against Rails 3.2, 4.0 and 4.1.
79
79
 
80
80
  ```
81
81
  gem install isolate
@@ -84,8 +84,13 @@ rake test:all
84
84
 
85
85
  ## Changelog
86
86
 
87
+ 1.1.0
88
+
89
+ * Custom subdomain provided in your default_url_options now has precedence over the default subdomain-locale.
90
+
87
91
  1.0.0
88
92
 
93
+ * Links outside controllers now also point to the current locale. For example, in mailers.
89
94
  * Now compatible with the new I18n.enforce\_available\_locales.
90
95
  * No subdomain is now deafult instead of "www". Can be reverted by setting config.default\_domain.
91
96
  * Separate website's default locale (config.default\_locale) from the global default locale (config.i18n.default\_locale).
@@ -18,7 +18,7 @@ module SubdomainLocale
18
18
 
19
19
  initializer "subdomain_locale.url_helpers" do
20
20
  require "subdomain_locale/url_for"
21
- Rails.application.routes.url_helpers.send :include, SubdomainLocale::UrlFor
21
+ Rails.application.routes.extend SubdomainLocale::UrlFor
22
22
  end
23
23
 
24
24
  initializer "subdomain_locale.controller" do
@@ -7,23 +7,24 @@ module SubdomainLocale
7
7
  # url_for params.merge(locale: 'ru') # => /ru/current_path
8
8
  # After including this module:
9
9
  # url_for params.merge(locale: 'ru') # => http://ru.example.com/current_path
10
- def url_for(options=nil)
11
- if options.is_a?(Hash)
12
- options = options.dup
13
- if options.key?(:locale)
14
- # Locale specified, force full URL
15
- locale = options.delete(:locale)
16
- options[:subdomain] = subdomain_locales.subdomain_for(locale)
17
- options[:only_path] = false
18
- elsif options.key?(:only_path) && !options[:only_path] && !options.key?(:subdomain)
19
- # Requested full URL, use current locale
20
- options[:subdomain] = subdomain_locales.subdomain_for(current_locale)
21
- end
10
+ def url_for(options)
11
+ options = options.dup
12
+ if options.key?(:locale)
13
+ # Locale specified, force full URL
14
+ locale = options.delete(:locale)
15
+ options[:subdomain] = subdomain_locales.subdomain_for(locale)
16
+ options[:only_path] = false
22
17
  end
23
18
 
24
19
  super
25
20
  end
26
21
 
22
+ def default_url_options
23
+ super.merge({
24
+ subdomain: subdomain_locales.subdomain_for(current_locale)
25
+ })
26
+ end
27
+
27
28
  def current_locale
28
29
  I18n.locale
29
30
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "subdomain_locale"
5
- spec.version = "1.0.0"
5
+ spec.version = "1.1.0"
6
6
  spec.authors = ["Semyon Perepelitsa"]
7
7
  spec.email = ["sema@sema.in"]
8
8
  spec.summary = "Set I18n locale based on subdomain (Rails plugin)."
@@ -1,2 +1,2 @@
1
- class HelloController < ApplicationController
1
+ class HelloController < ActionController::Base
2
2
  end
@@ -0,0 +1,5 @@
1
+ class BetaMailer < HelloMailer
2
+ def default_url_options
3
+ super.merge(subdomain: "beta")
4
+ end
5
+ end
data/test/mapping_test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require_relative "test_helper"
2
2
 
3
- class MappingTest < MiniTest::Unit::TestCase
3
+ class MappingTest < ActiveSupport::TestCase
4
4
  include SubdomainLocale
5
5
 
6
6
  def setup
data/test/rails_test.rb CHANGED
@@ -48,8 +48,14 @@ class HelloControllerTest < ActionController::TestCase
48
48
  end
49
49
 
50
50
  class HelloMailerTest < ActionController::TestCase
51
- def test
51
+ def test_locale_domain
52
52
  mail = I18n.with_locale(:uk) { HelloMailer.world }
53
53
  assert_equal "http://ua.example.com/", mail.body.to_s.lines[3].chomp
54
54
  end
55
+
56
+ # BetaMailer overrides default_url_options
57
+ def test_custom_domain
58
+ mail = I18n.with_locale(:uk) { BetaMailer.world }
59
+ assert_equal "http://beta.example.com/", mail.body.to_s.lines[3].chomp
60
+ end
55
61
  end
data/test/test_helper.rb CHANGED
@@ -5,3 +5,10 @@ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
5
  require "minitest/autorun"
6
6
  require "rails/test_help"
7
7
  Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Mail 2.5 gives warnings, fixed in 2.6
10
+ require "mail"
11
+ Mail::Sendmail
12
+ ##
13
+
14
+ $VERBOSE = true
data/test/url_for_test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require_relative "test_helper"
2
2
 
3
- class UrlForTest < MiniTest::Unit::TestCase
3
+ class UrlForTest < ActiveSupport::TestCase
4
4
  module UrlFor
5
5
  def url_for(*args)
6
6
  args
@@ -27,26 +27,11 @@ class UrlForTest < MiniTest::Unit::TestCase
27
27
  assert_equal [{foo: 'bar'}], @actual
28
28
  end
29
29
 
30
- def test_string_argument
31
- @actual = url_for('/bar')
32
- assert_equal ['/bar'], @actual
33
- end
34
-
35
30
  def test_locale
36
31
  @actual = url_for(foo: 'bar', locale: :ru)
37
32
  assert_equal [{foo: 'bar', subdomain: 'ru', only_path: false}], @actual
38
33
  end
39
34
 
40
- def test_only_path
41
- @actual = url_for(foo: 'bar', locale: :ru, only_path: true)
42
- assert_equal [{foo: 'bar', subdomain: 'ru', only_path: false}], @actual
43
- end
44
-
45
- def test_implicit_locale
46
- @actual = url_for(foo: 'bar', only_path: false)
47
- assert_equal [{foo: 'bar', subdomain: 'ru', only_path: false}], @actual
48
- end
49
-
50
35
  def test_hash_immutable
51
36
  orig_params = { foo: 'bar', locale: :ru }
52
37
  params = orig_params.dup.freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subdomain_locale
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Semyon Perepelitsa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-10 00:00:00.000000000 Z
11
+ date: 2014-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -41,12 +41,11 @@ files:
41
41
  - lib/subdomain_locale/railtie.rb
42
42
  - lib/subdomain_locale/url_for.rb
43
43
  - subdomain_locale.gemspec
44
- - test/dummy/app/controllers/application_controller.rb
45
44
  - test/dummy/app/controllers/hello_controller.rb
45
+ - test/dummy/app/mailers/beta_mailer.rb
46
46
  - test/dummy/app/mailers/hello_mailer.rb
47
47
  - test/dummy/app/views/hello/world.html.erb
48
48
  - test/dummy/app/views/hello_mailer/world.text.erb
49
- - test/dummy/app/views/layouts/application.html.erb
50
49
  - test/dummy/config.ru
51
50
  - test/dummy/config/application.rb
52
51
  - test/dummy/config/environment.rb
@@ -83,12 +82,11 @@ signing_key:
83
82
  specification_version: 4
84
83
  summary: Set I18n locale based on subdomain (Rails plugin).
85
84
  test_files:
86
- - test/dummy/app/controllers/application_controller.rb
87
85
  - test/dummy/app/controllers/hello_controller.rb
86
+ - test/dummy/app/mailers/beta_mailer.rb
88
87
  - test/dummy/app/mailers/hello_mailer.rb
89
88
  - test/dummy/app/views/hello/world.html.erb
90
89
  - test/dummy/app/views/hello_mailer/world.text.erb
91
- - test/dummy/app/views/layouts/application.html.erb
92
90
  - test/dummy/config.ru
93
91
  - test/dummy/config/application.rb
94
92
  - test/dummy/config/environment.rb
@@ -1,3 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- protect_from_forgery
3
- end
@@ -1,12 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= csrf_meta_tags %>
6
- </head>
7
- <body>
8
-
9
- <%= yield %>
10
-
11
- </body>
12
- </html>