Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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)
cond_sql_operator = scope_val.nil? ? 'IS' : '='
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@url_owner_conditions.first << " AND #{scope} #{cond_sql_operator} ?"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [81/80]

@url_owner_conditions << scope_val
end
end

Expand Down
13 changes: 13 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,18 @@ 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: [:other, :another]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use %i or %I for an array of symbols.

end

@doc = Document.create(title: "Mocumentary", other: "Suddenly, I care if I'm unique",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [89/80]

another: nil)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of a hash literal if they span more than one line.

@other_doc = Document.create(title: "Mocumentary", other: "Suddenly, I care if I'm unique",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [95/80]

another: nil)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of a hash literal if they span more than one line.

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 Expand Up @@ -422,4 +434,5 @@ def url_taken?(url)
@doc = Document.create(title: "unique")
assert_equal "unique-3", @doc.url
end

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at class body end.

end