Skip to content
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

Issue #451 parsing filters with curlies #452

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/graphiti/scoping/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ def parse_string_arrays(value, singular_filter)
# Find the quoted strings
quotes = value.scan(/{{.*?}}/)
# remove them from the rest
quotes.each { |q| value.gsub!(q, "") }
non_quotes = quotes.inject(value) { |v, q| v.gsub(q, "") }
# remove the quote characters from the quoted strings
quotes.each { |q| q.gsub!("{{", "").gsub!("}}", "") }
# merge everything back together into an array
value = if singular_filter
Array(value) + quotes
Array(non_quotes) + quotes
else
Array(value.split(",")) + quotes
Array(non_quotes.split(",")) + quotes
end
# remove any blanks that are left
value.reject! { |v| v.length.zero? }
Expand Down
14 changes: 14 additions & 0 deletions spec/filtering_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ def self.name
expect(records.map(&:id)).to eq([employee1.id])
end

context "retains filtering value" do
it "when value includes curly brackets" do
params[:filter] = {first_name: "{{John}}"}
records
expect(params[:filter]).to eq(first_name: "{{John}}")
end

it "when value does not include curly brackets" do
params[:filter] = {first_name: "John"}
records
expect(params[:filter]).to eq(first_name: "John")
end
end

context "when filter is type hash" do
before do
resource.filter :by_json, :hash do
Expand Down
Loading