Skip to content

Conversation

@masonhale
Copy link

Current scope implementation fails if one or more of the scope attribute values is nil.

One may want to use nullable values as scope parameters when using stringex/acts_as_url in combination with a 'soft-delete' solution such as https://github.com/JackDanger/permanent_records

In this case, 'live' records will have a nil value for the deleted_at column, but deleted records will have a specific value. By including the deleted_at column in the acts_as_url scope, one can ensure that url slugs for live records will be unique, while also avoiding having 'deleted' records polluting the available URL space.

@doc = Document.create(title: "unique")
assert_equal "unique-3", @doc.url
end

Copy link
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.

@doc = Document.create(title: "Mocumentary", other: "Suddenly, I care if I'm unique",
another: nil)
@other_doc = Document.create(title: "Mocumentary", other: "Suddenly, I care if I'm unique",
another: nil)
Copy link
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.


@doc = Document.create(title: "Mocumentary", other: "Suddenly, I care if I'm unique",
another: nil)
@other_doc = Document.create(title: "Mocumentary", other: "Suddenly, I care if I'm unique",
Copy link
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]

end

@doc = Document.create(title: "Mocumentary", other: "Suddenly, I care if I'm unique",
another: nil)
Copy link
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.

acts_as_url :title, scope: [:other, :another]
end

@doc = Document.create(title: "Mocumentary", other: "Suddenly, I care if I'm unique",
Copy link
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]


def test_should_create_uniuque_urls_for_nil_scope_values
Document.class_eval do
acts_as_url :title, scope: [:other, :another]
Copy link
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.

@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} ?"
Copy link
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.first << " and #{scope} = ?"
@url_owner_conditions << instance.send(scope)
scope_val = instance.send(scope)
cond_sql_operator = scope_val.nil? ? 'IS' : '='
Copy link
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.

other: "scope key",
another: nil)

@other_doc = Document.create(title: "Soft Deleted Document",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Trailing whitespace detected.

acts_as_url :title, scope: %i[other, another]
end

@doc = Document.create(title: "Soft Deleted Document",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Trailing whitespace detected.


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

Choose a reason for hiding this comment

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

Within %i/%I, ':' and ',' are unnecessary and may be unwanted in the resulting symbols.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants