Skip to content

Commit

Permalink
Allow Class Resources, call #to_s for defined resource_name
Browse files Browse the repository at this point in the history
If using a class as the resource:

  resource Order do
  end

The resource_name will be a class, which causes issues when sorting for
sections. By calling `#to_s` on the `args.first` when first dealing with
the resource we can ensure that we are always working with a string for
the resource_name.
  • Loading branch information
kevinjalbert committed Oct 14, 2015
1 parent 2c8f4df commit 64cfcf5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rspec_api_documentation/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ module DSL
# +block+:: Block to pass into describe
#
def resource(*args, &block)
options = if args.last.is_a?(Hash) then args.pop else {} end
options = args.last.is_a?(Hash) ? args.pop : {}
options[:api_doc_dsl] = :resource
options[:resource_name] = args.first
options[:resource_name] = args.first.to_s
options[:document] ||= :all
args.push(options)
describe(*args, &block)
Expand Down
7 changes: 7 additions & 0 deletions spec/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -583,3 +583,10 @@
expect(example.metadata[:document]).to eq(:not_all)
end
end

class Order; end
resource Order do
it 'should have a string resource_name' do |example|
expect(example.metadata[:resource_name]).to eq(Order.to_s)
end
end

0 comments on commit 64cfcf5

Please sign in to comment.