Commit 6d0731e4 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Test resetting password and validating username

parent 1e75c7db
...@@ -24,7 +24,9 @@ describe JenkinsService do ...@@ -24,7 +24,9 @@ describe JenkinsService do
it { is_expected.to belong_to :project } it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook } it { is_expected.to have_one :service_hook }
end end
let(:project) { create(:project) } let(:project) { create(:project) }
let(:jenkins_params) do let(:jenkins_params) do
{ {
active: true, active: true,
...@@ -44,19 +46,36 @@ describe JenkinsService do ...@@ -44,19 +46,36 @@ describe JenkinsService do
properties: { properties: {
jenkins_url: 'http://jenkins.example.com/', jenkins_url: 'http://jenkins.example.com/',
password: 'password', password: 'password',
username: nil, username: 'username',
} }
) )
end end
subject { @jenkins_service } subject { @jenkins_service }
context 'when the service is active' do context 'when the service is active' do
let(:active) { true } let(:active) { true }
context 'when password was not touched' do
before do
allow(subject).to receive(:password_touched?).and_return(false)
end
it { is_expected.not_to validate_presence_of :username }
end
context 'when password was touched' do
before do
allow(subject).to receive(:password_touched?).and_return(true)
end
it { is_expected.to validate_presence_of :username } it { is_expected.to validate_presence_of :username }
end end
end
context 'when the service is inactive' do context 'when the service is inactive' do
let(:active) { false } let(:active) { false }
it { is_expected.not_to validate_presence_of :username } it { is_expected.not_to validate_presence_of :username }
end end
end end
...@@ -130,12 +149,18 @@ describe JenkinsService do ...@@ -130,12 +149,18 @@ describe JenkinsService do
) )
end end
it 'reset password if url changed' do it 'resets password if url changed' do
@jenkins_service.jenkins_url = 'http://jenkins-edited.example.com/' @jenkins_service.jenkins_url = 'http://jenkins-edited.example.com/'
@jenkins_service.save @jenkins_service.save
expect(@jenkins_service.password).to be_nil expect(@jenkins_service.password).to be_nil
end end
it 'resets password if username is blank' do
@jenkins_service.username = ''
@jenkins_service.save
expect(@jenkins_service.password).to be_nil
end
it 'does not reset password if username changed' do it 'does not reset password if username changed' do
@jenkins_service.username = 'some_name' @jenkins_service.username = 'some_name'
@jenkins_service.save @jenkins_service.save
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment