copy_tuner_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/.gitignore +18 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +9 -0
  4. data/Appraisals +15 -0
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +161 -0
  7. data/README.md +4 -0
  8. data/Rakefile +28 -0
  9. data/copy_tuner_client.gemspec +33 -0
  10. data/features/rails.feature +270 -0
  11. data/features/step_definitions/copycopter_server_steps.rb +64 -0
  12. data/features/step_definitions/rails_steps.rb +172 -0
  13. data/features/support/env.rb +11 -0
  14. data/features/support/rails_server.rb +124 -0
  15. data/gemfiles/2.3.gemfile +7 -0
  16. data/gemfiles/2.3.gemfile.lock +105 -0
  17. data/gemfiles/3.0.gemfile +7 -0
  18. data/gemfiles/3.0.gemfile.lock +147 -0
  19. data/gemfiles/3.1.gemfile +11 -0
  20. data/gemfiles/3.1.gemfile.lock +191 -0
  21. data/init.rb +1 -0
  22. data/lib/copy_tuner_client/cache.rb +144 -0
  23. data/lib/copy_tuner_client/client.rb +136 -0
  24. data/lib/copy_tuner_client/configuration.rb +224 -0
  25. data/lib/copy_tuner_client/errors.rb +12 -0
  26. data/lib/copy_tuner_client/i18n_backend.rb +92 -0
  27. data/lib/copy_tuner_client/poller.rb +44 -0
  28. data/lib/copy_tuner_client/prefixed_logger.rb +45 -0
  29. data/lib/copy_tuner_client/process_guard.rb +92 -0
  30. data/lib/copy_tuner_client/rails.rb +21 -0
  31. data/lib/copy_tuner_client/railtie.rb +12 -0
  32. data/lib/copy_tuner_client/request_sync.rb +39 -0
  33. data/lib/copy_tuner_client/version.rb +7 -0
  34. data/lib/copy_tuner_client.rb +75 -0
  35. data/lib/tasks/copy_tuner_client_tasks.rake +20 -0
  36. data/spec/copy_tuner_client/cache_spec.rb +273 -0
  37. data/spec/copy_tuner_client/client_spec.rb +236 -0
  38. data/spec/copy_tuner_client/configuration_spec.rb +305 -0
  39. data/spec/copy_tuner_client/i18n_backend_spec.rb +157 -0
  40. data/spec/copy_tuner_client/poller_spec.rb +108 -0
  41. data/spec/copy_tuner_client/prefixed_logger_spec.rb +37 -0
  42. data/spec/copy_tuner_client/process_guard_spec.rb +118 -0
  43. data/spec/copy_tuner_client/request_sync_spec.rb +47 -0
  44. data/spec/copy_tuner_client_spec.rb +19 -0
  45. data/spec/spec_helper.rb +29 -0
  46. data/spec/support/client_spec_helpers.rb +8 -0
  47. data/spec/support/defines_constants.rb +44 -0
  48. data/spec/support/fake_client.rb +53 -0
  49. data/spec/support/fake_copy_tuner_app.rb +175 -0
  50. data/spec/support/fake_html_safe_string.rb +20 -0
  51. data/spec/support/fake_logger.rb +68 -0
  52. data/spec/support/fake_passenger.rb +27 -0
  53. data/spec/support/fake_resque_job.rb +18 -0
  54. data/spec/support/fake_unicorn.rb +13 -0
  55. data/spec/support/middleware_stack.rb +13 -0
  56. data/spec/support/writing_cache.rb +17 -0
  57. data/tmp/projects.json +1 -0
  58. metadata +389 -0
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ log/*
2
+ tmp/**/*
3
+ tmp/*
4
+ coverage/*
5
+ rdoc/
6
+ tags
7
+
8
+ db/schema.rb
9
+ db/*.sqlite3
10
+ public/system
11
+
12
+ *.swp
13
+ *.DS_Store
14
+ .yardoc
15
+ doc
16
+ pkg
17
+ *.gem
18
+ .bundle
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+
6
+ gemfile:
7
+ - gemfiles/2.3.gemfile
8
+ - gemfiles/3.0.gemfile
9
+ - gemfiles/3.1.gemfile
data/Appraisals ADDED
@@ -0,0 +1,15 @@
1
+ appraise '2.3' do
2
+ gem 'rails', '2.3.14'
3
+ end
4
+
5
+ appraise '3.0' do
6
+ gem 'rails', '3.0.3'
7
+ end
8
+
9
+ appraise '3.1' do
10
+ gem 'rails', '3.1.0'
11
+ gem 'jquery-rails'
12
+ gem 'uglifier'
13
+ gem 'sass-rails'
14
+ gem 'coffee-rails'
15
+ end
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,161 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ copy_tuner_client (0.0.1)
5
+ i18n (>= 0.5.0)
6
+ json
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ actionmailer (3.1.0)
12
+ actionpack (= 3.1.0)
13
+ mail (~> 2.3.0)
14
+ actionpack (3.1.0)
15
+ activemodel (= 3.1.0)
16
+ activesupport (= 3.1.0)
17
+ builder (~> 3.0.0)
18
+ erubis (~> 2.7.0)
19
+ i18n (~> 0.6)
20
+ rack (~> 1.3.2)
21
+ rack-cache (~> 1.0.3)
22
+ rack-mount (~> 0.8.2)
23
+ rack-test (~> 0.6.1)
24
+ sprockets (~> 2.0.0)
25
+ activemodel (3.1.0)
26
+ activesupport (= 3.1.0)
27
+ bcrypt-ruby (~> 3.0.0)
28
+ builder (~> 3.0.0)
29
+ i18n (~> 0.6)
30
+ activerecord (3.1.0)
31
+ activemodel (= 3.1.0)
32
+ activesupport (= 3.1.0)
33
+ arel (~> 2.2.1)
34
+ tzinfo (~> 0.3.29)
35
+ activeresource (3.1.0)
36
+ activemodel (= 3.1.0)
37
+ activesupport (= 3.1.0)
38
+ activesupport (3.1.0)
39
+ multi_json (~> 1.0)
40
+ addressable (2.2.6)
41
+ appraisal (0.4.0)
42
+ bundler
43
+ rake
44
+ arel (2.2.1)
45
+ aruba (0.3.7)
46
+ childprocess (>= 0.1.9)
47
+ cucumber (>= 0.10.5)
48
+ rspec (>= 2.6.0)
49
+ bcrypt-ruby (3.0.0)
50
+ bourne (1.0)
51
+ mocha (= 0.9.8)
52
+ builder (3.0.0)
53
+ childprocess (0.2.2)
54
+ ffi (~> 1.0.6)
55
+ crack (0.1.8)
56
+ cucumber (0.10.7)
57
+ builder (>= 2.1.2)
58
+ diff-lcs (>= 1.1.2)
59
+ gherkin (~> 2.4.0)
60
+ json (>= 1.4.6)
61
+ term-ansicolor (>= 1.0.5)
62
+ daemons (1.1.4)
63
+ diff-lcs (1.1.3)
64
+ erubis (2.7.0)
65
+ eventmachine (0.12.10)
66
+ ffi (1.0.9)
67
+ gherkin (2.4.18)
68
+ json (>= 1.4.6)
69
+ hike (1.2.1)
70
+ i18n (0.6.0)
71
+ json (1.5.4)
72
+ mail (2.3.0)
73
+ i18n (>= 0.4.0)
74
+ mime-types (~> 1.16)
75
+ treetop (~> 1.4.8)
76
+ mime-types (1.16)
77
+ mocha (0.9.8)
78
+ rake
79
+ multi_json (1.0.3)
80
+ polyglot (0.3.2)
81
+ rack (1.3.2)
82
+ rack-cache (1.0.3)
83
+ rack (>= 0.4)
84
+ rack-mount (0.8.3)
85
+ rack (>= 1.0.0)
86
+ rack-ssl (1.3.2)
87
+ rack
88
+ rack-test (0.6.1)
89
+ rack (>= 1.0)
90
+ rails (3.1.0)
91
+ actionmailer (= 3.1.0)
92
+ actionpack (= 3.1.0)
93
+ activerecord (= 3.1.0)
94
+ activeresource (= 3.1.0)
95
+ activesupport (= 3.1.0)
96
+ bundler (~> 1.0)
97
+ railties (= 3.1.0)
98
+ railties (3.1.0)
99
+ actionpack (= 3.1.0)
100
+ activesupport (= 3.1.0)
101
+ rack-ssl (~> 1.3.2)
102
+ rake (>= 0.8.7)
103
+ rdoc (~> 3.4)
104
+ thor (~> 0.14.6)
105
+ rake (0.9.2)
106
+ rdoc (3.9.4)
107
+ rspec (2.6.0)
108
+ rspec-core (~> 2.6.0)
109
+ rspec-expectations (~> 2.6.0)
110
+ rspec-mocks (~> 2.6.0)
111
+ rspec-core (2.6.4)
112
+ rspec-expectations (2.6.0)
113
+ diff-lcs (~> 1.1.2)
114
+ rspec-mocks (2.6.0)
115
+ sham_rack (1.3.3)
116
+ rack
117
+ sinatra (1.2.6)
118
+ rack (~> 1.1)
119
+ tilt (>= 1.2.2, < 2.0)
120
+ sprockets (2.0.0)
121
+ hike (~> 1.2)
122
+ rack (~> 1.0)
123
+ tilt (~> 1.1, != 1.3.0)
124
+ sqlite3 (1.3.4)
125
+ sqlite3-ruby (1.3.3)
126
+ sqlite3 (>= 1.3.3)
127
+ term-ansicolor (1.0.6)
128
+ thin (1.2.11)
129
+ daemons (>= 1.0.9)
130
+ eventmachine (>= 0.12.6)
131
+ rack (>= 1.0.0)
132
+ thor (0.14.6)
133
+ tilt (1.3.3)
134
+ treetop (1.4.10)
135
+ polyglot
136
+ polyglot (>= 0.3.1)
137
+ tzinfo (0.3.29)
138
+ webmock (1.7.6)
139
+ addressable (~> 2.2, > 2.2.5)
140
+ crack (>= 0.1.7)
141
+ yard (0.7.2)
142
+
143
+ PLATFORMS
144
+ ruby
145
+
146
+ DEPENDENCIES
147
+ appraisal (~> 0.4)
148
+ aruba (~> 0.3.2)
149
+ bourne
150
+ copy_tuner_client!
151
+ cucumber (~> 0.10.0)
152
+ i18n
153
+ rails (~> 3.1.0)
154
+ rake (= 0.9.2)
155
+ rspec (~> 2.3)
156
+ sham_rack
157
+ sinatra
158
+ sqlite3-ruby
159
+ thin
160
+ webmock
161
+ yard
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ CopyTuner Client
2
+ =================
3
+
4
+ [TODO] Write After
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'appraisal'
3
+ require 'cucumber/rake/task'
4
+ require 'rspec/core/rake_task'
5
+ require 'yard'
6
+
7
+ desc 'Default: run the specs and features.'
8
+ task :default => :spec do
9
+ system "rake -s appraisal cucumber;"
10
+ end
11
+
12
+ desc 'Test the copy_tuner_client plugin.'
13
+ RSpec::Core::RakeTask.new do |t|
14
+ t.rspec_opts = ['--color', "--format progress"]
15
+ t.pattern = 'spec/copy_tuner_client/**/*_spec.rb'
16
+ end
17
+
18
+ desc "Run cucumber features"
19
+ Cucumber::Rake::Task.new do |t|
20
+ t.cucumber_opts = [
21
+ '--tags', '~@wip',
22
+ '--format', (ENV['CUCUMBER_FORMAT'] || 'progress')
23
+ ]
24
+ end
25
+
26
+ YARD::Rake::YardocTask.new do |t|
27
+ t.files = ['lib/**/*.rb']
28
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
+ require 'copy_tuner_client/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.add_dependency 'i18n', '>= 0.5.0'
7
+ s.add_dependency 'json'
8
+ s.add_development_dependency 'appraisal', '~> 0.4'
9
+ s.add_development_dependency 'aruba', '~> 0.3.2'
10
+ s.add_development_dependency 'bourne'
11
+ s.add_development_dependency 'cucumber', '~> 0.10.0'
12
+ s.add_development_dependency 'i18n'
13
+ s.add_development_dependency 'rails', '~> 3.1.0'
14
+ s.add_development_dependency 'rake', '0.9.2'
15
+ s.add_development_dependency 'rspec', '~> 2.3'
16
+ s.add_development_dependency 'sham_rack'
17
+ s.add_development_dependency 'sinatra'
18
+ s.add_development_dependency 'sqlite3-ruby'
19
+ s.add_development_dependency 'thin'
20
+ s.add_development_dependency 'webmock'
21
+ s.add_development_dependency 'yard'
22
+ s.authors = ['thoughtbot']
23
+ s.email = 'support@thoughtbot.com'
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
25
+ s.files = `git ls-files`.split("\n")
26
+ s.homepage = 'https://github.com/SonicGarden/copy-tuner-ruby-client'
27
+ s.name = 'copy_tuner_client'
28
+ s.platform = Gem::Platform::RUBY
29
+ s.require_paths = ['lib']
30
+ s.summary = 'Client for the CopyTuner copy management service'
31
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
32
+ s.version = CopyTunerClient::VERSION
33
+ end
@@ -0,0 +1,270 @@
1
+ @disable-bundler
2
+ Feature: Using copy_tuner in a rails app
3
+
4
+ Background:
5
+ Given I have a copy_tuner project with an api key of "abc123"
6
+ When I generate a rails application
7
+ And I configure the copy_tuner client with api key "abc123"
8
+
9
+ Scenario: copy_tuner in the controller
10
+ Given the "abc123" project has the following blurbs:
11
+ | key | draft content |
12
+ | en.users.index.controller-test | This is a test |
13
+ When I write to "app/controllers/users_controller.rb" with:
14
+ """
15
+ class UsersController < ActionController::Base
16
+ def index
17
+ @text = t("users.index.controller-test", :default => "default")
18
+ end
19
+ end
20
+ """
21
+ When I route the "users" resource
22
+ And I write to "app/views/users/index.html.erb" with:
23
+ """
24
+ <%= @text %>
25
+ """
26
+ When I start the application
27
+ And I wait for changes to be synchronized
28
+ Then the copy_tuner client version and environment should have been logged
29
+ Then the log should contain "Downloaded translations"
30
+ When I visit /users/
31
+ Then the response should contain "This is a test"
32
+ And the log should not contain "DEPRECATION WARNING"
33
+
34
+ Scenario: copy_tuner in the view
35
+ Given the "abc123" project has the following blurbs:
36
+ | key | draft content |
37
+ | en.users.index.view-test | This is a test |
38
+ When I write to "app/controllers/users_controller.rb" with:
39
+ """
40
+ class UsersController < ActionController::Base
41
+ def index
42
+ render
43
+ end
44
+ end
45
+ """
46
+ When I route the "users" resource
47
+ And I write to "app/views/users/index.html.erb" with:
48
+ """
49
+ <%= t(".view-test", :default => "default") %>
50
+ """
51
+ When I start the application
52
+ And I wait for changes to be synchronized
53
+ And I visit /users/
54
+ Then the response should contain "This is a test"
55
+
56
+ Scenario: copy_tuner detects updates to copy
57
+ Given the "abc123" project has the following blurbs:
58
+ | key | draft content |
59
+ | en.users.index.controller-test | Old content |
60
+ When I write to "app/controllers/users_controller.rb" with:
61
+ """
62
+ class UsersController < ActionController::Base
63
+ def index
64
+ @text = t("users.index.controller-test", :default => "default")
65
+ end
66
+ end
67
+ """
68
+ When I route the "users" resource
69
+ And I write to "app/views/users/index.html.erb" with:
70
+ """
71
+ <%= @text %>
72
+ """
73
+ When I start the application
74
+ And I visit /users/
75
+ Then the response should contain "Old content"
76
+ When the the following blurbs are updated in the "abc123" project:
77
+ | key | draft content |
78
+ | en.users.index.controller-test | New content |
79
+ And I visit /users/
80
+ Then the response should contain "New content"
81
+
82
+ Scenario: missing key
83
+ When I write to "app/controllers/users_controller.rb" with:
84
+ """
85
+ class UsersController < ActionController::Base
86
+ def index
87
+ render :action => "index"
88
+ end
89
+ end
90
+ """
91
+ When I route the "users" resource
92
+ And I write to "app/views/users/index.html.erb" with:
93
+ """
94
+ <%= t(".404", :default => "not found") %>
95
+ """
96
+ When I start the application
97
+ And I visit /users/
98
+ Then the response should contain "not found"
99
+ And the "abc123" project should have the following blurbs:
100
+ | key | draft content |
101
+ | en.users.index.404 | not found |
102
+ And the log should contain "Uploaded missing translations"
103
+
104
+ Scenario: copy_tuner in production
105
+ Given the "abc123" project has the following blurbs:
106
+ | key | published content | draft content |
107
+ | en.users.index.controller-test | This is a test | Extra extra |
108
+ | en.users.index.unpublished-test | | Extra extra |
109
+ When I write to "app/controllers/users_controller.rb" with:
110
+ """
111
+ class UsersController < ActionController::Base
112
+ def index
113
+ @text = t("users.index.controller-test", :default => "default")
114
+ @unpublished = t("users.index.unpublished-test", :default => "Unpublished")
115
+ t("users.index.unknown-test", :default => "Unknown")
116
+ end
117
+ end
118
+ """
119
+ When I route the "users" resource
120
+ And I write to "app/views/users/index.html.erb" with:
121
+ """
122
+ <%= @text %>
123
+ <%= @unpublished %>
124
+ """
125
+ When I start the application in the "production" environment
126
+ And I wait for changes to be synchronized
127
+ And I visit /users/
128
+ Then the response should contain "This is a test"
129
+ And the response should contain "Unpublished"
130
+ And I wait for changes to be synchronized
131
+ And the "abc123" project should have the following blurbs:
132
+ | key | draft content |
133
+ | en.users.index.unknown-test | Unknown |
134
+
135
+ Scenario: configure a bad api key
136
+ When I configure the copy_tuner client with api key "bogus"
137
+ And I start the application
138
+ And I wait for changes to be synchronized
139
+ Then the log should contain "Invalid API key: bogus"
140
+
141
+ Scenario: deploy
142
+ Given the "abc123" project has the following blurbs:
143
+ | key | draft content | published content |
144
+ | test.one | expected one | unexpected one |
145
+ | test.two | expected two | unexpected two |
146
+ When I successfully rake "copy_tuner:deploy"
147
+ And the output should contain "Successfully marked all blurbs as published"
148
+ Then the "abc123" project should have the following blurbs:
149
+ | key | draft content | published content |
150
+ | test.one | expected one | expected one |
151
+ | test.two | expected two | expected two |
152
+
153
+ Scenario: fallback on the simple I18n backend
154
+ When I write to "config/locales/en.yml" with:
155
+ """
156
+ en:
157
+ test:
158
+ key: Hello, %{name}
159
+ """
160
+ When I write to "app/controllers/users_controller.rb" with:
161
+ """
162
+ class UsersController < ActionController::Base
163
+ def index
164
+ render :text => t("test.key", :name => 'Joe')
165
+ end
166
+ end
167
+ """
168
+ When I route the "users" resource
169
+ And I start the application
170
+ And I visit /users/
171
+ Then the response should contain "Hello, Joe"
172
+ When I wait for changes to be synchronized
173
+ Then the "abc123" project should have the following blurbs:
174
+ | key | draft content |
175
+ | en.test.key | Hello, %{name} |
176
+
177
+ Scenario: preserve localization keys
178
+ When I write to "app/controllers/users_controller.rb" with:
179
+ """
180
+ class UsersController < ActionController::Base
181
+ def index
182
+ render
183
+ end
184
+ end
185
+ """
186
+ When I route the "users" resource
187
+ And I write to "app/views/users/index.html.erb" with:
188
+ """
189
+ <%= number_to_currency(2.5) %>
190
+ """
191
+ When I start the application
192
+ And I visit /users/
193
+ Then the response should contain "$2.50"
194
+ When I wait for changes to be synchronized
195
+ Then the "abc123" project should not have the "en.number.format" blurb
196
+
197
+ Scenario: view validation errors
198
+ When I write to "app/models/user.rb" with:
199
+ """
200
+ class User < ActiveRecord::Base
201
+ validates_presence_of :name
202
+ end
203
+ """
204
+ When I write to "db/migrate/1_create_users.rb" with:
205
+ """
206
+ class CreateUsers < ActiveRecord::Migration
207
+ def self.up
208
+ create_table :users do |t|
209
+ t.string :name
210
+ end
211
+ end
212
+ end
213
+ """
214
+ When I write to "app/controllers/users_controller.rb" with:
215
+ """
216
+ class UsersController < ActionController::Base
217
+ def index
218
+ @user = User.new
219
+ @user.valid?
220
+ render
221
+ end
222
+ end
223
+ """
224
+ When I route the "users" resource
225
+ And I write to "app/views/users/index.html.erb" with:
226
+ """
227
+ <%= @user.errors.full_messages.first %>
228
+ """
229
+ When I successfully rake "db:migrate"
230
+ And I configure the copy_tuner client to use published data
231
+ And I start the application
232
+ And I visit /users/
233
+ Then the response should contain "Name can't be blank"
234
+ When I wait for changes to be synchronized
235
+ Then the "abc123" project should have the following error blurbs:
236
+ | key | draft content |
237
+ | user.attributes.name.blank | can't be blank |
238
+
239
+ Scenario: ensure keys are synced with short lived processes
240
+ When I configure the copy_tuner client to have a polling delay of 86400 seconds
241
+ And I start the application
242
+ And I run a short lived process that sets the key "threaded.key" to "all your base"
243
+ Then the "abc123" project should have the following blurbs:
244
+ | key | draft content |
245
+ | en.threaded.key | all your base |
246
+
247
+ Scenario: support pluralization
248
+ Given I write to "app/controllers/users_controller.rb" with:
249
+ """
250
+ class UsersController < ActionController::Base
251
+ def index
252
+ render
253
+ end
254
+ end
255
+ """
256
+ And I route the "users" resource
257
+ And I write to "app/views/users/index.html.erb" with:
258
+ """
259
+ <%= time_ago_in_words(1.hour.ago) %> ago
260
+ <%= time_ago_in_words(2.hours.ago) %> ago
261
+ """
262
+ When I start the application
263
+ And I visit /users/
264
+ Then the response should contain "1 hour ago"
265
+ And the response should contain "2 hours ago"
266
+ When I wait for changes to be synchronized
267
+ Then the "abc123" project should have the following blurbs:
268
+ | key | draft content |
269
+ | en.datetime.distance_in_words.about_x_hours.one | about 1 hour |
270
+ | en.datetime.distance_in_words.about_x_hours.other | about %{count} hours |