Skip to content
Snippets Groups Projects
Commit 59b6564e authored by Valery Sizov's avatar Valery Sizov
Browse files

address comments

parent dc9100d1
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -45,7 +45,7 @@ class TeamcityService < CiService
end
 
def reset_password
if prop_updated?(:teamcity_url) && !prop_updated?(:password)
if prop_updated?(:teamcity_url) && !password_touched?
self.password = nil
end
end
Loading
Loading
Loading
Loading
@@ -125,8 +125,9 @@ class Service < ActiveRecord::Base
# ActiveRecord does not provide a mechanism to track changes in serialized keys.
# This is why we need to perform extra query to do it mannually.
def prop_updated?(prop_name)
return false if send("#{prop_name}_was").nil?
send("#{prop_name}_was") != send(prop_name)
value_was = send("#{prop_name}_was")
return false if value_was.nil?
value_was != send(prop_name)
end
 
def async_execute(data)
Loading
Loading
Loading
Loading
@@ -41,18 +41,19 @@ describe TeamcityService, models: true do
)
end
 
it "reset password if url changed" do
it "reset password if url is changed" do
@teamcity_service.teamcity_url = 'http://gitlab1.com'
@teamcity_service.save
expect(@teamcity_service.password).to be_nil
end
 
it "does not reset password if username changed" do
it "does not reset password if username is changed" do
@teamcity_service.username = "some_name"
@teamcity_service.save
expect(@teamcity_service.password).to eq("password")
end
 
it "does not reset password if new url is set together with password" do
@teamcity_service.teamcity_url = 'http://gitlab_edited.com'
@teamcity_service.password = '123'
Loading
Loading
@@ -60,5 +61,41 @@ describe TeamcityService, models: true do
expect(@teamcity_service.password).to eq("123")
expect(@teamcity_service.teamcity_url).to eq("http://gitlab_edited.com")
end
it "does not reset password if new url is set together with password, even if it's the same password" do
@teamcity_service.teamcity_url = 'http://gitlab_edited.com'
@teamcity_service.password = 'password'
@teamcity_service.save
expect(@teamcity_service.password).to eq("password")
expect(@teamcity_service.teamcity_url).to eq("http://gitlab_edited.com")
end
context "when no password was set before" do
before do
@teamcity_service = TeamcityService.create(
project: create(:project),
properties: {
teamcity_url: 'http://gitlab.com',
username: 'mic'
}
)
end
it "saves password if new url is set together with password" do
@teamcity_service.teamcity_url = 'http://gitlab_edited.com'
@teamcity_service.password = 'password'
@teamcity_service.save
expect(@teamcity_service.password).to eq("password")
expect(@teamcity_service.teamcity_url).to eq("http://gitlab_edited.com")
end
end
it "resets password if url is changed, even if setter called multiple times" do
@teamcity_service.teamcity_url = 'http://gitlab1.com'
@teamcity_service.teamcity_url = 'http://gitlab1.com'
@teamcity_service.save
expect(@teamcity_service.password).to be_nil
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment