From a070ae4a320f8da830862e1dd11eea8b1281ab8c Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Tue, 6 Sep 2016 16:13:04 -0500 Subject: Style fixes and better tests. --- spec/gitlab_lfs_authentication_spec.rb | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'spec/gitlab_lfs_authentication_spec.rb') diff --git a/spec/gitlab_lfs_authentication_spec.rb b/spec/gitlab_lfs_authentication_spec.rb index ff715cf..9e93a07 100644 --- a/spec/gitlab_lfs_authentication_spec.rb +++ b/spec/gitlab_lfs_authentication_spec.rb @@ -1,22 +1,37 @@ require 'spec_helper' require 'gitlab_lfs_authentication' +require 'json' describe GitlabLfsAuthentication do - let(:user) { { 'username' => 'dzaporozhets', 'lfs_token' => 'wsnys8Zm8Jn7zyhHTAAK' } } - subject do - GitlabLfsAuthentication.new('dzaporozhets', 'wsnys8Zm8Jn7zyhHTAAK', 'http://gitlab.dev/repo') + GitlabLfsAuthentication.build_from_json( + JSON.generate( + { + username: 'dzaporozhets', + lfs_token: 'wsnys8Zm8Jn7zyhHTAAK', + repository_http_path: 'http://gitlab.dev/repo' + } + ) + ) end - describe '#initialize' do + describe '#build_from_json' do it { subject.username.should == 'dzaporozhets' } it { subject.lfs_token.should == 'wsnys8Zm8Jn7zyhHTAAK' } it { subject.repository_http_path.should == 'http://gitlab.dev/repo' } end - describe '#authenticate!' do + describe '#authentication_payload' do result = "{\"header\":{\"Authorization\":\"Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL\"},\"href\":\"http://gitlab.dev/repo/info/lfs/\"}" - it { subject.authenticate!.should == result } + it { subject.authentication_payload.should eq(result) } + + it 'should be a proper JSON' do + payload = subject.authentication_payload + json_payload = JSON.parse(payload) + + json_payload['header']['Authorization'].should eq('Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL') + json_payload['href'].should eq('http://gitlab.dev/repo/info/lfs/') + end end end -- cgit v1.2.1