-
Notifications
You must be signed in to change notification settings - Fork 158
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
Add support for nil scope values (such as deleted_at), with unit test #198
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' : '=' | ||
@url_owner_conditions.first << " AND #{scope} #{cond_sql_operator} ?" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [89/80] |
||
another: nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [95/80] |
||
another: nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -422,4 +434,5 @@ def url_taken?(url) | |
@doc = Document.create(title: "unique") | ||
assert_equal "unique-3", @doc.url | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at class body end. |
||
end |
There was a problem hiding this comment.
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.