Skip to content

Commit

Permalink
Merge pull request #21 from GabrielNagy/allow-searching-by-string
Browse files Browse the repository at this point in the history
Support passing strings in with_ scope
  • Loading branch information
shkm authored Aug 26, 2024
2 parents 0ece7e4 + cc7a658 commit 6fd34bf
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
/test/dummy/log/*.log
/test/dummy/tmp/
/test/dummy/dummy_test
/test/dummy/*-wal
/test/dummy/*-shm
/Gemfile.lock
/coverage
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ gem "standard"

group :test do
gem "pg"
gem "sqlite3"
gem "sqlite3", "~> 1.4"
gem "mysql2"
gem "simplecov", require: false
gem 'simplecov-cobertura', require: false
Expand Down
2 changes: 1 addition & 1 deletion lib/enummer/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def enummer(values)

def _enummer_build_with_scope(attribute_name, value_names)
scope "with_#{attribute_name}", lambda { |desired|
expected = Array.wrap(desired).sum(0) { |value| 1 << value_names.index(value) }
expected = Array.wrap(desired).sum(0) { |value| 1 << value_names.index(value.to_sym) }

where("#{attribute_name} & :expected = :expected", expected: expected)
}
Expand Down
2 changes: 2 additions & 0 deletions test/enummer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def setup

test "with_ scope returns users with all of those bits set" do
assert_equal [@user1], User.with_permissions(%i[execute read write])
assert_equal [@user1], User.with_permissions(%w[execute read write])
assert_equal [@user1, @user2], User.with_permissions(['read', :write])
end

test "not scopes return users without those bits set" do
Expand Down

0 comments on commit 6fd34bf

Please sign in to comment.