Skip to content

Commit 64cfcf5

Browse files
committed
Allow Class Resources, call #to_s for defined resource_name
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.
1 parent 2c8f4df commit 64cfcf5

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

lib/rspec_api_documentation/dsl.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ module DSL
1818
# +block+:: Block to pass into describe
1919
#
2020
def resource(*args, &block)
21-
options = if args.last.is_a?(Hash) then args.pop else {} end
21+
options = args.last.is_a?(Hash) ? args.pop : {}
2222
options[:api_doc_dsl] = :resource
23-
options[:resource_name] = args.first
23+
options[:resource_name] = args.first.to_s
2424
options[:document] ||= :all
2525
args.push(options)
2626
describe(*args, &block)

spec/dsl_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,3 +583,10 @@
583583
expect(example.metadata[:document]).to eq(:not_all)
584584
end
585585
end
586+
587+
class Order; end
588+
resource Order do
589+
it 'should have a string resource_name' do |example|
590+
expect(example.metadata[:resource_name]).to eq(Order.to_s)
591+
end
592+
end

0 commit comments

Comments
 (0)