rory 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rory/cli/generators/templates/app/.rspec +1 -0
  3. data/{spec/fixture_app/log/test.log → lib/rory/cli/generators/templates/app/config/initializers/.empty_directory} +0 -0
  4. data/lib/rory/cli/generators/templates/app/models/.empty_directory +0 -0
  5. data/lib/rory/version.rb +1 -1
  6. data/rory.gemspec +1 -1
  7. metadata +4 -44
  8. data/spec/fixture_app/config/application.rb +0 -6
  9. data/spec/fixture_app/config/routes.rb +0 -16
  10. data/spec/fixture_app/controllers/base_filtered_controller.rb +0 -9
  11. data/spec/fixture_app/controllers/filtered_controller.rb +0 -10
  12. data/spec/fixture_app/controllers/for_reals_controller.rb +0 -14
  13. data/spec/fixture_app/controllers/goose/lumpies_controller.rb +0 -12
  14. data/spec/fixture_app/controllers/goose/wombat/rabbits_controller.rb +0 -14
  15. data/spec/fixture_app/controllers/stub_controller.rb +0 -10
  16. data/spec/fixture_app/lib/dummy_middleware.rb +0 -13
  17. data/spec/fixture_app/views/for_reals/but_wait.html.erb +0 -1
  18. data/spec/fixture_app/views/for_reals/custom.html.erb +0 -1
  19. data/spec/fixture_app/views/for_reals/srsly.html.erb +0 -1
  20. data/spec/fixture_app/views/layouts/surround.html.erb +0 -1
  21. data/spec/fixture_app/views/test/a_link.html.erb +0 -1
  22. data/spec/fixture_app/views/test/double_nested.html.erb +0 -1
  23. data/spec/fixture_app/views/test/dynamic.html.erb +0 -1
  24. data/spec/fixture_app/views/test/letsgo.html.erb +0 -1
  25. data/spec/fixture_app/views/test/nested.html.erb +0 -1
  26. data/spec/fixture_app/views/test/static.html.erb +0 -1
  27. data/spec/lib/rory/application_spec.rb +0 -353
  28. data/spec/lib/rory/cli/generate_spec.rb +0 -16
  29. data/spec/lib/rory/cli/generators/application_spec.rb +0 -35
  30. data/spec/lib/rory/cli/root_spec.rb +0 -30
  31. data/spec/lib/rory/cli_spec.rb +0 -10
  32. data/spec/lib/rory/controller_spec.rb +0 -261
  33. data/spec/lib/rory/dispatcher_spec.rb +0 -187
  34. data/spec/lib/rory/initializers_spec.rb +0 -77
  35. data/spec/lib/rory/logger_spec.rb +0 -90
  36. data/spec/lib/rory/middleware_stack_spec.rb +0 -86
  37. data/spec/lib/rory/parameter_filter_spec.rb +0 -50
  38. data/spec/lib/rory/renderer/context_spec.rb +0 -41
  39. data/spec/lib/rory/renderer_spec.rb +0 -50
  40. data/spec/lib/rory/request_id_spec.rb +0 -56
  41. data/spec/lib/rory/request_parameter_logger_spec.rb +0 -100
  42. data/spec/lib/rory/request_spec.rb +0 -14
  43. data/spec/lib/rory/route_spec.rb +0 -15
  44. data/spec/lib/rory/support_spec.rb +0 -119
  45. data/spec/lib/rory_spec.rb +0 -15
  46. data/spec/requests/controller_spec.rb +0 -27
  47. data/spec/spec_helper.rb +0 -25
  48. data/spec/support/generation_helpers.rb +0 -19
  49. data/spec/support/shared_examples/path_generation.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c207c6ca9b666cfe7491b6e74a8031286dff0f9f
4
- data.tar.gz: 89c7cfd6f0c04dc0a813911d0e31935aeee12aee
3
+ metadata.gz: 3c2614566864c6eb2c8647067a7565c2afdcfa0e
4
+ data.tar.gz: af297aa8a0b21ea82ce229fe8d1128576d932038
5
5
  SHA512:
6
- metadata.gz: 1a1a283981ba88f3495d08b90070a84dd8c91bc3c52bcdd7830738eddc7819efda4e3f68e6ac4a049510434c92f6f17c41cd7b0379dcdec3d01788f38c36f281
7
- data.tar.gz: 0807c432dbfc12a8436602309ed7b249d28b467e37a6f30a27e353d75fcc59c284667a9f97955fd5be8242581e1d8e0c7415cb792d4a75cb0787066dda40fe9f
6
+ metadata.gz: 8d78888aaa95dea67ceed90adbeee129fc72dc81cf75b444b3cd4e0badc102c73e8b804ba5c2b544ec578b3aabdf67041024aee3834211081b42e92acea61c0c
7
+ data.tar.gz: a1c9f7af6cc2cde9b8a940ffd9086479df1d59dc49d88d26e309bfc54701e2efec766d74b3aa92a89b1e678c0cc1513ccf4770075cfdb27c4f3a77d8adc597b4
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -1,3 +1,3 @@
1
1
  module Rory
2
- VERSION = '0.9.1'
2
+ VERSION = '0.9.2'
3
3
  end
@@ -23,7 +23,7 @@ EOF
23
23
  s.required_rubygems_version = ">= 1.3.6"
24
24
 
25
25
  s.extra_rdoc_files = ["LICENSE.txt", "README.md"]
26
- s.files = Dir['{lib/**/*,spec/**/*}'] +
26
+ s.files = Dir["lib/**/{*,.[a-z]*}"] +
27
27
  %w(LICENSE.txt Rakefile README.md rory.gemspec)
28
28
  s.licenses = ["MIT"]
29
29
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ravi Gadad
@@ -247,12 +247,15 @@ files:
247
247
  - lib/rory/cli.rb
248
248
  - lib/rory/cli/generate.rb
249
249
  - lib/rory/cli/generators/application.rb
250
+ - lib/rory/cli/generators/templates/app/.rspec
250
251
  - lib/rory/cli/generators/templates/app/Gemfile.tt
251
252
  - lib/rory/cli/generators/templates/app/Rakefile.tt
252
253
  - lib/rory/cli/generators/templates/app/config.ru.tt
253
254
  - lib/rory/cli/generators/templates/app/config/application.rb.tt
255
+ - lib/rory/cli/generators/templates/app/config/initializers/.empty_directory
254
256
  - lib/rory/cli/generators/templates/app/config/routes.rb.tt
255
257
  - lib/rory/cli/generators/templates/app/controllers/application_controller.rb
258
+ - lib/rory/cli/generators/templates/app/models/.empty_directory
256
259
  - lib/rory/cli/generators/templates/app/spec/spec_helper.rb
257
260
  - lib/rory/cli/root.rb
258
261
  - lib/rory/controller.rb
@@ -275,49 +278,6 @@ files:
275
278
  - lib/tasks/db.rake
276
279
  - lib/tasks/rory.rake
277
280
  - rory.gemspec
278
- - spec/fixture_app/config/application.rb
279
- - spec/fixture_app/config/routes.rb
280
- - spec/fixture_app/controllers/base_filtered_controller.rb
281
- - spec/fixture_app/controllers/filtered_controller.rb
282
- - spec/fixture_app/controllers/for_reals_controller.rb
283
- - spec/fixture_app/controllers/goose/lumpies_controller.rb
284
- - spec/fixture_app/controllers/goose/wombat/rabbits_controller.rb
285
- - spec/fixture_app/controllers/stub_controller.rb
286
- - spec/fixture_app/lib/dummy_middleware.rb
287
- - spec/fixture_app/log/test.log
288
- - spec/fixture_app/views/for_reals/but_wait.html.erb
289
- - spec/fixture_app/views/for_reals/custom.html.erb
290
- - spec/fixture_app/views/for_reals/srsly.html.erb
291
- - spec/fixture_app/views/layouts/surround.html.erb
292
- - spec/fixture_app/views/test/a_link.html.erb
293
- - spec/fixture_app/views/test/double_nested.html.erb
294
- - spec/fixture_app/views/test/dynamic.html.erb
295
- - spec/fixture_app/views/test/letsgo.html.erb
296
- - spec/fixture_app/views/test/nested.html.erb
297
- - spec/fixture_app/views/test/static.html.erb
298
- - spec/lib/rory/application_spec.rb
299
- - spec/lib/rory/cli/generate_spec.rb
300
- - spec/lib/rory/cli/generators/application_spec.rb
301
- - spec/lib/rory/cli/root_spec.rb
302
- - spec/lib/rory/cli_spec.rb
303
- - spec/lib/rory/controller_spec.rb
304
- - spec/lib/rory/dispatcher_spec.rb
305
- - spec/lib/rory/initializers_spec.rb
306
- - spec/lib/rory/logger_spec.rb
307
- - spec/lib/rory/middleware_stack_spec.rb
308
- - spec/lib/rory/parameter_filter_spec.rb
309
- - spec/lib/rory/renderer/context_spec.rb
310
- - spec/lib/rory/renderer_spec.rb
311
- - spec/lib/rory/request_id_spec.rb
312
- - spec/lib/rory/request_parameter_logger_spec.rb
313
- - spec/lib/rory/request_spec.rb
314
- - spec/lib/rory/route_spec.rb
315
- - spec/lib/rory/support_spec.rb
316
- - spec/lib/rory_spec.rb
317
- - spec/requests/controller_spec.rb
318
- - spec/spec_helper.rb
319
- - spec/support/generation_helpers.rb
320
- - spec/support/shared_examples/path_generation.rb
321
281
  homepage: http://github.com/screamingmuse/rory
322
282
  licenses:
323
283
  - MIT
@@ -1,6 +0,0 @@
1
- module Fixture
2
- class Application < Rory::Application
3
- turn_off_request_logging!
4
- filter_parameters :orcas, :noodles
5
- end
6
- end
@@ -1,16 +0,0 @@
1
- Fixture::Application.set_routes do
2
- match 'foo/:id/bar', :to => 'foo#bar', :methods => [:get, :post]
3
- match 'this/:path/is/:very_awesome', :to => 'awesome#rad'
4
- scope :method => [:get] do
5
- scope :module => 'goose' do
6
- match 'lumpies/:lump', :to => 'lumpies#show'
7
- end
8
- scope :module => 'goose/wombat' do
9
- match 'rabbits/:chew', :to => 'rabbits#chew'
10
- end
11
- end
12
- match '/', :to => 'root#vegetable', :methods => [:get]
13
- match '/', :to => 'root#no_vegetable', :methods => [:delete]
14
- match 'for_reals/switching', :to => 'for_reals#switching', :methods => [:get]
15
- match 'for_reals/:parbles', :to => 'for_reals#srsly', :methods => [:get]
16
- end
@@ -1,9 +0,0 @@
1
- class BaseFilteredController < Rory::Controller
2
- before_action :pickle_something, :except => [:eat]
3
- after_action :rub_tummy, :if => :horses_exist?
4
- after_action :smile, :only => [:eat]
5
-
6
- def horses_exist?
7
- params[:horses] != 'missing'
8
- end
9
- end
@@ -1,10 +0,0 @@
1
- require_relative 'base_filtered_controller'
2
-
3
- class FilteredController < BaseFilteredController
4
- before_action :make_it_tasty, :unless => proc { !horses_exist? }
5
- before_action :make_it_nutritious, :only => [:eat]
6
- after_action :sleep, :except => [:eat]
7
-
8
- def eat
9
- end
10
- end
@@ -1,14 +0,0 @@
1
- class ForRealsController < Rory::Controller
2
- def srsly
3
- expose :gibbit => @params[:parbles]
4
- expose :but_when => 'again'
5
- end
6
-
7
- def switching
8
- if json_requested?
9
- render :json => { :a => 1 }
10
- else
11
- render 'for_reals/custom', :status => 404
12
- end
13
- end
14
- end
@@ -1,12 +0,0 @@
1
- module Goose
2
- class LumpiesController
3
- def initialize(args, routing, context)
4
- @args = args
5
- end
6
-
7
- def present
8
- @args[:in_scoped_controller] = true
9
- @args
10
- end
11
- end
12
- end
@@ -1,14 +0,0 @@
1
- module Goose
2
- module Wombat
3
- class RabbitsController
4
- def initialize(args, routing, context)
5
- @args = args
6
- end
7
-
8
- def present
9
- @args[:in_scoped_controller] = true
10
- @args
11
- end
12
- end
13
- end
14
- end
@@ -1,10 +0,0 @@
1
- class StubController
2
- def initialize(args, routing, context)
3
- @args = args
4
- end
5
-
6
- def present
7
- @args[:present_called] = true
8
- @args
9
- end
10
- end
@@ -1,13 +0,0 @@
1
- class DummyMiddleware
2
- attr_accessor :prefix
3
-
4
- def initialize(app, *args, &block)
5
- @app = app
6
- @args = args
7
- block.call(self)
8
- end
9
-
10
- def call(env)
11
- @app.call("#{prefix} #{@args.first}")
12
- end
13
- end
@@ -1 +0,0 @@
1
- But it's <%= when_is_it %> enough!
@@ -1 +0,0 @@
1
- Oh, a secret!
@@ -1 +0,0 @@
1
- You've done it <%= but_when %>, <%= gibbit %>!
@@ -1 +0,0 @@
1
- Surrounding <%= yield %> is fun
@@ -1 +0,0 @@
1
- You came from <%= base_path %>.
@@ -1 +0,0 @@
1
- Don't Say <%= render 'test/nested' %>
@@ -1 +0,0 @@
1
- Word: <%= word %>
@@ -1 +0,0 @@
1
- Let's go content
@@ -1 +0,0 @@
1
- A Bad <%= render 'test/dynamic', :locals => { :word => 'Poop' } %>!
@@ -1 +0,0 @@
1
- Static content
@@ -1,353 +0,0 @@
1
- require_relative '../../fixture_app/lib/dummy_middleware'
2
-
3
- RSpec.describe Rory::Application do
4
- let(:subject) {
5
- Object.const_set(test_rory_app_name, Class.new(Rory::Application).tap { |app|
6
- app.root = root
7
- app.turn_off_request_logging!
8
- })
9
- Object.const_get(test_rory_app_name)
10
- }
11
-
12
- let(:test_rory_app_name){
13
- "TestRory#{('a'..'z').to_a.sample(5).join}"
14
- }
15
- let(:root){"spec/fixture_app"}
16
-
17
- before do
18
- Rory::Application.initializers.clear
19
- Rory::Application.initializer_default_middleware
20
- end
21
-
22
- describe ".root=" do
23
- let(:root) { "current_app" }
24
- before { `ln -s spec/fixture_app current_app` }
25
- after { `rm current_app` }
26
-
27
- it 'appends to the load path' do
28
- expect($:).to receive(:unshift).with(Pathname("current_app").realpath)
29
- subject
30
- end
31
- end
32
-
33
- describe ".root" do
34
- let(:root) { "current_app" }
35
- before { `ln -s spec/fixture_app current_app` }
36
- after { `rm current_app` }
37
-
38
- it "returns the realpath" do
39
- expect(subject.root.to_s).to match(/spec\/fixture_app/)
40
- end
41
- end
42
-
43
- describe ".configure" do
44
- it 'yields the given block to self' do
45
- subject.configure do |c|
46
- expect(c).to eq(subject.instance)
47
- end
48
- end
49
- end
50
-
51
- describe '.config_path' do
52
- it 'is set to {root}/config by default' do
53
- expect(subject.config_path).to eq(
54
- Pathname.new(subject.root).join('config')
55
- )
56
- end
57
-
58
- it 'raises exception if root not set' do
59
- Rory.application = nil
60
- class RootlessApp < Rory::Application; end
61
- expect {
62
- RootlessApp.config_path
63
- }.to raise_error(RootlessApp::RootNotConfigured)
64
- Rory.application = subject.instance
65
- end
66
- end
67
-
68
- describe '.log_path' do
69
- it 'is set to {root}/config by default' do
70
- expect(subject.log_path).to eq(
71
- Pathname.new(subject.root).join('log')
72
- )
73
- end
74
-
75
- it 'raises exception if root not set' do
76
- Rory.application = nil
77
- class RootlessApp < Rory::Application; end
78
- expect {
79
- RootlessApp.config_path
80
- }.to raise_error(RootlessApp::RootNotConfigured)
81
- Rory.application = subject.instance
82
- end
83
- end
84
-
85
- describe ".respond_to?" do
86
- it 'returns true if the instance said so' do
87
- expect(subject.instance).to receive(:respond_to?).with(:goat).and_return(true)
88
- expect(subject.respond_to?(:goat)).to be_truthy
89
- end
90
-
91
- it 'does the usual thing if instance says no' do
92
- expect(subject.instance).to receive(:respond_to?).twice.and_return(false)
93
- expect(subject.respond_to?(:to_s)).to be_truthy
94
- expect(subject.respond_to?(:obviously_not_a_real_method)).to be_falsey
95
- end
96
- end
97
-
98
- describe ".dispatcher" do
99
- it "returns new dispatcher rack app" do
100
- allow(Rory::Dispatcher).to receive(:rack_app).
101
- with(subject).and_return(:dispatcher_app)
102
- expect(subject.dispatcher).to eq(:dispatcher_app)
103
- end
104
- end
105
-
106
- describe ".call" do
107
- it "calls the stack with the given environment" do
108
- stack = double
109
- allow(stack).to receive(:call).with(:the_env).and_return(:expected)
110
- expect(subject.instance).to receive(:stack).and_return(stack)
111
- expect(subject.call(:the_env)).to eq(:expected)
112
- end
113
- end
114
-
115
- describe ".log_file" do
116
- it "creates the log file directory if it does not exist" do
117
- file = double(:sync= => true)
118
- allow(File).to receive(:exists?).and_return(false)
119
- allow(Dir).to receive(:mkdir).and_return(true)
120
- allow(File).to receive(:open).and_return(file)
121
- expect(subject.log_file).to eq(file)
122
- end
123
-
124
- it "returns the file and does not create the log file directory if it does not exist" do
125
- file = double(:sync= => true)
126
- allow(File).to receive(:exists?).and_return(true)
127
- allow(File).to receive(:open).and_return(file)
128
- expect(subject.log_file).to eq(file)
129
- end
130
- end
131
-
132
- describe ".logger" do
133
- it "returns a logger" do
134
- logger = double
135
- allow_any_instance_of(subject).to receive(:log_file)
136
- allow(Logger).to receive(:new).and_return(logger)
137
- expect(subject.logger).to eq(logger)
138
- end
139
- end
140
-
141
- describe ".turn_off_request_logging!" do
142
- it "resets stack and turns off request logging" do
143
- subject.instance.instance_variable_set(:@request_logging, :true)
144
- expect(subject.request_logging_on?).to eq(true)
145
- expect(subject.instance).to receive(:reset_stack)
146
- subject.turn_off_request_logging!
147
- expect(subject.request_logging_on?).to eq(false)
148
- end
149
- end
150
-
151
- describe ".filter_parameters" do
152
- it "resets stack and sets parameters to filter" do
153
- expect(subject.instance).to receive(:reset_stack)
154
- subject.filter_parameters :dog, :kitty
155
- expect(subject.parameters_to_filter).to eq([:dog, :kitty])
156
- end
157
- end
158
-
159
- describe ".reset_stack" do
160
- it "clears memoization of stack" do
161
- stack = subject.stack
162
- expect(subject.stack).to eq(stack)
163
- subject.reset_stack
164
- expect(subject.stack).not_to eq(stack)
165
- end
166
- end
167
-
168
- describe ".stack" do
169
- it "returns a rack builder instance with configured middleware" do
170
- builder = double
171
- allow(subject.instance).to receive(:dispatcher).
172
- and_return(:the_dispatcher)
173
- allow(Rack::Builder).to receive(:new).and_return(builder)
174
- subject.use_middleware :horse
175
- expect(subject.instance).to receive(:request_middleware).with(no_args)
176
- expect(builder).to receive(:use).with(:horse)
177
- expect(builder).to receive(:run).with(:the_dispatcher)
178
- expect(subject.stack).to eq(builder)
179
- end
180
- end
181
-
182
- describe ".parameters_to_filter" do
183
- it "returns [:password] by default" do
184
- expect(subject.parameters_to_filter).to eq([:password])
185
- end
186
- end
187
-
188
- describe ".use_default_middleware" do
189
- it "adds middleware when request logging is on" do
190
- allow(subject.instance).to receive(:request_logging_on?).and_return(true)
191
- allow(subject.instance).to receive(:parameters_to_filter).and_return([:horses])
192
- allow(subject.instance).to receive(:logger).and_return(:the_logger)
193
- expect(subject.instance).to receive(:use_middleware).with(Rory::RequestId, :uuid_prefix => Rory::Support.tokenize(test_rory_app_name))
194
- expect(subject.instance).to receive(:use_middleware).with(Rack::PostBodyContentTypeParser)
195
- expect(subject.instance).to receive(:use_middleware).with(Rack::CommonLogger, :the_logger)
196
- expect(subject.instance).to receive(:use_middleware).with(Rory::RequestParameterLogger, :the_logger, :filters => [:horses])
197
- subject.request_middleware
198
- end
199
-
200
- it "does not add middleware when request logging is off" do
201
- allow(subject.instance).to receive(:request_logging_on?).and_return(false)
202
- expect(subject.instance).to receive(:use_middleware).never
203
- subject.request_middleware
204
- end
205
- end
206
-
207
- describe ".load_config_data" do
208
- it "returns parsed yaml file with given name from directory at config_path" do
209
- allow_any_instance_of(subject).to receive(:config_path).and_return('Africa the Great')
210
- allow(YAML).to receive(:load_file).with(
211
- File.expand_path(File.join('Africa the Great', 'foo_type.yml'))).
212
- and_return(:oscar_the_grouch_takes_a_nap)
213
- expect(subject.load_config_data(:foo_type)).to eq(:oscar_the_grouch_takes_a_nap)
214
- end
215
- end
216
-
217
- describe ".connect_db" do
218
- it "sets up sequel connection to DB from YAML file" do
219
- config = { 'development' => :expected }
220
- logger_array = []
221
- allow(subject.instance).to receive(:logger).and_return(:the_logger)
222
- allow(subject.instance).to receive(:load_config_data).with(:database).and_return(config)
223
- expect(Sequel).to receive(:connect).with(:expected).and_return(double(:loggers => logger_array))
224
- subject.connect_db('development')
225
- expect(logger_array).to match_array([:the_logger])
226
- end
227
- end
228
-
229
- describe ".spin_up" do
230
- it "connects the database" do
231
- expect_any_instance_of(Rory::Application).to receive(:connect_db)
232
- Rory::Application.spin_up
233
- end
234
- end
235
-
236
- describe '.auto_require_paths' do
237
- after(:each) do
238
- subject.instance.instance_variable_set(:@auto_require_paths, nil)
239
- end
240
-
241
- it 'includes initializers, models, controllers, and helpers by default' do
242
- expect(subject.auto_require_paths).to eq(['config/initializers', 'models', 'controllers', 'helpers'])
243
- end
244
-
245
- it 'accepts new paths' do
246
- subject.auto_require_paths << 'chocolates'
247
- expect(subject.auto_require_paths).to eq(['config/initializers', 'models', 'controllers', 'helpers', 'chocolates'])
248
- end
249
- end
250
-
251
- describe '.require_all_files' do
252
- it 'requires all files in auto_require_paths' do
253
- allow_any_instance_of(subject).to receive(:auto_require_paths).and_return(['goats', 'rhubarbs'])
254
- [:goats, :rhubarbs].each do |folder|
255
- expect(Rory::Support).to receive(:require_all_files_in_directory).
256
- with(Pathname.new(subject.root).join("#{folder}"))
257
- end
258
- subject.require_all_files
259
- end
260
- end
261
-
262
- describe '.use_middleware' do
263
- it 'adds the given middleware to the stack, retaining args and block' do
264
-
265
- subject.use_middleware DummyMiddleware, :puppy do |dm|
266
- dm.prefix = 'a salubrious'
267
- end
268
-
269
- expect(subject.instance).to receive(:dispatcher).
270
- and_return(dispatch_stack_mock = double)
271
- expect(dispatch_stack_mock).to receive(:call).
272
- with('a salubrious puppy')
273
- subject.call({})
274
- subject.middleware.clear
275
- end
276
- end
277
-
278
- context "with fixture application" do
279
- subject { Fixture::Application }
280
- describe ".routes" do
281
- it "generates a collection of routing objects from route configuration" do
282
- expect(subject.routes).to eq [
283
- Rory::Route.new('foo/:id/bar', :to => 'foo#bar', :methods => [:get, :post]),
284
- Rory::Route.new('this/:path/is/:very_awesome', :to => 'awesome#rad'),
285
- Rory::Route.new('lumpies/:lump', :to => 'lumpies#show', :methods => [:get], :module => 'goose'),
286
- Rory::Route.new('rabbits/:chew', :to => 'rabbits#chew', :methods => [:get], :module => 'goose/wombat'),
287
- Rory::Route.new('', :to => 'root#vegetable', :methods => [:get]),
288
- Rory::Route.new('', :to => 'root#no_vegetable', :methods => [:delete]),
289
- Rory::Route.new('for_reals/switching', :to => 'for_reals#switching', :methods => [:get]),
290
- Rory::Route.new('for_reals/:parbles', :to => 'for_reals#srsly', :methods => [:get])
291
- ]
292
- end
293
- end
294
-
295
- describe ".parameters_to_filter" do
296
- it "returns overridden parameters" do
297
- expect(subject.parameters_to_filter).to eq([:orcas, :noodles])
298
- end
299
- end
300
- end
301
-
302
- describe ".initializers" do
303
- describe ".insert_after" do
304
- it "inserts initializer before another" do
305
- probe = []
306
- Rory::Application.initializers.add("insert_after.A") { probe << "insert_after.A" }
307
- Rory::Application.initializers.add("insert_after.B") { probe << "insert_after.B" }
308
- Rory::Application.initializers.insert_after("insert_after.A", "insert_after.C") { probe << "insert_after.C" }
309
-
310
- expect { subject.run_initializers }.to change { probe }.from([]).
311
- to(%w(insert_after.A insert_after.C insert_after.B))
312
- end
313
- end
314
-
315
- describe ".add" do
316
- it "runs the code inside any initializer block" do
317
- probe = :initializers_not_run
318
- Rory::Application.initializers.add "add.test" do
319
- probe = :was_run
320
- end
321
- expect { subject.run_initializers }.to change { probe }.from(:initializers_not_run).to(:was_run)
322
- end
323
-
324
- it "passes the app instance to the block" do
325
- probe = :block_not_called
326
- Rory::Application.initializers.add "add.test_passes_app" do |app|
327
- probe = :block_called
328
- expect(app.class.superclass).to eq Rory::Application
329
- end
330
- expect { subject.run_initializers }.to change { probe }.from(:block_not_called).to(:block_called)
331
- end
332
- end
333
- end
334
-
335
- describe "#middleware" do
336
- before { subject.middleware.clear }
337
-
338
- describe "#insert_before" do
339
- it "places the middleware order right after the given class" do
340
- subject.instance.instance_variable_set(:@request_logging, :true)
341
- Rory::Application.initializers.add "insert_before.dummy_middleware" do |app|
342
- app.middleware.insert_before Rory::RequestId, DummyMiddleware, :puppy
343
- end
344
- subject.run_initializers
345
- expect(subject.middleware.map(&:klass)).to eq [DummyMiddleware,
346
- Rory::RequestId,
347
- Rack::PostBodyContentTypeParser,
348
- Rack::CommonLogger,
349
- Rory::RequestParameterLogger]
350
- end
351
- end
352
- end
353
- end