Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use more permissive argument passthrough for insert_all and upsert_all #275

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions acceptance/cases/models/insert_all_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def test_insert_all
assert_raise(NotImplementedError) { Author.insert_all(values) }
end

def test_insert
value = { id: Author.next_sequence_value, name: "Alice" }

assert_raise(NotImplementedError) { Author.insert(value) }
end

def test_insert_all!
values = [
{ id: Author.next_sequence_value, name: "Alice" },
Expand Down Expand Up @@ -85,6 +91,22 @@ def test_insert_all_with_buffered_mutation_transaction
assert_equal "Carol", authors[2].name
end

def test_upsert
Author.create id: 1, name: "David"
authors = Author.all.order(:name)
assert_equal 1, authors.length
assert_equal "David", authors[0].name

value = { id: 1, name: "Alice" }

Author.upsert(value)

authors = Author.all.order(:name)

assert_equal 1, authors.length
assert_equal "Alice", authors[0].name
end

def test_upsert_all
Author.create id: 1, name: "David"
authors = Author.all.order(:name)
Expand Down
6 changes: 3 additions & 3 deletions lib/activerecord_spanner_adapter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def self._upsert_record values
_buffer_record values, :insert_or_update
end

def self.insert_all _attributes, _returning: nil, _unique_by: nil
def self.insert_all _attributes, **_kwargs
raise NotImplementedError, "Cloud Spanner does not support skip_duplicates."
end

def self.insert_all! attributes, returning: nil
def self.insert_all! attributes, **kwargs
return super unless spanner_adapter?
return super if active_transaction? && !buffered_mutations?

Expand All @@ -90,7 +90,7 @@ def self.insert_all! attributes, returning: nil
end
end

def self.upsert_all attributes, returning: nil, unique_by: nil
def self.upsert_all attributes, **kwargs
return super unless spanner_adapter?
if active_transaction? && !buffered_mutations?
raise NotImplementedError, "Cloud Spanner does not support upsert using DML. " \
Expand Down