Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cancan
Manage
Activity
Members
Plan
External wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Github Mirror
coopdevs
cancan
Commits
eb2826f1
Commit
eb2826f1
authored
14 years ago
by
Ryan Bates
Browse files
Options
Downloads
Patches
Plain Diff
adding more MetaWhere comparison operators
parent
a4926917
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/cancan/model_adapters/active_record_adapter.rb
+11
-3
11 additions, 3 deletions
lib/cancan/model_adapters/active_record_adapter.rb
spec/cancan/model_adapters/active_record_adapter_spec.rb
+18
-1
18 additions, 1 deletion
spec/cancan/model_adapters/active_record_adapter_spec.rb
with
29 additions
and
4 deletions
lib/cancan/model_adapters/active_record_adapter.rb
+
11
−
3
View file @
eb2826f1
...
@@ -11,9 +11,17 @@ module CanCan
...
@@ -11,9 +11,17 @@ module CanCan
def
self
.
matches_condition?
(
subject
,
name
,
value
)
def
self
.
matches_condition?
(
subject
,
name
,
value
)
subject_value
=
subject
.
send
(
name
.
column
)
subject_value
=
subject
.
send
(
name
.
column
)
case
name
.
method
case
name
.
method
.
to_sym
when
"lt"
then
subject_value
<
value
when
:eq
then
subject_value
==
value
when
"gt"
then
subject_value
>
value
when
:not_eq
then
subject_value
!=
value
when
:in
then
value
.
include?
(
subject_value
)
when
:not_in
then
!
value
.
include?
(
subject_value
)
when
:lt
then
subject_value
<
value
when
:lteq
then
subject_value
<=
value
when
:gt
then
subject_value
>
value
when
:gteq
then
subject_value
>=
value
when
:matches
then
subject_value
.
downcase
.
include?
(
value
.
downcase
)
when
:does_not_match
then
!
subject_value
.
downcase
.
include?
(
value
.
downcase
)
else
raise
NotImplemented
,
"The
#{
name
.
method
}
MetaWhere condition is not supported."
else
raise
NotImplemented
,
"The
#{
name
.
method
}
MetaWhere condition is not supported."
end
end
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/cancan/model_adapters/active_record_adapter_spec.rb
+
18
−
1
View file @
eb2826f1
...
@@ -19,6 +19,7 @@ if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record"
...
@@ -19,6 +19,7 @@ if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record"
with_model
:article
do
with_model
:article
do
table
do
|
t
|
table
do
|
t
|
t
.
string
"name"
t
.
boolean
"published"
t
.
boolean
"published"
t
.
boolean
"secret"
t
.
boolean
"secret"
t
.
integer
"priority"
t
.
integer
"priority"
...
@@ -227,11 +228,27 @@ if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record"
...
@@ -227,11 +228,27 @@ if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record"
it
"should match any MetaWhere condition"
do
it
"should match any MetaWhere condition"
do
adapter
=
CanCan
::
ModelAdapters
::
ActiveRecordAdapter
adapter
=
CanCan
::
ModelAdapters
::
ActiveRecordAdapter
article1
=
Article
.
new
(
:priority
=>
1
)
article1
=
Article
.
new
(
:priority
=>
1
,
:name
=>
"Hello World"
)
adapter
.
matches_condition?
(
article1
,
:priority
.
eq
,
1
).
should
be_true
adapter
.
matches_condition?
(
article1
,
:priority
.
eq
,
2
).
should
be_false
adapter
.
matches_condition?
(
article1
,
:priority
.
ne
,
2
).
should
be_true
adapter
.
matches_condition?
(
article1
,
:priority
.
ne
,
1
).
should
be_false
adapter
.
matches_condition?
(
article1
,
:priority
.
in
,
[
1
,
2
]).
should
be_true
adapter
.
matches_condition?
(
article1
,
:priority
.
in
,
[
2
,
3
]).
should
be_false
adapter
.
matches_condition?
(
article1
,
:priority
.
nin
,
[
2
,
3
]).
should
be_true
adapter
.
matches_condition?
(
article1
,
:priority
.
nin
,
[
1
,
2
]).
should
be_false
adapter
.
matches_condition?
(
article1
,
:priority
.
lt
,
2
).
should
be_true
adapter
.
matches_condition?
(
article1
,
:priority
.
lt
,
2
).
should
be_true
adapter
.
matches_condition?
(
article1
,
:priority
.
lt
,
1
).
should
be_false
adapter
.
matches_condition?
(
article1
,
:priority
.
lt
,
1
).
should
be_false
adapter
.
matches_condition?
(
article1
,
:priority
.
lteq
,
1
).
should
be_true
adapter
.
matches_condition?
(
article1
,
:priority
.
lteq
,
0
).
should
be_false
adapter
.
matches_condition?
(
article1
,
:priority
.
gt
,
0
).
should
be_true
adapter
.
matches_condition?
(
article1
,
:priority
.
gt
,
0
).
should
be_true
adapter
.
matches_condition?
(
article1
,
:priority
.
gt
,
1
).
should
be_false
adapter
.
matches_condition?
(
article1
,
:priority
.
gt
,
1
).
should
be_false
adapter
.
matches_condition?
(
article1
,
:priority
.
gteq
,
1
).
should
be_true
adapter
.
matches_condition?
(
article1
,
:priority
.
gteq
,
2
).
should
be_false
adapter
.
matches_condition?
(
article1
,
:name
.
like
,
"ello worl"
).
should
be_true
adapter
.
matches_condition?
(
article1
,
:name
.
like
,
"helo"
).
should
be_false
adapter
.
matches_condition?
(
article1
,
:name
.
nlike
,
"helo"
).
should
be_true
adapter
.
matches_condition?
(
article1
,
:name
.
nlike
,
"ello worl"
).
should
be_false
end
end
end
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment