localeapp 0.0.7 → 0.0.8
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.
- data/.rvmrc +1 -1
- data/bin/localeapp +9 -9
- data/features/localeapp_binary.feature +17 -17
- data/features/support/env.rb +2 -2
- data/init.rb +1 -1
- data/lib/{locale_app → localeapp}/api_call.rb +2 -2
- data/lib/{locale_app → localeapp}/api_caller.rb +8 -8
- data/lib/{locale_app → localeapp}/cli/install.rb +7 -7
- data/lib/{locale_app → localeapp}/cli/pull.rb +5 -5
- data/lib/{locale_app → localeapp}/cli/push.rb +3 -3
- data/lib/{locale_app → localeapp}/cli/update.rb +3 -3
- data/lib/{locale_app → localeapp}/configuration.rb +7 -7
- data/lib/localeapp/exception_handler.rb +21 -0
- data/lib/{locale_app → localeapp}/key_checker.rb +6 -6
- data/lib/{locale_app → localeapp}/missing_translations.rb +1 -1
- data/lib/{locale_app → localeapp}/poller.rb +7 -7
- data/lib/{locale_app → localeapp}/rails/2_3_translation_helper_monkeypatch.rb +2 -2
- data/lib/localeapp/rails/controller.rb +34 -0
- data/lib/{locale_app → localeapp}/rails/flatten.rb +0 -0
- data/lib/{locale_app → localeapp}/rails.rb +11 -11
- data/lib/{locale_app → localeapp}/routes.rb +5 -5
- data/lib/{locale_app → localeapp}/sender.rb +8 -8
- data/lib/{locale_app/tasks/locale_app.rake → localeapp/tasks/localeapp.rake} +2 -2
- data/lib/{locale_app → localeapp}/updater.rb +2 -2
- data/lib/localeapp/version.rb +3 -0
- data/lib/localeapp.rb +98 -1
- data/localeapp.gemspec +2 -2
- data/run_ci +1 -1
- data/spec/{locale_app → localeapp}/api_call_spec.rb +3 -3
- data/spec/{locale_app → localeapp}/api_caller_spec.rb +4 -4
- data/spec/{locale_app → localeapp}/cli/install_spec.rb +3 -3
- data/spec/{locale_app → localeapp}/cli/pull_spec.rb +9 -9
- data/spec/{locale_app → localeapp}/cli/push_spec.rb +2 -2
- data/spec/localeapp/cli/update_spec.rb +18 -0
- data/spec/{locale_app → localeapp}/configuration_spec.rb +6 -6
- data/spec/{locale_app → localeapp}/exception_handler_spec.rb +6 -6
- data/spec/{locale_app → localeapp}/key_checker_spec.rb +3 -3
- data/spec/{locale_app → localeapp}/missing_translations_spec.rb +5 -5
- data/spec/{locale_app → localeapp}/poller_spec.rb +5 -5
- data/spec/{locale_app → localeapp}/rails/controller_spec.rb +28 -28
- data/spec/{locale_app → localeapp}/routes_spec.rb +2 -2
- data/spec/{locale_app → localeapp}/sender_spec.rb +6 -6
- data/spec/{locale_app → localeapp}/updater_spec.rb +2 -2
- data/spec/spec_helper.rb +7 -7
- data/spec/support/{locale_app_integration_data.rb → localeapp_integration_data.rb} +1 -1
- data/spec/support/{locale_app_synchronization_data.rb → localeapp_synchronization_data.rb} +1 -1
- metadata +57 -58
- data/lib/locale_app/exception_handler.rb +0 -21
- data/lib/locale_app/rails/controller.rb +0 -34
- data/lib/locale_app/version.rb +0 -3
- data/lib/locale_app.rb +0 -98
- data/spec/locale_app/cli/update_spec.rb +0 -18
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'rest-client'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
module
|
4
|
+
module Localeapp
|
5
5
|
class Sender
|
6
|
-
include ::
|
7
|
-
include ::
|
6
|
+
include ::Localeapp::ApiCall
|
7
|
+
include ::Localeapp::Routes
|
8
8
|
|
9
9
|
def post_translation(locale, key, options, value = nil)
|
10
10
|
options ||= {}
|
@@ -19,15 +19,15 @@ module LocaleApp
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def handle_single_translation_success(response)
|
22
|
-
|
22
|
+
Localeapp.log([translations_url, response.code, @data.inspect].join(' - '))
|
23
23
|
end
|
24
24
|
|
25
25
|
def handle_single_translation_failure(response)
|
26
|
-
|
26
|
+
Localeapp.log([translations_url, response.code, @data.inspect].join(' - '))
|
27
27
|
end
|
28
28
|
|
29
29
|
def post_missing_translations
|
30
|
-
to_send =
|
30
|
+
to_send = Localeapp.missing_translations.to_send
|
31
31
|
return if to_send.empty?
|
32
32
|
@data = { :translations => to_send }
|
33
33
|
api_call :missing_translations,
|
@@ -39,11 +39,11 @@ module LocaleApp
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def handle_missing_translation_success(response)
|
42
|
-
|
42
|
+
Localeapp.log([translations_url, response.code, @data.inspect].join(' - '))
|
43
43
|
end
|
44
44
|
|
45
45
|
def handle_missing_translation_failure(response)
|
46
|
-
|
46
|
+
Localeapp.log([translations_url, response.code, @data.inspect].join(' - '))
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
namespace :
|
1
|
+
namespace :localeapp do
|
2
2
|
desc 'Imports the en.yml file to the LocaleServer'
|
3
3
|
task :import => :environment do
|
4
4
|
require 'flatten'
|
@@ -13,7 +13,7 @@ namespace :locale_app do
|
|
13
13
|
nil
|
14
14
|
).each do |key, value|
|
15
15
|
puts "#{key} => #{value}"
|
16
|
-
|
16
|
+
Localeapp.sender.post_translation(locale, key, {}, value)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module
|
1
|
+
module Localeapp
|
2
2
|
class Updater
|
3
3
|
|
4
4
|
def update(data)
|
5
5
|
data['locales'].each do |short_code|
|
6
|
-
filename = File.join(
|
6
|
+
filename = File.join(Localeapp.configuration.translation_data_directory, "#{short_code}.yml")
|
7
7
|
|
8
8
|
if File.exist?(filename)
|
9
9
|
translations = YAML.load(File.read(filename))
|
data/lib/localeapp.rb
CHANGED
@@ -1 +1,98 @@
|
|
1
|
-
|
1
|
+
# AUDIT: Find a better way of doing this
|
2
|
+
begin
|
3
|
+
require 'i18n'
|
4
|
+
rescue LoadError
|
5
|
+
# we're in 2.3 and we need to load rails to get the vendored i18n
|
6
|
+
require 'thread' # for rubygems > 1.6.0 support
|
7
|
+
require 'active_support'
|
8
|
+
end
|
9
|
+
|
10
|
+
begin
|
11
|
+
require 'i18n/core_ext/hash'
|
12
|
+
rescue LoadError
|
13
|
+
# Assume that we're in rails 2.3 and AS supplies deep_merge
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
require 'localeapp/version'
|
18
|
+
require 'localeapp/configuration'
|
19
|
+
require 'localeapp/routes'
|
20
|
+
require 'localeapp/api_call'
|
21
|
+
require 'localeapp/api_caller'
|
22
|
+
require 'localeapp/sender'
|
23
|
+
require 'localeapp/poller'
|
24
|
+
require 'localeapp/updater'
|
25
|
+
require 'localeapp/key_checker'
|
26
|
+
require 'localeapp/missing_translations'
|
27
|
+
|
28
|
+
require 'localeapp/cli/install'
|
29
|
+
require 'localeapp/cli/pull'
|
30
|
+
require 'localeapp/cli/push'
|
31
|
+
require 'localeapp/cli/update'
|
32
|
+
|
33
|
+
# AUDIT: Will this work on ruby 1.9.x
|
34
|
+
$KCODE="UTF8" if RUBY_VERSION < '1.9'
|
35
|
+
|
36
|
+
require 'ya2yaml'
|
37
|
+
|
38
|
+
module Localeapp
|
39
|
+
API_VERSION = "1"
|
40
|
+
LOG_PREFIX = "** [Localeapp] "
|
41
|
+
|
42
|
+
class << self
|
43
|
+
# An Localeapp configuration object.
|
44
|
+
attr_accessor :configuration
|
45
|
+
|
46
|
+
# The sender object is responsible for delivering formatted data to the Localeapp server.
|
47
|
+
attr_accessor :sender
|
48
|
+
|
49
|
+
# The poller object is responsible for retrieving data for the Localeapp server
|
50
|
+
attr_accessor :poller
|
51
|
+
|
52
|
+
# The updater object is responsible for merging translations into the i18n backend
|
53
|
+
attr_accessor :updater
|
54
|
+
|
55
|
+
# The missing_translations object is responsible for keeping track of missing translations
|
56
|
+
# that will be sent to the backend
|
57
|
+
attr_reader :missing_translations
|
58
|
+
|
59
|
+
|
60
|
+
# Writes out the given message to the #logger
|
61
|
+
def log(message)
|
62
|
+
logger.info LOG_PREFIX + message if logger
|
63
|
+
end
|
64
|
+
|
65
|
+
def debug(message)
|
66
|
+
logger.debug(LOG_PREFIX + message) if logger
|
67
|
+
end
|
68
|
+
|
69
|
+
# Look for the Rails logger currently defined
|
70
|
+
def logger
|
71
|
+
self.configuration && self.configuration.logger
|
72
|
+
end
|
73
|
+
|
74
|
+
# @example Configuration
|
75
|
+
# Localeapp.configure do |config|
|
76
|
+
# config.api_key = '1234567890abcdef'
|
77
|
+
# end
|
78
|
+
def configure
|
79
|
+
self.configuration ||= Configuration.new
|
80
|
+
yield(configuration)
|
81
|
+
self.sender = Sender.new
|
82
|
+
self.poller = Poller.new
|
83
|
+
self.updater = Updater.new
|
84
|
+
@missing_translations = MissingTranslations.new
|
85
|
+
end
|
86
|
+
|
87
|
+
# requires the Localeapp configuration
|
88
|
+
def include_config_file(file_path=nil)
|
89
|
+
file_path ||= File.join(Dir.pwd, 'config', 'initializers', 'localeapp')
|
90
|
+
begin
|
91
|
+
require file_path
|
92
|
+
true
|
93
|
+
rescue
|
94
|
+
false
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/localeapp.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "
|
3
|
+
require "localeapp/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "localeapp"
|
7
|
-
s.version =
|
7
|
+
s.version = Localeapp::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Christopher Dell", "Chris McGrath"]
|
10
10
|
s.email = ["chris@tigrish.com", "chris@octopod.info"]
|
data/run_ci
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class ApiCallTest
|
4
|
-
include
|
4
|
+
include Localeapp::ApiCall
|
5
5
|
end
|
6
6
|
|
7
|
-
describe
|
7
|
+
describe Localeapp::ApiCall, "#api_call(endpoint, options = {})" do
|
8
8
|
it "creates an ApiCaller object and tells it to make the call" do
|
9
9
|
api_call_test = ApiCallTest.new
|
10
10
|
api_call = double('api_call')
|
11
11
|
api_call.should_receive(:call).with(api_call_test)
|
12
|
-
|
12
|
+
Localeapp::ApiCaller.should_receive(:new).with(:endpoint, { :foo => :bar }).and_return(api_call)
|
13
13
|
api_call_test.api_call(:endpoint, { :foo => :bar })
|
14
14
|
end
|
15
15
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Localeapp::ApiCaller, ".new(endpoint, options = {})" do
|
4
4
|
it "stores the endpoint and options" do
|
5
|
-
api_caller =
|
5
|
+
api_caller = Localeapp::ApiCaller.new(:endpoint, :foo => :bar)
|
6
6
|
api_caller.endpoint.should == :endpoint
|
7
7
|
api_caller.options.should == { :foo => :bar }
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
11
|
+
describe Localeapp::ApiCaller, "#call(object)" do
|
12
12
|
before do
|
13
|
-
@api_caller =
|
13
|
+
@api_caller = Localeapp::ApiCaller.new(:test)
|
14
14
|
@url = 'http://example.com/test'
|
15
15
|
@api_caller.stub!(:test_endpoint).and_return([:get, @url])
|
16
16
|
@api_caller.stub!(:sleep_if_retrying)
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require '
|
2
|
+
require 'localeapp/cli/install'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe Localeapp::CLI::Install, '.execute(key, output = $stdout)' do
|
5
5
|
before(:each) do
|
6
6
|
@output = StringIO.new
|
7
|
-
@command =
|
7
|
+
@command = Localeapp::CLI::Install.new
|
8
8
|
end
|
9
9
|
|
10
10
|
it "displays error if key is nil" do
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require '
|
2
|
+
require 'localeapp/cli/pull'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe Localeapp::CLI::Pull, "#execute" do
|
5
5
|
before do
|
6
6
|
@output = StringIO.new
|
7
|
-
@puller =
|
7
|
+
@puller = Localeapp::CLI::Pull.new(@output)
|
8
8
|
end
|
9
9
|
|
10
10
|
it "makes the api call to the translations endpoint" do
|
@@ -20,25 +20,25 @@ describe LocaleApp::CLI::Pull, "#execute" do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
23
|
+
describe Localeapp::CLI::Pull, "#update_backend(response)" do
|
24
24
|
before do
|
25
25
|
@test_data = ['test data'].to_json
|
26
26
|
@output = StringIO.new
|
27
|
-
@puller =
|
27
|
+
@puller = Localeapp::CLI::Pull.new(@output)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "calls the updater" do
|
31
31
|
with_configuration do
|
32
|
-
|
33
|
-
|
32
|
+
Localeapp.poller.stub!(:write_synchronization_data!)
|
33
|
+
Localeapp.updater.should_receive(:update).with(['test data'])
|
34
34
|
@puller.update_backend(@test_data)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
it "writes the synchronization data" do
|
39
39
|
with_configuration do
|
40
|
-
|
41
|
-
|
40
|
+
Localeapp.updater.stub!(:update)
|
41
|
+
Localeapp.poller.should_receive(:write_synchronization_data!)
|
42
42
|
@puller.update_backend(@test_data)
|
43
43
|
end
|
44
44
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Localeapp::CLI::Push, "#execute(file)" do
|
4
4
|
before do
|
5
5
|
@output = StringIO.new
|
6
|
-
@pusher =
|
6
|
+
@pusher = Localeapp::CLI::Push.new(@output)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "creates a new file object and makes the api call to the translations endpoint" do
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'localeapp/cli/update'
|
3
|
+
|
4
|
+
describe Localeapp::CLI::Update, "#execute" do
|
5
|
+
before do
|
6
|
+
@output = StringIO.new
|
7
|
+
@updater = Localeapp::CLI::Update.new(@output)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "creates a Poller and calls poll! on it" do
|
11
|
+
with_configuration do
|
12
|
+
poller = Localeapp::Poller.new
|
13
|
+
poller.should_receive(:poll!)
|
14
|
+
Localeapp::Poller.should_receive(:new).and_return(poller)
|
15
|
+
@updater.execute
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Localeapp::Configuration do
|
4
4
|
before(:each) do
|
5
|
-
@configuration =
|
5
|
+
@configuration = Localeapp::Configuration.new
|
6
6
|
end
|
7
7
|
|
8
8
|
it "sets the host by default" do
|
@@ -98,16 +98,16 @@ describe LocaleApp::Configuration do
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
-
describe
|
101
|
+
describe Localeapp::Configuration, "#write_initial(path)" do
|
102
102
|
it "creates a configuration file containing just the api key at the given path" do
|
103
|
-
configuration =
|
103
|
+
configuration = Localeapp::Configuration.new
|
104
104
|
configuration.api_key = "APIKEY"
|
105
105
|
path = 'test_path'
|
106
106
|
file = stub('file')
|
107
107
|
file.should_receive(:write).with <<-CONTENT
|
108
|
-
require '
|
108
|
+
require 'localeapp/rails'
|
109
109
|
|
110
|
-
|
110
|
+
Localeapp.configure do |config|
|
111
111
|
config.api_key = 'APIKEY'
|
112
112
|
config.host = 'api.localeapp.com'
|
113
113
|
config.port = 80
|
@@ -1,21 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require '
|
2
|
+
require 'localeapp/exception_handler'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe Localeapp::ExceptionHandler, '#call(exception, locale, key, options)' do
|
5
5
|
before(:each) do
|
6
|
-
|
6
|
+
Localeapp.configure do |config|
|
7
7
|
config.api_key = 'abcdef'
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
it "adds the missing translation to the missing translation list" do
|
12
|
-
|
12
|
+
Localeapp.missing_translations.should_receive(:add).with(:en, 'foo', { :baz => 'bam' })
|
13
13
|
I18n.t('foo', :baz => 'bam')
|
14
14
|
end
|
15
15
|
|
16
16
|
it "handles when the key is an array of keys" do
|
17
|
-
|
18
|
-
|
17
|
+
Localeapp.missing_translations.should_receive(:add).with(:en, 'foo', {})
|
18
|
+
Localeapp.missing_translations.should_receive(:add).with(:en, 'bar', {})
|
19
19
|
I18n.t(['foo', 'bar'])
|
20
20
|
end
|
21
21
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Localeapp::KeyChecker, "#check(key)" do
|
4
4
|
it "returns false and an empty hash if the response from locale app is a 404" do
|
5
5
|
FakeWeb.register_uri(:get, 'http://api.localeapp.com/v1/projects/TEST_KEY.json', :body => "", :status => ['404', 'Not Found'])
|
6
6
|
with_configuration do
|
7
|
-
@checker =
|
7
|
+
@checker = Localeapp::KeyChecker.new
|
8
8
|
end
|
9
9
|
@checker.check('TEST_KEY').should == [false, {}]
|
10
10
|
end
|
@@ -12,7 +12,7 @@ describe LocaleApp::KeyChecker, "#check(key)" do
|
|
12
12
|
it "returns true and and the parsed json hash if the response from locale app is a 200" do
|
13
13
|
FakeWeb.register_uri(:get, 'http://api.localeapp.com/v1/projects/TEST_KEY.json', :body => valid_project_data.to_json, :status => ['200', 'OK'])
|
14
14
|
with_configuration do
|
15
|
-
@checker =
|
15
|
+
@checker = Localeapp::KeyChecker.new
|
16
16
|
end
|
17
17
|
@checker.check('TEST_KEY').should == [true, valid_project_data]
|
18
18
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require '
|
2
|
+
require 'localeapp/missing_translations'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe Localeapp::MissingTranslations, "#add(locale, key, options = {})" do
|
5
5
|
it "stores the missing translation data" do
|
6
|
-
translations =
|
6
|
+
translations = Localeapp::MissingTranslations.new
|
7
7
|
translations.add(:en, 'foo', { :baz => 'bam' })
|
8
8
|
translations[:en].should include('foo')
|
9
9
|
translations[:en]['foo'].options.should == { :baz => 'bam' }
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
describe
|
13
|
+
describe Localeapp::MissingTranslations, "#to_send" do
|
14
14
|
it "returns an array of missing translation data that needs to be sent to localeapp.com" do
|
15
|
-
translations =
|
15
|
+
translations = Localeapp::MissingTranslations.new
|
16
16
|
translations.add(:en, 'foo', { :baz => 'bam' })
|
17
17
|
translations.add(:es, 'bar')
|
18
18
|
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Localeapp::Poller do
|
4
4
|
before do
|
5
5
|
@updated_at = Time.now.to_i
|
6
|
-
with_configuration(:synchronization_data_file =>
|
7
|
-
@poller =
|
6
|
+
with_configuration(:synchronization_data_file => LocaleappSynchronizationData::setup(nil, @updated_at), :api_key => 'TEST_KEY') do
|
7
|
+
@poller = Localeapp::Poller.new
|
8
8
|
end
|
9
9
|
@hash = { 'translations' => {}, 'deleted' => [], 'locales' => [] }
|
10
10
|
end
|
11
11
|
|
12
12
|
after do
|
13
|
-
|
13
|
+
LocaleappSynchronizationData::destroy
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "#needs_reloading?" do
|
@@ -54,7 +54,7 @@ describe LocaleApp::Poller do
|
|
54
54
|
|
55
55
|
it "passes the data through to the Updater" do
|
56
56
|
FakeWeb.register_uri(:get, "http://api.localeapp.com/v1/projects/TEST_KEY/translations.json?updated_at=#{@updated_at}", :body => @hash.to_json, :status => ['200', 'OK'], :date => Time.now.httpdate)
|
57
|
-
|
57
|
+
Localeapp.updater.should_receive(:update).with(@hash)
|
58
58
|
@poller.poll!
|
59
59
|
end
|
60
60
|
end
|
@@ -7,64 +7,64 @@ class TestController
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
require '
|
10
|
+
require 'localeapp/rails/controller'
|
11
11
|
|
12
|
-
describe
|
12
|
+
describe Localeapp::Rails::Controller, '#handle_translation_updates' do
|
13
13
|
before do
|
14
|
-
TestController.send(:include,
|
15
|
-
with_configuration(:synchronization_data_file =>
|
14
|
+
TestController.send(:include, Localeapp::Rails::Controller)
|
15
|
+
with_configuration(:synchronization_data_file => LocaleappSynchronizationData::setup) do
|
16
16
|
@controller = TestController.new
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
after do
|
21
|
-
|
21
|
+
LocaleappSynchronizationData::destroy
|
22
22
|
end
|
23
23
|
|
24
24
|
context "when polling is enabled" do
|
25
25
|
before do
|
26
|
-
|
27
|
-
|
26
|
+
Localeapp.configuration.environment_name = 'development' # reloading enabled
|
27
|
+
Localeapp.configuration.disabled_reloading_environments << 'development'
|
28
28
|
end
|
29
29
|
|
30
30
|
it "calls poller.poll! when the synchronization file's polled_at has changed" do
|
31
|
-
|
32
|
-
|
31
|
+
Localeapp.poller.write_synchronization_data!(01234, 56789)
|
32
|
+
Localeapp.poller.should_receive(:poll!)
|
33
33
|
@controller.handle_translation_updates
|
34
34
|
end
|
35
35
|
|
36
36
|
it "doesn't call poller.poll! when the synchronization file's polled_at is the same" do
|
37
|
-
|
37
|
+
Localeapp.poller.should_not_receive(:poll!)
|
38
38
|
@controller.handle_translation_updates
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
context "when polling is disabled" do
|
43
43
|
before do
|
44
|
-
|
45
|
-
|
44
|
+
Localeapp.configuration.environment_name = 'production' # reloading disabled
|
45
|
+
Localeapp.configuration.disabled_reloading_environments << 'production'
|
46
46
|
end
|
47
47
|
|
48
48
|
it "doesn't poller.poll! when the synchronization file's polled_at has changed" do
|
49
|
-
|
50
|
-
|
49
|
+
Localeapp.poller.write_synchronization_data!(01234, 56789)
|
50
|
+
Localeapp.poller.should_not_receive(:poll!)
|
51
51
|
@controller.handle_translation_updates
|
52
52
|
end
|
53
53
|
|
54
54
|
it "doesn't poller.poll! when the synchronization file's polled_at is the same" do
|
55
|
-
|
55
|
+
Localeapp.poller.should_not_receive(:poll!)
|
56
56
|
@controller.handle_translation_updates
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
context "when reloading is enabled" do
|
61
61
|
before do
|
62
|
-
|
63
|
-
|
62
|
+
Localeapp.configuration.environment_name = 'development' # reloading enabled
|
63
|
+
Localeapp.configuration.disabled_polling_environments << 'development'
|
64
64
|
end
|
65
65
|
|
66
66
|
it "calls I18n.reload! when the synchronization file's updated_at has changed" do
|
67
|
-
|
67
|
+
Localeapp.poller.write_synchronization_data!(01234, 56789)
|
68
68
|
I18n.should_receive(:reload!)
|
69
69
|
@controller.handle_translation_updates
|
70
70
|
end
|
@@ -77,12 +77,12 @@ describe LocaleApp::Rails::Controller, '#handle_translation_updates' do
|
|
77
77
|
|
78
78
|
context "when reloading is disabled" do
|
79
79
|
before do
|
80
|
-
|
81
|
-
|
80
|
+
Localeapp.configuration.environment_name = 'production' # reloading disabled
|
81
|
+
Localeapp.configuration.disabled_polling_environments << 'production'
|
82
82
|
end
|
83
83
|
|
84
84
|
it "doesn't call I18n.reload! when the synchronization file's updated_at has changed" do
|
85
|
-
|
85
|
+
Localeapp.poller.write_synchronization_data!(01234, 56789)
|
86
86
|
I18n.should_not_receive(:reload!)
|
87
87
|
@controller.handle_translation_updates
|
88
88
|
end
|
@@ -94,24 +94,24 @@ describe LocaleApp::Rails::Controller, '#handle_translation_updates' do
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
describe
|
97
|
+
describe Localeapp::Rails::Controller, '#send_missing_translations' do
|
98
98
|
before(:each) do
|
99
|
-
|
99
|
+
Localeapp.configure do |config|
|
100
100
|
config.api_key = 'abcdef'
|
101
101
|
end
|
102
|
-
TestController.send(:include,
|
102
|
+
TestController.send(:include, Localeapp::Rails::Controller)
|
103
103
|
@controller = TestController.new
|
104
104
|
end
|
105
105
|
|
106
106
|
it "does nothing when sending is disabled" do
|
107
|
-
|
108
|
-
|
107
|
+
Localeapp.configuration.environment_name = 'test'
|
108
|
+
Localeapp.sender.should_not_receive(:post_missing_translations)
|
109
109
|
@controller.send_missing_translations
|
110
110
|
end
|
111
111
|
|
112
112
|
it "proceeds when configuration is enabled" do
|
113
|
-
|
114
|
-
|
113
|
+
Localeapp.configuration.environment_name = 'development'
|
114
|
+
Localeapp.sender.should_receive(:post_missing_translations)
|
115
115
|
@controller.send_missing_translations
|
116
116
|
end
|
117
117
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class TestRoutes
|
4
|
-
include
|
4
|
+
include Localeapp::Routes
|
5
5
|
end
|
6
6
|
|
7
|
-
describe
|
7
|
+
describe Localeapp::Routes do
|
8
8
|
before(:each) do
|
9
9
|
@routes = TestRoutes.new
|
10
10
|
@config = {:host => 'test.host', :api_key => 'API_KEY'}
|