copycopter_client 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.textile +71 -0
- data/Rakefile +38 -0
- data/features/rails.feature +267 -0
- data/features/step_definitions/copycopter_server_steps.rb +65 -0
- data/features/step_definitions/rails_steps.rb +134 -0
- data/features/support/env.rb +8 -0
- data/features/support/rails_server.rb +118 -0
- data/init.rb +2 -0
- data/lib/copycopter_client/client.rb +117 -0
- data/lib/copycopter_client/configuration.rb +197 -0
- data/lib/copycopter_client/errors.rb +13 -0
- data/lib/copycopter_client/helper.rb +40 -0
- data/lib/copycopter_client/i18n_backend.rb +100 -0
- data/lib/copycopter_client/prefixed_logger.rb +41 -0
- data/lib/copycopter_client/rails.rb +31 -0
- data/lib/copycopter_client/railtie.rb +13 -0
- data/lib/copycopter_client/sync.rb +145 -0
- data/lib/copycopter_client/version.rb +8 -0
- data/lib/copycopter_client.rb +58 -0
- data/lib/tasks/copycopter_client_tasks.rake +6 -0
- data/spec/copycopter_client/client_spec.rb +208 -0
- data/spec/copycopter_client/configuration_spec.rb +252 -0
- data/spec/copycopter_client/helper_spec.rb +86 -0
- data/spec/copycopter_client/i18n_backend_spec.rb +133 -0
- data/spec/copycopter_client/prefixed_logger_spec.rb +25 -0
- data/spec/copycopter_client/sync_spec.rb +295 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/support/client_spec_helpers.rb +9 -0
- data/spec/support/defines_constants.rb +38 -0
- data/spec/support/fake_client.rb +42 -0
- data/spec/support/fake_copycopter_app.rb +136 -0
- data/spec/support/fake_html_safe_string.rb +20 -0
- data/spec/support/fake_logger.rb +68 -0
- data/spec/support/fake_passenger.rb +27 -0
- data/spec/support/fake_unicorn.rb +14 -0
- metadata +121 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
h1. Copycopter Client
|
2
|
+
|
3
|
+
This is the client gem for integrating apps with "Copycopter":http://copycopter.com.
|
4
|
+
|
5
|
+
The client integrates with the I18n gem so that you can access copy text and translations from a Copycopter project.
|
6
|
+
|
7
|
+
h2. Installation
|
8
|
+
|
9
|
+
Just install the gem:
|
10
|
+
|
11
|
+
<pre>gem install copycopter_client</pre>
|
12
|
+
|
13
|
+
h3. Rails 3
|
14
|
+
|
15
|
+
Add the following line to your <code>Gemfile</code>:
|
16
|
+
|
17
|
+
<pre>gem "copycopter_client"</pre>
|
18
|
+
|
19
|
+
Then run <code>bundle install</code>.
|
20
|
+
|
21
|
+
h3. Rails 2
|
22
|
+
|
23
|
+
Add the following line to your <code>config/environment.rb</code>:
|
24
|
+
|
25
|
+
<pre>config.gem 'copycopter_client'</pre>
|
26
|
+
|
27
|
+
Then run <code>rake gems:install</code>. We also recommend vendoring the gem by running <code>rake gems:unpack:dependencies GEM=copycopter_client</code>.
|
28
|
+
|
29
|
+
h2. Configuration
|
30
|
+
|
31
|
+
Add the following to your application:
|
32
|
+
|
33
|
+
<pre>
|
34
|
+
CopycopterClient.configure do |config|
|
35
|
+
config.api_key = "YOUR API KEY HERE"
|
36
|
+
end
|
37
|
+
</pre>
|
38
|
+
|
39
|
+
In a Rails application, this should be saved as <code>config/initializers/copycopter.rb</code>. You can find the API key on the project page on the Copycopter website. See the {CopycopterClient::Configuration} class for a full list of configuration options.
|
40
|
+
|
41
|
+
h2. Usage
|
42
|
+
|
43
|
+
You can access blurbs from Copycopter by using <code>I18n.translate</code>. This is also aliased as <code>translate</code> or just <code>t</code> inside Rails controllers and views.
|
44
|
+
|
45
|
+
<pre>
|
46
|
+
# In a controller
|
47
|
+
def index
|
48
|
+
flash[:success] = t("users.create.success", :default => "User created")
|
49
|
+
end
|
50
|
+
|
51
|
+
# In a view
|
52
|
+
<%= t(".welcome", :default => "Why hello there") %>
|
53
|
+
|
54
|
+
# Global scope (for example, in a Rake task)
|
55
|
+
I18n.translate("system.tasks_complete", :default => "Tasks complete")
|
56
|
+
|
57
|
+
# Interpolation
|
58
|
+
I18n.translate("mailer.welcome", :default => "Welcome, %{name}!", :name => @user.name)
|
59
|
+
</pre>
|
60
|
+
|
61
|
+
See the "I18n documentation":http://rdoc.info/github/svenfuchs/i18n/master/file/README.textile documentation for more examples.
|
62
|
+
|
63
|
+
h2. Deploys
|
64
|
+
|
65
|
+
Blurbs start out as draft copy, and won't be displayed in production environments until they're published. If you want to publish all draft copy when deploying to production, you can use the <code>copycopter:deploy</code> rake task:
|
66
|
+
|
67
|
+
<pre>rake copycopter:deploy</pre>
|
68
|
+
|
69
|
+
h2. About
|
70
|
+
|
71
|
+
Copyright (c) 2010 "thoughtbot, inc.":http://thoughtbot.com, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'appraisal'
|
4
|
+
require 'rake'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'rake/rdoctask'
|
7
|
+
require 'rake/gempackagetask'
|
8
|
+
require 'cucumber/rake/task'
|
9
|
+
require 'spec/rake/spectask'
|
10
|
+
require 'yard'
|
11
|
+
|
12
|
+
desc 'Default: run the specs and features.'
|
13
|
+
task :default => :spec do
|
14
|
+
system("rake -s appraisal cucumber;")
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Test the copycopter_client plugin.'
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/copycopter_client/**/*_spec.rb']
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Run cucumber features"
|
24
|
+
Cucumber::Rake::Task.new do |t|
|
25
|
+
t.cucumber_opts = ['--tags', '~@wip',
|
26
|
+
'--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
|
27
|
+
end
|
28
|
+
|
29
|
+
YARD::Rake::YardocTask.new do |t|
|
30
|
+
t.files = ['lib/**/*.rb']
|
31
|
+
end
|
32
|
+
|
33
|
+
eval("$specification = begin; #{IO.read('copycopter_client.gemspec')}; end")
|
34
|
+
Rake::GemPackageTask.new($specification) do |package|
|
35
|
+
package.need_zip = true
|
36
|
+
package.need_tar = true
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,267 @@
|
|
1
|
+
@disable-bundler @puts @announce
|
2
|
+
Feature: Using copycopter in a rails app
|
3
|
+
|
4
|
+
Background:
|
5
|
+
Given I have a copycopter project with an api key of "abc123"
|
6
|
+
When I generate a rails application
|
7
|
+
And I configure the copycopter client with api key "abc123"
|
8
|
+
|
9
|
+
Scenario: copycopter 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 copycopter 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: copycopter 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: copycopter 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 wait for changes to be synchronized
|
75
|
+
And I visit /users/
|
76
|
+
Then the response should contain "Old content"
|
77
|
+
When the the following blurbs are updated in the "abc123" project:
|
78
|
+
| key | draft content |
|
79
|
+
| en.users.index.controller-test | New content |
|
80
|
+
And I wait for changes to be synchronized
|
81
|
+
And I visit /users/
|
82
|
+
Then the response should contain "New content"
|
83
|
+
|
84
|
+
Scenario: missing key
|
85
|
+
When I write to "app/controllers/users_controller.rb" with:
|
86
|
+
"""
|
87
|
+
class UsersController < ActionController::Base
|
88
|
+
def index
|
89
|
+
render :action => "index"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
"""
|
93
|
+
When I route the "users" resource
|
94
|
+
And I write to "app/views/users/index.html.erb" with:
|
95
|
+
"""
|
96
|
+
<%= t(".404", :default => "not found") %>
|
97
|
+
"""
|
98
|
+
When I start the application
|
99
|
+
And I visit /users/
|
100
|
+
Then the response should contain "not found"
|
101
|
+
When I wait for changes to be synchronized
|
102
|
+
Then the "abc123" project should have the following blurbs:
|
103
|
+
| key | draft content |
|
104
|
+
| en.users.index.404 | not found |
|
105
|
+
And the log should contain "Uploaded missing translations"
|
106
|
+
|
107
|
+
Scenario: copycopter in production
|
108
|
+
Given the "abc123" project has the following blurbs:
|
109
|
+
| key | published content | draft content |
|
110
|
+
| en.users.index.controller-test | This is a test | Extra extra |
|
111
|
+
When I write to "app/controllers/users_controller.rb" with:
|
112
|
+
"""
|
113
|
+
class UsersController < ActionController::Base
|
114
|
+
def index
|
115
|
+
@text = t("users.index.controller-test", :default => "default")
|
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
|
+
"""
|
124
|
+
When I configure the copycopter client to use published data
|
125
|
+
And I start the application
|
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
|
+
|
130
|
+
Scenario: backwards compatibility
|
131
|
+
Given the "abc123" project has the following blurbs:
|
132
|
+
| key | draft content |
|
133
|
+
| en.users.index.controller-test | Controller blurb |
|
134
|
+
| en.users.index.view-test | View blurb |
|
135
|
+
When I write to "app/controllers/users_controller.rb" with:
|
136
|
+
"""
|
137
|
+
class UsersController < ActionController::Base
|
138
|
+
def index
|
139
|
+
@text = s('.controller-test')
|
140
|
+
render
|
141
|
+
end
|
142
|
+
end
|
143
|
+
"""
|
144
|
+
When I route the "users" resource
|
145
|
+
And I write to "app/views/users/index.html.erb" with:
|
146
|
+
"""
|
147
|
+
<%= @text %>
|
148
|
+
<%= s(".view-test", "default") %>
|
149
|
+
"""
|
150
|
+
When I start the application
|
151
|
+
And I wait for changes to be synchronized
|
152
|
+
And I visit /users/
|
153
|
+
Then the response should contain "Controller blurb"
|
154
|
+
And the response should contain "View blurb"
|
155
|
+
|
156
|
+
Scenario: configure a bad api key
|
157
|
+
When I configure the copycopter client with api key "bogus"
|
158
|
+
And I start the application
|
159
|
+
And I wait for changes to be synchronized
|
160
|
+
Then the log should contain "Invalid API key: bogus"
|
161
|
+
|
162
|
+
Scenario: deploy
|
163
|
+
Given the "abc123" project has the following blurbs:
|
164
|
+
| key | draft content | published content |
|
165
|
+
| test.one | expected one | unexpected one |
|
166
|
+
| test.two | expected two | unexpected two |
|
167
|
+
When I successfully rake "copycopter:deploy"
|
168
|
+
Then the "abc123" project should have the following blurbs:
|
169
|
+
| key | draft content | published content |
|
170
|
+
| test.one | expected one | expected one |
|
171
|
+
| test.two | expected two | expected two |
|
172
|
+
|
173
|
+
Scenario: fallback on the simple I18n backend
|
174
|
+
When I write to "config/locales/en.yml" with:
|
175
|
+
"""
|
176
|
+
en:
|
177
|
+
test:
|
178
|
+
key: Hello, %{name}
|
179
|
+
"""
|
180
|
+
When I write to "app/controllers/users_controller.rb" with:
|
181
|
+
"""
|
182
|
+
class UsersController < ActionController::Base
|
183
|
+
def index
|
184
|
+
render :text => t("test.key", :name => 'Joe')
|
185
|
+
end
|
186
|
+
end
|
187
|
+
"""
|
188
|
+
When I route the "users" resource
|
189
|
+
And I start the application
|
190
|
+
And I visit /users/
|
191
|
+
Then the response should contain "Hello, Joe"
|
192
|
+
When I wait for changes to be synchronized
|
193
|
+
Then the "abc123" project should have the following blurbs:
|
194
|
+
| key | draft content |
|
195
|
+
| en.test.key | Hello, %{name} |
|
196
|
+
|
197
|
+
Scenario: preserve localization keys
|
198
|
+
When I write to "app/controllers/users_controller.rb" with:
|
199
|
+
"""
|
200
|
+
class UsersController < ActionController::Base
|
201
|
+
def index
|
202
|
+
render
|
203
|
+
end
|
204
|
+
end
|
205
|
+
"""
|
206
|
+
When I route the "users" resource
|
207
|
+
And I write to "app/views/users/index.html.erb" with:
|
208
|
+
"""
|
209
|
+
<%= number_to_currency(2.5) %>
|
210
|
+
"""
|
211
|
+
When I start the application
|
212
|
+
And I visit /users/
|
213
|
+
Then the response should contain "$2.50"
|
214
|
+
When I wait for changes to be synchronized
|
215
|
+
Then the "abc123" project should not have the "en.number.format" blurb
|
216
|
+
|
217
|
+
Scenario: view validation errors
|
218
|
+
When I write to "app/models/user.rb" with:
|
219
|
+
"""
|
220
|
+
class User < ActiveRecord::Base
|
221
|
+
validates_presence_of :name
|
222
|
+
end
|
223
|
+
"""
|
224
|
+
When I write to "db/migrate/1_create_users.rb" with:
|
225
|
+
"""
|
226
|
+
class CreateUsers < ActiveRecord::Migration
|
227
|
+
def self.up
|
228
|
+
create_table :users do |t|
|
229
|
+
t.string :name
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
"""
|
234
|
+
When I write to "app/controllers/users_controller.rb" with:
|
235
|
+
"""
|
236
|
+
class UsersController < ActionController::Base
|
237
|
+
def index
|
238
|
+
@user = User.new
|
239
|
+
@user.valid?
|
240
|
+
render
|
241
|
+
end
|
242
|
+
end
|
243
|
+
"""
|
244
|
+
When I route the "users" resource
|
245
|
+
And I write to "app/views/users/index.html.erb" with:
|
246
|
+
"""
|
247
|
+
<%= @user.errors.full_messages.first %>
|
248
|
+
"""
|
249
|
+
When I successfully rake "db:migrate"
|
250
|
+
And I configure the copycopter client to use published data
|
251
|
+
And I start the application
|
252
|
+
And I visit /users/
|
253
|
+
Then the response should contain "Name can't be blank"
|
254
|
+
When I wait for changes to be synchronized
|
255
|
+
Then the "abc123" project should have the following error blurbs:
|
256
|
+
| key | draft content |
|
257
|
+
| user.attributes.name.blank | can't be blank |
|
258
|
+
|
259
|
+
|
260
|
+
Scenario: ensure keys are synced with short lived processes
|
261
|
+
When I configure the copycopter client to have a polling delay of 86400 seconds
|
262
|
+
And I start the application
|
263
|
+
And I run a short lived process that sets the key "threaded.key" to "all your base"
|
264
|
+
Then the "abc123" project should have the following blurbs:
|
265
|
+
| key | draft content |
|
266
|
+
| en.threaded.key | all your base |
|
267
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.join(PROJECT_ROOT, "spec", "support", "fake_copycopter_app")
|
2
|
+
|
3
|
+
Given /^I have a copycopter project with an api key of "([^"]*)"$/ do |api_key|
|
4
|
+
FakeCopycopterApp.add_project api_key
|
5
|
+
end
|
6
|
+
|
7
|
+
Given /^the "([^"]*)" project has the following blurbs:$/ do |api_key, table|
|
8
|
+
project = FakeCopycopterApp.project(api_key)
|
9
|
+
table.hashes.each do |blurb_hash|
|
10
|
+
key = blurb_hash['key']
|
11
|
+
data = { 'draft' => { key => blurb_hash['draft content'] },
|
12
|
+
'published' => { key => blurb_hash['published content'] } }
|
13
|
+
project.update(data)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
When /^the the following blurbs are updated in the "([^"]*)" project:$/ do |api_key, table|
|
18
|
+
Given %{the "#{api_key}" project has the following blurbs:}, table
|
19
|
+
end
|
20
|
+
|
21
|
+
Then /^the "([^"]*)" project should have the following blurbs:$/ do |api_key, table|
|
22
|
+
project = FakeCopycopterApp.project(api_key)
|
23
|
+
table.hashes.each do |blurb_hash|
|
24
|
+
key = blurb_hash['key']
|
25
|
+
|
26
|
+
if blurb_hash['draft content']
|
27
|
+
unless project.draft[key] == blurb_hash['draft content']
|
28
|
+
raise "Expected #{blurb_hash['draft content']} for #{key} but got #{project.draft[key]}\nExisting keys: #{project.draft.inspect}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if blurb_hash['published content']
|
33
|
+
unless project.published[key] == blurb_hash['published content']
|
34
|
+
raise "Expected #{blurb_hash['published content']} for #{key} but got #{project.published[key]}\nExisting keys: #{project.published.inspect}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Then /^the "([^"]*)" project should have the following error blurbs:$/ do |api_key, table|
|
41
|
+
prefix = 'en.activerecord.errors.models'
|
42
|
+
|
43
|
+
rows = table.hashes.map do |error_blurb|
|
44
|
+
"| #{prefix}.#{error_blurb['key']} | #{error_blurb['draft content']} |"
|
45
|
+
end
|
46
|
+
|
47
|
+
steps %{
|
48
|
+
Then the "#{api_key}" project should have the following blurbs:
|
49
|
+
| key | draft content |
|
50
|
+
#{rows.join("\n")}
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
Then /^the "([^"]*)" project should not have the "([^"]*)" blurb$/ do |api_key, blurb_key|
|
55
|
+
project = FakeCopycopterApp.project(api_key)
|
56
|
+
project.draft[blurb_key].should be_nil
|
57
|
+
end
|
58
|
+
|
59
|
+
When /^I wait for changes to be synchronized$/ do
|
60
|
+
sleep(3)
|
61
|
+
end
|
62
|
+
|
63
|
+
FakeCopycopterApp.start
|
64
|
+
After { FakeCopycopterApp.reset }
|
65
|
+
|
@@ -0,0 +1,134 @@
|
|
1
|
+
When "I generate a rails application" do
|
2
|
+
if Rails::VERSION::MAJOR == 3
|
3
|
+
subcommand = 'new'
|
4
|
+
else
|
5
|
+
subcommand = ''
|
6
|
+
end
|
7
|
+
|
8
|
+
run_simple("rails _#{Rails::VERSION::STRING}_ #{subcommand} testapp")
|
9
|
+
cd("testapp")
|
10
|
+
|
11
|
+
if Rails::VERSION::MAJOR == 3
|
12
|
+
append_to_file("Gemfile", <<-GEMS)
|
13
|
+
gem "thin"
|
14
|
+
gem "sham_rack"
|
15
|
+
gem "sinatra"
|
16
|
+
gem "json"
|
17
|
+
GEMS
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
When /^I configure the copycopter client with api key "([^"]*)"$/ do |api_key|
|
22
|
+
create_file("config/initializers/copycopter.rb", <<-RUBY)
|
23
|
+
CopycopterClient.configure do |config|
|
24
|
+
config.api_key = "#{api_key}"
|
25
|
+
config.polling_delay = 1
|
26
|
+
config.host = 'localhost'
|
27
|
+
config.port = #{FakeCopycopterApp.port}
|
28
|
+
end
|
29
|
+
RUBY
|
30
|
+
|
31
|
+
if Rails::VERSION::MAJOR == 3
|
32
|
+
append_to_file("Gemfile", <<-GEMS)
|
33
|
+
gem "copycopter_client", :path => "../../.."
|
34
|
+
GEMS
|
35
|
+
else
|
36
|
+
in_current_dir { FileUtils.rm_f("vendor/plugins/copycopter") }
|
37
|
+
run_simple("ln -s #{PROJECT_ROOT} vendor/plugins/copycopter")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
When "I start the application" do
|
42
|
+
in_current_dir do
|
43
|
+
RailsServer.start(ENV['RAILS_PORT'], @announce_stderr)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
When /^I visit (\/.*)$/ do |path|
|
48
|
+
@last_response = RailsServer.get(path)
|
49
|
+
end
|
50
|
+
|
51
|
+
When /^I configure the copycopter client to use published data$/ do
|
52
|
+
in_current_dir do
|
53
|
+
config_path = "config/initializers/copycopter.rb"
|
54
|
+
contents = IO.read(config_path)
|
55
|
+
contents.sub!("end", " config.development_environments = []\nend")
|
56
|
+
File.open(config_path, "w") { |file| file.write(contents) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
When /^I configure the copycopter client to have a polling delay of (\d+) seconds$/ do |polling_delay|
|
61
|
+
in_current_dir do
|
62
|
+
config_path = "config/initializers/copycopter.rb"
|
63
|
+
contents = IO.read(config_path)
|
64
|
+
contents.sub!(/config.polling_delay = .+/, "config.polling_delay = #{polling_delay}")
|
65
|
+
File.open(config_path, "w") { |file| file.write(contents) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
Then /^the copycopter client version and environment should have been logged$/ do
|
70
|
+
client_version = CopycopterClient::VERSION
|
71
|
+
environment_info = "[Ruby: #{RUBY_VERSION}]"
|
72
|
+
environment_info << " [Rails: #{Rails::VERSION::STRING}]"
|
73
|
+
environment_info << " [Env: development]"
|
74
|
+
steps %{
|
75
|
+
Then the log should contain "Client #{client_version} ready"
|
76
|
+
Then the log should contain "Environment Info: #{environment_info}"
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
Then /^the log should contain "([^"]*)"$/ do |line|
|
81
|
+
prefix = "** [Copycopter] "
|
82
|
+
pattern = Regexp.compile([Regexp.escape(prefix), Regexp.escape(line)].join(".*"))
|
83
|
+
log_path = "log/development.log"
|
84
|
+
in_current_dir do
|
85
|
+
File.open(log_path) do |file|
|
86
|
+
unless file.readlines.any? { |file_line| file_line =~ pattern }
|
87
|
+
raise "In log file:\n#{IO.read(log_path)}\n\nMissing line:\n#{pattern}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
Then /^the log should not contain "([^"]*)"$/ do |line|
|
94
|
+
log_path = "log/development.log"
|
95
|
+
in_current_dir do
|
96
|
+
File.open(log_path) do |file|
|
97
|
+
if bad_line = file.readlines.detect { |file_line| file_line.include?(line) }
|
98
|
+
raise "In log file:\n#{log_path}\n\nGot unexpected line:\n#{bad_line}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
When /^I successfully rake "([^"]*)"$/ do |task|
|
105
|
+
run_simple("rake #{task}")
|
106
|
+
end
|
107
|
+
|
108
|
+
Then /^the response should contain "([^"]+)"$/ do |text|
|
109
|
+
@last_response.body.should include(text)
|
110
|
+
end
|
111
|
+
|
112
|
+
When /^I route the "([^"]+)" resource$/ do |resource|
|
113
|
+
if Rails::VERSION::MAJOR == 3
|
114
|
+
draw = "Testapp::Application.routes.draw do\n"
|
115
|
+
else
|
116
|
+
draw = "ActionController::Routing::Routes.draw do |map|\nmap."
|
117
|
+
end
|
118
|
+
|
119
|
+
routes = "#{draw}resources :#{resource}\nend"
|
120
|
+
|
121
|
+
create_file("config/routes.rb", routes, false)
|
122
|
+
end
|
123
|
+
|
124
|
+
When /^I run a short lived process that sets the key "([^"]*)" to "([^"]*)"$/ do |key, value|
|
125
|
+
if Rails::VERSION::MAJOR == 3
|
126
|
+
run_simple %[script/rails runner 'I18n.translate("#{key}", :default => "#{value}")']
|
127
|
+
else
|
128
|
+
run_simple %[script/runner 'I18n.translate("#{key}", :default => "#{value}")']
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
After do
|
133
|
+
RailsServer.stop
|
134
|
+
end
|