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.
This commit is contained in:
parent
a31a6cb92b
commit
81e11da856
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user