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,100 +0,0 @@
1
- describe Rory::RequestParameterLogger do
2
-
3
- let(:logger) { double(:write) }
4
- let(:app) { double(:call) }
5
- subject { described_class.new(app, logger, :filters => :filters) }
6
-
7
- describe '#initialize' do
8
- it 'returns a new RequestParameterLogger' do
9
- expect(subject).to be_an_instance_of(Rory::RequestParameterLogger)
10
- end
11
-
12
- it 'returns a new RequestParameterLogger with parameters' do
13
- expect(subject.instance_variable_get(:@app)).to eq(app)
14
- expect(subject.instance_variable_get(:@logger)).to eq(logger)
15
- expect(subject.instance_variable_get(:@filters)).to eq(:filters)
16
- end
17
-
18
- it 'defaults filters to empty array' do
19
- no_filter_logger = described_class.new(app, logger)
20
- expect(no_filter_logger.instance_variable_get(:@filters)).to eq([])
21
- end
22
- end
23
-
24
- describe '#log_request' do
25
-
26
- context 'when logger responds to write' do
27
- it 'writes the request to the logger' do
28
- allow(subject).to receive(:request_signature).and_return('request_signature')
29
- allow(subject).to receive(:filtered_params).and_return('filtered_params')
30
- expect(logger).to receive(:write).exactly(2).times
31
- subject.send(:log_request)
32
- end
33
- end
34
-
35
- context 'when logger does not respond to write' do
36
- let(:logger) { double(:info) }
37
- it 'writes the request to the logger' do
38
- allow(subject).to receive(:request_signature).and_return('request_signature')
39
- allow(subject).to receive(:filtered_params).and_return('filtered_params')
40
- expect(logger).to receive(:info).exactly(2).times
41
- subject.send(:log_request)
42
- end
43
- end
44
- end
45
-
46
- describe '#logger' do
47
- it 'returns @logger' do
48
- expect(subject.send(:logger)).to eq(logger)
49
- end
50
-
51
- it 'returns rack.errors ' do
52
- subject = described_class.new(:app)
53
- subject.instance_variable_set(:@env, {'rack.errors' => 'cocoa'})
54
- expect(subject.send(:logger)).to eq('cocoa')
55
- end
56
- end
57
-
58
- describe '#filtered_params' do
59
- it 'filters the params' do
60
- expect(Rory::ParameterFilter).to receive(:new).and_return(double(:filter => nil))
61
- expect(subject).to receive(:unfiltered_params)
62
- subject.send(:filtered_params)
63
- end
64
- end
65
-
66
- describe '#unfiltered_params' do
67
- it 'returns unfiltered params' do
68
- expect(Rack::Request).to receive(:new).and_return(double(:params => nil))
69
- subject.send(:unfiltered_params)
70
- end
71
- end
72
-
73
- describe '#request_signature' do
74
- it 'returns a request signature formatted string' do
75
- env = {
76
- 'REQUEST_METHOD' => "POST",
77
- 'PATH_INFO' => "/mushy_mushy",
78
- 'REMOTE_ADDR' => "127.0.0.1"
79
- }
80
-
81
- allow(Time).to receive(:now).and_return("2015-06-08 15:16:42 -0700")
82
- subject.instance_variable_set(:@env, env)
83
- expect(subject.send(:request_signature)).to eq('Started POST "/mushy_mushy" for 127.0.0.1 at 2015-06-08 15:16:42 -0700')
84
- end
85
- end
86
-
87
-
88
- describe '#call' do
89
- it 'writes the request and parameters to the log file' do
90
- env = {
91
- 'rack.input' => double(:rewind => nil)
92
- }
93
- expect(app).to receive(:call).with(env)
94
- expect(subject).to receive(:log_request)
95
-
96
- subject.call(env)
97
- expect(subject.instance_variable_get(:@env)).to eq(env)
98
- end
99
- end
100
- end
@@ -1,14 +0,0 @@
1
- RSpec.describe Rory::Request do
2
- describe "#uuid" do
3
- it "returns the value set by env['rory.request_id']" do
4
- env = { "rory.request_id" => "uuid-from_rory_request" }
5
- expect(described_class.new(env).uuid).to eq "uuid-from_rory_request"
6
- end
7
-
8
- context "when no key exists" do
9
- it "returns nil" do
10
- expect(described_class.new({}).uuid).to eq nil
11
- end
12
- end
13
- end
14
- end
@@ -1,15 +0,0 @@
1
- describe Rory::Route do
2
- describe '#name' do
3
- it 'returns concatenated controller and action' do
4
- route = described_class.new('/whatever', :to => 'pigeons#index')
5
- expect(route.name).to eq 'pigeons_index'
6
- end
7
- end
8
-
9
- describe "#path_params" do
10
- it "extracts params from path into hash" do
11
- route = described_class.new('/spoons/:spoon_id/forks/:fork_id', :to => 'cutlery#index')
12
- expect(route.path_params('spoons/4/forks/yay')).to eq({ :spoon_id => "4", :fork_id => "yay" })
13
- end
14
- end
15
- end
@@ -1,119 +0,0 @@
1
- describe Rory::Support do
2
- describe ".camelize" do
3
- it "camelizes given snake-case string" do
4
- expect(Rory::Support.camelize('water_under_bridge')).to eq('WaterUnderBridge')
5
- end
6
-
7
- it "leaves already camel-cased string alone" do
8
- expect(Rory::Support.camelize('OliverDrankGasoline')).to eq('OliverDrankGasoline')
9
- end
10
- end
11
-
12
- describe '.require_all_files_in_directory' do
13
- it 'requires all files from given path' do
14
- allow(Dir).to receive(:[]).with(Pathname.new('spinach').join('**', '*.rb')).
15
- and_return(["pumpkins", "some_guy_dressed_as_liberace"])
16
- expect(Rory::Support).to receive(:require).with("pumpkins")
17
- expect(Rory::Support).to receive(:require).with("some_guy_dressed_as_liberace")
18
- Rory::Support.require_all_files_in_directory('spinach')
19
- end
20
- end
21
-
22
- describe '.constantize' do
23
- before(:all) do
24
- Object.const_set('OrigamiDeliveryMan', Module.new)
25
- OrigamiDeliveryMan.const_set('UnderWhere', Module.new)
26
- OrigamiDeliveryMan::UnderWhere.const_set('Skippy', Module.new)
27
- end
28
-
29
- after(:all) do
30
- Object.send(:remove_const, :OrigamiDeliveryMan)
31
- end
32
-
33
- it 'returns constant from camelized name' do
34
- expect(Rory::Support.constantize('OrigamiDeliveryMan')).
35
- to eq(OrigamiDeliveryMan)
36
- end
37
-
38
- it 'returns constant from snake-case string' do
39
- expect(Rory::Support.constantize('origami_delivery_man')).
40
- to eq(OrigamiDeliveryMan)
41
- end
42
-
43
- it 'returns namespaced constant' do
44
- expect(Rory::Support.constantize(
45
- 'origami_delivery_man/under_where/skippy'
46
- )).to eq(OrigamiDeliveryMan::UnderWhere::Skippy)
47
- end
48
- end
49
-
50
- describe '.tokenize' do
51
- it 'creates snake_case version of string' do
52
- expect(described_class.tokenize('Albus Dumbledore & his_friend')).to eq('albus_dumbledore_and_his_friend')
53
- end
54
-
55
- it 'uncamelizes' do
56
- expect(described_class.tokenize('thisStrangeJavalikeWord')).to eq('this_strange_javalike_word')
57
- end
58
-
59
- it 'returns nil if given nil' do
60
- expect(described_class.tokenize(nil)).to be_nil
61
- end
62
-
63
- it 'also handles symbols' do
64
- expect(described_class.tokenize(:yourFaceIsNice)).to eq('your_face_is_nice')
65
- end
66
- end
67
-
68
- describe ".try_to_hash" do
69
- it "returns given object if it does not respond to #to_hash" do
70
- object = double
71
- expect(described_class.try_to_hash(object)).to eq(object)
72
- end
73
-
74
- it "calls to_hash first if object responds to it" do
75
- object = double(:to_hash => { 'april' => 'friday' })
76
- expect(described_class.try_to_hash(object)).to eq({ 'april' => 'friday' })
77
- end
78
-
79
- it "converts each member of an array" do
80
- object = [
81
- double(:to_hash => :smurf),
82
- double(:to_hash => :nerf)
83
- ]
84
- expect(described_class.try_to_hash(object)).to eq([:smurf, :nerf])
85
- end
86
-
87
- it "converts deeply" do
88
- object = [
89
- {
90
- :perf => double(:to_hash => :smurf),
91
- :kerf => [
92
- double(:to_hash => :plurf),
93
- 'yurf'
94
- ],
95
- :erf => { :burf => double(:to_hash => :wurf) }
96
- },
97
- double(:to_hash => :nerf)
98
- ]
99
- expect(described_class.try_to_hash(object)).to eq(
100
- [
101
- {
102
- :perf => :smurf,
103
- :kerf => [ :plurf, 'yurf' ],
104
- :erf => { :burf => :wurf }
105
- },
106
- :nerf
107
- ]
108
- )
109
- end
110
- end
111
-
112
- describe ".encode_as_json" do
113
- it "calls #try_to_hash on object then jsonifies" do
114
- foo_hashed = double(:to_json => :jsonified)
115
- allow(described_class).to receive(:try_to_hash).with(:foo).and_return(foo_hashed)
116
- expect(described_class.encode_as_json(:foo)).to eq(:jsonified)
117
- end
118
- end
119
- end
@@ -1,15 +0,0 @@
1
- describe Rory do
2
- let!(:new_app) { Class.new(Rory::Application) }
3
-
4
- describe '.application' do
5
- it 'is by default set to the Rory::Application instance' do
6
- expect(Rory.application).to eq(new_app.instance)
7
- end
8
- end
9
-
10
- describe '.root' do
11
- it 'returns root of application' do
12
- expect(Rory.root).to eq(new_app.root)
13
- end
14
- end
15
- end
@@ -1,27 +0,0 @@
1
- describe "Controller" do
2
- describe "presentation", :type => :feature do
3
- it 'renders default action template' do
4
- visit '/for_reals/pickles'
5
-
6
- expect(page).to have_text("You've done it again, pickles!")
7
- expect(page.status_code).to eq 200
8
- expect(page.response_headers['Content-Type']).to eq('text/html')
9
- end
10
-
11
- it 'renders json' do
12
- visit '/for_reals/switching.json'
13
-
14
- expect(page).to have_text({ :a => 1 }.to_json)
15
- expect(page.status_code).to eq 200
16
- expect(page.response_headers['Content-Type']).to eq('application/json')
17
- end
18
-
19
- it 'renders custom template' do
20
- visit '/for_reals/switching'
21
-
22
- expect(page).to have_text("Oh, a secret!")
23
- expect(page.status_code).to eq 404
24
- expect(page.response_headers['Content-Type']).to eq('text/html')
25
- end
26
- end
27
- end
@@ -1,25 +0,0 @@
1
- require 'simplecov'
2
- SimpleCov.start
3
-
4
- ENV['RORY_ENV'] = 'test'
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'rspec'
8
- require 'capybara/rspec'
9
- require 'rory'
10
- require 'rack'
11
-
12
- # Requires supporting files with custom matchers and macros, etc,
13
- # in ./support/ and its subdirectories.
14
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
15
-
16
- require_relative 'fixture_app/config/application'
17
- Fixture::Application.root = File.join(File.dirname(__FILE__), 'fixture_app')
18
- Fixture::Application.require_all_files
19
-
20
- Capybara.app = Fixture::Application
21
-
22
- RSpec.configure do |config|
23
- config.order = "random"
24
- config.include GenerationHelpers
25
- end
@@ -1,19 +0,0 @@
1
- module GenerationHelpers
2
- def sandbox_directory
3
- Pathname.new(
4
- File.join(File.dirname(__FILE__), "..", "sandbox")
5
- )
6
- end
7
-
8
- def capture_output
9
- begin
10
- $stdout = StringIO.new
11
- yield
12
- result = $stdout.string
13
- ensure
14
- $stdout = STDOUT
15
- end
16
-
17
- result
18
- end
19
- end
@@ -1,27 +0,0 @@
1
- RSpec.configure do |c|
2
- c.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:'
3
- end
4
-
5
- shared_examples 'path_generation' do
6
- describe '#path_to' do
7
- it 'returns mask from route with given name prepended with root slash' do
8
- allow(path_generator).to receive(:base_path).and_return(nil)
9
- expect(path_generator.path_to('awesome_rad')).
10
- to eq '/this/:path/is/:very_awesome'
11
- end
12
-
13
- it 'prepends base_path to returned mask' do
14
- allow(path_generator).to receive(:base_path).and_return('/strawminos')
15
- expect(path_generator.path_to('awesome_rad')).
16
- to eq '/strawminos/this/:path/is/:very_awesome'
17
- end
18
-
19
- it 'substitutes tokens with given fields' do
20
- allow(path_generator).to receive(:base_path).and_return('/strawminos')
21
- expect(path_generator.path_to('awesome_rad', :path => 'house', :very_awesome => 352)).
22
- to eq '/strawminos/this/house/is/352'
23
- end
24
- end
25
- end
26
-
27
-