Skip to content

Commit

Permalink
Filled out some specs for #716.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Aug 16, 2014
1 parent 3b347a3 commit fac8392
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 44 deletions.
4 changes: 0 additions & 4 deletions lib/grape/dsl/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ module DSL
module Callbacks
extend ActiveSupport::Concern

included do

end

module ClassMethods
def before(&block)
imbue(:befores, [block])
Expand Down
4 changes: 0 additions & 4 deletions lib/grape/dsl/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ module DSL
module Configuration
extend ActiveSupport::Concern

included do

end

module ClassMethods
attr_writer :logger
attr_reader :settings
Expand Down
4 changes: 0 additions & 4 deletions lib/grape/dsl/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ module DSL
module Helpers
extend ActiveSupport::Concern

included do

end

module ClassMethods
# Add helper methods that will be accessible from any
# endpoint within this namespace (and child namespaces).
Expand Down
4 changes: 0 additions & 4 deletions lib/grape/dsl/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ module DSL
module Middleware
extend ActiveSupport::Concern

included do

end

module ClassMethods
# Apply a custom middleware to the API. Applies
# to the current namespace and any children, but
Expand Down
7 changes: 0 additions & 7 deletions lib/grape/dsl/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ module DSL
module Parameters
extend ActiveSupport::Concern

included do

end

module ClassMethods
end

def use(*names)
named_params = @api.settings[:named_params] || {}
options = names.last.is_a?(Hash) ? names.pop : {}
Expand Down
4 changes: 0 additions & 4 deletions lib/grape/dsl/request_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ module DSL
module RequestResponse
extend ActiveSupport::Concern

included do

end

module ClassMethods
# Specify the default format for the API's serializers.
# May be `:json` or `:txt` (default).
Expand Down
4 changes: 0 additions & 4 deletions lib/grape/dsl/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ module DSL
module Routing
extend ActiveSupport::Concern

included do

end

module ClassMethods
attr_reader :endpoints, :routes, :route_set

Expand Down
4 changes: 0 additions & 4 deletions lib/grape/dsl/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ module DSL
module Validations
extend ActiveSupport::Concern

included do

end

module ClassMethods
def reset_validations!
settings.peek[:declared_params] = []
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def initialize(opts, &block)
@type = opts[:type]
@declared_params = []

instance_eval(&block)
instance_eval(&block) if block_given?

configure_declared_params
end
Expand Down
2 changes: 1 addition & 1 deletion spec/grape/dsl/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test
it 'uses provided modules' do
mod = Module.new

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

expect(subject.mod).not_to eq mod
Expand Down
42 changes: 35 additions & 7 deletions spec/grape/dsl/validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,50 @@ module DSL
module ValidationsSpec
class Dummy
include Grape::DSL::Validations

def self.settings
@settings ||= Grape::Util::HashStack.new
end
end
end

describe Validations do
subject { Class.new(ValidationsSpec::Dummy) }
subject { ValidationsSpec::Dummy }

describe '.reset_validations!' do
before do
subject.settings.peek[:declared_params] = ['dummy']
subject.settings.peek[:validations] = ['dummy']
subject.reset_validations!
end

it 'resets declared params' do
expect(subject.settings.peek[:declared_params]).to be_empty
end

xdescribe '.reset_validations!' do
it 'does some thing'
it 'resets validations' do
expect(subject.settings.peek[:validations]).to be_empty
end
end

xdescribe '.params' do
it 'does some thing'
describe '.params' do
it 'returns a ParamsScope' do
expect(subject.params).to be_a Grape::Validations::ParamsScope
end

it 'evaluates block' do
expect { subject.params { raise 'foo' } }.to raise_error RuntimeError, 'foo'
end
end

xdescribe '.document_attribute' do
it 'does some thing'
describe '.document_attribute' do
before do
subject.document_attribute([full_name: 'xxx'], foo: 'bar')
end

it 'creates last_description' do
expect(subject.instance_variable_get(:'@last_description')).to eq(params: { 'xxx' => { foo: 'bar' } })
end
end
end
end
Expand Down

0 comments on commit fac8392

Please sign in to comment.