|
31 | 31 | end |
32 | 32 |
|
33 | 33 | it "returns only specified fields when options given" do |
34 | | - options = {"name" => {}, "email" => {}} |
| 34 | + options = { "name" => {}, "email" => {} } |
35 | 35 | fields = repository.fields(options: options) |
36 | 36 | expect(fields.keys).to eq(["name", "email"]) |
37 | 37 | end |
|
72 | 72 | end |
73 | 73 |
|
74 | 74 | it "returns only specified fields when fields given", :aggregate_failures do |
75 | | - attrs = repository.index_record_attrs(author, fields: {"name" => nil, "email" => nil}) |
| 75 | + attrs = repository.index_record_attrs(author, fields: { "name" => nil, "email" => nil }) |
76 | 76 | expect(attrs.keys).to eq(["name", "email"]) |
77 | 77 | expect(attrs["name"]).to eq(author.name) |
78 | 78 | end |
|
93 | 93 | end |
94 | 94 |
|
95 | 95 | it "sorts when sort option given" do |
96 | | - records, = repository.list(page: 1, limit: 10, sort: {name: :desc}) |
| 96 | + records, = repository.list(page: 1, limit: 10, sort: { name: :desc }) |
97 | 97 | names = records.map(&:name) |
98 | 98 | expect(names).to eq(names.sort.reverse) |
99 | 99 | end |
|
104 | 104 |
|
105 | 105 | it "filters string fields with LIKE" do |
106 | 106 | title_field = TinyAdmin::Field.new(name: "title", title: "Title", type: :string) |
107 | | - filters = {title_field => {value: "post 1"}} |
| 107 | + filters = { title_field => { value: "post 1" } } |
108 | 108 | results = post_repository.apply_filters(Post.all, filters) |
109 | 109 | results.each do |post| |
110 | 110 | expect(post.title.downcase).to include("post 1") |
|
114 | 114 | it "filters non-string fields with equality" do |
115 | 115 | author = Author.first |
116 | 116 | author_field = TinyAdmin::Field.new(name: "author_id", title: "Author", type: :integer) |
117 | | - filters = {author_field => {value: author.id}} |
| 117 | + filters = { author_field => { value: author.id } } |
118 | 118 | results = post_repository.apply_filters(Post.all, filters) |
119 | 119 | results.each do |post| |
120 | 120 | expect(post.author_id).to eq(author.id) |
|
123 | 123 |
|
124 | 124 | it "skips filters with nil or empty values" do |
125 | 125 | title_field = TinyAdmin::Field.new(name: "title", title: "Title", type: :string) |
126 | | - filters = {title_field => {value: nil}} |
| 126 | + filters = { title_field => { value: nil } } |
127 | 127 | results = post_repository.apply_filters(Post.all, filters) |
128 | 128 | expect(results.count).to eq(Post.count) |
129 | 129 | end |
130 | 130 |
|
131 | 131 | it "sanitizes SQL LIKE input" do |
132 | 132 | title_field = TinyAdmin::Field.new(name: "title", title: "Title", type: :string) |
133 | | - filters = {title_field => {value: "100%"}} |
| 133 | + filters = { title_field => { value: "100%" } } |
134 | 134 | # Should not raise or cause SQL injection |
135 | 135 | expect { post_repository.apply_filters(Post.all, filters).to_a }.not_to raise_error |
136 | 136 | end |
|
0 commit comments