diff options
author | Stan Hu <stanhu@gmail.com> | 2017-03-21 03:00:09 +0000 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-03-21 17:13:24 +0800 |
commit | f76f50592973002182f24e17f44f062689ac145f (patch) | |
tree | 9ef6376974c13bdbf97d73f9218c8dbe3cf65e81 | |
parent | aab54d752a901d8621783d1eaae3da026cd3c66a (diff) | |
download | gitlab-ce-f76f50592973002182f24e17f44f062689ac145f.tar.gz |
Merge branch 'rs-issue-29592' into 'master'
Handle Route#name being nil after an update
Closes #29592
See merge request !10102
-rw-r--r-- | app/models/route.rb | 2 | ||||
-rw-r--r-- | spec/models/route_spec.rb | 12 |
2 files changed, 11 insertions, 3 deletions
diff --git a/app/models/route.rb b/app/models/route.rb index 73574a6206b..41e6eb7cb73 100644 --- a/app/models/route.rb +++ b/app/models/route.rb @@ -21,7 +21,7 @@ class Route < ActiveRecord::Base attributes[:path] = route.path.sub(path_was, path) end - if name_changed? && route.name.present? + if name_changed? && name_was.present? && route.name.present? attributes[:name] = route.name.sub(name_was, name) end diff --git a/spec/models/route_spec.rb b/spec/models/route_spec.rb index 0b222022e62..bc8ae4ae5a8 100644 --- a/spec/models/route_spec.rb +++ b/spec/models/route_spec.rb @@ -43,14 +43,22 @@ describe Route, models: true do end context 'name update' do - before { route.update_attributes(name: 'bar') } - it "updates children routes with new path" do + route.update_attributes(name: 'bar') + expect(described_class.exists?(name: 'bar')).to be_truthy expect(described_class.exists?(name: 'bar / test')).to be_truthy expect(described_class.exists?(name: 'bar / test / foo')).to be_truthy expect(described_class.exists?(name: 'gitlab-org')).to be_truthy end + + it 'handles a rename from nil' do + # Note: using `update_columns` to skip all validation and callbacks + route.update_columns(name: nil) + + expect { route.update_attributes(name: 'bar') } + .to change { route.name }.from(nil).to('bar') + end end end end |