diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-24 18:08:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-24 18:08:44 +0300 |
commit | 120f4aaedc8fe830a3f572491d240d8ee6addefb (patch) | |
tree | a2138baa55dfa67d292fb1a83ce686ee7f5d10a5 /spec/models | |
parent | 729e3765d5feb762df1ccfbc228a8dd4662aa3f9 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/concerns/optionally_search_spec.rb | 30 | ||||
-rw-r--r-- | spec/models/project_services/discord_service_spec.rb | 18 |
2 files changed, 39 insertions, 9 deletions
diff --git a/spec/models/concerns/optionally_search_spec.rb b/spec/models/concerns/optionally_search_spec.rb index 71cf536db89..e1eb4cf8cd2 100644 --- a/spec/models/concerns/optionally_search_spec.rb +++ b/spec/models/concerns/optionally_search_spec.rb @@ -3,28 +3,39 @@ require 'spec_helper' describe OptionallySearch do - let(:model) do - Class.new(ActiveRecord::Base) do - self.table_name = 'users' - - include OptionallySearch + describe '.search' do + let(:model) do + Class.new do + include OptionallySearch + end end - end - describe '.search' do it 'raises NotImplementedError' do expect { model.search('foo') }.to raise_error(NotImplementedError) end end describe '.optionally_search' do + let(:model) do + Class.new(ActiveRecord::Base) do + self.table_name = 'users' + + include OptionallySearch + + def self.search(query, **options) + [query, options] + end + end + end + context 'when a query is given' do it 'delegates to the search method' do expect(model) .to receive(:search) .with('foo', {}) + .and_call_original - model.optionally_search('foo') + expect(model.optionally_search('foo')).to eq(['foo', {}]) end end @@ -33,8 +44,9 @@ describe OptionallySearch do expect(model) .to receive(:search) .with('foo', some_option: true) + .and_call_original - model.optionally_search('foo', some_option: true) + expect(model.optionally_search('foo', some_option: true)).to eq(['foo', { some_option: true }]) end end diff --git a/spec/models/project_services/discord_service_spec.rb b/spec/models/project_services/discord_service_spec.rb index 96ac532dcd1..b5a54676dd7 100644 --- a/spec/models/project_services/discord_service_spec.rb +++ b/spec/models/project_services/discord_service_spec.rb @@ -31,6 +31,24 @@ describe DiscordService do WebMock.stub_request(:post, webhook_url) end + it 'uses the right embed parameters' do + builder = Discordrb::Webhooks::Builder.new + + allow_next_instance_of(Discordrb::Webhooks::Client) do |client| + allow(client).to receive(:execute).and_yield(builder) + end + + subject.execute(sample_data) + + expect(builder.to_json_hash[:embeds].first).to include( + description: start_with("#{user.name} pushed to branch [master](http://localhost/#{project.namespace.path}/#{project.path}/commits/master) of"), + author: hash_including( + icon_url: start_with('https://www.gravatar.com/avatar/'), + name: user.name + ) + ) + end + context 'DNS rebind to local address' do before do stub_dns(webhook_url, ip_address: '192.168.2.120') |