Commit c43a82cd authored by Shinya Maeda's avatar Shinya Maeda

specs for serializers.

parent 709b8b61
require 'spec_helper' require 'spec_helper'
describe ClusterEntity do describe ClusterEntity do
set(:cluster) { create(:gcp_cluster, :errored) } describe '#as_json' do
let(:request) { double('request') } subject { described_class.new(cluster).as_json }
let(:entity) do context 'when provider type is gcp' do
described_class.new(cluster) let(:cluster) { create(:cluster, provider_type: :gcp, provider_gcp: provider) }
end
describe '#as_json' do context 'when status is creating' do
subject { entity.as_json } let(:provider) { create(:provider_gcp, :creating) }
it 'contains status' do it 'has corresponded data' do
expect(subject[:status]).to eq(:errored) expect(subject[:status]).to eq(:creating)
expect(subject[:status_reason]).to be_nil
end
end
context 'when status is errored' do
let(:provider) { create(:provider_gcp, :errored) }
it 'has corresponded data' do
expect(subject[:status]).to eq(:errored)
expect(subject[:status_reason]).to eq(provider.status_reason)
end
end
end end
it 'contains status reason' do context 'when provider type is user' do
expect(subject[:status_reason]).to eq('general error') let(:cluster) { create(:cluster, provider_type: :user) }
it 'has nil' do
expect(subject[:status]).to be_nil
expect(subject[:status_reason]).to be_nil
end
end end
end end
end end
require 'spec_helper' require 'spec_helper'
describe ClusterSerializer do describe ClusterSerializer do
let(:serializer) do
described_class.new
end
describe '#represent_status' do describe '#represent_status' do
subject { serializer.represent_status(resource) } subject { described_class.new.represent_status(cluster) }
context 'when provider type is gcp' do
let(:cluster) { create(:cluster, provider_type: :gcp, provider_gcp: provider) }
let(:provider) { create(:provider_gcp, :errored) }
it 'serializes only status' do
expect(subject.keys).to contain_exactly(:status, :status_reason)
end
end
context 'when represents only status' do context 'when provider type is user' do
let(:resource) { create(:gcp_cluster, :errored) } let(:cluster) { create(:cluster, provider_type: :user) }
it 'serializes only status' do it 'serializes only status' do
expect(subject.keys).to contain_exactly(:status, :status_reason) expect(subject.keys).to contain_exactly(:status, :status_reason)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment