localeapp 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/lib/localeapp/poller.rb +13 -2
- data/lib/localeapp/rails/controller.rb +3 -3
- data/lib/localeapp/version.rb +1 -1
- data/lib/localeapp.rb +4 -0
- data/spec/localeapp/poller_spec.rb +65 -17
- metadata +4 -4
data/CHANGELOG.md
CHANGED
data/lib/localeapp/poller.rb
CHANGED
@@ -27,7 +27,7 @@ module Localeapp
|
|
27
27
|
|
28
28
|
def write_synchronization_data!(polled_at, updated_at)
|
29
29
|
File.open(Localeapp.configuration.synchronization_data_file, 'w+') do |f|
|
30
|
-
f.write({:polled_at => polled_at, :updated_at => updated_at}.to_yaml)
|
30
|
+
f.write({:polled_at => polled_at.to_i, :updated_at => updated_at.to_i}.to_yaml)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -49,13 +49,24 @@ module Localeapp
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def handle_success(response)
|
52
|
+
Localeapp.log_with_time "poll success"
|
52
53
|
@success = true
|
53
54
|
Localeapp.updater.update(Localeapp.load_yaml(response))
|
54
|
-
write_synchronization_data!(
|
55
|
+
write_synchronization_data!(current_time, Time.parse(response.headers[:date]))
|
55
56
|
end
|
56
57
|
|
57
58
|
def handle_failure(response)
|
59
|
+
if response.code == 304
|
60
|
+
Localeapp.log_with_time "No new data"
|
61
|
+
# Nothing new, update synchronization files
|
62
|
+
write_synchronization_data!(current_time, updated_at)
|
63
|
+
end
|
58
64
|
@success = false
|
59
65
|
end
|
66
|
+
|
67
|
+
private
|
68
|
+
def current_time
|
69
|
+
Time.now
|
70
|
+
end
|
60
71
|
end
|
61
72
|
end
|
@@ -8,16 +8,16 @@ module Localeapp
|
|
8
8
|
|
9
9
|
def handle_translation_updates
|
10
10
|
unless ::Localeapp.configuration.polling_disabled?
|
11
|
-
::Localeapp.
|
11
|
+
::Localeapp.log_with_time 'Handling translation updates'
|
12
12
|
if ::Localeapp.poller.needs_polling?
|
13
|
-
::Localeapp.
|
13
|
+
::Localeapp.log_with_time 'polling'
|
14
14
|
::Localeapp.poller.poll!
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
unless ::Localeapp.configuration.reloading_disabled?
|
19
19
|
if ::Localeapp.poller.needs_reloading?
|
20
|
-
::Localeapp.
|
20
|
+
::Localeapp.log_with_time 'reloading I18n'
|
21
21
|
I18n.reload!
|
22
22
|
::Localeapp.poller.updated_at = ::Localeapp.poller.synchronization_data[:updated_at]
|
23
23
|
end
|
data/lib/localeapp/version.rb
CHANGED
data/lib/localeapp.rb
CHANGED
@@ -40,37 +40,85 @@ describe Localeapp::Poller do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
describe "#write_synchronization_data!(polled_at, updated_at)" do
|
43
|
+
let(:polled_at_time) { Time.at(1000000) }
|
44
|
+
let(:updated_at_time) { Time.at(1000010) }
|
45
|
+
|
43
46
|
it "updates polled_at in the synchronization file" do
|
44
47
|
polled_at = lambda { @poller.synchronization_data[:polled_at] }
|
45
|
-
expect { @poller.write_synchronization_data!(
|
48
|
+
expect { @poller.write_synchronization_data!(polled_at_time, updated_at_time) }.to change(polled_at, :call).to(polled_at_time.to_i)
|
46
49
|
end
|
47
50
|
|
48
51
|
it "updates updated_at in the synchronization file" do
|
49
52
|
updated_at = lambda { @poller.synchronization_data[:updated_at] }
|
50
|
-
expect { @poller.write_synchronization_data!(
|
53
|
+
expect { @poller.write_synchronization_data!(polled_at_time, updated_at_time) }.to change(updated_at, :call).to(updated_at_time.to_i)
|
51
54
|
end
|
52
55
|
end
|
53
|
-
|
56
|
+
|
54
57
|
describe "#poll!" do
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
58
|
+
let(:polled_at_time) { Time.at(1000000) }
|
59
|
+
let(:updated_at_time) { Time.at(1000010) }
|
60
|
+
|
61
|
+
describe "when response is 304 Not Modified" do
|
62
|
+
before do
|
63
|
+
FakeWeb.register_uri(:get, "https://api.localeapp.com/v1/projects/TEST_KEY/translations.yml?updated_at=#{@updated_at}", :body => '', :status => ['304', 'Not Modified'], :date => updated_at_time.httpdate)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns false" do
|
67
|
+
@poller.poll!.should == false
|
68
|
+
end
|
69
|
+
|
70
|
+
it "updates the polled_at but not the updated_at synchronization data" do
|
71
|
+
@poller.stub!(:current_time).and_return(polled_at_time)
|
72
|
+
@poller.should_receive(:write_synchronization_data!).with(polled_at_time, @updated_at)
|
73
|
+
@poller.poll!
|
74
|
+
end
|
59
75
|
|
60
|
-
|
61
|
-
|
62
|
-
|
76
|
+
it "updates the synchronization data" do
|
77
|
+
@poller.should_receive(:write_synchronization_data!)
|
78
|
+
@poller.poll!
|
79
|
+
end
|
63
80
|
end
|
64
81
|
|
65
|
-
|
66
|
-
|
67
|
-
|
82
|
+
describe "when response is 50x" do
|
83
|
+
before do
|
84
|
+
FakeWeb.register_uri(:get, "https://api.localeapp.com/v1/projects/TEST_KEY/translations.yml?updated_at=#{@updated_at}", :body => '', :status => ['500', 'Internal Server Error'])
|
85
|
+
end
|
86
|
+
|
87
|
+
it "returns false" do
|
88
|
+
@poller.poll!.should == false
|
89
|
+
end
|
90
|
+
|
91
|
+
it "doesn't update the synchronization data" do
|
92
|
+
@poller.should_not_receive(:write_synchronization_data!)
|
93
|
+
@poller.poll!
|
94
|
+
end
|
68
95
|
end
|
69
96
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
97
|
+
describe "when response is 200" do
|
98
|
+
before do
|
99
|
+
FakeWeb.register_uri(:get,
|
100
|
+
"https://api.localeapp.com/v1/projects/TEST_KEY/translations.yml?updated_at=#{@updated_at}",
|
101
|
+
:body => @hash.to_yaml,
|
102
|
+
:status => ['200', 'OK'],
|
103
|
+
:date => updated_at_time.httpdate
|
104
|
+
)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "returns true" do
|
108
|
+
@poller.poll!.should == true
|
109
|
+
end
|
110
|
+
|
111
|
+
it "updates the polled_at and the updated_at synchronization data" do
|
112
|
+
@poller.stub!(:current_time).and_return(polled_at_time)
|
113
|
+
@poller.should_receive(:write_synchronization_data!).with(polled_at_time, updated_at_time)
|
114
|
+
@poller.poll!
|
115
|
+
end
|
116
|
+
|
117
|
+
it "passes the data through to the Updater" do
|
118
|
+
FakeWeb.register_uri(:get, "https://api.localeapp.com/v1/projects/TEST_KEY/translations.yml?updated_at=#{@updated_at}", :body => @hash.to_yaml, :status => ['200', 'OK'], :date => Time.now.httpdate)
|
119
|
+
Localeapp.updater.should_receive(:update).with(@hash)
|
120
|
+
@poller.poll!
|
121
|
+
end
|
74
122
|
end
|
75
123
|
end
|
76
124
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: localeapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 2
|
10
|
+
version: 0.6.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Christopher Dell
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-10-
|
19
|
+
date: 2012-10-15 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: i18n
|