debian-mirror-gitlab/spec/serializers/suggestion_entity_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.5 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe SuggestionEntity do
2019-02-15 15:39:39 +05:30
include RepoHelpers
let(:user) { create(:user) }
let(:request) { double('request', current_user: user) }
let(:suggestion) { create(:suggestion) }
let(:entity) { described_class.new(suggestion, request: request) }
subject { entity.as_json }
it 'exposes correct attributes' do
2020-07-28 23:09:34 +05:30
expect(subject.keys).to match_array([:id, :appliable, :applied, :diff_lines, :current_user, :inapplicable_reason])
2019-02-15 15:39:39 +05:30
end
it 'exposes current user abilities' do
expect(subject[:current_user]).to include(:can_apply)
end
2020-07-28 23:09:34 +05:30
describe 'inapplicable_reason' do
let(:inapplicable_reason) { subject[:inapplicable_reason] }
before do
allow(Ability).to receive(:allowed?).and_call_original
allow(Ability)
.to receive(:allowed?)
.with(user, :apply_suggestion, suggestion)
.and_return(can_apply_suggestion)
end
context 'when user can apply suggestion' do
let(:can_apply_suggestion) { true }
before do
2020-10-24 23:57:45 +05:30
allow(suggestion).to receive(:inapplicable_reason).and_return("Can't apply this suggestion.")
2020-07-28 23:09:34 +05:30
end
2020-10-24 23:57:45 +05:30
it 'returns the inapplicable reason' do
expect(inapplicable_reason).to eq(suggestion.inapplicable_reason)
2020-07-28 23:09:34 +05:30
end
end
context 'when user cannot apply suggestion' do
let(:can_apply_suggestion) { false }
it 'returns appropriate message' do
expect(inapplicable_reason).to eq("You don't have write access to the source branch.")
end
end
end
2019-02-15 15:39:39 +05:30
end