Make scope creation optional#6
Conversation
| @@ -1,3 +1,7 @@ | |||
| require 'bundler' | |||
There was a problem hiding this comment.
Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
|
|
||
| it 'defines inactive! method' do | ||
| subject.methods.should include(:inactive!) | ||
| it 'define inactive scope' do |
There was a problem hiding this comment.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
| describe 'with :active and opposite param' do | ||
| subject { ArticleWithOpposite } | ||
|
|
||
| it 'define active scope' do |
There was a problem hiding this comment.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
|
|
||
| it 'define inactive scope' do | ||
| subject.class.methods.should include(:inactive) | ||
| describe 'with :active and opposite param' do |
There was a problem hiding this comment.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
|
|
||
| describe 'with :active and opposite param' do | ||
| subject { ArticleWithOpposite.new } | ||
| describe 'with :active param and scope: :reactive' do |
There was a problem hiding this comment.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
| @@ -0,0 +1,6 @@ | |||
| class ArticleWithScopeFalse < ActiveRecord::Base | |||
There was a problem hiding this comment.
Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.
| @@ -0,0 +1,6 @@ | |||
| class ArticleWithScope < ActiveRecord::Base | |||
| include ActAsTimeAsBoolean | |||
| self.table_name= 'article' | |||
There was a problem hiding this comment.
Layout/SpaceAroundOperators: Surrounding space missing for operator =.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
| @@ -0,0 +1,6 @@ | |||
| class ArticleWithScope < ActiveRecord::Base | |||
There was a problem hiding this comment.
Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.
| unless options[:scope] == false | ||
| scope_name = options[:scope] || field | ||
| scope scope_name, -> { | ||
| where "#{table_name}.#{field}_at IS NOT NULL AND #{table_name}.#{field}_at <= ?", Time.current |
There was a problem hiding this comment.
Metrics/LineLength: Line is too long. [104/80]
| } | ||
| unless options[:scope] == false | ||
| scope_name = options[:scope] || field | ||
| scope scope_name, -> { |
There was a problem hiding this comment.
Style/Lambda: Use the lambda method for multiline lambdas.
|
ignoring @houndci-bot for now; happy to make more fixes to the code which, in all its simplicity, I find quite useful. |
The code
was causing the following error (since Rails 5.2):
This change allows one to work around this error, either by saying:
or alternatively: