-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathkey_format_spec.rb
55 lines (46 loc) · 1.25 KB
/
key_format_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'spec_helper'
describe JSONAPI::Serializable::Resource do
let(:klass) do
Class.new(JSONAPI::Serializable::Resource) do
type 'foo'
id { 'bar' }
end
end
let(:object) { User.new }
let(:resource) { klass.new(object: object) }
subject { resource.as_jsonapi }
context 'when keys are formatted' do
let(:resource) do
klass.new(object: object)
end
before do
klass.class_eval do
extend JSONAPI::Serializable::Resource::KeyFormat
key_format ->(k) { k.to_s.capitalize }
attribute :name
attribute :address
relationship :posts
belongs_to :author
has_many :comments
has_one :review
end
end
expected = {
type: :foo,
id: 'bar',
attributes: { Name: nil, Address: nil }
}
it { is_expected.to eq(expected) }
context 'when inheriting' do
let(:subclass) { Class.new(klass) }
let(:resource) { subclass.new(object: object) }
it { is_expected.to eq(expected) }
end
end
context 'when KeyFormat is prepended' do
it 'outputs a deprecation warning' do
expect { klass.prepend JSONAPI::Serializable::Resource::KeyFormat }
.to output(/DERPRECATION WARNING/).to_stderr
end
end
end