From 81e11da8567d6725db87163e746ac7ce4e601e7d Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 24 Nov 2015 11:37:37 +0100 Subject: [PATCH] Fix error when default branch tries to be autosaved For some reason when branch from V2 models is being saved, it tries to also update relationships for V3 models, at least in tests. This fails, because default_branch association on the V3 Repository model has a primary key set to [:id, :default_branch]. In theory we use composite keys plugin, but it seems that it doesn't cover that case and because of that AR fails with an error "[:id, :default_branch] is not a Symbol" when it tries to call Model#send with primary_key as an argument. This commit fixes the issue by overriding the send method on the Repository model to not fail when AR does repository.send([:id, :default_branch_name]), when it needs to fetch a primary key. This is hacky, but I haven't found a nicer way to get around it. --- lib/travis/api/v3/models/repository.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/travis/api/v3/models/repository.rb b/lib/travis/api/v3/models/repository.rb index 6bf8f4de..b5cd94f8 100644 --- a/lib/travis/api/v3/models/repository.rb +++ b/lib/travis/api/v3/models/repository.rb @@ -49,5 +49,17 @@ module Travis::API::V3 rescue ActiveRecord::RecordNotUnique branches.where(name: name).first end + + def id_default_branch + [id, default_branch_name] + end + + def send(name, *args, &block) + if name == [:id, :default_branch] + name = :id_default_branch + end + + __send__(name, *args, &block) + end end end