|
43 | 43 | end
|
44 | 44 | end
|
45 | 45 |
|
46 |
| - context 'none of columns are connected' do |
| 46 | + context 'when none of columns are connected' do |
47 | 47 | before(:each) do
|
48 | 48 | allow(datatable).to receive(:searchable_columns) { [] }
|
49 | 49 | end
|
50 | 50 |
|
51 |
| - it 'returns empty query result' do |
52 |
| - datatable.params[:search] = { value: 'msmith' } |
53 |
| - expect(datatable.send(:build_conditions_for_datatable)).to be_blank |
54 |
| - end |
55 |
| - end |
56 |
| - |
57 |
| - context 'with search query' do |
58 | 51 | context 'when search value is a string' do
|
59 | 52 | before(:each) do
|
60 |
| - datatable.params[:search] = { value: 'john', regex: 'false' } |
| 53 | + datatable.params[:search] = { value: 'msmith' } |
61 | 54 | end
|
62 | 55 |
|
63 |
| - it 'returns a filtering query' do |
| 56 | + it 'returns empty query result' do |
| 57 | + expect(datatable.send(:build_conditions_for_datatable)).to be_blank |
| 58 | + end |
| 59 | + |
| 60 | + it 'returns filtered results' do |
64 | 61 | query = datatable.send(:build_conditions_for_datatable)
|
65 | 62 | results = records.where(query).map(&:username)
|
66 |
| - expect(results).to include('johndoe') |
67 |
| - expect(results).not_to include('msmith') |
| 63 | + expect(results).to eq ['johndoe', 'msmith'] |
68 | 64 | end
|
69 | 65 | end
|
70 | 66 |
|
71 | 67 | context 'when search value is space-separated string' do
|
72 | 68 | before(:each) do
|
73 |
| - datatable.instance_variable_set :@searchable_columns, [] |
74 |
| - datatable.params[:search] = { value: 'foo bar', regex: 'false' } |
| 69 | + datatable.params[:search] = { value: 'foo bar' } |
75 | 70 | end
|
76 | 71 |
|
77 |
| - it 'returns a filtering query' do |
| 72 | + it 'returns empty query result' do |
| 73 | + expect(datatable.send(:build_conditions_for_datatable)).to be_blank |
| 74 | + end |
| 75 | + |
| 76 | + it 'returns filtered results' do |
78 | 77 | query = datatable.send(:build_conditions_for_datatable)
|
79 | 78 | results = records.where(query).map(&:username)
|
80 | 79 | expect(results).to eq ['johndoe', 'msmith']
|
81 | 80 | end
|
82 | 81 | end
|
| 82 | + end |
83 | 83 |
|
84 |
| - context 'when search value is comma-separated string' do |
| 84 | + context 'with search query' do |
| 85 | + context 'when search value is a string' do |
85 | 86 | before(:each) do
|
86 |
| - datatable.instance_variable_set :@searchable_columns, [] |
87 |
| - datatable.params[:search] = { value: 'foo, bar', regex: 'false' } |
88 |
| - expect(datatable).to receive(:global_search_delimiter).and_return(', ') |
| 87 | + datatable.params[:search] = { value: 'john', regex: 'false' } |
89 | 88 | end
|
90 | 89 |
|
91 | 90 | it 'returns a filtering query' do
|
92 | 91 | query = datatable.send(:build_conditions_for_datatable)
|
93 | 92 | results = records.where(query).map(&:username)
|
94 |
| - expect(results).to eq ['johndoe', 'msmith'] |
| 93 | + expect(results).to include('johndoe') |
| 94 | + expect(results).not_to include('msmith') |
| 95 | + end |
| 96 | + end |
| 97 | + |
| 98 | + context 'when search value is space-separated string' do |
| 99 | + before(:each) do |
| 100 | + datatable.params[:search] = { value: 'john doe', regex: 'false' } |
| 101 | + end |
| 102 | + |
| 103 | + it 'returns a filtering query' do |
| 104 | + query = datatable.send(:build_conditions_for_datatable) |
| 105 | + results = records.where(query).map(&:username) |
| 106 | + expect(results).to eq ['johndoe'] |
| 107 | + expect(results).not_to include('msmith') |
95 | 108 | end
|
96 | 109 | end
|
97 | 110 | end
|
|
0 commit comments