localeapp 0.6.7 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
data/bin/localeapp CHANGED
@@ -24,6 +24,16 @@ else
24
24
  end
25
25
 
26
26
  pre do |global_options, command, options, args|
27
+ global_options[:k] = if global_options[:k]
28
+ global_options[:k]
29
+ elsif ENV['LOCALEAPP_API_KEY']
30
+ ENV['LOCALEAPP_API_KEY']
31
+ elsif File.exist?('.env') && IO.read('.env') =~ /^LOCALEAPP_API_KEY=(\w+)$/
32
+ $1
33
+ else
34
+ nil
35
+ end
36
+
27
37
  if Localeapp.has_config_file? || !global_options[:k].nil?
28
38
  true
29
39
  else
@@ -43,7 +53,10 @@ arg_name "<api_key>"
43
53
  command :install do |c|
44
54
  c.desc "install configuration files in .localeapp/"
45
55
  c.switch [:s, 'standalone']
46
-
56
+
57
+ c.desc "create configuration when using localeapp via a heroku addon (PRE ALPHA)"
58
+ c.switch [:h, 'heroku']
59
+
47
60
  c.desc "install a skeleton project suitable for Github"
48
61
  c.switch [:g, 'github']
49
62
 
@@ -51,6 +64,7 @@ command :install do |c|
51
64
  key = args.first
52
65
  installer = Localeapp::CLI::Install.new
53
66
  installer.config_type = :standalone if options[:standalone]
67
+ installer.config_type = :heroku if options[:heroku]
54
68
  installer.config_type = :github if options[:github]
55
69
  installer.config_type ||= :rails
56
70
  unless installer.execute(key)
data/features/add.feature CHANGED
@@ -44,3 +44,30 @@ Feature: Adding a translation from the command line
44
44
  Sending key: foo.baz
45
45
  Success!
46
46
  """
47
+
48
+ Scenario: Running add with no initializer file, passing the key via an ENV variable
49
+ In order to add a key and translation content
50
+ When I have a valid project on localeapp.com with api key "MYAPIKEY"
51
+ When I have a LOCALEAPP_API_KEY env variable set to "MYAPIKEY"
52
+ When I run `localeapp add foo.baz en:"test en content"`
53
+ Then the output should contain:
54
+ """
55
+ Localeapp Add
56
+
57
+ Sending key: foo.baz
58
+ Success!
59
+ """
60
+ Then I clear the LOCALEAPP_API_KEY env variable
61
+
62
+ Scenario: Running add with no initializer file, passing the key via a .env file
63
+ In order to add a key and translation content
64
+ When I have a valid project on localeapp.com with api key "MYAPIKEY"
65
+ When I have a .env file containing the api key "MYAPIKEY"
66
+ When I run `localeapp add foo.baz en:"test en content"`
67
+ Then the output should contain:
68
+ """
69
+ Localeapp Add
70
+
71
+ Sending key: foo.baz
72
+ Success!
73
+ """
@@ -28,7 +28,9 @@ Feature: Installation
28
28
  Checking API key: MYAPIKEY
29
29
  Success!
30
30
  Project: Test Project
31
- Default Locale: en (English)
31
+ NOTICE: you probably want to add .localeapp to your .gitignore file
32
+ Writing configuration file to .localeapp/config.rb
33
+ WARNING: please create the locales directory. Your translation data will be stored there.
32
34
  """
33
35
  And help should not be displayed
34
36
  And a file named ".localeapp/config.rb" should exist
@@ -45,7 +47,8 @@ Feature: Installation
45
47
  Checking API key: MYAPIKEY
46
48
  Success!
47
49
  Project: Test Project
48
- Default Locale: en (English)
50
+ NOTICE: you probably want to add .localeapp to your .gitignore file
51
+ Writing configuration file to .localeapp/config.rb
49
52
  """
50
53
  And help should not be displayed
51
54
  And a file named ".localeapp/config.rb" should exist
@@ -53,6 +56,27 @@ Feature: Installation
53
56
  And a file named "README.md" should exist
54
57
  And the exit status should be 0
55
58
 
59
+ Scenario: Running heroku install with no api key
60
+ In order to configure my project to use localeapp as a heroku addon
61
+ When I have a valid heroku project
62
+ And I run `localeapp install --heroku`
63
+ Then the output should contain:
64
+ """
65
+ Localeapp Install
66
+
67
+ Getting API key from heroku config
68
+ Add the following line to your .env file for Foreman
69
+ LOCALEAPP_API_KEY=MYAPIKEY
70
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
71
+ Checking API key: MYAPIKEY
72
+ Success!
73
+ Project: Test Project
74
+ Default Locale: en (English)
75
+ """
76
+ And help should not be displayed
77
+ And a file named "config/initializers/localeapp.rb" should exist
78
+ And the file "config/initializers/localeapp.rb" should contain "config.api_key = ENV['LOCALEAPP_API_KEY']"
79
+ And the exit status should be 0
56
80
 
57
81
  Scenario: Running install with bad api key
58
82
  In order to configure my project and check my api key is correct
@@ -9,6 +9,13 @@ When /^I have a valid project on localeapp\.com with api key "([^"]*)"$/ do |api
9
9
  add_fake_web_uri(:post, "https://api.localeapp.com/v1/projects/#{api_key}/translations/missing.json", ["202", "OK"], '')
10
10
  end
11
11
 
12
+ When /^I have a valid heroku project/ do
13
+ uri = "https://api.localeapp.com/v1/projects/MYAPIKEY.json"
14
+ body = valid_project_data.to_json
15
+ add_fake_web_uri(:get, uri, ['200', 'OK'], body)
16
+ ENV['CUCUMBER_HEROKU_TEST_API_KEY'] = 'MYAPIKEY'
17
+ end
18
+
12
19
  When /^I have a valid project on localeapp\.com but an incorrect api key "([^"]*)"$/ do |bad_api_key|
13
20
  uri = "https://api.localeapp.com/v1/projects/#{bad_api_key}.json"
14
21
  body = valid_project_data.to_json
@@ -34,6 +41,23 @@ When /^I have a valid project on localeapp\.com with api key "([^"]*)" and the t
34
41
  add_fake_web_uri(:post, uri + '/rename', ['200', 'OK'], '')
35
42
  end
36
43
 
44
+ When /^I have a LOCALEAPP_API_KEY env variable set to "(.*?)"$/ do |api_key|
45
+ ENV['LOCALEAPP_API_KEY'] = api_key
46
+ end
47
+
48
+ Then /^I clear the LOCALEAPP_API_KEY env variable$/ do
49
+ ENV['LOCALEAPP_API_KEY'] = nil
50
+ end
51
+
52
+ When /^I have a \.env file containing the api key "(.*?)"$/ do |api_key|
53
+ steps %Q{
54
+ And a file named ".env" with:
55
+ """
56
+ LOCALEAPP_API_KEY=#{api_key}
57
+ """
58
+ }
59
+ end
60
+
37
61
  When /^an initializer file$/ do
38
62
  steps %Q{
39
63
  And a file named "config/initializers/localeapp.rb" with:
@@ -5,70 +5,228 @@ module Localeapp
5
5
 
6
6
  def initialize(args = {})
7
7
  super
8
- @config_type = :rails
8
+ @config_type = :default
9
9
  end
10
10
 
11
- def execute(key)
12
- @output.puts "Localeapp Install"
13
- @output.puts ""
14
- @output.puts "Checking API key: #{key}"
15
- if key.nil?
16
- @output.puts "ERROR: You must supply an API key"
17
- return
18
- end
19
- valid_key, project_data = check_key(key)
20
- if valid_key
21
- @output.puts "Success!"
22
- @output.puts "Project: #{project_data['name']}"
23
- localeapp_default_code = project_data['default_locale']['code']
24
- @output.puts "Default Locale: #{localeapp_default_code} (#{project_data['default_locale']['name']})"
11
+ def execute(key = nil)
12
+ installer("#{config_type.to_s.capitalize}Installer").execute(key)
13
+ end
14
+
15
+ def installer(installer_class)
16
+ self.class.const_get(installer_class).new(@output)
17
+ end
25
18
 
26
- if config_type == :rails
27
- if I18n.default_locale.to_s != localeapp_default_code
28
- @output.puts "WARNING: I18n.default_locale is #{I18n.default_locale}, change in config/environment.rb (Rails 2) or config/application.rb (Rails 3)"
29
- end
30
- config_file_path = "config/initializers/localeapp.rb"
31
- data_directory = "config/locales"
19
+ class DefaultInstaller
20
+ attr_accessor :key, :project_data, :config_file_path, :data_directory
21
+
22
+ def initialize(output)
23
+ @output = output
24
+ end
25
+
26
+ def execute(key = nil)
27
+ self.key = key
28
+ print_header
29
+ if validate_key
30
+ check_default_locale
31
+ set_config_paths
32
+ @output.puts "Writing configuration file to #{config_file_path}"
33
+ write_config_file
34
+ check_data_directory_exists
35
+ true
32
36
  else
33
- if config_type == :standalone
34
- @output.puts "NOTICE: you probably want to add .localeapp to your .gitignore file"
35
- end
36
- config_file_path = ".localeapp/config.rb"
37
- data_directory = "locales"
37
+ false
38
+ end
39
+ end
40
+
41
+ def print_header
42
+ @output.puts "Localeapp Install"
43
+ @output.puts ""
44
+ end
45
+
46
+ def validate_key
47
+ @output.puts "Checking API key: #{key}"
48
+ if key.nil?
49
+ @output.puts "ERROR: You must supply an API key"
50
+ return false
38
51
  end
39
52
 
40
- @output.puts "Writing configuration file to #{config_file_path}"
41
- if config_type == :github
42
- write_github_configuration_file config_file_path, project_data
53
+ valid_key, @project_data = check_key(key)
54
+ if valid_key
55
+ @output.puts "Success!"
56
+ @output.puts "Project: #{project_data['name']}"
57
+ true
43
58
  else
44
- write_configuration_file config_file_path
59
+ @output.puts "ERROR: Project not found"
60
+ false
45
61
  end
62
+ end
46
63
 
64
+ def check_default_locale
65
+ localeapp_default_code = project_data['default_locale']['code']
66
+ @output.puts "Default Locale: #{localeapp_default_code} (#{project_data['default_locale']['name']})"
67
+ if I18n.default_locale.to_s != localeapp_default_code
68
+ @output.puts "WARNING: I18n.default_locale is #{I18n.default_locale}, change in config/environment.rb (Rails 2) or config/application.rb (Rails 3)"
69
+ end
70
+ end
71
+
72
+ def set_config_paths
73
+ @config_file_path = "config/initializers/localeapp.rb"
74
+ @data_directory = "config/locales"
75
+ end
76
+
77
+ def write_config_file
78
+ create_config_dir
79
+ write_rails_config
80
+ end
81
+
82
+ def write_rails_config
83
+ File.open(config_file_path, 'w+') do |file|
84
+ file.write <<-CONTENT
85
+ require 'localeapp/rails'
86
+
87
+ Localeapp.configure do |config|
88
+ config.api_key = '#{key}'
89
+ end
90
+ CONTENT
91
+ end
92
+ end
93
+
94
+ def check_data_directory_exists
47
95
  unless File.directory?(data_directory)
48
96
  @output.puts "WARNING: please create the #{data_directory} directory. Your translation data will be stored there."
49
97
  end
50
- true
51
- else
52
- @output.puts "ERROR: Project not found"
53
- false
98
+ end
99
+
100
+ def check_key(key)
101
+ Localeapp::KeyChecker.new.check(key)
102
+ end
103
+
104
+ private
105
+ def config_dir
106
+ File.dirname(config_file_path)
107
+ end
108
+
109
+ def create_config_dir
110
+ FileUtils.mkdir_p(config_dir)
54
111
  end
55
112
  end
56
113
 
57
- private
58
- def check_key(key)
59
- Localeapp::KeyChecker.new.check(key)
114
+ class HerokuInstaller < DefaultInstaller
115
+ def validate_key
116
+ @output.puts "Getting API key from heroku config"
117
+ get_heroku_api_key
118
+ if key.nil?
119
+ @output.puts "ERROR: No api key found in heroku config, have you installed the localeapp addon?"
120
+ return
121
+ else
122
+ @output.puts "Add the following line to your .env file for Foreman"
123
+ @output.puts "LOCALEAPP_API_KEY=#{key}"
124
+ @output.puts '^' * 80
125
+ end
126
+ super
127
+ end
128
+
129
+ def get_heroku_api_key
130
+ self.key = if ENV['CUCUMBER_HEROKU_TEST_API_KEY']
131
+ ENV['CUCUMBER_HEROKU_TEST_API_KEY']
132
+ elsif ENV['LOCALEAPP_API_KEY']
133
+ ENV['LOCALEAPP_API_KEY']
134
+ elsif File.exist?('.env') && IO.read('.env') =~ /^LOCALEAPP_API_KEY=(\w+)$/
135
+ $1
136
+ else
137
+ nil
138
+ end
139
+ end
140
+
141
+ def write_rails_config
142
+ File.open(config_file_path, 'w+') do |file|
143
+ file.write <<-CONTENT
144
+ require 'localeapp/rails'
145
+
146
+ Localeapp.configure do |config|
147
+ config.api_key = ENV['LOCALEAPP_API_KEY']
148
+ config.poll_interval = 300 if defined?(Rails) && Rails.env.staging?
149
+ config.polling_environments = [:development, :staging]
150
+ config.reloading_environments = [:development, :staging]
151
+ config.sending_environments = [:development, :staging]
152
+ end
153
+
154
+ # Pull latest when dyno restarts on staging
155
+ if defined?(Rails) && Rails.env.staging?
156
+ Localeapp::CLI::Pull.new.execute
157
+ end
158
+ CONTENT
159
+ end
160
+ end
60
161
  end
61
162
 
62
- def write_configuration_file(path)
63
- if config_type == :rails
64
- Localeapp.configuration.write_rails_configuration(path)
65
- else
66
- Localeapp.configuration.write_standalone_configuration(path)
163
+ class StandaloneInstaller < DefaultInstaller
164
+ def check_default_locale
165
+ # do nothing standalone
166
+ end
167
+
168
+ def set_config_paths
169
+ @output.puts "NOTICE: you probably want to add .localeapp to your .gitignore file"
170
+ @config_file_path = ".localeapp/config.rb"
171
+ @data_directory = "locales"
172
+ end
173
+
174
+ def write_config_file
175
+ create_config_dir
176
+ write_standalone_config
177
+ end
178
+
179
+ private
180
+ def write_standalone_config
181
+ File.open(config_file_path, 'w+') do |file|
182
+ file.write <<-CONTENT
183
+ Localeapp.configure do |config|
184
+ config.api_key = '#{key}'
185
+ config.translation_data_directory = '#{data_directory}'
186
+ config.synchronization_data_file = '#{config_dir}/log.yml'
187
+ config.daemon_pid_file = '#{config_dir}/localeapp.pid'
188
+ end
189
+ CONTENT
190
+ end
67
191
  end
68
192
  end
69
193
 
70
- def write_github_configuration_file(path, project_data)
71
- Localeapp.configuration.write_github_configuration(path, project_data)
194
+ class GithubInstaller < StandaloneInstaller
195
+ def write_config_file
196
+ super
197
+ create_data_directory
198
+ create_gitignore
199
+ create_readme
200
+ end
201
+
202
+ private
203
+ def create_data_directory
204
+ FileUtils.mkdir_p(data_directory)
205
+ end
206
+
207
+ def create_gitignore
208
+ File.open('.gitignore', 'a+') do |file|
209
+ file.write config_dir
210
+ end
211
+ end
212
+
213
+ def create_readme
214
+ File.open('README.md', 'w+') do |file|
215
+ file.write <<-CONTENT
216
+ # #{project_data['name']}
217
+
218
+ A ruby translation project managed on [Locale](http://www.localeapp.com/) that's open to all!
219
+
220
+ ## Contributing to #{project_data['name']}
221
+
222
+ - Edit the translations directly on the [#{project_data['name']}](http://www.localeapp.com/projects/public?search=#{project_data['name']}) project on Locale.
223
+ - **That's it!**
224
+ - The maintainer will then pull translations from the Locale project and push to Github.
225
+
226
+ Happy translating!
227
+ CONTENT
228
+ end
229
+ end
72
230
  end
73
231
  end
74
232
  end
@@ -109,58 +109,5 @@ module Localeapp
109
109
  def sending_disabled?
110
110
  !sending_environments.map { |v| v.to_s }.include?(environment_name)
111
111
  end
112
-
113
- def write_rails_configuration(path)
114
- dir = File.dirname(path)
115
- FileUtils.mkdir_p(dir)
116
- File.open(path, 'w+') do |file|
117
- file.write <<-CONTENT
118
- require 'localeapp/rails'
119
-
120
- Localeapp.configure do |config|
121
- config.api_key = '#{@api_key}'
122
- end
123
- CONTENT
124
- end
125
- end
126
-
127
- def write_standalone_configuration(path)
128
- dir = File.dirname(path)
129
- FileUtils.mkdir_p(dir)
130
- File.open(path, 'w+') do |file|
131
- file.write <<-CONTENT
132
- Localeapp.configure do |config|
133
- config.api_key = '#{@api_key}'
134
- config.translation_data_directory = 'locales'
135
- config.synchronization_data_file = '.localeapp/log.yml'
136
- config.daemon_pid_file = '.localeapp/localeapp.pid'
137
- end
138
- CONTENT
139
- end
140
- end
141
-
142
- def write_github_configuration(path, project_data)
143
- write_standalone_configuration(path)
144
- FileUtils.mkdir_p('locales')
145
- File.open('.gitignore', 'a+') do |file|
146
- file.write ".localeapp"
147
- end
148
- File.open('README.md', 'w+') do |file|
149
- file.write <<-CONTENT
150
- # #{project_data['name']}
151
-
152
- A ruby translation project managed on [Locale](http://www.localeapp.com/) that's open to all!
153
-
154
- ## Contributing to #{project_data['name']}
155
-
156
- - Edit the translations directly on the [#{project_data['name']}](http://www.localeapp.com/projects/public?search=#{project_data['name']}) project on Locale.
157
- - **That's it!**
158
- - The maintainer will then pull translations from the Locale project and push to Github.
159
-
160
- Happy translating!
161
- CONTENT
162
- end
163
- end
164
-
165
112
  end
166
113
  end
@@ -1,3 +1,3 @@
1
1
  module Localeapp
2
- VERSION = "0.6.7"
2
+ VERSION = "0.6.8"
3
3
  end
@@ -1,71 +1,314 @@
1
1
  require 'spec_helper'
2
2
  require 'localeapp/cli/install'
3
3
 
4
- describe Localeapp::CLI::Install, '.execute(key, output = $stdout)' do
5
- before(:each) do
6
- @output = StringIO.new
7
- @command = Localeapp::CLI::Install.new(:output => @output)
4
+ describe Localeapp::CLI::Install, '.execute(key = nil)' do
5
+ let(:output) { StringIO.new }
6
+ let(:key) { 'MYAPIKEY' }
7
+ let(:command) { Localeapp::CLI::Install.new(:output => output) }
8
+
9
+ it "creates the installer based on the config type" do
10
+ command.config_type = :heroku
11
+ command.should_receive(:installer).with("HerokuInstaller").and_return(stub.as_null_object)
12
+ command.execute(key)
13
+ end
14
+
15
+ it "executes the installer with the given key" do
16
+ installer = stub(:installer)
17
+ installer.should_receive(:execute).with(key)
18
+ command.stub!(:installer).and_return(installer)
19
+ command.execute(key)
20
+ end
21
+ end
22
+
23
+ describe Localeapp::CLI::Install::DefaultInstaller, '#execute(key = nil)' do
24
+ let(:output) { StringIO.new }
25
+ let(:key) { 'MYAPIKEY' }
26
+ let(:installer) { Localeapp::CLI::Install::DefaultInstaller.new(output) }
27
+
28
+ before do
29
+ installer.stub!(:print_header)
30
+ installer.stub!(:validate_key).and_return(false)
31
+ end
32
+
33
+ it "prints the header" do
34
+ installer.should_receive(:print_header)
35
+ installer.execute
36
+ end
37
+
38
+ it "validates the key" do
39
+ installer.should_receive(:key=).with(key)
40
+ installer.should_receive(:validate_key)
41
+ installer.execute(key)
42
+ end
43
+
44
+ context "When key validation fails" do
45
+ it "returns false" do
46
+ installer.execute(key).should == false
47
+ end
48
+ end
49
+
50
+ context "When key validation is successful" do
51
+ before do
52
+ installer.stub!(:validate_key).and_return(true)
53
+ installer.stub!(:check_default_locale)
54
+ installer.stub!(:set_config_paths)
55
+ installer.stub!(:write_config_file)
56
+ installer.stub!(:check_data_directory_exists)
57
+ end
58
+
59
+ it "checks the default locale" do
60
+ installer.should_receive(:check_default_locale)
61
+ installer.execute(key)
62
+ end
63
+
64
+ it "sets the configuration paths" do
65
+ installer.should_receive(:set_config_paths)
66
+ installer.execute(key)
67
+ end
68
+
69
+ it "writes the configuration file" do
70
+ installer.should_receive(:write_config_file)
71
+ installer.execute(key)
72
+ end
73
+
74
+ it "checks the data directory exists" do
75
+ installer.should_receive(:check_data_directory_exists)
76
+ installer.execute(key)
77
+ end
78
+
79
+ it "returns true" do
80
+ installer.execute(key).should == true
81
+ end
82
+ end
83
+ end
84
+
85
+ describe Localeapp::CLI::Install::DefaultInstaller, '#validate_key(key)' do
86
+ let(:output) { StringIO.new }
87
+ let(:key) { 'MYAPIKEY' }
88
+ let(:installer) { Localeapp::CLI::Install::DefaultInstaller.new(output) }
89
+
90
+ before do
91
+ installer.key = key
8
92
  end
9
93
 
10
94
  it "displays error if key is nil" do
11
- @command.execute(nil)
12
- @output.string.should match(/You must supply an API key/)
95
+ installer.key = nil
96
+ installer.validate_key
97
+ output.string.should match(/You must supply an API key/)
13
98
  end
14
99
 
15
100
  it "displays error if the key is there but isn't valid on localeapp.com" do
16
- @command.stub!(:check_key).and_return([false, {}])
17
- @command.execute('API_KEY')
18
- @output.string.should match(/Project not found/)
101
+ installer.stub!(:check_key).and_return([false, {}])
102
+ installer.validate_key
103
+ output.string.should match(/Project not found/)
104
+ end
105
+
106
+ it "displays project name if the key is there and valid on localeapp.com" do
107
+ installer.stub!(:check_key).and_return([true, valid_project_data])
108
+ installer.validate_key
109
+ output.string.should match(/Test Project/)
110
+ end
111
+ end
112
+
113
+ describe Localeapp::CLI::Install::DefaultInstaller, '#check_default_locale' do
114
+ let(:output) { StringIO.new }
115
+ let(:installer) { Localeapp::CLI::Install::DefaultInstaller.new(output) }
116
+
117
+ before do
118
+ installer.stub!(:project_data).and_return(valid_project_data)
19
119
  end
20
120
 
21
- it "displays project name and base locale if the key is there and valid on localeapp.com" do
22
- @command.stub!(:check_key).and_return([true, valid_project_data])
23
- @command.stub!(:write_configuration_file)
24
- @command.execute('API_KEY')
25
- @output.string.should match(/Test Project/)
26
- @output.string.should match(/en \(English\)/)
121
+ it "displays project base locale" do
122
+ installer.check_default_locale
123
+ output.string.should match(/en \(English\)/)
27
124
  end
28
125
 
29
126
  it "displays warning if I18n.default_locale doesn't match what's configured on localeapp.com" do
30
127
  I18n.stub(:default_locale).and_return(:es)
31
- @command.stub!(:check_key).and_return([true, valid_project_data])
32
- @command.stub!(:write_configuration_file)
33
- @command.execute('API_KEY')
34
- @output.string.should match(%r{WARNING: I18n.default_locale is es, change in config/environment.rb \(Rails 2\) or config/application.rb \(Rails 3\)})
128
+ installer.check_default_locale
129
+ output.string.should match(%r{WARNING: I18n.default_locale is es, change in config/environment.rb \(Rails 2\) or config/application.rb \(Rails 3\)})
35
130
  end
131
+ end
132
+
133
+ describe Localeapp::CLI::Install::DefaultInstaller, '#set_config_paths' do
134
+ let(:output) { StringIO.new }
135
+ let(:installer) { Localeapp::CLI::Install::DefaultInstaller.new(output) }
136
+
137
+ before do
138
+ installer.set_config_paths
139
+ end
140
+
141
+ it "sets the initializer config_file_path for a rails app" do
142
+ installer.config_file_path.should == "config/initializers/localeapp.rb"
143
+ end
144
+
145
+ it "sets the data directory for a rails app" do
146
+ installer.data_directory.should == "config/locales"
147
+ end
148
+ end
149
+
150
+ describe Localeapp::CLI::Install::DefaultInstaller, '#write_config_file' do
151
+ let(:output) { StringIO.new }
152
+ let(:config_file_path) { 'config/initializers/localeapp.rb' }
153
+ let(:key) { 'APIKEY' }
154
+ let(:installer) { Localeapp::CLI::Install::DefaultInstaller.new(output) }
36
155
 
37
- it "asks the default configuration to write itself" do
38
- @command.stub!(:check_key).and_return([true, valid_project_data])
39
- @command.should_receive(:write_configuration_file).with('config/initializers/localeapp.rb')
40
- @command.execute('API_KEY')
156
+ it "creates a configuration file containing just the api key" do
157
+ installer.key = key
158
+ installer.config_file_path = config_file_path
159
+ file = stub('file')
160
+ file.should_receive(:write).with <<-CONTENT
161
+ require 'localeapp/rails'
162
+
163
+ Localeapp.configure do |config|
164
+ config.api_key = 'APIKEY'
165
+ end
166
+ CONTENT
167
+ File.should_receive(:open).with(config_file_path, 'w+').and_yield(file)
168
+ installer.write_config_file
41
169
  end
170
+ end
42
171
 
43
- it "asks the configuration to write itself to .localeapp when the --standalone switch is set" do
44
- @command.stub!(:check_key).and_return([true, valid_project_data])
45
- @command.config_type = :standalone
46
- @command.should_receive(:write_configuration_file).with('.localeapp/config.rb')
47
- @command.execute('API_KEY')
172
+ describe Localeapp::CLI::Install::DefaultInstaller, '#check_data_directory_exists' do
173
+ let(:output) { StringIO.new }
174
+ let(:data_directory) { 'locales' }
175
+ let(:installer) { Localeapp::CLI::Install::DefaultInstaller.new(output) }
176
+
177
+ before do
178
+ installer.data_directory = data_directory
48
179
  end
49
180
 
50
181
  it "displays warning if config.translation_data_directory doesn't exist" do
51
- @command.stub!(:check_key).and_return([true, valid_project_data])
52
- @command.stub!(:write_configuration_file)
53
- @command.execute('API_KEY')
54
- @output.string.should match(/Your translation data will be stored there./)
182
+ File.stub(:directory?).with(data_directory).and_return(false)
183
+ installer.check_data_directory_exists
184
+ output.string.should match(/Your translation data will be stored there./)
55
185
  end
56
186
 
57
187
  it "doesn't display a warning if translation_data_directory exists" do
58
- @command.stub!(:check_key).and_return([true, valid_project_data])
59
- @command.stub!(:write_configuration_file)
60
- File.should_receive(:directory?).and_return(true)
61
- @command.execute('API_KEY')
62
- @output.string.should_not match(/Your translation data will be stored there./)
63
- end
64
-
65
- it "asks the github configuration to write itself" do
66
- @command.stub!(:check_key).and_return([true, valid_project_data])
67
- @command.config_type = :github
68
- @command.should_receive(:write_github_configuration_file).with('.localeapp/config.rb', valid_project_data)
69
- @command.execute('API_KEY')
188
+ File.stub(:directory?).with(data_directory).and_return(true)
189
+ installer.check_data_directory_exists
190
+ output.string.should == ''
191
+ end
192
+ end
193
+
194
+ describe Localeapp::CLI::Install::HerokuInstaller, '#write_config_file' do
195
+ let(:output) { StringIO.new }
196
+ let(:config_file_path) { 'config/initializers/localeapp.rb' }
197
+ let(:key) { 'APIKEY' }
198
+ let(:installer) { Localeapp::CLI::Install::HerokuInstaller.new(output) }
199
+
200
+ it "creates a configuration file setup for staging / production on heroku" do
201
+ installer.key = key
202
+ installer.config_file_path = config_file_path
203
+ file = stub('file')
204
+ file.should_receive(:write).with <<-CONTENT
205
+ require 'localeapp/rails'
206
+
207
+ Localeapp.configure do |config|
208
+ config.api_key = ENV['LOCALEAPP_API_KEY']
209
+ config.poll_interval = 300 if defined?(Rails) && Rails.env.staging?
210
+ config.polling_environments = [:development, :staging]
211
+ config.reloading_environments = [:development, :staging]
212
+ config.sending_environments = [:development, :staging]
213
+ end
214
+
215
+ # Pull latest when dyno restarts on staging
216
+ if defined?(Rails) && Rails.env.staging?
217
+ Localeapp::CLI::Pull.new.execute
218
+ end
219
+ CONTENT
220
+ File.should_receive(:open).with(config_file_path, 'w+').and_yield(file)
221
+ installer.write_config_file
222
+ end
223
+ end
224
+ describe Localeapp::CLI::Install::StandaloneInstaller, '#check_default_locale' do
225
+ let(:output) { StringIO.new }
226
+ let(:installer) { Localeapp::CLI::Install::StandaloneInstaller.new(output) }
227
+
228
+ it "does nothing" do
229
+ installer.check_default_locale
230
+ output.string.should == ''
231
+ end
232
+ end
233
+
234
+ describe Localeapp::CLI::Install::StandaloneInstaller, '#set_config_paths' do
235
+ let(:output) { StringIO.new }
236
+ let(:installer) { Localeapp::CLI::Install::StandaloneInstaller.new(output) }
237
+
238
+ before do
239
+ installer.set_config_paths
240
+ end
241
+
242
+ it "sets the initializer config_file_path for a standalone app" do
243
+ installer.config_file_path.should == ".localeapp/config.rb"
244
+ end
245
+
246
+ it "sets the data directory for a standalone app" do
247
+ installer.data_directory.should == "locales"
248
+ end
249
+ end
250
+
251
+ describe Localeapp::CLI::Install::StandaloneInstaller, '#write_config_file' do
252
+ let(:output) { StringIO.new }
253
+ let(:key) { 'APIKEY' }
254
+ let(:config_file_path) { '.localeapp/config.rb' }
255
+ let(:data_directory) { 'locales' }
256
+ let(:installer) { Localeapp::CLI::Install::StandaloneInstaller.new(output) }
257
+
258
+ it "creates a configuration file containing the dot file configuration at the given config_file_path" do
259
+ installer.stub!(:create_config_dir).and_return(File.dirname(config_file_path))
260
+ installer.key = key
261
+ installer.config_file_path = config_file_path
262
+ installer.data_directory = data_directory
263
+ file = stub('file')
264
+ file.should_receive(:write).with <<-CONTENT
265
+ Localeapp.configure do |config|
266
+ config.api_key = 'APIKEY'
267
+ config.translation_data_directory = 'locales'
268
+ config.synchronization_data_file = '.localeapp/log.yml'
269
+ config.daemon_pid_file = '.localeapp/localeapp.pid'
270
+ end
271
+ CONTENT
272
+ File.should_receive(:open).with(config_file_path, 'w+').and_yield(file)
273
+ installer.write_config_file
274
+ end
275
+ end
276
+
277
+ describe Localeapp::CLI::Install::GithubInstaller, '#write_config_file' do
278
+ let(:output) { StringIO.new }
279
+ let(:key) { 'APIKEY' }
280
+ let(:config_file_path) { '.localeapp/config.rb' }
281
+ let(:data_directory) { 'locales' }
282
+ let(:installer) { Localeapp::CLI::Install::GithubInstaller.new(output) }
283
+
284
+ before do
285
+ installer.key = key
286
+ installer.config_file_path = config_file_path
287
+ installer.data_directory = data_directory
288
+ installer.stub!(:create_config_dir).and_return(File.dirname(config_file_path))
289
+ installer.stub!(:write_standalone_config)
290
+ installer.stub!(:create_data_directory)
291
+ installer.stub!(:create_gitignore)
292
+ installer.stub!(:create_readme)
293
+ end
294
+
295
+ it "creates a standalone configuration file" do
296
+ installer.should_receive(:write_standalone_config)
297
+ installer.write_config_file
298
+ end
299
+
300
+ it "creates the data_directory" do
301
+ installer.should_receive(:create_data_directory)
302
+ installer.write_config_file
303
+ end
304
+
305
+ it "creates the .gitignore file" do
306
+ installer.should_receive(:create_gitignore)
307
+ installer.write_config_file
308
+ end
309
+
310
+ it "creates the READMI file" do
311
+ installer.should_receive(:create_readme)
312
+ installer.write_config_file
70
313
  end
71
314
  end
@@ -163,58 +163,3 @@ describe Localeapp::Configuration do
163
163
  end
164
164
  end
165
165
  end
166
-
167
- describe Localeapp::Configuration, "#write_rails_configuration(path)" do
168
- it "creates a configuration file containing just the api key at the given path" do
169
- configuration = Localeapp::Configuration.new
170
- configuration.api_key = "APIKEY"
171
- path = 'test_path'
172
- file = stub('file')
173
- file.should_receive(:write).with <<-CONTENT
174
- require 'localeapp/rails'
175
-
176
- Localeapp.configure do |config|
177
- config.api_key = 'APIKEY'
178
- end
179
- CONTENT
180
- File.should_receive(:open).with(path, 'w+').and_yield(file)
181
- configuration.write_rails_configuration(path)
182
- end
183
- end
184
-
185
-
186
- describe Localeapp::Configuration, "#write_standalone_configuration(path)" do
187
- it "creates a configuration file containing the dot file configuration at the given path" do
188
- configuration = Localeapp::Configuration.new
189
- configuration.api_key = "APIKEY"
190
- path = 'test_path'
191
- file = stub('file')
192
- file.should_receive(:write).with <<-CONTENT
193
- Localeapp.configure do |config|
194
- config.api_key = 'APIKEY'
195
- config.translation_data_directory = 'locales'
196
- config.synchronization_data_file = '.localeapp/log.yml'
197
- config.daemon_pid_file = '.localeapp/localeapp.pid'
198
- end
199
- CONTENT
200
- File.should_receive(:open).with(path, 'w+').and_yield(file)
201
- configuration.write_standalone_configuration(path)
202
- end
203
- end
204
-
205
-
206
- describe Localeapp::Configuration, "#write_github_configuration(path, project_data)" do
207
- let(:configuration) { Localeapp::Configuration.new }
208
- let(:project_data) { {"name"=>"Test Project", "default_locale"=>{"name"=>"English", "code"=>"en"}} }
209
- let(:path) { '.localeapp/config.rb' }
210
-
211
- it "writes github configuration files" do
212
- configuration.should_receive(:write_standalone_configuration).with(path)
213
- file = stub('file')
214
- file.should_receive(:write).exactly(2).times.and_return('content')
215
- FileUtils.should_receive(:mkdir_p).with('locales')
216
- File.should_receive(:open).with('.gitignore', 'a+').and_yield(file)
217
- File.should_receive(:open).with('README.md', 'w+').and_yield(file)
218
- configuration.write_github_configuration(path, project_data)
219
- end
220
- 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: 9
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 7
10
- version: 0.6.7
9
+ - 8
10
+ version: 0.6.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christopher Dell
@@ -16,12 +16,13 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-11-12 00:00:00 Z
19
+ date: 2012-11-23 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: i18n
23
+ type: :runtime
23
24
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
26
  none: false
26
27
  requirements:
27
28
  - - ">="
@@ -30,12 +31,12 @@ dependencies:
30
31
  segments:
31
32
  - 0
32
33
  version: "0"
33
- type: :runtime
34
- version_requirements: *id001
34
+ requirement: *id001
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: json
37
+ type: :runtime
37
38
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
40
  none: false
40
41
  requirements:
41
42
  - - ">="
@@ -44,12 +45,12 @@ dependencies:
44
45
  segments:
45
46
  - 0
46
47
  version: "0"
47
- type: :runtime
48
- version_requirements: *id002
48
+ requirement: *id002
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rest-client
51
+ type: :runtime
51
52
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
53
54
  none: false
54
55
  requirements:
55
56
  - - ">="
@@ -58,12 +59,12 @@ dependencies:
58
59
  segments:
59
60
  - 0
60
61
  version: "0"
61
- type: :runtime
62
- version_requirements: *id003
62
+ requirement: *id003
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: ya2yaml
65
+ type: :runtime
65
66
  prerelease: false
66
- requirement: &id004 !ruby/object:Gem::Requirement
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
67
68
  none: false
68
69
  requirements:
69
70
  - - ">="
@@ -72,12 +73,12 @@ dependencies:
72
73
  segments:
73
74
  - 0
74
75
  version: "0"
75
- type: :runtime
76
- version_requirements: *id004
76
+ requirement: *id004
77
77
  - !ruby/object:Gem::Dependency
78
78
  name: gli
79
+ type: :runtime
79
80
  prerelease: false
80
- requirement: &id005 !ruby/object:Gem::Requirement
81
+ version_requirements: &id005 !ruby/object:Gem::Requirement
81
82
  none: false
82
83
  requirements:
83
84
  - - ">="
@@ -86,12 +87,12 @@ dependencies:
86
87
  segments:
87
88
  - 0
88
89
  version: "0"
89
- type: :runtime
90
- version_requirements: *id005
90
+ requirement: *id005
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rake
93
+ type: :development
93
94
  prerelease: false
94
- requirement: &id006 !ruby/object:Gem::Requirement
95
+ version_requirements: &id006 !ruby/object:Gem::Requirement
95
96
  none: false
96
97
  requirements:
97
98
  - - ">="
@@ -100,12 +101,12 @@ dependencies:
100
101
  segments:
101
102
  - 0
102
103
  version: "0"
103
- type: :development
104
- version_requirements: *id006
104
+ requirement: *id006
105
105
  - !ruby/object:Gem::Dependency
106
106
  name: rack
107
+ type: :development
107
108
  prerelease: false
108
- requirement: &id007 !ruby/object:Gem::Requirement
109
+ version_requirements: &id007 !ruby/object:Gem::Requirement
109
110
  none: false
110
111
  requirements:
111
112
  - - ">="
@@ -114,12 +115,12 @@ dependencies:
114
115
  segments:
115
116
  - 0
116
117
  version: "0"
117
- type: :development
118
- version_requirements: *id007
118
+ requirement: *id007
119
119
  - !ruby/object:Gem::Dependency
120
120
  name: rspec
121
+ type: :development
121
122
  prerelease: false
122
- requirement: &id008 !ruby/object:Gem::Requirement
123
+ version_requirements: &id008 !ruby/object:Gem::Requirement
123
124
  none: false
124
125
  requirements:
125
126
  - - "="
@@ -130,12 +131,12 @@ dependencies:
130
131
  - 11
131
132
  - 0
132
133
  version: 2.11.0
133
- type: :development
134
- version_requirements: *id008
134
+ requirement: *id008
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: yard
137
+ type: :development
137
138
  prerelease: false
138
- requirement: &id009 !ruby/object:Gem::Requirement
139
+ version_requirements: &id009 !ruby/object:Gem::Requirement
139
140
  none: false
140
141
  requirements:
141
142
  - - "="
@@ -146,12 +147,12 @@ dependencies:
146
147
  - 6
147
148
  - 7
148
149
  version: 0.6.7
149
- type: :development
150
- version_requirements: *id009
150
+ requirement: *id009
151
151
  - !ruby/object:Gem::Dependency
152
152
  name: RedCloth
153
+ type: :development
153
154
  prerelease: false
154
- requirement: &id010 !ruby/object:Gem::Requirement
155
+ version_requirements: &id010 !ruby/object:Gem::Requirement
155
156
  none: false
156
157
  requirements:
157
158
  - - "="
@@ -162,12 +163,12 @@ dependencies:
162
163
  - 2
163
164
  - 9
164
165
  version: 4.2.9
165
- type: :development
166
- version_requirements: *id010
166
+ requirement: *id010
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: aruba
169
+ type: :development
169
170
  prerelease: false
170
- requirement: &id011 !ruby/object:Gem::Requirement
171
+ version_requirements: &id011 !ruby/object:Gem::Requirement
171
172
  none: false
172
173
  requirements:
173
174
  - - "="
@@ -178,12 +179,12 @@ dependencies:
178
179
  - 4
179
180
  - 11
180
181
  version: 0.4.11
181
- type: :development
182
- version_requirements: *id011
182
+ requirement: *id011
183
183
  - !ruby/object:Gem::Dependency
184
184
  name: fakeweb
185
+ type: :development
185
186
  prerelease: false
186
- requirement: &id012 !ruby/object:Gem::Requirement
187
+ version_requirements: &id012 !ruby/object:Gem::Requirement
187
188
  none: false
188
189
  requirements:
189
190
  - - "="
@@ -194,8 +195,7 @@ dependencies:
194
195
  - 3
195
196
  - 0
196
197
  version: 1.3.0
197
- type: :development
198
- version_requirements: *id012
198
+ requirement: *id012
199
199
  description: Synchronizes i18n translation keys and content with localeapp.com so you don't have to manage translations by hand.
200
200
  email:
201
201
  - chris@tigrish.com
@@ -319,7 +319,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
319
319
  requirements: []
320
320
 
321
321
  rubyforge_project: localeapp
322
- rubygems_version: 1.8.24
322
+ rubygems_version: 1.8.6
323
323
  signing_key:
324
324
  specification_version: 3
325
325
  summary: Easy i18n translation management with localeapp.com