summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-01-27 13:02:59 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-01-27 13:02:59 +0100
commit42e3f0fd7888ab8ebe11801e01dd3ca1f33b20cf (patch)
tree9840de93c579b1a6422144a0352493d45f6978bb /spec
parent256a7735f8cb8872a7f7595590300e2fd952428e (diff)
downloadgitlab-ce-42e3f0fd7888ab8ebe11801e01dd3ca1f33b20cf.tar.gz
Return serializable hash from a represented serializer
Diffstat (limited to 'spec')
-rw-r--r--spec/serializers/analytics_build_serializer_spec.rb10
-rw-r--r--spec/serializers/analytics_issue_serializer_spec.rb5
-rw-r--r--spec/serializers/analytics_merge_request_serializer_spec.rb5
-rw-r--r--spec/serializers/analytics_stage_serializer_spec.rb14
-rw-r--r--spec/serializers/analytics_summary_serializer_spec.rb19
-rw-r--r--spec/serializers/environment_serializer_spec.rb9
-rw-r--r--spec/serializers/pipeline_serializer_spec.rb6
7 files changed, 28 insertions, 40 deletions
diff --git a/spec/serializers/analytics_build_serializer_spec.rb b/spec/serializers/analytics_build_serializer_spec.rb
index f0551c78671..e3b1dd93dc2 100644
--- a/spec/serializers/analytics_build_serializer_spec.rb
+++ b/spec/serializers/analytics_build_serializer_spec.rb
@@ -1,17 +1,13 @@
require 'spec_helper'
describe AnalyticsBuildSerializer do
- let(:serializer) do
- described_class
- .new.represent(resource)
- end
-
- let(:json) { serializer.as_json }
let(:resource) { create(:ci_build) }
+ subject { described_class.new.represent(resource) }
+
context 'when there is a single object provided' do
it 'contains important elements of analyticsBuild' do
- expect(json)
+ expect(subject)
.to include(:name, :branch, :short_sha, :date, :total_time, :url, :author)
end
end
diff --git a/spec/serializers/analytics_issue_serializer_spec.rb b/spec/serializers/analytics_issue_serializer_spec.rb
index 6afbb2df35c..2f08958a783 100644
--- a/spec/serializers/analytics_issue_serializer_spec.rb
+++ b/spec/serializers/analytics_issue_serializer_spec.rb
@@ -1,14 +1,13 @@
require 'spec_helper'
describe AnalyticsIssueSerializer do
- let(:serializer) do
+ subject do
described_class
.new(project: project, entity: :merge_request)
.represent(resource)
end
let(:user) { create(:user) }
- let(:json) { serializer.as_json }
let(:project) { create(:project) }
let(:resource) do
{
@@ -23,7 +22,7 @@ describe AnalyticsIssueSerializer do
context 'when there is a single object provided' do
it 'contains important elements of the issue' do
- expect(json).to include(:title, :iid, :created_at, :total_time, :url, :author)
+ expect(subject).to include(:title, :iid, :created_at, :total_time, :url, :author)
end
end
end
diff --git a/spec/serializers/analytics_merge_request_serializer_spec.rb b/spec/serializers/analytics_merge_request_serializer_spec.rb
index cdfae27193f..62067cc0ef2 100644
--- a/spec/serializers/analytics_merge_request_serializer_spec.rb
+++ b/spec/serializers/analytics_merge_request_serializer_spec.rb
@@ -1,14 +1,13 @@
require 'spec_helper'
describe AnalyticsMergeRequestSerializer do
- let(:serializer) do
+ subject do
described_class
.new(project: project, entity: :merge_request)
.represent(resource)
end
let(:user) { create(:user) }
- let(:json) { serializer.as_json }
let(:project) { create(:project) }
let(:resource) do
{
@@ -24,7 +23,7 @@ describe AnalyticsMergeRequestSerializer do
context 'when there is a single object provided' do
it 'contains important elements of the merge request' do
- expect(json).to include(:title, :iid, :created_at, :total_time, :url, :author, :state)
+ expect(subject).to include(:title, :iid, :created_at, :total_time, :url, :author, :state)
end
end
end
diff --git a/spec/serializers/analytics_stage_serializer_spec.rb b/spec/serializers/analytics_stage_serializer_spec.rb
index f9951826683..be6aa7c65c3 100644
--- a/spec/serializers/analytics_stage_serializer_spec.rb
+++ b/spec/serializers/analytics_stage_serializer_spec.rb
@@ -1,13 +1,13 @@
require 'spec_helper'
describe AnalyticsStageSerializer do
- let(:serializer) do
- described_class
- .new.represent(resource)
+ subject do
+ described_class.new.represent(resource)
end
- let(:json) { serializer.as_json }
- let(:resource) { Gitlab::CycleAnalytics::CodeStage.new(project: double, options: {}) }
+ let(:resource) do
+ Gitlab::CycleAnalytics::CodeStage.new(project: double, options: {})
+ end
before do
allow_any_instance_of(Gitlab::CycleAnalytics::BaseStage).to receive(:median).and_return(1.12)
@@ -15,10 +15,10 @@ describe AnalyticsStageSerializer do
end
it 'it generates payload for single object' do
- expect(json).to be_kind_of Hash
+ expect(subject).to be_kind_of Hash
end
it 'contains important elements of AnalyticsStage' do
- expect(json).to include(:title, :description, :value)
+ expect(subject).to include(:title, :description, :value)
end
end
diff --git a/spec/serializers/analytics_summary_serializer_spec.rb b/spec/serializers/analytics_summary_serializer_spec.rb
index 7a84c8b0b40..5d7a94c2d02 100644
--- a/spec/serializers/analytics_summary_serializer_spec.rb
+++ b/spec/serializers/analytics_summary_serializer_spec.rb
@@ -1,29 +1,28 @@
require 'spec_helper'
describe AnalyticsSummarySerializer do
- let(:serializer) do
- described_class
- .new.represent(resource)
+ subject do
+ described_class.new.represent(resource)
end
- let(:json) { serializer.as_json }
let(:project) { create(:empty_project) }
let(:user) { create(:user) }
+
let(:resource) do
- Gitlab::CycleAnalytics::Summary::Issue.new(project: double,
- from: 1.day.ago,
- current_user: user)
+ Gitlab::CycleAnalytics::Summary::Issue
+ .new(project: double, from: 1.day.ago, current_user: user)
end
before do
- allow_any_instance_of(Gitlab::CycleAnalytics::Summary::Issue).to receive(:value).and_return(1.12)
+ allow_any_instance_of(Gitlab::CycleAnalytics::Summary::Issue)
+ .to receive(:value).and_return(1.12)
end
it 'it generates payload for single object' do
- expect(json).to be_kind_of Hash
+ expect(subject).to be_kind_of Hash
end
it 'contains important elements of AnalyticsStage' do
- expect(json).to include(:title, :value)
+ expect(subject).to include(:title, :value)
end
end
diff --git a/spec/serializers/environment_serializer_spec.rb b/spec/serializers/environment_serializer_spec.rb
index b7ed4eb0239..3c37660885d 100644
--- a/spec/serializers/environment_serializer_spec.rb
+++ b/spec/serializers/environment_serializer_spec.rb
@@ -1,16 +1,15 @@
require 'spec_helper'
describe EnvironmentSerializer do
- let(:serializer) do
+ let(:user) { create(:user) }
+ let(:project) { create(:project) }
+
+ let(:json) do
described_class
.new(user: user, project: project)
.represent(resource)
end
- let(:json) { serializer.as_json }
- let(:user) { create(:user) }
- let(:project) { create(:project) }
-
context 'when there is a single object provided' do
before do
create(:ci_build, :manual, name: 'manual1',
diff --git a/spec/serializers/pipeline_serializer_spec.rb b/spec/serializers/pipeline_serializer_spec.rb
index 3a32cb394dd..7cbf131e41e 100644
--- a/spec/serializers/pipeline_serializer_spec.rb
+++ b/spec/serializers/pipeline_serializer_spec.rb
@@ -7,11 +7,7 @@ describe PipelineSerializer do
described_class.new(user: user)
end
- let(:entity) do
- serializer.represent(resource)
- end
-
- subject { entity.as_json }
+ subject { serializer.represent(resource) }
describe '#represent' do
context 'when used without pagination' do