Skip to content

Commit fac8392

Browse files
committed
Filled out some specs for ruby-grape#716.
1 parent 3b347a3 commit fac8392

11 files changed

+37
-44
lines changed

lib/grape/dsl/callbacks.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ module DSL
55
module Callbacks
66
extend ActiveSupport::Concern
77

8-
included do
9-
10-
end
11-
128
module ClassMethods
139
def before(&block)
1410
imbue(:befores, [block])

lib/grape/dsl/configuration.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ module DSL
55
module Configuration
66
extend ActiveSupport::Concern
77

8-
included do
9-
10-
end
11-
128
module ClassMethods
139
attr_writer :logger
1410
attr_reader :settings

lib/grape/dsl/helpers.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ module DSL
55
module Helpers
66
extend ActiveSupport::Concern
77

8-
included do
9-
10-
end
11-
128
module ClassMethods
139
# Add helper methods that will be accessible from any
1410
# endpoint within this namespace (and child namespaces).

lib/grape/dsl/middleware.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ module DSL
55
module Middleware
66
extend ActiveSupport::Concern
77

8-
included do
9-
10-
end
11-
128
module ClassMethods
139
# Apply a custom middleware to the API. Applies
1410
# to the current namespace and any children, but

lib/grape/dsl/parameters.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ module DSL
55
module Parameters
66
extend ActiveSupport::Concern
77

8-
included do
9-
10-
end
11-
12-
module ClassMethods
13-
end
14-
158
def use(*names)
169
named_params = @api.settings[:named_params] || {}
1710
options = names.last.is_a?(Hash) ? names.pop : {}

lib/grape/dsl/request_response.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ module DSL
55
module RequestResponse
66
extend ActiveSupport::Concern
77

8-
included do
9-
10-
end
11-
128
module ClassMethods
139
# Specify the default format for the API's serializers.
1410
# May be `:json` or `:txt` (default).

lib/grape/dsl/routing.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ module DSL
55
module Routing
66
extend ActiveSupport::Concern
77

8-
included do
9-
10-
end
11-
128
module ClassMethods
139
attr_reader :endpoints, :routes, :route_set
1410

lib/grape/dsl/validations.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ module DSL
55
module Validations
66
extend ActiveSupport::Concern
77

8-
included do
9-
10-
end
11-
128
module ClassMethods
139
def reset_validations!
1410
settings.peek[:declared_params] = []

lib/grape/validations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def initialize(opts, &block)
9090
@type = opts[:type]
9191
@declared_params = []
9292

93-
instance_eval(&block)
93+
instance_eval(&block) if block_given?
9494

9595
configure_declared_params
9696
end

spec/grape/dsl/helpers_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test
4242
it 'uses provided modules' do
4343
mod = Module.new
4444

45-
expect(subject).to receive(:set).with(:helpers, kind_of(Grape::DSL::Helpers::BaseHelper)).and_call_original
45+
expect(subject).to receive(:set).with(:helpers, kind_of(Grape::DSL::Helpers::BaseHelper)).and_call_original
4646
subject.helpers(mod, &proc)
4747

4848
expect(subject.mod).not_to eq mod

spec/grape/dsl/validations_spec.rb

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,50 @@ module DSL
55
module ValidationsSpec
66
class Dummy
77
include Grape::DSL::Validations
8+
9+
def self.settings
10+
@settings ||= Grape::Util::HashStack.new
11+
end
812
end
913
end
1014

1115
describe Validations do
12-
subject { Class.new(ValidationsSpec::Dummy) }
16+
subject { ValidationsSpec::Dummy }
17+
18+
describe '.reset_validations!' do
19+
before do
20+
subject.settings.peek[:declared_params] = ['dummy']
21+
subject.settings.peek[:validations] = ['dummy']
22+
subject.reset_validations!
23+
end
24+
25+
it 'resets declared params' do
26+
expect(subject.settings.peek[:declared_params]).to be_empty
27+
end
1328

14-
xdescribe '.reset_validations!' do
15-
it 'does some thing'
29+
it 'resets validations' do
30+
expect(subject.settings.peek[:validations]).to be_empty
31+
end
1632
end
1733

18-
xdescribe '.params' do
19-
it 'does some thing'
34+
describe '.params' do
35+
it 'returns a ParamsScope' do
36+
expect(subject.params).to be_a Grape::Validations::ParamsScope
37+
end
38+
39+
it 'evaluates block' do
40+
expect { subject.params { raise 'foo' } }.to raise_error RuntimeError, 'foo'
41+
end
2042
end
2143

22-
xdescribe '.document_attribute' do
23-
it 'does some thing'
44+
describe '.document_attribute' do
45+
before do
46+
subject.document_attribute([full_name: 'xxx'], foo: 'bar')
47+
end
48+
49+
it 'creates last_description' do
50+
expect(subject.instance_variable_get(:'@last_description')).to eq(params: { 'xxx' => { foo: 'bar' } })
51+
end
2452
end
2553
end
2654
end

0 commit comments

Comments
 (0)