Permalink
Browse files

Merge pull request #64 from alphagov/fix_routeable_artefact_delete

Fix nil error in RouteableArtefact#delete
  • Loading branch information...
2 parents 8229144 + b3d5031 commit ebe31b645ab5e78f56ddaa5c74619afc4f868a56 @jamiecobbett jamiecobbett committed Mar 12, 2013
Showing with 28 additions and 1 deletion.
  1. +1 −1 app/models/routable_artefact.rb
  2. +27 −0 test/unit/routable_artefact_test.rb
@@ -39,7 +39,7 @@ def submit
end
def delete
- ([@artefact.slug] + @artefact.paths + @artefact.prefixes).each do |path|
+ ([@artefact.slug] + (@artefact.paths || []) + (@artefact.prefixes || [])).each do |path|
router.delete_route(path)
end
end
@@ -80,4 +80,31 @@ class RoutableArtefactTest < ActiveSupport::TestCase
Router.any_instance.stubs(:create_route)
@routable.submit
end
+
+ context "deleting routes for an artefact" do
+
+ should "delete the artefact slug from the router" do
+ Router.any_instance.expects(:delete_route).with(@artefact.slug)
+ @routable.delete
+ end
+
+ should "delete all paths and prefixes as well as the slug" do
+ @artefact.paths = ["foo", "bar"]
+ @artefact.prefixes = ["baz"]
+ Router.any_instance.expects(:delete_route).with(@artefact.slug)
+ Router.any_instance.expects(:delete_route).with("foo")
+ Router.any_instance.expects(:delete_route).with("bar")
+ Router.any_instance.expects(:delete_route).with("baz")
+ @routable.delete
+ end
+
+ should "cope with paths or prefixes being set to nil" do
+ @artefact.paths = nil
+ @artefact.prefixes = nil
+ Router.any_instance.expects(:delete_route).with(@artefact.slug)
+ assert_nothing_raised do
+ @routable.delete
+ end
+ end
+ end
end

0 comments on commit ebe31b6

Please sign in to comment.