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
@@ -1,16 +0,0 @@
1
- require "rory/cli"
2
-
3
- RSpec.describe Rory::CLI::Generate do
4
- describe "#app" do
5
- it "starts Generators::Application" do
6
- proxy = instance_double(Rory::CLI::Generators::Application)
7
- allow(proxy).to receive(:parent_options=).with({})
8
- allow(Rory::CLI::Generators::Application).to receive(:new).
9
- with(["frog"], any_args).
10
- and_return(proxy)
11
-
12
- expect(proxy).to receive(:invoke_all)
13
- subject.app("frog")
14
- end
15
- end
16
- end
@@ -1,35 +0,0 @@
1
- require "rory/cli"
2
-
3
- describe Rory::CLI::Generators::Application do
4
- let(:options) { {} }
5
- let(:args) { ["an app"] }
6
- subject { described_class.new(args, options, :destination_root => sandbox_directory) }
7
-
8
- after(:each) do
9
- FileUtils.rm_rf sandbox_directory
10
- end
11
-
12
- context "with default options" do
13
- it "generates a new application directory with no optional files" do
14
- capture_output { subject.invoke_all }
15
- expect(sandbox_directory.join("an_app")).to be_a_directory
16
- expect(sandbox_directory.join("an_app", "config.ru")).to be_a_file
17
- expect(sandbox_directory.join("an_app", ".rspec")).not_to be_a_file
18
- end
19
-
20
- it "logs the output" do
21
- result = capture_output { subject.invoke_all }
22
- expect(result).to include("create an_app")
23
- end
24
- end
25
-
26
- context "with default options" do
27
- let(:options) { { rspec: true } }
28
-
29
- it "adds rspec files" do
30
- capture_output { subject.invoke_all }
31
- expect(sandbox_directory.join("an_app", ".rspec")).to be_a_file
32
- expect(sandbox_directory.join("an_app", "spec", "spec_helper.rb")).to be_a_file
33
- end
34
- end
35
- end
@@ -1,30 +0,0 @@
1
- require "rory/cli"
2
-
3
- RSpec.describe Rory::CLI::Root do
4
- describe "#version" do
5
- it "says the current Rory VERSION constant" do
6
- expect(subject).to receive(:say).with("rory #{Rory::VERSION}")
7
- subject.version
8
- end
9
- end
10
-
11
- describe "#generate" do
12
- it "delegates to generate" do
13
- expect(Rory::CLI::Root.subcommand_classes["generate"]).
14
- to eq(Rory::CLI::Generate)
15
- end
16
- end
17
-
18
- describe "#new" do
19
- it "starts Generators::Application" do
20
- proxy = instance_double(Rory::CLI::Generators::Application)
21
- allow(proxy).to receive(:parent_options=).with({})
22
- allow(Rory::CLI::Generators::Application).to receive(:new).
23
- with(["frog"], any_args).
24
- and_return(proxy)
25
-
26
- expect(proxy).to receive(:invoke_all)
27
- subject.new("frog")
28
- end
29
- end
30
- end
@@ -1,10 +0,0 @@
1
- require "rory/cli"
2
-
3
- RSpec.describe Rory::CLI do
4
- describe "#start" do
5
- it "delegates to Root class" do
6
- allow(Rory::CLI::Root).to receive(:start).and_return(:started)
7
- expect(described_class.start).to eq :started
8
- end
9
- end
10
- end
@@ -1,261 +0,0 @@
1
- describe Rory::Controller do
2
- subject { Rory::Controller.new(@request, @routing) }
3
-
4
- before :each do
5
- @routing = {
6
- :route => Rory::Route.new('', :to => 'test#letsgo')
7
- }
8
-
9
- @request = double('Rack::Request', {
10
- :params => { 'violet' => 'invisibility', :dash => 'superspeed' },
11
- :script_name => 'script_root'
12
- })
13
- end
14
-
15
- it_has_behavior 'path_generation' do
16
- let(:path_generator) {
17
- Rory::Controller.new(@request, @routing, Fixture::Application)
18
- }
19
- end
20
-
21
- describe '#layout' do
22
- it 'defaults to nil' do
23
- expect(subject.layout).to be_nil
24
- end
25
- end
26
-
27
- describe '#params' do
28
- it 'returns params from request, converted for indifferent key access' do
29
- expect(subject.params).to eq({
30
- 'violet' => 'invisibility',
31
- 'dash' => 'superspeed',
32
- :violet => 'invisibility',
33
- :dash => 'superspeed'
34
- })
35
- end
36
- end
37
-
38
- describe "#redirect" do
39
- it "delegates to dispatcher from request" do
40
- @routing[:dispatcher] = dispatcher = double
41
- expect(dispatcher).to receive(:redirect).with(:whatever)
42
- subject.redirect(:whatever)
43
- end
44
- end
45
-
46
- describe "#render_not_found" do
47
- it "delegates to dispatcher from request" do
48
- @routing[:dispatcher] = dispatcher = double
49
- expect(dispatcher).to receive(:render_not_found)
50
- subject.render_not_found
51
- end
52
- end
53
-
54
- describe "#base_path" do
55
- it "returns script_name from request" do
56
- expect(subject.base_path).to eq 'script_root'
57
- end
58
- end
59
-
60
- describe "#present" do
61
- context "with filters" do
62
- subject { FilteredController.new(@request, @routing) }
63
-
64
- it "calls filters and action from route if exists on controller" do
65
- [:pickle_something, :make_it_tasty, :letsgo, :rub_tummy, :sleep, :render].each do |m|
66
- expect(subject).to receive(m).ordered
67
- end
68
- subject.present
69
- end
70
-
71
- context "on sub-subclass" do
72
- let(:grandchild) { Class.new(FilteredController) }
73
- let(:greatgrandchild) { Class.new(grandchild) }
74
- subject { greatgrandchild.new(@request, @routing) }
75
-
76
- it "assembles list of all filter actions from ancestry" do
77
- grandchild.before_action :do_a_jig
78
- greatgrandchild.before_action :take_a_deep_breath
79
-
80
- [:pickle_something, :make_it_tasty, :do_a_jig, :take_a_deep_breath, :letsgo, :rub_tummy, :sleep, :render].each do |m|
81
- expect(subject).to receive(m).ordered
82
- end
83
- subject.present
84
- end
85
- end
86
-
87
- it "short circuits if a before_action generates a response" do
88
- def subject.pickle_something
89
- @response = 'stuff'
90
- end
91
- [:make_it_tasty, :letsgo, :rub_tummy, :sleep, :render].each do |m|
92
- expect(subject).to receive(m).never
93
- end
94
- subject.present
95
- end
96
-
97
- it "does not short circuit after_actions if action generates response" do
98
- def subject.letsgo
99
- @response = 'stuff'
100
- end
101
- expect(subject).to receive(:pickle_something).ordered
102
- expect(subject).to receive(:make_it_tasty).ordered
103
- expect(subject).to receive(:letsgo).ordered.and_call_original
104
- expect(subject).to receive(:rub_tummy).ordered
105
- expect(subject).to receive(:sleep).ordered
106
- expect(subject).to receive(:render).never
107
- subject.present
108
- end
109
-
110
- it "doesn't try to call action from route if nonexistent on controller" do
111
- allow(@routing[:route]).to receive(:action).and_return('no worries')
112
- [:pickle_something, :make_it_tasty, :rub_tummy, :sleep, :render].each do |m|
113
- expect(subject).to receive(m).ordered
114
- end
115
- expect { subject.present }.not_to raise_error
116
- end
117
-
118
- it "filters before and after actions on :only and :except" do
119
- @routing[:route] = Rory::Route.new('', :to => 'test#eat')
120
- expect(subject).to receive(:make_it_tasty).ordered
121
- expect(subject).to receive(:make_it_nutritious).ordered
122
- expect(subject).to receive(:eat).ordered
123
- expect(subject).to receive(:rub_tummy).ordered
124
- expect(subject).to receive(:smile).ordered
125
- expect(subject).to receive(:sleep).never
126
- expect(subject).to receive(:render).ordered
127
- subject.present
128
- end
129
-
130
- it "filters before and after actions on :if and :unless" do
131
- @routing[:route] = Rory::Route.new('', :to => 'test#eat')
132
- @request = double('Rack::Request', {
133
- :params => { 'horses' => 'missing' },
134
- :script_name => 'script_root'
135
- })
136
- expect(subject).to receive(:make_it_tasty).never
137
- expect(subject).to receive(:make_it_nutritious).ordered
138
- expect(subject).to receive(:eat).ordered
139
- expect(subject).to receive(:rub_tummy).never
140
- expect(subject).to receive(:smile).ordered
141
- expect(subject).to receive(:sleep).never
142
- expect(subject).to receive(:render).ordered
143
- subject.present
144
- end
145
- end
146
-
147
- it "just returns a response if @response exists" do
148
- subject.instance_variable_set(:@response, 'Forced response')
149
- expect(subject.present).to eq('Forced response')
150
- end
151
-
152
- it "sends a previously set @body to render" do
153
- subject.instance_variable_set(:@body, 'Forced body')
154
- allow(subject).to receive(:render).with(:body => 'Forced body').and_return("Forced response")
155
- expect(subject.present).to eq('Forced response')
156
- end
157
-
158
- it "returns the result of render" do
159
- allow(subject).to receive(:render).with(:body => nil).and_return("The response")
160
- expect(subject.present).to eq('The response')
161
- end
162
- end
163
-
164
- describe "#render" do
165
- it "returns the result of #generate_body_for_render as a rack response" do
166
- allow(subject).to receive(:default_content_type).and_return("a prison")
167
- allow(subject).to receive(:generate_for_render).and_return("Valoop!")
168
- expect(subject.render).to eq([
169
- 200,
170
- {'Content-type' => 'a prison', 'charset' => 'UTF-8'},
171
- ["Valoop!"]
172
- ])
173
- end
174
-
175
- it "returns given body as a rack response" do
176
- allow(subject).to receive(:default_content_type).and_return("snooj/woz")
177
- expect(subject.render(:body => 'Forced body')).to eq([
178
- 200,
179
- {'Content-type' => 'snooj/woz', 'charset' => 'UTF-8'},
180
- ["Forced body"]
181
- ])
182
- end
183
- end
184
-
185
- describe "#json_requested?" do
186
- it "delegates to dispatcher" do
187
- allow(subject).to receive(:dispatcher).and_return(double(:json_requested? => :snakes))
188
- expect(subject.json_requested?).to eq(:snakes)
189
- end
190
- end
191
-
192
- describe "#generate_for_render" do
193
- it "renders and returns the default template if not json" do
194
- allow(subject).to receive(:generate_body_from_template).with("test/letsgo", {}).and_return("Whee")
195
- expect(subject.generate_for_render).to eq("Whee")
196
- end
197
-
198
- it "renders and returns the given template if not json" do
199
- allow(subject).to receive(:generate_body_from_template).with("engines", {}).and_return("Oh dear")
200
- expect(subject.generate_for_render(:template => 'engines')).to eq("Oh dear")
201
- end
202
-
203
- it "returns json version of given json object if json" do
204
- allow(subject).to receive(:generate_json_from_object).with(:an_object, {}).and_return("Oh dear")
205
- expect(subject.generate_for_render(:json => :an_object)).to eq("Oh dear")
206
- end
207
- end
208
-
209
- describe "#generate_json_from_object" do
210
- it "encodes given object as json" do
211
- allow(Rory::Support).to receive(:encode_as_json).with(:foo).and_return(:encoded_foo)
212
- expect(subject.generate_json_from_object(:foo)).to eq(:encoded_foo)
213
- end
214
- end
215
-
216
- describe "#generate_body_from_template" do
217
- it "returns rendered template with given name" do
218
- expect(subject.generate_body_from_template('test/letsgo', :app => Fixture::Application)).to eq("Let's go content")
219
- end
220
-
221
- it "returns renderer output" do
222
- allow(Rory::Renderer).to receive(:new).
223
- with('not/real', subject.default_renderer_options).
224
- and_return(double('Renderer', :render => 'Here ya go'))
225
- expect(subject.generate_body_from_template('not/real')).to eq('Here ya go')
226
- end
227
-
228
- it "passes layout, exposed locals, and app to renderer" do
229
- subject = Rory::Controller.new(@request, @routing, :scooby)
230
- subject.expose(:a => 1)
231
- allow(subject).to receive(:layout).and_return('pretend')
232
- renderer_options = {
233
- :layout => 'pretend',
234
- :locals => { :a => 1 },
235
- :app => :scooby,
236
- :base_path => 'script_root'
237
- }
238
- allow(Rory::Renderer).to receive(:new).
239
- with('also/fake', renderer_options).
240
- and_return(double('Renderer', :render => 'Scamazing!'))
241
- expect(subject.generate_body_from_template('also/fake')).to eq('Scamazing!')
242
- end
243
- end
244
-
245
- describe "#default_content_type" do
246
- it "returns 'text/html' if not json" do
247
- allow(subject).to receive(:json_requested?).and_return(false)
248
- expect(subject.default_content_type).to eq('text/html')
249
- end
250
-
251
- it "returns 'application/json' if json requested" do
252
- allow(subject).to receive(:json_requested?).and_return(true)
253
- expect(subject.default_content_type).to eq('application/json')
254
- end
255
-
256
- it "returns 'application/json' if options has :json key" do
257
- allow(subject).to receive(:json_requested?).and_return(false)
258
- expect(subject.default_content_type(:json => 'woo')).to eq('application/json')
259
- end
260
- end
261
- end
@@ -1,187 +0,0 @@
1
- describe Rory::Dispatcher do
2
- subject { Rory::Dispatcher.new(request, Fixture::Application) }
3
- let(:request) { {} }
4
-
5
- describe "#extension" do
6
- it "returns the extension of the path requested" do
7
- allow(subject).to receive(:full_path).and_return("whatever/nerds.pickles")
8
- expect(subject.extension).to eq("pickles")
9
- end
10
-
11
- it "returns nil if no extension" do
12
- allow(subject).to receive(:full_path).and_return("whatever/nerds")
13
- expect(subject.extension).to be_nil
14
- end
15
- end
16
-
17
- describe "#path_without_extension" do
18
- it "returns path with extension removed" do
19
- allow(subject).to receive(:full_path).and_return("whatever/nerds.pickles")
20
- expect(subject.path_without_extension).to eq("whatever/nerds")
21
- end
22
-
23
- it "returns path unchanged if no extension" do
24
- allow(subject).to receive(:full_path).and_return("whatever/nerds")
25
- expect(subject.path_without_extension).to eq("whatever/nerds")
26
- end
27
- end
28
-
29
- describe "#json_requested?" do
30
- it "returns true if extension is 'json'" do
31
- allow(subject).to receive(:extension).and_return("json")
32
- expect(subject.json_requested?).to be_truthy
33
- end
34
-
35
- it "returns false if extension is not 'json'" do
36
- allow(subject).to receive(:extension).and_return("pachyderms")
37
- expect(subject.json_requested?).to be_falsey
38
- end
39
- end
40
-
41
- describe "#redirect" do
42
- it "redirects to given path if path has scheme" do
43
- redirection = subject.redirect('http://example.example')
44
- expect(redirection[0..1]).to eq([
45
- 302, {'Content-type' => 'text/html', 'Location'=> 'http://example.example' }
46
- ])
47
- end
48
-
49
- it "adds request host and scheme and redirects if path has no scheme" do
50
- allow(request).to receive_messages('scheme' => 'happy', 'host_with_port' => 'somewhere.yay')
51
- redirection = subject.redirect('/example')
52
- expect(redirection[0..1]).to eq([
53
- 302, {'Content-type' => 'text/html', 'Location'=> 'happy://somewhere.yay/example' }
54
- ])
55
- end
56
- end
57
-
58
- describe ".rack_app" do
59
- it "returns a callable object that dispatches to a new dispatcher" do
60
- allow(Rack::Request).to receive(:new).with(:env).and_return(:a_request)
61
- allow(described_class).to receive(:new).with(:a_request, :the_app).and_return(subject)
62
- allow(subject).to receive(:dispatch).and_return(:the_dispatch)
63
- expect(described_class.rack_app(:the_app).call(:env)).to eq(:the_dispatch)
64
- end
65
- end
66
-
67
- describe "#dispatch" do
68
- let(:request) { { :whatever => :yay } }
69
- before(:each) do
70
- allow(request).to receive_messages(:path_info => '/', :request_method => 'GET', :params => {})
71
- end
72
-
73
- it "renders a 404 if the requested path is invalid" do
74
- allow(subject).to receive(:get_route).and_return(nil)
75
- expect(subject.dispatch[0..1]).to eq([404, {"Content-type"=>"text/html"}])
76
- end
77
-
78
- it "instantiates a controller with the parsed request and calls present" do
79
- route = Rory::Route.new('', :to => 'stub#index')
80
- allow(subject).to receive(:get_route).and_return(route)
81
- expect(subject.dispatch).to eq({
82
- :whatever => :yay,
83
- :present_called => true # see StubController in /spec/fixture_app
84
- })
85
- end
86
-
87
- it "dispatches properly to a scoped controller" do
88
- route = Rory::Route.new('', :to => 'lumpies#index', :module => 'goose')
89
- allow(subject).to receive(:get_route).and_return(route)
90
- expect(subject.dispatch).to eq({
91
- :whatever => :yay,
92
- :in_scoped_controller => true # see Goose::LumpiesController in /spec/fixture_app
93
- })
94
- end
95
-
96
- it "dispatches properly to a nested scoped controller" do
97
- route = Rory::Route.new('', :to => 'rabbits#index', :module => 'goose/wombat')
98
- allow(subject).to receive(:get_route).and_return(route)
99
- expect(subject.dispatch).to eq({
100
- :whatever => :yay,
101
- :in_scoped_controller => true # see Goose::Wombat::RabbitsController in /spec/fixture_app
102
- })
103
- end
104
- end
105
-
106
- describe "#route" do
107
- before(:each) do
108
- allow(request).to receive_messages(:params => {})
109
- end
110
-
111
- it "returns route from request if already set" do
112
- subject.instance_variable_set(:@routing, { :route => 'snaky pigeons' })
113
- expect(subject.route).to eq('snaky pigeons')
114
- end
115
-
116
- it "matches the path from the request to the routes table" do
117
- allow(request).to receive_messages(:path_info => '/foo/3/bar', :request_method => 'GET')
118
- expect(subject.route).to eq Rory::Route.new('/foo/:id/bar', {
119
- :to => 'foo#bar',
120
- :methods => [:get, :post]
121
- })
122
- end
123
-
124
- it "ignores extensions when matching path to routes table" do
125
- allow(request).to receive_messages(:path_info => '/foo/3/bar.csv', :request_method => 'GET')
126
- expect(subject.extension).to eq('csv')
127
- expect(subject.route).to eq Rory::Route.new('/foo/:id/bar', {
128
- :to => 'foo#bar',
129
- :methods => [:get, :post]
130
- })
131
- end
132
-
133
- it "uses override method from params if exists" do
134
- allow(request).to receive_messages(:path_info => '/', :params => { '_method' => 'delete' }, :request_method => 'PUT')
135
- expect(subject.route).to eq Rory::Route.new('/', {
136
- :to => 'root#no_vegetable',
137
- :methods => [:delete]
138
- })
139
- end
140
-
141
- it "deletes override method from params" do
142
- allow(request).to receive_messages(:path_info => '/', :params => { '_method' => 'delete', 'goats' => 'not_sheep' }, :request_method => 'PUT')
143
- subject.route
144
- expect(request.params).to eq('goats' => 'not_sheep')
145
- end
146
-
147
- it "works with empty path" do
148
- allow(request).to receive_messages(:path_info => '', :request_method => 'GET')
149
- expect(subject.route).to eq Rory::Route.new('/', {
150
- :to => 'root#vegetable',
151
- :methods => [:get]
152
- })
153
- end
154
-
155
- it "works with root url represented by slash" do
156
- allow(request).to receive_messages(:path_info => '/', :request_method => 'GET')
157
- expect(subject.route).to eq Rory::Route.new('/', {
158
- :to => 'root#vegetable',
159
- :methods => [:get]
160
- })
161
- end
162
-
163
- it "returns nil if no route found" do
164
- allow(request).to receive_messages(:path_info => '/umbrellas', :request_method => 'GET')
165
- expect(subject.route).to be_nil
166
- end
167
-
168
- it "returns nil if no context" do
169
- subject = Rory::Dispatcher.new(request)
170
- expect(subject.route).to be_nil
171
- end
172
-
173
- it "returns nil if route found but method is not allowed" do
174
- allow(request).to receive_messages(:path_info => '/foo', :request_method => 'GET')
175
- expect(subject.route).to be_nil
176
- end
177
-
178
- it "assigns named matches to params hash" do
179
- allow(request).to receive_messages(:path_info => '/this/some-thing_or-other/is/wicked', :request_method => 'GET')
180
- expect(subject.route).to eq Rory::Route.new('/this/:path/is/:very_awesome', {
181
- :to => 'awesome#rad'
182
- })
183
-
184
- expect(request.params).to eq({:path=>"some-thing_or-other", :very_awesome=>"wicked"})
185
- end
186
- end
187
- end