From e5792ae904173385a6f7451d6c9f34a7b530bc3e Mon Sep 17 00:00:00 2001 From: Alexander Bach Date: Wed, 8 Apr 2015 09:28:23 +0200 Subject: [PATCH] Test for absence of done_ratio in case of respective Setting --- .../work_package_payload_representer_spec.rb | 20 +++++++++++++------ .../work_package_representer_spec.rb | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/spec/lib/api/v3/work_packages/form/work_package_payload_representer_spec.rb b/spec/lib/api/v3/work_packages/form/work_package_payload_representer_spec.rb index e793f9822c..f28ee72c85 100644 --- a/spec/lib/api/v3/work_packages/form/work_package_payload_representer_spec.rb +++ b/spec/lib/api/v3/work_packages/form/work_package_payload_representer_spec.rb @@ -29,13 +29,13 @@ require 'spec_helper' describe ::API::V3::WorkPackages::Form::WorkPackagePayloadRepresenter do - let(:work_package) { + let(:work_package) do FactoryGirl.build(:work_package, start_date: Date.today.to_datetime, due_date: Date.today.to_datetime, created_at: DateTime.now, updated_at: DateTime.now) - } + end let(:representer) { described_class.create(work_package) } before { allow(work_package).to receive(:lock_version).and_return(1) } @@ -79,10 +79,18 @@ describe ::API::V3::WorkPackages::Form::WorkPackagePayloadRepresenter do end describe 'percentage done' do - it { is_expected.to have_json_path('percentageDone') } - it { is_expected.to have_json_type(Integer).at_path('percentageDone') } - it do - is_expected.to be_json_eql(work_package.done_ratio.to_json).at_path('percentageDone') + context 'percentage done enabled' do + it { is_expected.to have_json_path('percentageDone') } + it { is_expected.to have_json_type(Integer).at_path('percentageDone') } + it do + is_expected.to be_json_eql(work_package.done_ratio.to_json).at_path('percentageDone') + end + end + + context 'percentage done disabled' do + before { allow(Setting).to receive(:work_package_done_ratio).and_return('disabled') } + + it { is_expected.to_not have_json_path('percentageDone') } end end diff --git a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb index a0bd1fa226..a3c40341ed 100644 --- a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb +++ b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb @@ -218,7 +218,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do context 'setting disabled' do before { allow(Setting).to receive(:work_package_done_ratio).and_return('disabled') } - it { expect(parse_json(subject)['percentageDone']).to be_nil } + it { is_expected.to_not have_json_path('percentageDone') } end end end