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

Made filter search case-insensetive for mongoid #1246

Merged
merged 4 commits into from
Jul 16, 2012
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
2 changes: 1 addition & 1 deletion app/controllers/rails_admin/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def list_entries(model_config = @model_config, auth_scope_key = :index, addition
end

private

def get_layout
"rails_admin/#{request.headers['X-PJAX'] ? 'pjax' : 'application'}"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/adapters/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def build_statement(column, type, value, operator)
return if value.blank?
value = case operator
when 'default', 'like'
Regexp.compile(Regexp.escape(value))
Regexp.compile(Regexp.escape(value), Regexp::IGNORECASE)
when 'starts_with'
Regexp.compile("^#{Regexp.escape(value)}")
when 'ends_with'
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/adapters/mongoid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,10 @@ class CustomValiated
it "supports string type query" do
@abstract_model.send(:build_statement, :field, :string, "", nil).should be_nil
@abstract_model.send(:build_statement, :field, :string, "foo", "was").should be_nil
@abstract_model.send(:build_statement, :field, :string, "foo", "default").should == {:field=>/foo/}
@abstract_model.send(:build_statement, :field, :string, "foo", "like").should == {:field=>/foo/}
@abstract_model.send(:build_statement, :field, :string, "foo", "starts_with").should == {:field=>/^foo/}
@abstract_model.send(:build_statement, :field, :string, "foo", "ends_with").should == {:field=>/foo$/}
@abstract_model.send(:build_statement, :field, :string, "foo", "default").should == {:field=>/foo/i}
@abstract_model.send(:build_statement, :field, :string, "foo", "like").should == {:field=>/foo/i}
@abstract_model.send(:build_statement, :field, :string, "foo", "starts_with").should == {:field=>/^foo/i}
@abstract_model.send(:build_statement, :field, :string, "foo", "ends_with").should == {:field=>/foo$/i}
@abstract_model.send(:build_statement, :field, :string, "foo", "is").should == {:field=>'foo'}
end

Expand Down