diff options
| author | Jacob Vosmaer <jacob@gitlab.com> | 2017-11-22 13:45:26 +0100 |
|---|---|---|
| committer | Jacob Vosmaer <jacob@gitlab.com> | 2017-11-22 13:45:26 +0100 |
| commit | c18c61a49af70a18e7767f8d649ca2b1924689e2 (patch) | |
| tree | de953251b5bd0ce912bc276303b1bac81a4bfdb3 /spec | |
| parent | e548c613346a09ba2fc8dfd6ed64da6628ec6a45 (diff) | |
| download | gitlab-ce-c18c61a49af70a18e7767f8d649ca2b1924689e2.tar.gz | |
Fix encoding bugs in Gitlab::Git::User
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/lib/gitlab/encoding_helper_spec.rb | 1 | ||||
| -rw-r--r-- | spec/lib/gitlab/git/user_spec.rb | 17 | ||||
| -rw-r--r-- | spec/support/matchers/be_binary.rb | 9 |
3 files changed, 21 insertions, 6 deletions
diff --git a/spec/lib/gitlab/encoding_helper_spec.rb b/spec/lib/gitlab/encoding_helper_spec.rb index 9151c66afb3..f6e5c55240f 100644 --- a/spec/lib/gitlab/encoding_helper_spec.rb +++ b/spec/lib/gitlab/encoding_helper_spec.rb @@ -9,6 +9,7 @@ describe Gitlab::EncodingHelper do ["nil", nil, nil], ["empty string", "".encode("ASCII-8BIT"), "".encode("UTF-8")], ["invalid utf-8 encoded string", "my bad string\xE5".force_encoding("UTF-8"), "my bad string"], + ["frozen non-ascii string", "é".force_encoding("ASCII-8BIT").freeze, "é".encode("UTF-8")], [ 'leaves ascii only string as is', 'ascii only string', diff --git a/spec/lib/gitlab/git/user_spec.rb b/spec/lib/gitlab/git/user_spec.rb index eb8db819045..1ceb99be11e 100644 --- a/spec/lib/gitlab/git/user_spec.rb +++ b/spec/lib/gitlab/git/user_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' describe Gitlab::Git::User do - let(:username) { 'janedo' } - let(:name) { 'Jane Doe' } - let(:email) { 'janedoe@example.com' } + let(:username) { 'janedoe' } + let(:name) { 'Jane Doé' } + let(:email) { 'janedoé@example.com' } let(:gl_id) { 'user-123' } let(:user) do described_class.new(username, name, email, gl_id) @@ -13,7 +13,7 @@ describe Gitlab::Git::User do describe '.from_gitaly' do let(:gitaly_user) do - Gitaly::User.new(gl_username: username, name: name, email: email, gl_id: gl_id) + Gitaly::User.new(gl_username: username, name: name.b, email: email.b, gl_id: gl_id) end subject { described_class.from_gitaly(gitaly_user) } @@ -48,8 +48,13 @@ describe Gitlab::Git::User do it 'creates a Gitaly::User with the correct data' do expect(subject).to be_a(Gitaly::User) expect(subject.gl_username).to eq(username) - expect(subject.name).to eq(name) - expect(subject.email).to eq(email) + + expect(subject.name).to eq(name.b) + expect(subject.name).to be_binary + + expect(subject.email).to eq(email.b) + expect(subject.email).to be_binary + expect(subject.gl_id).to eq(gl_id) end end diff --git a/spec/support/matchers/be_binary.rb b/spec/support/matchers/be_binary.rb new file mode 100644 index 00000000000..c517d7370be --- /dev/null +++ b/spec/support/matchers/be_binary.rb @@ -0,0 +1,9 @@ +RSpec::Matchers.define :be_binary do |_| + match do |actual| + actual.is_a?(String) && actual.encoding == Encoding.find('ASCII-8BIT') + end + + description do + "be a String with binary encoding" + end +end |
