summaryrefslogtreecommitdiff
path: root/spec/models/route_spec.rb
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2017-03-20 19:17:14 -0400
committerRobert Speicher <rspeicher@gmail.com>2017-03-20 19:17:14 -0400
commit9bf9e6eb38b955791abce475dbaec1001d6c39c0 (patch)
treeded2d40410270b25fca5e0c7a5692611031390c7 /spec/models/route_spec.rb
parentb075d38c9b98d4b39441bd29d2c36be4637b6f72 (diff)
downloadgitlab-ce-9bf9e6eb38b955791abce475dbaec1001d6c39c0.tar.gz
Handle Route#name being nil after an update
It was possible for the `routes.name` field to be `NULL`, causing `name_was` to be `nil` after a rename, resulting a bad first argument to `sub` when attempting to rename descendants. This change adds a condition to make sure `name_was` is present before attempting the descendant update.
Diffstat (limited to 'spec/models/route_spec.rb')
-rw-r--r--spec/models/route_spec.rb12
1 files changed, 10 insertions, 2 deletions
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