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,77 +0,0 @@
1
- RSpec.describe Rory::Initializers do
2
-
3
- describe "#unshift" do
4
- it "adds an item to the front" do
5
- subject.unshift("test.1unshift") {}
6
- subject.unshift("test.2unshift") {}
7
- expect(subject.initializers.map(&:name)).to eq %w(test.2unshift test.1unshift)
8
- end
9
- end
10
-
11
- describe "#insert" do
12
- it "adds an item before another" do
13
- subject.add("test.1insert") {}
14
- subject.insert("test.1insert", "test.2insert") {}
15
- expect(subject.initializers.map(&:name)).to eq %w(test.2insert test.1insert)
16
- end
17
- end
18
-
19
- describe "#insert_before" do
20
- it "adds an item before another" do
21
- subject.add("test.1insert_before") {}
22
- subject.insert_before("test.1insert_before", "test.2insert_before") {}
23
- expect(subject.initializers.map(&:name)).to eq %w(test.2insert_before test.1insert_before)
24
- end
25
- end
26
-
27
- describe "#insert_after" do
28
- it "adds an item at certain point after a given initializer" do
29
- subject.add("test.1insert_after") {}
30
- subject.add("test.2insert_after") {}
31
- subject.insert_after("test.1insert_after", "test.3insert_after") {}
32
- expect(subject.initializers.map(&:name)).to eq %w(test.1insert_after test.3insert_after test.2insert_after)
33
- end
34
- end
35
-
36
- describe "#delete" do
37
- it "removes a given initializer from loading" do
38
- subject.add("test.delete") {}
39
- subject.delete("test.delete")
40
- expect(subject.initializers.map(&:name)).to eq []
41
- end
42
- end
43
-
44
- describe "#add" do
45
- it "push an item on the list to be loaded" do
46
- subject.add("test.1add") {}
47
- subject.add("test.2add") {}
48
- expect(subject.initializers.map(&:name)).to eq %w(test.1add test.2add)
49
- end
50
-
51
- context "when two initializers have the same name" do
52
- it "raises an error" do
53
- subject.add("same_name_test") {}
54
- expect{subject.add("same_name_test") {}}.to raise_error(/Initializer name: 'same_name_test' is already used./)
55
- end
56
- end
57
- end
58
-
59
- describe "#run" do
60
- it "runs the initializers when given an app" do
61
- probe = :block_not_run
62
- subject.add("test.1add") { |app| probe = app }
63
- subject.run(:this_is_the_app)
64
- expect(probe).to eq :this_is_the_app
65
- end
66
- end
67
-
68
- context "delegated array methods" do
69
- [:each, :clear, :size, :last, :first].each do |meth|
70
- it "##{meth}" do
71
- expect(subject.initializers).to receive(meth)
72
- subject.public_send(meth)
73
- end
74
- end
75
- end
76
- end
77
-
@@ -1,90 +0,0 @@
1
- require "logger"
2
- require "thread/inheritable_attributes"
3
- require "rory/logger"
4
-
5
- describe Rory::Logger do
6
- subject { described_class.new(string_io) }
7
- let(:string_io) { StringIO.new }
8
- let(:result) { string_io.tap(&:rewind).read }
9
-
10
- let(:simple_format) {
11
- subject.formatter = Proc.new do |severity, _, _, msg, tagged|
12
- "#{severity} #{tagged} - #{msg}"
13
- end
14
- }
15
-
16
- let(:rory_request_id) { "1111-2222" }
17
-
18
- before { Thread.current[:inheritable_attributes] = {:rory_request_id => rory_request_id} }
19
- after { Thread.current[:inheritable_attributes] = nil }
20
-
21
- context "when tagged is empty" do
22
- subject { described_class.new(string_io, tagged: []) }
23
- it "does not tag anything" do
24
- simple_format
25
- subject.<< "Hello"
26
- expect(result).to eq "Hello"
27
- end
28
- end
29
-
30
- context "creating custom tags" do
31
- subject { described_class.new(string_io, tagged: [:custom_tag, :request_id]) }
32
- it "needs an instance method go along with new tag" do
33
- def subject.custom_tag
34
- "Words.."
35
- end
36
- simple_format
37
- subject.<< "Hello"
38
- expect(result).to eq "custom_tag=Words.. request_id=1111-2222 Hello"
39
- end
40
- end
41
-
42
- describe "#<<" do
43
- it "tags are present with this form" do
44
- simple_format
45
- subject.<< "Hello"
46
- expect(result).to eq "request_id=1111-2222 Hello"
47
- end
48
- end
49
-
50
- context "when a tagged values has spaces" do
51
- let(:rory_request_id) { "1111 2222" }
52
- it "is quoted" do
53
- simple_format
54
- subject.<< "Good Morning"
55
- expect(result).to eq 'request_id="1111 2222" Good Morning'
56
- end
57
- end
58
-
59
- describe "#info" do
60
- it "severity level is set to INFO" do
61
- simple_format
62
- subject.info "Hello"
63
- expect(result).to eq "INFO request_id=1111-2222 - Hello"
64
- end
65
- end
66
-
67
- describe "#formatter" do
68
- it "define a custom formatting" do
69
- subject.formatter = Proc.new do |_, _, _, msg, tagged|
70
- "This is formatted: #{tagged} - #{msg}"
71
- end
72
- subject.info "Hello"
73
- expect(result).to eq "This is formatted: request_id=1111-2222 - Hello"
74
- end
75
-
76
- it "has default formatting" do
77
- subject.info "Goodbye"
78
- expect(result).to match /request_id=1111-2222.*INFO -- : Goodbye\n/
79
- end
80
- end
81
-
82
- describe "integration with Rack::CommonLogger" do
83
- it "only prepends tags" do
84
- [200, { "REMOTE_ADDR" => "127.0.0.1", "HTTP_VERSION" => "1.1" }, ""]
85
- Rack::CommonLogger.new(Proc.new { |a| a }, subject).send(:log, { "REMOTE_ADDR" => "127.0.0.1", "HTTP_VERSION" => "1.1", Rack::QUERY_STRING => "abc" }, 200, {}, 1)
86
- "I, [1111-2222 - 2016-01-20T16:30:52.193516 #5341] INFO -- : 127.0.0.1 - - [20/Jan/2016:16:30:52 -0800] \" ?abc 1.1\" 200 - 1453336251.1934\n\n"
87
- expect(result).to match /request_id=1111-2222 127.0.0.1 - - /
88
- end
89
- end
90
- end
@@ -1,86 +0,0 @@
1
- RSpec.describe Rory::MiddlewareStack do
2
-
3
- let(:middleware_order) { subject.middlewares.map(&:klass).map(&:name) }
4
-
5
- describe "#unshift" do
6
- it "adds an item to the front" do
7
- subject.unshift(double(name: "unshift1")) {}
8
- subject.unshift(double(name: "unshift2"), 1, 2)
9
-
10
- expect(middleware_order).to eq %w(unshift2 unshift1)
11
- end
12
- end
13
-
14
- describe "#insert" do
15
- it "adds an item to the end" do
16
- insert1 = (double(name: "insert1"))
17
- subject.use(insert1) {}
18
- subject.insert(insert1, double(name: "insert2"), 1, 2)
19
-
20
- expect(middleware_order).to eq %w(insert2 insert1)
21
- end
22
- end
23
-
24
- describe "#insert_before" do
25
- it "adds an item to the end" do
26
- insert1 = (double(name: "insert_before1"))
27
- subject.use(insert1) {}
28
- subject.insert(insert1, double(name: "insert_before2"), 1, 2)
29
-
30
- expect(middleware_order).to eq %w(insert_before2 insert_before1)
31
- end
32
- end
33
-
34
- describe "#insert_after" do
35
- it "adds an item at certain point after a given middleware" do
36
- insert_after1 = double(name: "test.1insert_after")
37
- subject.use(insert_after1) {}
38
- subject.use(double(name: "test.2insert_after")) {}
39
- subject.insert_after(insert_after1, double(name: "test.3insert_after")) {}
40
- expect(middleware_order).to eq %w(test.1insert_after test.3insert_after test.2insert_after)
41
- end
42
- end
43
-
44
- describe "#delete" do
45
- it "removes a given middleware from loading" do
46
- test_delete = double(name: "delete")
47
- subject.use(test_delete)
48
- subject.delete(test_delete)
49
- expect(middleware_order).to eq []
50
- end
51
- end
52
-
53
- describe "#use" do
54
- it "push an item on the list to be loaded" do
55
- subject.use(double(name: "use1")) {}
56
- subject.use(double(name: "use2"), 1, 2)
57
-
58
- expect(middleware_order).to eq %w(use1 use2)
59
- end
60
-
61
- it "arguments will be saved" do
62
- subject.use(double(name: "use1")) {}
63
- subject.use(double(name: "use2"), 1, 2)
64
-
65
- expect(subject.middlewares.map(&:args)).to eq [[], [1, 2]]
66
- end
67
-
68
- it "blocks will be saved" do
69
- probe = :block_not_called
70
- subject.use(double(name: "use1")) {probe = :block_called}
71
- subject.use(double(name: "use2"), 1, 2)
72
- subject.middlewares.map(&:block).compact.map(&:call)
73
- expect(probe).to eq :block_called
74
- end
75
- end
76
-
77
- context "delegated array methods" do
78
- [:each, :clear, :size, :last, :first].each do |meth|
79
- it "##{meth}" do
80
- expect(subject.middlewares).to receive(meth)
81
- subject.public_send(meth)
82
- end
83
- end
84
- end
85
- end
86
-
@@ -1,50 +0,0 @@
1
- describe Rory::ParameterFilter do
2
-
3
- describe '#initialize' do
4
- it 'sets the filters' do
5
- expect(subject.instance_variable_get(:@filters)).to eq []
6
- end
7
- end
8
-
9
- describe '#filter' do
10
- it 'returns params unchanged' do
11
- unfiltered_params = {"address"=>"11802 MCDONALD ST, Los Angeles, CA 90230",
12
- "owners"=>[{"first_name"=>"GOLD", "last_name"=>"PATH", "ssn"=>"000-02-9999"}],
13
- "overrides"=>{"ofac_7403"=>"clear"}}
14
-
15
- expect(subject.filter(unfiltered_params)).to eq unfiltered_params
16
- end
17
-
18
- it 'returns params filtered by' do
19
- subject = described_class.new([:ssn])
20
- unfiltered_params = {"address"=>"11802 MCDONALD ST, Los Angeles, CA 90230",
21
- "owners"=>[{"first_name"=>"GOLD", "last_name"=>"PATH", "ssn"=>"000-02-9999"}],
22
- "overrides"=>{"ofac_7403"=>"clear"}}
23
-
24
- filtered_params = {"address"=>"11802 MCDONALD ST, Los Angeles, CA 90230",
25
- "owners"=>[{"first_name"=>"GOLD", "last_name"=>"PATH", "ssn"=>"[FILTERED]"}],
26
- "overrides"=>{"ofac_7403"=>"clear"}}
27
-
28
-
29
- expect(subject.filter(unfiltered_params)).to eq filtered_params
30
- end
31
-
32
- it 'filters based upon regex' do
33
-
34
- filter_words = []
35
- filter_words << /ofac*/
36
-
37
- subject = described_class.new(filter_words)
38
-
39
- unfiltered_params = {:address=>"11802 MCDONALD ST, Los Angeles, CA 90230",
40
- "owners"=>[{"first_name"=>"GOLD", "last_name"=>"PATH", "ssn"=>"000-02-9999"}],
41
- "overrides"=>{"ofac_7403"=>"clear"}}
42
-
43
- filtered_params = {:address=>"11802 MCDONALD ST, Los Angeles, CA 90230",
44
- "owners"=>[{"first_name"=>"GOLD", "last_name"=>"PATH", "ssn"=>"000-02-9999"}],
45
- "overrides"=>{"ofac_7403"=>"[FILTERED]"}}
46
-
47
- expect(subject.filter(unfiltered_params)).to eq filtered_params
48
- end
49
- end
50
- end
@@ -1,41 +0,0 @@
1
- describe Rory::Renderer::Context do
2
- it_has_behavior 'path_generation' do
3
- let(:path_generator) {
4
- Rory::Renderer::Context.new({
5
- :app => Fixture::Application
6
- })
7
- }
8
- end
9
-
10
- describe "#render" do
11
- it "returns sub-renderer output" do
12
- renderer_context = Rory::Renderer::Context.new({
13
- :app => :an_app,
14
- :base_path => 'yoyo'
15
- })
16
- passed_renderer_options = {
17
- :layout => false, :app => :an_app, :base_path => 'yoyo'
18
- }
19
- allow(Rory::Renderer).to receive(:new).
20
- with('not/real', passed_renderer_options).
21
- and_return(double('Renderer', :render => 'Here ya go'))
22
- expect(renderer_context.render('not/real')).to eq('Here ya go')
23
- end
24
-
25
- it "does not pass locals or layout to sub-renderer" do
26
- renderer_context = Rory::Renderer::Context.new({
27
- :locals => { :thing => :great },
28
- :app => :an_app,
29
- :base_path => 'yoyo',
30
- :layout => 'groooovy'
31
- })
32
- passed_renderer_options = {
33
- :layout => false, :app => :an_app, :base_path => 'yoyo'
34
- }
35
- allow(Rory::Renderer).to receive(:new).
36
- with('also/fake', passed_renderer_options).
37
- and_return(double('Renderer', :render => 'Scamazing!'))
38
- expect(renderer_context.render('also/fake')).to eq('Scamazing!')
39
- end
40
- end
41
- end
@@ -1,50 +0,0 @@
1
- describe Rory::Renderer do
2
- describe "#render" do
3
- let(:app) { Fixture::Application }
4
-
5
- it "returns text of template" do
6
- renderer = Rory::Renderer.new('test/static', :app => app)
7
- expect(renderer.render).to eq('Static content')
8
- end
9
-
10
- it "returns text of template in given layout" do
11
- controller = Rory::Renderer.new('test/static', :layout => 'surround', :app => app)
12
- expect(controller.render).to eq('Surrounding Static content is fun')
13
- end
14
-
15
- it "handles symbolized layout name" do
16
- controller = Rory::Renderer.new('test/static', :layout => :surround, :app => app)
17
- expect(controller.render).to eq('Surrounding Static content is fun')
18
- end
19
-
20
- it "exposes locals to template" do
21
- controller = Rory::Renderer.new('test/dynamic', :locals => { :word => 'hockey' }, :app => app)
22
- expect(controller.render).to eq('Word: hockey')
23
- end
24
-
25
- it "can render nested templates" do
26
- controller = Rory::Renderer.new('test/double_nested', :locals => { :word => 'hockey' }, :app => app)
27
- expect(controller.render).to eq(
28
- "Don't Say A Bad Word: Poop!"
29
- )
30
- end
31
-
32
- it "exposes base_path to template" do
33
- controller = Rory::Renderer.new('test/a_link', :base_path => 'spoo', :app => app)
34
- expect(controller.render).to eq('You came from spoo.')
35
- end
36
- end
37
-
38
- describe '#view_path' do
39
- it 'returns path to template from app root' do
40
- fake_app = double('Application', :root => 'marbles')
41
- renderer = Rory::Renderer.new('goose', :app => fake_app)
42
- expect(renderer.view_path).to eq(File.expand_path(File.join('views', 'goose.html.erb'), 'marbles'))
43
- end
44
-
45
- it 'uses Rory.root if no app specified' do
46
- renderer = Rory::Renderer.new('goose', :app => double(:root => "horse"))
47
- expect(renderer.view_path).to eq(File.expand_path(File.join('views', 'goose.html.erb'), "horse"))
48
- end
49
- end
50
- end
@@ -1,56 +0,0 @@
1
- RSpec.describe Rory::RequestId do
2
- subject { described_class.new(Proc.new {|env|[200, headers, ""] },
3
- uuid_prefix: uuid_prefix,
4
- uuid_creator: class_double(SecureRandom, uuid: "1234")) }
5
- after { Thread.current[:inheritable_attributes] = nil }
6
- let(:headers) { {} }
7
- let(:env) { {} }
8
- let(:uuid_prefix) { nil }
9
-
10
- context "when no external_request_id is set" do
11
- before { subject.call(env) }
12
-
13
- it "sets env['rory.request_id']" do
14
- expect(env["rory.request_id"]).to eq "1234"
15
- end
16
-
17
- it "sets header['X-Request-Id']" do
18
- expect(headers["X-Request-Id"]).to eq "1234"
19
- end
20
-
21
- it "sets Thread.current[:rory_request_id]" do
22
- expect(Thread.current.get_inheritable_attribute(:rory_request_id)).to eq "1234"
23
- end
24
-
25
- context "the uuid can be given a prefixed to know where it was created" do
26
- let(:uuid_prefix) { "app_name" }
27
- it { expect(Thread.current.get_inheritable_attribute(:rory_request_id)).to eq "app_name-1234" }
28
- end
29
- end
30
-
31
- context "when external_request_id is set" do
32
- before { subject.call(env) }
33
- let(:env) { { "HTTP_X_REQUEST_ID" => "4321" } }
34
-
35
- it "sets env['rory.request_id']" do
36
- expect(env["rory.request_id"]).to eq "4321"
37
- end
38
-
39
- it "sets header['X-Request-Id']" do
40
- expect(headers["X-Request-Id"]).to eq "4321"
41
- end
42
-
43
- it "sets Thread.current[:rory_request_id]" do
44
- expect(Thread.current.get_inheritable_attribute(:rory_request_id)).to eq "4321"
45
- end
46
- end
47
-
48
- context "use default SecureRandom" do
49
- subject { described_class.new(Proc.new {|env|[200, headers, ""] },
50
- uuid_prefix: uuid_prefix).call({}) }
51
- it "call uuid on SecureRandom" do
52
- expect(SecureRandom).to receive(:uuid).once
53
- subject
54
- end
55
- end
56
- end