rails-queue 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,65 @@
1
+ # Original File: RAILS_ROOT/actionmailer/test/abstract_unit.rb
2
+ require File.expand_path('../../../../rails/load_paths', __FILE__)
3
+ require 'active_support/core_ext/kernel/reporting'
4
+
5
+ # These are the normal settings that will be set up by Railties
6
+ # TODO: Have these tests support other combinations of these values
7
+ silence_warnings do
8
+ Encoding.default_internal = "UTF-8"
9
+ Encoding.default_external = "UTF-8"
10
+ end
11
+
12
+ require 'minitest/autorun'
13
+ require 'action_mailer'
14
+ require 'action_mailer/test_case'
15
+ require "rails-queue"
16
+
17
+ silence_warnings do
18
+ # These external dependencies have warnings :/
19
+ require 'mail'
20
+ end
21
+
22
+ # Show backtraces for deprecated behavior for quicker cleanup.
23
+ ActiveSupport::Deprecation.debug = true
24
+
25
+ # Bogus template processors
26
+ ActionView::Template.register_template_handler :haml, lambda { |template| "Look its HAML!".inspect }
27
+ ActionView::Template.register_template_handler :bak, lambda { |template| "Lame backup".inspect }
28
+
29
+ FIXTURE_LOAD_PATH = File.expand_path('../fixtures', File.dirname(__FILE__))
30
+ ActionMailer::Base.view_paths = FIXTURE_LOAD_PATH
31
+
32
+ class MockSMTP
33
+ def self.deliveries
34
+ @@deliveries
35
+ end
36
+
37
+ def initialize
38
+ @@deliveries = []
39
+ end
40
+
41
+ def sendmail(mail, from, to)
42
+ @@deliveries << [mail, from, to]
43
+ end
44
+
45
+ def start(*args)
46
+ yield self
47
+ end
48
+ end
49
+
50
+ class Net::SMTP
51
+ def self.new(*args)
52
+ MockSMTP.new
53
+ end
54
+ end
55
+
56
+ def set_delivery_method(method)
57
+ @old_delivery_method = ActionMailer::Base.delivery_method
58
+ ActionMailer::Base.delivery_method = method
59
+ end
60
+
61
+ def restore_delivery_method
62
+ ActionMailer::Base.delivery_method = @old_delivery_method
63
+ end
64
+
65
+ ActiveSupport::Deprecation.silenced = true
@@ -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,305 @@
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
+ # overwrite the default `build_app` method to inject the gem for testing
27
+ def build_app
28
+ super
29
+
30
+ # inject the path to the gem we're testing
31
+ environment = File.read("#{app_path}/config/application.rb")
32
+ if environment =~ /(module AppTemplate)/
33
+ rails_queue_path = File.expand_path(
34
+ "../../../../lib/rails-queue", __FILE__
35
+ )
36
+ File.open("#{app_path}/config/application.rb", 'w') do |f|
37
+ f.puts $` + %Q(\nrequire "#{rails_queue_path}"\n) + $1 + $'
38
+ end
39
+ end
40
+ end
41
+
42
+
43
+ def app_template_path
44
+ File.join Dir.tmpdir, 'app_template'
45
+ end
46
+
47
+ def tmp_path(*args)
48
+ @tmp_path ||= File.realpath(Dir.mktmpdir)
49
+ File.join(@tmp_path, *args)
50
+ end
51
+
52
+ def app_path(*args)
53
+ tmp_path(*%w[app] + args)
54
+ end
55
+
56
+ def framework_path
57
+ RAILS_FRAMEWORK_ROOT
58
+ end
59
+
60
+ def rails_root
61
+ app_path
62
+ end
63
+ end
64
+
65
+ module Rack
66
+ def app(env = "production")
67
+ old_env = ENV["RAILS_ENV"]
68
+ @app ||= begin
69
+ ENV["RAILS_ENV"] = env
70
+ require "#{app_path}/config/environment"
71
+ Rails.application
72
+ end
73
+ ensure
74
+ ENV["RAILS_ENV"] = old_env
75
+ end
76
+
77
+ def extract_body(response)
78
+ "".tap do |body|
79
+ response[2].each {|chunk| body << chunk }
80
+ end
81
+ end
82
+
83
+ def get(path)
84
+ @app.call(::Rack::MockRequest.env_for(path))
85
+ end
86
+
87
+ def assert_welcome(resp)
88
+ assert_equal 200, resp[0]
89
+ assert resp[1]["Content-Type"] = "text/html"
90
+ assert extract_body(resp).match(/Welcome aboard/)
91
+ end
92
+
93
+ def assert_success(resp)
94
+ assert_equal 202, resp[0]
95
+ end
96
+
97
+ def assert_missing(resp)
98
+ assert_equal 404, resp[0]
99
+ end
100
+
101
+ def assert_header(key, value, resp)
102
+ assert_equal value, resp[1][key.to_s]
103
+ end
104
+
105
+ def assert_body(expected, resp)
106
+ assert_equal expected, extract_body(resp)
107
+ end
108
+ end
109
+
110
+ module Generation
111
+ # Build an application by invoking the generator and going through the whole stack.
112
+ def build_app(options = {})
113
+ @prev_rails_env = ENV['RAILS_ENV']
114
+ ENV['RAILS_ENV'] = 'development'
115
+
116
+ FileUtils.rm_rf(app_path)
117
+ FileUtils.cp_r(app_template_path, app_path)
118
+
119
+ # Delete the initializers unless requested
120
+ unless options[:initializers]
121
+ Dir["#{app_path}/config/initializers/*.rb"].each do |initializer|
122
+ File.delete(initializer)
123
+ end
124
+ end
125
+
126
+ gemfile_path = "#{app_path}/Gemfile"
127
+ if options[:gemfile].blank? && File.exist?(gemfile_path)
128
+ File.delete gemfile_path
129
+ end
130
+
131
+ routes = File.read("#{app_path}/config/routes.rb")
132
+ if routes =~ /(\n\s*end\s*)\Z/
133
+ File.open("#{app_path}/config/routes.rb", 'w') do |f|
134
+ f.puts $` + "\nmatch ':controller(/:action(/:id))(.:format)', via: :all\n" + $1
135
+ end
136
+ end
137
+
138
+ add_to_config <<-RUBY
139
+ config.eager_load = false
140
+ config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
141
+ config.session_store :cookie_store, key: "_myapp_session"
142
+ config.active_support.deprecation = :log
143
+ config.action_controller.allow_forgery_protection = false
144
+ RUBY
145
+ end
146
+
147
+ def teardown_app
148
+ ENV['RAILS_ENV'] = @prev_rails_env if @prev_rails_env
149
+ end
150
+
151
+ # Make a very basic app, without creating the whole directory structure.
152
+ # This is faster and simpler than the method above.
153
+ def make_basic_app
154
+ require "rails"
155
+ require "action_controller/railtie"
156
+
157
+ app = Class.new(Rails::Application)
158
+ app.config.eager_load = false
159
+ app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
160
+ app.config.session_store :cookie_store, key: "_myapp_session"
161
+ app.config.active_support.deprecation = :log
162
+
163
+ yield app if block_given?
164
+ app.initialize!
165
+
166
+ app.routes.draw do
167
+ get "/" => "omg#index"
168
+ end
169
+
170
+ require 'rack/test'
171
+ extend ::Rack::Test::Methods
172
+ end
173
+
174
+ def simple_controller
175
+ controller :foo, <<-RUBY
176
+ class FooController < ApplicationController
177
+ def index
178
+ render text: "foo"
179
+ end
180
+ end
181
+ RUBY
182
+
183
+ app_file 'config/routes.rb', <<-RUBY
184
+ AppTemplate::Application.routes.draw do
185
+ get ':controller(/:action)'
186
+ end
187
+ RUBY
188
+ end
189
+
190
+ class Bukkit
191
+ attr_reader :path
192
+
193
+ def initialize(path)
194
+ @path = path
195
+ end
196
+
197
+ def write(file, string)
198
+ path = "#{@path}/#{file}"
199
+ FileUtils.mkdir_p(File.dirname(path))
200
+ File.open(path, "w") {|f| f.puts string }
201
+ end
202
+
203
+ def delete(file)
204
+ File.delete("#{@path}/#{file}")
205
+ end
206
+ end
207
+
208
+ def engine(name)
209
+ dir = "#{app_path}/random/#{name}"
210
+ FileUtils.mkdir_p(dir)
211
+
212
+ app = File.readlines("#{app_path}/config/application.rb")
213
+ app.insert(2, "$:.unshift(\"#{dir}/lib\")")
214
+ app.insert(3, "require #{name.inspect}")
215
+
216
+ File.open("#{app_path}/config/application.rb", 'r+') do |f|
217
+ f.puts app
218
+ end
219
+
220
+ Bukkit.new(dir).tap do |bukkit|
221
+ yield bukkit if block_given?
222
+ end
223
+ end
224
+
225
+ def script(script)
226
+ Dir.chdir(app_path) do
227
+ `#{Gem.ruby} #{app_path}/script/rails #{script}`
228
+ end
229
+ end
230
+
231
+ def add_to_config(str)
232
+ environment = File.read("#{app_path}/config/application.rb")
233
+ if environment =~ /(\n\s*end\s*end\s*)\Z/
234
+ File.open("#{app_path}/config/application.rb", 'w') do |f|
235
+ f.puts $` + "\n#{str}\n" + $1
236
+ end
237
+ end
238
+ end
239
+
240
+ def add_to_env_config(env, str)
241
+ environment = File.read("#{app_path}/config/environments/#{env}.rb")
242
+ if environment =~ /(\n\s*end\s*)\Z/
243
+ File.open("#{app_path}/config/environments/#{env}.rb", 'w') do |f|
244
+ f.puts $` + "\n#{str}\n" + $1
245
+ end
246
+ end
247
+ end
248
+
249
+ def remove_from_config(str)
250
+ file = "#{app_path}/config/application.rb"
251
+ contents = File.read(file)
252
+ contents.sub!(/#{str}/, "")
253
+ File.open(file, "w+") { |f| f.puts contents }
254
+ end
255
+
256
+ def app_file(path, contents)
257
+ FileUtils.mkdir_p File.dirname("#{app_path}/#{path}")
258
+ File.open("#{app_path}/#{path}", 'w') do |f|
259
+ f.puts contents
260
+ end
261
+ end
262
+
263
+ def remove_file(path)
264
+ FileUtils.rm_rf "#{app_path}/#{path}"
265
+ end
266
+
267
+ def controller(name, contents)
268
+ app_file("app/controllers/#{name}_controller.rb", contents)
269
+ end
270
+
271
+ def use_frameworks(arr)
272
+ to_remove = [:actionmailer,
273
+ :activerecord] - arr
274
+ $:.reject! {|path| path =~ %r'/(#{to_remove.join('|')})/' }
275
+ end
276
+
277
+ def boot_rails
278
+ require File.expand_path('../../../../rails/load_paths', __FILE__)
279
+ end
280
+ end
281
+ end
282
+
283
+ class ActiveSupport::TestCase
284
+ include TestHelpers::Paths
285
+ include TestHelpers::Rack
286
+ include TestHelpers::Generation
287
+ end
288
+
289
+ # Create a scope and build a fixture rails app
290
+ Module.new do
291
+ extend TestHelpers::Paths
292
+
293
+ # Build a rails app
294
+ FileUtils.rm_rf(app_template_path)
295
+ FileUtils.mkdir(app_template_path)
296
+
297
+ environment = File.expand_path('../../../../rails/load_paths', __FILE__)
298
+ require_environment = "-r #{environment}"
299
+
300
+ `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails new #{app_template_path} --skip-gemfile`
301
+ File.open("#{app_template_path}/config/boot.rb", 'w') do |f|
302
+ f.puts "require '#{environment}'"
303
+ f.puts "require 'rails/all'"
304
+ end
305
+ end unless defined?(RAILS_ISOLATED_ENGINE)
@@ -0,0 +1,18 @@
1
+ # Original File: RAILS_ROOT/actionmailer/test/mailers/base_mailer.rb
2
+ class BaseMailer < ActionMailer::Base
3
+ self.mailer_name = "base_mailer"
4
+
5
+ default to: 'system@test.lindsaar.net',
6
+ from: 'jose@test.plataformatec.com',
7
+ reply_to: 'mikel@test.lindsaar.net'
8
+
9
+ def welcome(hash = {})
10
+ headers['X-SPAM'] = "Not SPAM"
11
+ mail({subject: "The first email on new API!"}.merge!(hash))
12
+ end
13
+ end
14
+
15
+ # Original File: RAILS_ROOT/actionmailer/test/mailers/async_mailer.rb
16
+ class AsyncMailer < BaseMailer
17
+ self.queue = Rails::Queue::TestQueue.new
18
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-queue
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.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-11-24 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: Rails.queue (from Rails 4), backported to Rails 3.2+
32
+ email:
33
+ - github@phlippers.net
34
+ - elskwid@gmail.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - lib/rails/queue/action_mailer/queued_message.rb
40
+ - lib/rails/queue/application.rb
41
+ - lib/rails/queue/configuration.rb
42
+ - lib/rails/queue/queue.rb
43
+ - lib/rails/queue/railtie.rb
44
+ - lib/rails/queue/version.rb
45
+ - lib/rails-queue.rb
46
+ - LICENSE.txt
47
+ - Rakefile
48
+ - README.md
49
+ - test/ci/before_script.sh
50
+ - test/fixtures/async_mailer/welcome.erb
51
+ - test/rails/frameworks_test.rb
52
+ - test/rails/queue/actionmailer/base_test.rb
53
+ - test/rails/queue/synchronous_queue_test.rb
54
+ - test/rails/queue/test_queue_test.rb
55
+ - test/rails/queue/threaded_consumer_test.rb
56
+ - test/rails/queue_test.rb
57
+ - test/rails-queue_test.rb
58
+ - test/support/action_mailer_abstract_unit.rb
59
+ - test/support/active_support_abstract_unit.rb
60
+ - test/support/empty_bool.rb
61
+ - test/support/isolation_abstract_unit.rb
62
+ - test/support/mailers.rb
63
+ homepage: http://wereprobablywrong.com/rails-queue
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ segments:
76
+ - 0
77
+ hash: -3550235712858628843
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ segments:
85
+ - 0
86
+ hash: -3550235712858628843
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 1.8.24
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Rails.queue (from Rails 4), backported to Rails 3.2+
93
+ test_files:
94
+ - test/ci/before_script.sh
95
+ - test/fixtures/async_mailer/welcome.erb
96
+ - test/rails/frameworks_test.rb
97
+ - test/rails/queue/actionmailer/base_test.rb
98
+ - test/rails/queue/synchronous_queue_test.rb
99
+ - test/rails/queue/test_queue_test.rb
100
+ - test/rails/queue/threaded_consumer_test.rb
101
+ - test/rails/queue_test.rb
102
+ - test/rails-queue_test.rb
103
+ - test/support/action_mailer_abstract_unit.rb
104
+ - test/support/active_support_abstract_unit.rb
105
+ - test/support/empty_bool.rb
106
+ - test/support/isolation_abstract_unit.rb
107
+ - test/support/mailers.rb