summaryrefslogtreecommitdiff
path: root/spec/serializers
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-10-28 14:32:07 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-11-02 14:26:57 +0100
commitacfe394018df50bfc08aa9e41265231747675646 (patch)
tree776b34a9f27c149d8863775f760036b2484ed866 /spec/serializers
parent2023511753d75545aa76968a2991dc962f7a99db (diff)
downloadgitlab-ce-acfe394018df50bfc08aa9e41265231747675646.tar.gz
Add PoC for resource serializers
Diffstat (limited to 'spec/serializers')
-rw-r--r--spec/serializers/entity_request_spec.rb26
-rw-r--r--spec/serializers/environment_serializer_spec.rb35
2 files changed, 61 insertions, 0 deletions
diff --git a/spec/serializers/entity_request_spec.rb b/spec/serializers/entity_request_spec.rb
new file mode 100644
index 00000000000..1c220a7b95d
--- /dev/null
+++ b/spec/serializers/entity_request_spec.rb
@@ -0,0 +1,26 @@
+require 'spec_helper'
+
+describe EntityRequest do
+ subject do
+ described_class.new(user: 'user', project: 'some project')
+ end
+
+ describe 'methods created' do
+ it 'defines accessible attributes' do
+ expect(subject.user).to eq 'user'
+ expect(subject.project).to eq 'some project'
+ end
+
+ it 'raises error when attribute is not defined' do
+ expect { subject.some_method }.to raise_error NoMethodError
+ end
+ end
+
+ describe '#merge!' do
+ before { subject.merge!(build: 'some build') }
+
+ it 'appends parameters' do
+ expect(subject.build).to eq 'some build'
+ end
+ end
+end
diff --git a/spec/serializers/environment_serializer_spec.rb b/spec/serializers/environment_serializer_spec.rb
new file mode 100644
index 00000000000..3470863681c
--- /dev/null
+++ b/spec/serializers/environment_serializer_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe EnvironmentSerializer do
+ let(:serializer) do
+ described_class.new(path: 'some path').represent(resource)
+ end
+
+ context 'when there is a single object provided' do
+ let(:resource) { create(:environment) }
+
+ it 'shows json' do
+ puts serializer.to_json
+ end
+
+ it 'it generates payload for single object' do
+ expect(parsed_json).to be_an_instance_of Hash
+ end
+ end
+
+ context 'when there is a collection of objects provided' do
+ let(:resource) { create_list(:environment, 2) }
+
+ it 'shows json' do
+ puts serializer.to_json
+ end
+
+ it 'generates payload for collection' do
+ expect(parsed_json).to be_an_instance_of Array
+ end
+ end
+
+ def parsed_json
+ JSON.parse(serializer.to_json)
+ end
+end