rory 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40ba6de912d0a2eff585bacee9ac6e17583bf70c
4
- data.tar.gz: de1a192df73c293d81945d0f015173c3e338484e
3
+ metadata.gz: df765583fa4f315b7f217e8324523d7dd4b3c2ba
4
+ data.tar.gz: f977ad97a93566d606319301ea03a06447c2a260
5
5
  SHA512:
6
- metadata.gz: 864bb31119f46b7f067df7dcb60779844b53efd383f8a40de18376054abb36263694a19b9f40fc0414fcf7ce36577a83a59d55e7f03cedf23e170309a409a2c1
7
- data.tar.gz: 23e76ae90efc1de98ecd4cd629ca64624eccc09576156d7cc7a647de7ab07a05326890b9fea1b54304e81138e997c86c51e347a7613a4b8f00e578ca017a08a0
6
+ metadata.gz: 3c2dd88f139db2931ebe7fdb9153c6ca4180d65f36622fdc51e18859ae55f6661636fe5c5b525564b9ac6973f9980a2e6266b8508317579f87bce4218b68bf83
7
+ data.tar.gz: 152c81f7ab8498553a4d4e1dce0d583c25d29bd882c8c776178e8b73815b3a3f9a08e2ab3e2300b8c95f50d0b2efc034348522125a0089efac00574ebc5c8a4f
@@ -118,15 +118,28 @@ module Rory
118
118
  end
119
119
 
120
120
  def turn_off_request_logging!
121
- @stack = nil
121
+ reset_stack
122
122
  @request_logging = false
123
123
  end
124
124
 
125
+ def parameters_to_filter
126
+ @parameters_to_filter || [:password]
127
+ end
128
+
129
+ def filter_parameters(*params)
130
+ reset_stack
131
+ @parameters_to_filter = params
132
+ end
133
+
134
+ def reset_stack
135
+ @stack = nil
136
+ end
137
+
125
138
  def use_default_middleware
126
139
  if request_logging_on?
127
140
  use_middleware Rack::PostBodyContentTypeParser
128
141
  use_middleware Rack::CommonLogger, logger
129
- use_middleware Rory::RequestParameterLogger, logger
142
+ use_middleware Rory::RequestParameterLogger, logger, :filters => parameters_to_filter
130
143
  end
131
144
  end
132
145
 
@@ -3,10 +3,10 @@ require_relative 'parameter_filter'
3
3
  module Rory
4
4
  class RequestParameterLogger
5
5
 
6
- def initialize(app, logger=nil, filters=[:password])
6
+ def initialize(app, logger = nil, options = {})
7
7
  @app = app
8
8
  @logger = logger
9
- @filters = filters
9
+ @filters = options.fetch(:filters, [])
10
10
  end
11
11
 
12
12
  def call(env)
@@ -1,3 +1,3 @@
1
1
  module Rory
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.1'
3
3
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.name = "rory"
9
9
  s.version = Rory::VERSION
10
10
  s.platform = Gem::Platform::RUBY
11
- s.authors = ["Ravi Gadad"]
11
+ s.authors = ["Ravi Gadad", "Michael Irey", "David Begin"]
12
12
  s.email = ["ravi@screamingmuse.com"]
13
13
  s.homepage = "http://github.com/screamingmuse/rory"
14
14
  s.summary = "Another Ruby web framework. Just what the world needs."
@@ -1,5 +1,6 @@
1
1
  module Fixture
2
2
  class Application < Rory::Application
3
3
  turn_off_request_logging!
4
+ filter_parameters :orcas, :noodles
4
5
  end
5
6
  end
@@ -61,14 +61,20 @@ describe Rory::Application do
61
61
  end
62
62
  end
63
63
 
64
+ describe ".dispatcher" do
65
+ it "returns new dispatcher rack app" do
66
+ allow(Rory::Dispatcher).to receive(:rack_app).
67
+ with(subject).and_return(:dispatcher_app)
68
+ expect(subject.dispatcher).to eq(:dispatcher_app)
69
+ end
70
+ end
71
+
64
72
  describe ".call" do
65
- it "forwards arg to new dispatcher, and calls dispatch" do
66
- dispatcher = double(:dispatch => :expected)
67
- rack_request = double(:media_type => 'application/json')
68
- env = { "rack.input" => double(:read => {}) }
69
- allow(Rack::Request).to receive(:new).with(env).and_return(rack_request)
70
- expect(Rory::Dispatcher).to receive(:new).with(rack_request, subject.instance).and_return(dispatcher)
71
- expect(subject.call(env)).to eq(:expected)
73
+ it "calls the stack with the given environment" do
74
+ stack = double
75
+ allow(stack).to receive(:call).with(:the_env).and_return(:expected)
76
+ expect(subject.instance).to receive(:stack).and_return(stack)
77
+ expect(subject.call(:the_env)).to eq(:expected)
72
78
  end
73
79
  end
74
80
 
@@ -90,7 +96,7 @@ describe Rory::Application do
90
96
  end
91
97
 
92
98
  describe ".logger" do
93
- it "reutrns a logger" do
99
+ it "returns a logger" do
94
100
  logger = double
95
101
  allow_any_instance_of(subject).to receive(:log_file)
96
102
  allow(Logger).to receive(:new).and_return(logger)
@@ -98,19 +104,68 @@ describe Rory::Application do
98
104
  end
99
105
  end
100
106
 
107
+ describe ".turn_off_request_logging!" do
108
+ it "resets stack and turns off request logging" do
109
+ subject.instance.instance_variable_set(:@request_logging, :true)
110
+ expect(subject.request_logging_on?).to eq(true)
111
+ expect(subject.instance).to receive(:reset_stack)
112
+ subject.turn_off_request_logging!
113
+ expect(subject.request_logging_on?).to eq(false)
114
+ end
115
+ end
116
+
117
+ describe ".filter_parameters" do
118
+ it "resets stack and sets parameters to filter" do
119
+ expect(subject.instance).to receive(:reset_stack)
120
+ subject.filter_parameters :dog, :kitty
121
+ expect(subject.parameters_to_filter).to eq([:dog, :kitty])
122
+ end
123
+ end
124
+
125
+ describe ".reset_stack" do
126
+ it "clears memoization of stack" do
127
+ stack = subject.stack
128
+ expect(subject.stack).to eq(stack)
129
+ subject.reset_stack
130
+ expect(subject.stack).not_to eq(stack)
131
+ end
132
+ end
133
+
134
+ describe ".stack" do
135
+ it "returns a rack builder instance with configured middleware" do
136
+ builder = double
137
+ allow(subject.instance).to receive(:dispatcher).
138
+ and_return(:the_dispatcher)
139
+ allow(Rack::Builder).to receive(:new).and_return(builder)
140
+ subject.use_middleware :horse
141
+ expect(subject.instance).to receive(:use_default_middleware)
142
+ expect(builder).to receive(:use).with(:horse)
143
+ expect(builder).to receive(:run).with(:the_dispatcher)
144
+ expect(subject.stack).to eq(builder)
145
+ end
146
+ end
147
+
148
+ describe ".parameters_to_filter" do
149
+ it "returns [:password] by default" do
150
+ expect(subject.parameters_to_filter).to eq([:password])
151
+ end
152
+ end
153
+
101
154
  describe ".use_default_middleware" do
102
155
  it "adds middleware when request logging is on" do
103
156
  allow(subject.instance).to receive(:request_logging_on?).and_return(true)
157
+ allow(subject.instance).to receive(:parameters_to_filter).and_return([:horses])
104
158
  allow(subject.instance).to receive(:logger).and_return(:the_logger)
159
+ expect(subject.instance).to receive(:use_middleware).with(Rack::PostBodyContentTypeParser)
160
+ expect(subject.instance).to receive(:use_middleware).with(Rack::CommonLogger, :the_logger)
161
+ expect(subject.instance).to receive(:use_middleware).with(Rory::RequestParameterLogger, :the_logger, :filters => [:horses])
105
162
  subject.use_default_middleware
106
- expect(subject.middleware.count).to_not eq(0)
107
163
  end
108
164
 
109
165
  it "does not add middleware when request logging is off" do
110
166
  allow(subject.instance).to receive(:request_logging_on?).and_return(false)
111
- allow(subject.instance).to receive(:logger).and_return(:the_logger)
167
+ expect(subject.instance).to receive(:use_middleware).never
112
168
  subject.use_default_middleware
113
- expect(subject.middleware.count).to eq(0)
114
169
  end
115
170
  end
116
171
 
@@ -201,5 +256,11 @@ describe Rory::Application do
201
256
  ]
202
257
  end
203
258
  end
259
+
260
+ describe ".parameters_to_filter" do
261
+ it "returns overridden parameters" do
262
+ expect(subject.parameters_to_filter).to eq([:orcas, :noodles])
263
+ end
264
+ end
204
265
  end
205
266
  end
@@ -55,6 +55,15 @@ describe Rory::Dispatcher do
55
55
  end
56
56
  end
57
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
+
58
67
  describe "#dispatch" do
59
68
  let(:request) { { :whatever => :yay } }
60
69
  before(:each) do
@@ -2,7 +2,7 @@ describe Rory::RequestParameterLogger do
2
2
 
3
3
  let(:logger) { double(:write) }
4
4
  let(:app) { double(:call) }
5
- subject { described_class.new(app, logger, :filters) }
5
+ subject { described_class.new(app, logger, :filters => :filters) }
6
6
 
7
7
  describe '#initialize' do
8
8
  it 'returns a new RequestParameterLogger' do
@@ -14,6 +14,11 @@ describe Rory::RequestParameterLogger do
14
14
  expect(subject.instance_variable_get(:@logger)).to eq(logger)
15
15
  expect(subject.instance_variable_get(:@filters)).to eq(:filters)
16
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
17
22
  end
18
23
 
19
24
  describe '#log_request' do
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ravi Gadad
8
+ - Michael Irey
9
+ - David Begin
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2015-06-16 00:00:00.000000000 Z
13
+ date: 2015-06-18 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: rack