Skip to content
Open
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
6 changes: 4 additions & 2 deletions lib/stringex/acts_as_url/adapter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ def add_new_record_url_owner_conditions

def add_scoped_url_owner_conditions
[settings.scope_for_url].flatten.compact.each do |scope|
@url_owner_conditions.first << " and #{scope} = ?"
@url_owner_conditions << instance.send(scope)
scope_val = instance.send(scope)
sql_operator = scope_val.nil? ? "IS" : "="
@url_owner_conditions.first << " AND #{scope} #{sql_operator} ?"
@url_owner_conditions << scope_val
end
end

Expand Down
16 changes: 16 additions & 0 deletions test/unit/acts_as_url_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,22 @@ def test_should_only_create_unique_urls_for_multiple_scopes_if_both_attributes_a
assert_not_equal @doc.url, @other_doc.url
end

def test_should_create_uniuque_urls_for_nil_scope_values
Document.class_eval do
acts_as_url :title, scope: %i[other another]
end

@doc = Document.create(title: "Soft Deleted Document",
other: "scope key",
another: nil)

@other_doc = Document.create(title: "Soft Deleted Document",
other: "scope key",
another: nil)

assert_not_equal @doc.url, @other_doc.url
end

def test_should_allow_setting_url_attribute
Document.class_eval do
# Manually undefining the url method on Document which, in a real class not reused for tests,
Expand Down