copy_tuner_client 0.5.2 → 0.8.0

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.
@@ -1,64 +0,0 @@
1
- require File.join(PROJECT_ROOT, "spec", "support", "fake_copy_tuner_app")
2
-
3
- Given /^I have a copy_tuner project with an api key of "([^"]*)"$/ do |api_key|
4
- FakeCopyTunerApp.add_project api_key
5
- end
6
-
7
- Given /^the "([^"]*)" project has the following blurbs:$/ do |api_key, table|
8
- project = FakeCopyTunerApp.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
- step %{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 = FakeCopyTunerApp.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 = FakeCopyTunerApp.project(api_key)
56
- expect(project.draft[blurb_key]).to be_nil
57
- end
58
-
59
- When /^I wait for changes to be synchronized$/ do
60
- sleep(3)
61
- end
62
-
63
- FakeCopyTunerApp.start
64
- After { FakeCopyTunerApp.reset }
@@ -1,187 +0,0 @@
1
- When "I generate a rails application" do
2
- if Rails::VERSION::MAJOR == 3
3
- subcommand = 'new'
4
- if Rails::VERSION::MINOR == 0
5
- options = ''
6
- else
7
- options = '--skip-bundle'
8
- end
9
- elsif Rails::VERSION::MAJOR == 4
10
- subcommand = 'new'
11
- options = '--skip-bundle'
12
- else
13
- subcommand = ''
14
- options = ''
15
- end
16
-
17
- run_simple("rails _#{Rails::VERSION::STRING}_ #{subcommand} testapp #{options}")
18
- cd("testapp")
19
-
20
- if Rails::VERSION::MAJOR == 3 or Rails::VERSION::MAJOR == 4
21
- append_to_file("Gemfile", <<-GEMS)
22
- gem "thin"
23
- gem "sham_rack"
24
- gem "sinatra"
25
- gem "json"
26
- GEMS
27
- # bundle installには時間がかかるので、timeout値を2時間に設定
28
- run_simple("bundle install", true, 7200)
29
-
30
- step(%{I remove lines containing "rjs" from "config/environments/development.rb"})
31
- end
32
- end
33
-
34
- When /^I configure the copy_tuner client with api key "([^"]*)"$/ do |api_key|
35
- write_file("config/initializers/copy_tuner.rb", <<-RUBY)
36
- CopyTunerClient.configure do |config|
37
- config.api_key = "#{api_key}"
38
- config.polling_delay = 1
39
- config.host = 'localhost'
40
- config.s3_host = 'localhost'
41
- config.secure = false
42
- config.sync_interval = 0
43
- config.port = #{FakeCopyTunerApp.port}
44
- end
45
- RUBY
46
-
47
- if Rails::VERSION::MAJOR == 3 or Rails::VERSION::MAJOR == 4
48
- append_to_file("Gemfile", <<-GEMS)
49
- gem "copy_tuner_client", :path => "../../.."
50
- GEMS
51
- else
52
- in_current_dir { FileUtils.rm_f("vendor/plugins/copy_tuner") }
53
- run_simple("ln -s #{PROJECT_ROOT} vendor/plugins/copy_tuner")
54
- end
55
- end
56
-
57
- When "I start the application" do
58
- step(%{I start the application in the "development" environment})
59
- end
60
-
61
- When /^I start the application in the "([^"]+)" environment$/ do |environment|
62
- in_current_dir do
63
- old_environment = ENV['RAILS_ENV']
64
- begin
65
- ENV['RAILS_ENV'] = environment
66
- if environment == 'production' and Rails::VERSION::MAJOR == 4
67
- if Rails::VERSION::MINOR != 0
68
- ENV["SECRET_KEY_BASE"] = '4f7d3eb907e873d8a9cbfc6997fd07a88bd2b8d23518717378254ed4a0c6ada5f83061714019b2972a782d51299f5e1ca003ff4b6f4b2000f1be0b3d33522b68'
69
- end
70
- end
71
- RailsServer.start(ENV['RAILS_PORT'], @announce_stderr)
72
- ensure
73
- ENV['RAILS_ENV'] = old_environment
74
- end
75
- end
76
- end
77
-
78
- When /^I visit (\/.*)$/ do |path|
79
- @last_response = RailsServer.get(path)
80
- end
81
-
82
- When /^I configure the copy_tuner client to use published data$/ do
83
- in_current_dir do
84
- config_path = "config/initializers/copy_tuner.rb"
85
- contents = IO.read(config_path)
86
- contents.sub!("end", " config.development_environments = []\nend")
87
- File.open(config_path, "w") { |file| file.write(contents) }
88
- end
89
- end
90
-
91
- When /^I configure the copy_tuner client to have a polling delay of (\d+) seconds$/ do |polling_delay|
92
- in_current_dir do
93
- config_path = "config/initializers/copy_tuner.rb"
94
- contents = IO.read(config_path)
95
- contents.sub!(/config.polling_delay = .+/, "config.polling_delay = #{polling_delay}")
96
- File.open(config_path, "w") { |file| file.write(contents) }
97
- end
98
- end
99
-
100
- Then /^the copy_tuner client version and environment should have been logged$/ do
101
- client_version = CopyTunerClient::VERSION
102
- environment_info = "[Ruby: #{RUBY_VERSION}]"
103
- environment_info << " [Rails: #{Rails::VERSION::STRING}]"
104
- environment_info << " [Env: development]"
105
- steps %{
106
- Then the log should contain "Client #{client_version} ready"
107
- Then the log should contain "Environment Info: #{environment_info}"
108
- }
109
- end
110
-
111
- Then /^the log should contain "([^"]*)"$/ do |line|
112
- prefix = "** [CopyTuner] "
113
- pattern = Regexp.compile([Regexp.escape(prefix), Regexp.escape(line)].join(".*"))
114
- log_path = "log/copy_tuner.log"
115
- in_current_dir do
116
- File.open(log_path) do |file|
117
- unless file.readlines.any? { |file_line| file_line =~ pattern }
118
- raise "In log file:\n#{IO.read(log_path)}\n\nMissing line:\n#{pattern}"
119
- end
120
- end
121
- end
122
- end
123
-
124
- Then /^the log should not contain "([^"]*)"$/ do |line|
125
- log_path = "log/copy_tuner.log"
126
- in_current_dir do
127
- File.open(log_path) do |file|
128
- if bad_line = file.readlines.detect { |file_line| file_line.include?(line) }
129
- raise "In log file:\n#{log_path}\n\nGot unexpected line:\n#{bad_line}"
130
- end
131
- end
132
- end
133
- end
134
-
135
- When /^I successfully rake "([^"]*)"$/ do |task|
136
- run_simple("rake #{task}")
137
- end
138
-
139
- Then /^the response should contain "([^"]+)"$/ do |text|
140
- expect(@last_response.body).to include(text)
141
- end
142
-
143
- When /^show me the page$/ do
144
- expect(@last_response.body).to be_nil
145
- end
146
-
147
- When /^I route the "([^"]+)" resource$/ do |resource|
148
- if Rails::VERSION::MAJOR == 3 or Rails::VERSION::MAJOR == 4
149
- draw = "Testapp::Application.routes.draw do\n"
150
- else
151
- draw = "ActionController::Routing::Routes.draw do |map|\nmap."
152
- end
153
-
154
- routes = "#{draw}resources :#{resource}\nend"
155
-
156
- overwrite_file("config/routes.rb", routes)
157
- end
158
-
159
- When /^I run a short lived process that sets the key "([^"]*)" to "([^"]*)" in "([^"]*)" environment$/ do |key, value, environment|
160
- if Rails::VERSION::MAJOR == 3
161
- run_simple %[script/rails runner -e #{environment} 'I18n.translate("#{key}", :default => "#{value}")']
162
- elsif Rails::VERSION::MAJOR == 4
163
- run_simple %[bin/rails runner -e #{environment} 'I18n.translate("#{key}", :default => "#{value}")']
164
- else
165
- run_simple %[script/runner -e #{environment} 'I18n.translate("#{key}", :default => "#{value}")']
166
- end
167
- end
168
-
169
- When /^I remove lines containing "([^"]*)" from "([^"]*)"$/ do |content, filename|
170
- in_current_dir do
171
- result = ""
172
- File.open(filename, "r") do |file|
173
- file.each_line do |line|
174
- result << line unless line.include?(content)
175
- end
176
- end
177
-
178
- File.open(filename, "w") do |file|
179
- file.write(result)
180
- end
181
- end
182
- end
183
-
184
-
185
- After do
186
- RailsServer.stop
187
- end
@@ -1,11 +0,0 @@
1
- require 'sham_rack'
2
- require 'aruba/cucumber'
3
- require 'rails/version'
4
-
5
- PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
6
- $LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
7
- require "copy_tuner_client/version"
8
-
9
- Before do
10
- @aruba_timeout_seconds = 15
11
- end
@@ -1,150 +0,0 @@
1
- require 'net/http'
2
-
3
- # Starts a Rails application server in a fork and waits for it to be responsive
4
- class RailsServer
5
- HOST = 'localhost'.freeze
6
-
7
- class << self
8
- attr_accessor :instance
9
- end
10
-
11
- def self.start(port = nil, debug = nil)
12
- self.instance = new(port, debug)
13
- self.instance.start
14
- self.instance
15
- end
16
-
17
- def self.stop
18
- self.instance.stop if instance
19
- self.instance = nil
20
- end
21
-
22
- def self.get(path)
23
- self.instance.get(path)
24
- end
25
-
26
- def self.post(path, data)
27
- self.instance.post(path, data)
28
- end
29
-
30
- def self.run(port, silent)
31
- if silent
32
- require 'stringio'
33
- $stdout = StringIO.new
34
- $stderr = StringIO.new
35
- end
36
-
37
- require './config/environment'
38
- require 'thin'
39
-
40
- if Rails::VERSION::MAJOR == 3 or Rails::VERSION::MAJOR == 4
41
- rails = Rails.application
42
- else
43
- rails = ActionController::Dispatcher.new
44
- end
45
- app = Identify.new(rails)
46
-
47
- Thin::Logging.silent = silent
48
- Rack::Handler::Thin.run(app, :Port => port, :AccessLog => [])
49
- end
50
-
51
- def self.app_host
52
- self.instance.app_host
53
- end
54
-
55
- def initialize(port, debug)
56
- @port = find_available_port
57
- @debug = debug
58
- end
59
-
60
- def start
61
- @pid = fork do
62
- command = "ruby -r#{__FILE__} -e 'RailsServer.run(#{@port}, #{(!@debug).inspect})'"
63
- puts command if @debug
64
- exec(command)
65
- end
66
- wait_until_responsive
67
- end
68
-
69
- def stop
70
- if @pid
71
- if ENV['TRAVIS']
72
- system("sudo kill -2 #{@pid}")
73
- else
74
- Process.kill('INT', @pid)
75
- end
76
-
77
- begin
78
- Timeout.timeout(10) do
79
- Process.waitpid(@pid)
80
- end
81
- rescue Timeout::Error
82
- if ENV['TRAVIS']
83
- system("sudo kill -9 #{@pid}")
84
- else
85
- Process.kill('KILL', @pid)
86
- end
87
- Process.waitpid(@pid)
88
- end
89
- @pid = nil
90
- end
91
- end
92
-
93
- def get(path)
94
- puts "GET #{path}" if @debug
95
- Net::HTTP.start(HOST, @port) { |http| http.get(path) }
96
- end
97
-
98
- def post(path, data)
99
- puts "POST #{path}\n#{data}" if @debug
100
- Net::HTTP.start(HOST, @port) { |http| http.post(path, data) }
101
- end
102
-
103
- def wait_until_responsive
104
- 20.times do
105
- if responsive?
106
- return true
107
- else
108
- sleep(0.5)
109
- end
110
- end
111
- raise "Couldn't connect to Rails application server at #{HOST}:#{@port}"
112
- end
113
-
114
- def responsive?
115
- response = Net::HTTP.start(HOST, @port) { |http| http.get('/__identify__') }
116
- response.is_a?(Net::HTTPSuccess)
117
- rescue Errno::ECONNREFUSED, Errno::EBADF
118
- return false
119
- end
120
-
121
- def app_host
122
- "http://#{HOST}:#{@port}"
123
- end
124
-
125
- private
126
-
127
- def find_available_port
128
- server = TCPServer.new('127.0.0.1', 0)
129
- server.addr[1]
130
- ensure
131
- server.close if server
132
- end
133
-
134
-
135
- # From Capybara::Server
136
-
137
- class Identify
138
- def initialize(app)
139
- @app = app
140
- end
141
-
142
- def call(env)
143
- if env["PATH_INFO"] == "/__identify__"
144
- [200, {}, 'OK']
145
- else
146
- @app.call(env)
147
- end
148
- end
149
- end
150
- end
data/gemfiles/5.1.gemfile DELETED
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "5.1.7"
6
-
7
- gemspec :path => "../"
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'copy_tuner_client'