Skip to content

Commit a15232b

Browse files
Shuhei Kitagawashishirmk
authored andcommitted
Add tests for set_id method
1 parent 43239af commit a15232b

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'spec_helper'
2+
3+
describe FastJsonapi::ObjectSerializer do
4+
include_context 'movie class'
5+
6+
context 'when setting id' do
7+
subject(:serializable_hash) { MovieSerializer.new(resource).serializable_hash }
8+
9+
before(:all) do
10+
MovieSerializer.set_id :owner_id
11+
end
12+
13+
context 'when one record is given' do
14+
let(:resource) { movie }
15+
16+
it 'returns correct hash which id equals owner_id' do
17+
expect(serializable_hash[:data][:id].to_i).to eq movie.owner_id
18+
end
19+
end
20+
21+
context 'when an array of records is given' do
22+
let(:resource) { [movie, movie] }
23+
24+
it 'returns correct hash which id equals owner_id' do
25+
expect(serializable_hash[:data][0][:id].to_i).to eq movie.owner_id
26+
expect(serializable_hash[:data][1][:id].to_i).to eq movie.owner_id
27+
end
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)