rails-four-queueing 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ # Original File: RAILS_ROOT/activesupport/test/abstract_unit.rb
2
+ ORIG_ARGV = ARGV.dup
3
+
4
+ # begin
5
+ # old, $VERBOSE = $VERBOSE, nil
6
+ # require File.expand_path('../../../load_paths', __FILE__)
7
+ # ensure
8
+ # $VERBOSE = old
9
+ # end
10
+
11
+ require 'active_support/core_ext/kernel/reporting'
12
+ require 'active_support/core_ext/string/encoding'
13
+
14
+ silence_warnings do
15
+ Encoding.default_internal = "UTF-8"
16
+ Encoding.default_external = "UTF-8"
17
+ end
18
+
19
+ require 'minitest/autorun'
20
+ require 'support/empty_bool'
21
+
22
+ ENV['NO_RELOAD'] = '1'
23
+ require 'active_support'
24
+
25
+ # Show backtraces for deprecated behavior for quicker cleanup.
26
+ ActiveSupport::Deprecation.debug = true
@@ -0,0 +1,8 @@
1
+ # Original File: RAILS_ROOT/activesupport/test/empty_bool.rb
2
+ class EmptyTrue
3
+ def empty?() true; end
4
+ end
5
+
6
+ class EmptyFalse
7
+ def empty?() false; end
8
+ end
@@ -0,0 +1,288 @@
1
+
2
+ # Note:
3
+ # It is important to keep this file as light as possible
4
+ # the goal for tests that require this is to test booting up
5
+ # rails from an empty state, so anything added here could
6
+ # hide potential failures
7
+ #
8
+ # It is also good to know what is the bare minimum to get
9
+ # Rails booted up.
10
+ require 'fileutils'
11
+
12
+ require 'bundler/setup' unless defined?(Bundler)
13
+ require 'minitest/autorun'
14
+ require 'active_support/test_case'
15
+
16
+ RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../../rails")
17
+
18
+ # These files do not require any others and are needed
19
+ # to run the tests
20
+ require "active_support/testing/isolation"
21
+ require "active_support/core_ext/kernel/reporting"
22
+ require 'tmpdir'
23
+
24
+ module TestHelpers
25
+ module Paths
26
+ def app_template_path
27
+ File.join Dir.tmpdir, 'app_template'
28
+ end
29
+
30
+ def tmp_path(*args)
31
+ @tmp_path ||= File.realpath(Dir.mktmpdir)
32
+ File.join(@tmp_path, *args)
33
+ end
34
+
35
+ def app_path(*args)
36
+ tmp_path(*%w[app] + args)
37
+ end
38
+
39
+ def framework_path
40
+ RAILS_FRAMEWORK_ROOT
41
+ end
42
+
43
+ def rails_root
44
+ app_path
45
+ end
46
+ end
47
+
48
+ module Rack
49
+ def app(env = "production")
50
+ old_env = ENV["RAILS_ENV"]
51
+ @app ||= begin
52
+ ENV["RAILS_ENV"] = env
53
+ require "#{app_path}/config/environment"
54
+ Rails.application
55
+ end
56
+ ensure
57
+ ENV["RAILS_ENV"] = old_env
58
+ end
59
+
60
+ def extract_body(response)
61
+ "".tap do |body|
62
+ response[2].each {|chunk| body << chunk }
63
+ end
64
+ end
65
+
66
+ def get(path)
67
+ @app.call(::Rack::MockRequest.env_for(path))
68
+ end
69
+
70
+ def assert_welcome(resp)
71
+ assert_equal 200, resp[0]
72
+ assert resp[1]["Content-Type"] = "text/html"
73
+ assert extract_body(resp).match(/Welcome aboard/)
74
+ end
75
+
76
+ def assert_success(resp)
77
+ assert_equal 202, resp[0]
78
+ end
79
+
80
+ def assert_missing(resp)
81
+ assert_equal 404, resp[0]
82
+ end
83
+
84
+ def assert_header(key, value, resp)
85
+ assert_equal value, resp[1][key.to_s]
86
+ end
87
+
88
+ def assert_body(expected, resp)
89
+ assert_equal expected, extract_body(resp)
90
+ end
91
+ end
92
+
93
+ module Generation
94
+ # Build an application by invoking the generator and going through the whole stack.
95
+ def build_app(options = {})
96
+ @prev_rails_env = ENV['RAILS_ENV']
97
+ ENV['RAILS_ENV'] = 'development'
98
+
99
+ FileUtils.rm_rf(app_path)
100
+ FileUtils.cp_r(app_template_path, app_path)
101
+
102
+ # Delete the initializers unless requested
103
+ unless options[:initializers]
104
+ Dir["#{app_path}/config/initializers/*.rb"].each do |initializer|
105
+ File.delete(initializer)
106
+ end
107
+ end
108
+
109
+ gemfile_path = "#{app_path}/Gemfile"
110
+ if options[:gemfile].blank? && File.exist?(gemfile_path)
111
+ File.delete gemfile_path
112
+ end
113
+
114
+ routes = File.read("#{app_path}/config/routes.rb")
115
+ if routes =~ /(\n\s*end\s*)\Z/
116
+ File.open("#{app_path}/config/routes.rb", 'w') do |f|
117
+ f.puts $` + "\nmatch ':controller(/:action(/:id))(.:format)', via: :all\n" + $1
118
+ end
119
+ end
120
+
121
+ add_to_config <<-RUBY
122
+ config.eager_load = false
123
+ config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
124
+ config.session_store :cookie_store, key: "_myapp_session"
125
+ config.active_support.deprecation = :log
126
+ config.action_controller.allow_forgery_protection = false
127
+ RUBY
128
+ end
129
+
130
+ def teardown_app
131
+ ENV['RAILS_ENV'] = @prev_rails_env if @prev_rails_env
132
+ end
133
+
134
+ # Make a very basic app, without creating the whole directory structure.
135
+ # This is faster and simpler than the method above.
136
+ def make_basic_app
137
+ require "rails"
138
+ require "action_controller/railtie"
139
+
140
+ app = Class.new(Rails::Application)
141
+ app.config.eager_load = false
142
+ app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
143
+ app.config.session_store :cookie_store, key: "_myapp_session"
144
+ app.config.active_support.deprecation = :log
145
+
146
+ yield app if block_given?
147
+ app.initialize!
148
+
149
+ app.routes.draw do
150
+ get "/" => "omg#index"
151
+ end
152
+
153
+ require 'rack/test'
154
+ extend ::Rack::Test::Methods
155
+ end
156
+
157
+ def simple_controller
158
+ controller :foo, <<-RUBY
159
+ class FooController < ApplicationController
160
+ def index
161
+ render text: "foo"
162
+ end
163
+ end
164
+ RUBY
165
+
166
+ app_file 'config/routes.rb', <<-RUBY
167
+ AppTemplate::Application.routes.draw do
168
+ get ':controller(/:action)'
169
+ end
170
+ RUBY
171
+ end
172
+
173
+ class Bukkit
174
+ attr_reader :path
175
+
176
+ def initialize(path)
177
+ @path = path
178
+ end
179
+
180
+ def write(file, string)
181
+ path = "#{@path}/#{file}"
182
+ FileUtils.mkdir_p(File.dirname(path))
183
+ File.open(path, "w") {|f| f.puts string }
184
+ end
185
+
186
+ def delete(file)
187
+ File.delete("#{@path}/#{file}")
188
+ end
189
+ end
190
+
191
+ def engine(name)
192
+ dir = "#{app_path}/random/#{name}"
193
+ FileUtils.mkdir_p(dir)
194
+
195
+ app = File.readlines("#{app_path}/config/application.rb")
196
+ app.insert(2, "$:.unshift(\"#{dir}/lib\")")
197
+ app.insert(3, "require #{name.inspect}")
198
+
199
+ File.open("#{app_path}/config/application.rb", 'r+') do |f|
200
+ f.puts app
201
+ end
202
+
203
+ Bukkit.new(dir).tap do |bukkit|
204
+ yield bukkit if block_given?
205
+ end
206
+ end
207
+
208
+ def script(script)
209
+ Dir.chdir(app_path) do
210
+ `#{Gem.ruby} #{app_path}/script/rails #{script}`
211
+ end
212
+ end
213
+
214
+ def add_to_config(str)
215
+ environment = File.read("#{app_path}/config/application.rb")
216
+ if environment =~ /(\n\s*end\s*end\s*)\Z/
217
+ File.open("#{app_path}/config/application.rb", 'w') do |f|
218
+ f.puts $` + "\n#{str}\n" + $1
219
+ end
220
+ end
221
+ end
222
+
223
+ def add_to_env_config(env, str)
224
+ environment = File.read("#{app_path}/config/environments/#{env}.rb")
225
+ if environment =~ /(\n\s*end\s*)\Z/
226
+ File.open("#{app_path}/config/environments/#{env}.rb", 'w') do |f|
227
+ f.puts $` + "\n#{str}\n" + $1
228
+ end
229
+ end
230
+ end
231
+
232
+ def remove_from_config(str)
233
+ file = "#{app_path}/config/application.rb"
234
+ contents = File.read(file)
235
+ contents.sub!(/#{str}/, "")
236
+ File.open(file, "w+") { |f| f.puts contents }
237
+ end
238
+
239
+ def app_file(path, contents)
240
+ FileUtils.mkdir_p File.dirname("#{app_path}/#{path}")
241
+ File.open("#{app_path}/#{path}", 'w') do |f|
242
+ f.puts contents
243
+ end
244
+ end
245
+
246
+ def remove_file(path)
247
+ FileUtils.rm_rf "#{app_path}/#{path}"
248
+ end
249
+
250
+ def controller(name, contents)
251
+ app_file("app/controllers/#{name}_controller.rb", contents)
252
+ end
253
+
254
+ def use_frameworks(arr)
255
+ to_remove = [:actionmailer,
256
+ :activerecord] - arr
257
+ $:.reject! {|path| path =~ %r'/(#{to_remove.join('|')})/' }
258
+ end
259
+
260
+ def boot_rails
261
+ require File.expand_path('../../../../rails/load_paths', __FILE__)
262
+ end
263
+ end
264
+ end
265
+
266
+ class ActiveSupport::TestCase
267
+ include TestHelpers::Paths
268
+ include TestHelpers::Rack
269
+ include TestHelpers::Generation
270
+ end
271
+
272
+ # Create a scope and build a fixture rails app
273
+ Module.new do
274
+ extend TestHelpers::Paths
275
+
276
+ # Build a rails app
277
+ FileUtils.rm_rf(app_template_path)
278
+ FileUtils.mkdir(app_template_path)
279
+
280
+ environment = File.expand_path('../../../../rails/load_paths', __FILE__)
281
+ require_environment = "-r #{environment}"
282
+
283
+ `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails new #{app_template_path} --skip-gemfile`
284
+ File.open("#{app_template_path}/config/boot.rb", 'w') do |f|
285
+ f.puts "require '#{environment}'"
286
+ f.puts "require 'rails/all'"
287
+ end
288
+ end unless defined?(RAILS_ISOLATED_ENGINE)
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-four-queueing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Phil Cohen
9
+ - Don Morrison
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-10-29 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 3.2.8
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 3.2.8
31
+ description: It's the Queue from Rails 4, backported to Rails 3.2+ for your Queueing
32
+ pleasure.
33
+ email:
34
+ - github@phlippers.net
35
+ - elskwid@gmail.com
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - lib/rails/four/application.rb
41
+ - lib/rails/four/configuration.rb
42
+ - lib/rails/four/queueing/engine.rb
43
+ - lib/rails/four/queueing/version.rb
44
+ - lib/rails/four/queueing.rb
45
+ - lib/rails-four-queueing.rb
46
+ - lib/tasks/rails-four-queueing_tasks.rake
47
+ - MIT-LICENSE
48
+ - Rakefile
49
+ - README.md
50
+ - test/ci/before_script.sh
51
+ - test/rails/four/queueing/synchronous_queue_test.rb
52
+ - test/rails/four/queueing/test_queue_test.rb
53
+ - test/rails/four/queueing/threaded_consumer_test.rb
54
+ - test/rails/initializers/frameworks_test.rb
55
+ - test/rails/queue_test.rb
56
+ - test/rails-four-queueing_test.rb
57
+ - test/support/active_support_abstract_unit.rb
58
+ - test/support/empty_bool.rb
59
+ - test/support/isolation_abstract_unit.rb
60
+ homepage: http://phlippers.net/rails-four-queueing
61
+ licenses: []
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ segments:
73
+ - 0
74
+ hash: -2226372685420353224
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ segments:
82
+ - 0
83
+ hash: -2226372685420353224
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.24
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: It's the Queue from Rails 4, backported to Rails 3.2+ for your Queueing pleasure.
90
+ test_files:
91
+ - test/ci/before_script.sh
92
+ - test/rails/four/queueing/synchronous_queue_test.rb
93
+ - test/rails/four/queueing/test_queue_test.rb
94
+ - test/rails/four/queueing/threaded_consumer_test.rb
95
+ - test/rails/initializers/frameworks_test.rb
96
+ - test/rails/queue_test.rb
97
+ - test/rails-four-queueing_test.rb
98
+ - test/support/active_support_abstract_unit.rb
99
+ - test/support/empty_bool.rb
100
+ - test/support/isolation_abstract_unit.rb