sorting_table_for 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.mdown +4 -0
- data/init.rb +0 -4
- data/lib/sorting_table_for.rb +3 -0
- data/lib/sorting_table_for/format_cell.rb +189 -0
- data/lib/sorting_table_for/format_line.rb +110 -0
- data/lib/sorting_table_for/i18n.rb +16 -9
- data/lib/sorting_table_for/model_scope.rb +76 -0
- data/lib/sorting_table_for/table_builder.rb +15 -306
- data/spec/db/schema.rb +1 -1
- data/spec/fixtures/{user.rb → sorting_table_for_user.rb} +2 -2
- data/spec/helpers/builder_spec.rb +8 -5
- data/spec/helpers/caption_spec.rb +7 -4
- data/spec/helpers/cell_value_spec.rb +7 -4
- data/spec/helpers/column_spec.rb +14 -11
- data/spec/helpers/footer_spec.rb +7 -4
- data/spec/helpers/header_spec.rb +33 -8
- data/spec/helpers/i18n_spec.rb +12 -7
- data/spec/locales/test.yml +11 -2
- data/spec/locales/test_rails3.yml +6 -4
- data/spec/model/sorting_table_model_scope_spec.rb +24 -18
- data/spec/spec_helper.rb +18 -0
- metadata +7 -15
- data/lib/model/sorting_table_model_scope.rb +0 -72
@@ -1,16 +1,19 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
-
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/sorting_table_for_user')
|
5
5
|
|
6
6
|
include SortingTableForSpecHelper
|
7
7
|
|
8
8
|
describe SortingTableFor, :type => :helper do
|
9
9
|
|
10
|
+
before :all do
|
11
|
+
(SortingTableFor::Tools::rails3?) ? routes_rails3 : routes_rails2
|
12
|
+
end
|
13
|
+
|
10
14
|
before :each do
|
11
|
-
@users =
|
12
|
-
helper.stub!(:
|
13
|
-
helper.stub!(:params).and_return({ :controller => 'fakes', :action => 'index' })
|
15
|
+
@users = SortingTableForUser.all
|
16
|
+
helper.stub!(:params).and_return({ :controller => 'sorting_table_for_users', :action => 'index' })
|
14
17
|
helper.output_buffer = ''
|
15
18
|
end
|
16
19
|
|
@@ -1,16 +1,19 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
-
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/sorting_table_for_user')
|
5
5
|
|
6
6
|
include SortingTableForSpecHelper
|
7
7
|
|
8
8
|
describe SortingTableFor, :type => :helper do
|
9
9
|
|
10
|
+
before :all do
|
11
|
+
(SortingTableFor::Tools::rails3?) ? routes_rails3 : routes_rails2
|
12
|
+
end
|
13
|
+
|
10
14
|
before :each do
|
11
|
-
@users =
|
12
|
-
helper.stub!(:
|
13
|
-
helper.stub!(:params).and_return({ :controller => 'fakes', :action => 'index' })
|
15
|
+
@users = SortingTableForUser.all
|
16
|
+
helper.stub!(:params).and_return({ :controller => 'sorting_table_for_users', :action => 'index' })
|
14
17
|
helper.output_buffer = ''
|
15
18
|
SortingTableFor::TableBuilder.default_boolean = [I18n.t(:bool_true, :scope => [:sorting_table_for, :columns]), I18n.t(:bool_false, :scope => [:sorting_table_for, :columns])]
|
16
19
|
SortingTableFor::TableBuilder.i18n_default_format_date = :default
|
data/spec/helpers/column_spec.rb
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
-
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/sorting_table_for_user')
|
5
5
|
|
6
6
|
include SortingTableForSpecHelper
|
7
7
|
|
8
8
|
describe SortingTableFor, :type => :helper do
|
9
9
|
|
10
|
+
before :all do
|
11
|
+
(SortingTableFor::Tools::rails3?) ? routes_rails3 : routes_rails2
|
12
|
+
end
|
13
|
+
|
10
14
|
before :each do
|
11
|
-
@users =
|
12
|
-
helper.stub!(:
|
13
|
-
helper.stub!(:params).and_return({ :controller => 'fakes', :action => 'index' })
|
15
|
+
@users = SortingTableForUser.all
|
16
|
+
helper.stub!(:params).and_return({ :controller => 'sorting_table_for_users', :action => 'index' })
|
14
17
|
helper.output_buffer = ''
|
15
18
|
end
|
16
19
|
|
@@ -21,7 +24,7 @@ describe SortingTableFor, :type => :helper do
|
|
21
24
|
html = table.columns
|
22
25
|
html.should have_comp_tag("tbody", :count => 1)
|
23
26
|
html.should have_comp_tag("tr", :count => (@users.size + 1))
|
24
|
-
html.should have_comp_tag("td", :count => (@users.size * (
|
27
|
+
html.should have_comp_tag("td", :count => (@users.size * (SortingTableForUser.content_columns.size + 2)) + 1)
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
@@ -33,7 +36,7 @@ describe SortingTableFor, :type => :helper do
|
|
33
36
|
|
34
37
|
it "should add colspan for total entries" do
|
35
38
|
helper.sorting_table_for(@users) do |table|
|
36
|
-
table.columns.should match("<td colspan=\"" + (
|
39
|
+
table.columns.should match("<td colspan=\"" + (SortingTableForUser.content_columns.size + 2).to_s + "\">")
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
@@ -45,7 +48,7 @@ describe SortingTableFor, :type => :helper do
|
|
45
48
|
|
46
49
|
it "should add colspan for total entries" do
|
47
50
|
helper.sorting_table_for(@users) do |table|
|
48
|
-
table.columns.should match("<td colspan=\"" + (
|
51
|
+
table.columns.should match("<td colspan=\"" + (SortingTableForUser.content_columns.size + 2).to_s + "\">")
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
@@ -85,7 +88,7 @@ describe SortingTableFor, :type => :helper do
|
|
85
88
|
it "should have option colspan" do
|
86
89
|
table_html = helper.sorting_table_for(@users) do |table|
|
87
90
|
html = table.columns :colspan => 5
|
88
|
-
html.should have_comp_tag('td[colspan="5"]', :count => (@users.size *
|
91
|
+
html.should have_comp_tag('td[colspan="5"]', :count => (@users.size * SortingTableForUser.content_columns.size))
|
89
92
|
end
|
90
93
|
end
|
91
94
|
|
@@ -347,7 +350,7 @@ describe SortingTableFor, :type => :helper do
|
|
347
350
|
helper.sorting_table_for(@users) do |table|
|
348
351
|
html = table.columns
|
349
352
|
html.should_not match("Total Entries " + @users.size.to_s)
|
350
|
-
html.should_not match("<td colspan=\"" + (
|
353
|
+
html.should_not match("<td colspan=\"" + (SortingTableForUser.content_columns.size + 2).to_s + "\">")
|
351
354
|
end
|
352
355
|
end
|
353
356
|
|
@@ -356,7 +359,7 @@ describe SortingTableFor, :type => :helper do
|
|
356
359
|
helper.sorting_table_for(@users) do |table|
|
357
360
|
html = table.columns
|
358
361
|
html.should match("Total Entries " + @users.size.to_s)
|
359
|
-
html.should match("<td colspan=\"" + (
|
362
|
+
html.should match("<td colspan=\"" + (SortingTableForUser.content_columns.size + 2).to_s + "\">")
|
360
363
|
end
|
361
364
|
end
|
362
365
|
|
@@ -383,7 +386,7 @@ describe SortingTableFor, :type => :helper do
|
|
383
386
|
it "should edit default actions" do
|
384
387
|
SortingTableFor::TableBuilder.default_actions = [:show, :edit_password, :edit, :delete]
|
385
388
|
helper.sorting_table_for(@users) do |table|
|
386
|
-
table.columns.should have_comp_tag("td", :count => (@users.size * (
|
389
|
+
table.columns.should have_comp_tag("td", :count => (@users.size * (SortingTableForUser.content_columns.size + 4)) + 1)
|
387
390
|
end
|
388
391
|
end
|
389
392
|
|
data/spec/helpers/footer_spec.rb
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
-
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/sorting_table_for_user')
|
5
5
|
|
6
6
|
include SortingTableForSpecHelper
|
7
7
|
|
8
8
|
describe SortingTableFor, :type => :helper do
|
9
9
|
|
10
|
+
before :all do
|
11
|
+
(SortingTableFor::Tools::rails3?) ? routes_rails3 : routes_rails2
|
12
|
+
end
|
13
|
+
|
10
14
|
before :each do
|
11
|
-
@users =
|
12
|
-
helper.stub!(:
|
13
|
-
helper.stub!(:params).and_return({ :controller => 'fakes', :action => 'index' })
|
15
|
+
@users = SortingTableForUser.all
|
16
|
+
helper.stub!(:params).and_return({ :controller => 'sorting_table_for_users', :action => 'index' })
|
14
17
|
helper.output_buffer = ''
|
15
18
|
end
|
16
19
|
|
data/spec/helpers/header_spec.rb
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
-
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/sorting_table_for_user')
|
5
5
|
|
6
6
|
include SortingTableForSpecHelper
|
7
7
|
|
8
8
|
describe SortingTableFor, :type => :helper do
|
9
|
+
|
10
|
+
before :all do
|
11
|
+
(SortingTableFor::Tools::rails3?) ? routes_rails3 : routes_rails2
|
12
|
+
end
|
9
13
|
|
10
14
|
before :each do
|
11
|
-
@users =
|
12
|
-
helper.stub!(:
|
13
|
-
helper.stub!(:params).and_return({ :controller => 'fakes', :action => 'index' })
|
15
|
+
@users = SortingTableForUser.all
|
16
|
+
helper.stub!(:params).and_return({ :controller => 'sorting_table_for_users', :action => 'index' })
|
14
17
|
helper.output_buffer = ''
|
15
18
|
end
|
16
19
|
|
@@ -58,7 +61,7 @@ describe SortingTableFor, :type => :helper do
|
|
58
61
|
it "should have option colspan" do
|
59
62
|
table_html = helper.sorting_table_for(@users) do |table|
|
60
63
|
html = table.headers :colspan => 5
|
61
|
-
html.should have_comp_tag('th[colspan="5"]', :count =>
|
64
|
+
html.should have_comp_tag('th[colspan="5"]', :count => SortingTableForUser.content_columns.size)
|
62
65
|
end
|
63
66
|
end
|
64
67
|
|
@@ -217,9 +220,31 @@ describe SortingTableFor, :type => :helper do
|
|
217
220
|
end
|
218
221
|
html.should have_comp_tag("th:nth-child(1)[class=cur-sort-not]")
|
219
222
|
html.should_not have_comp_tag("th:nth-child(2)[class=cur-sort-not]")
|
220
|
-
end
|
221
|
-
end
|
223
|
+
end
|
224
|
+
end
|
222
225
|
|
226
|
+
it "should works with options sort_as" do
|
227
|
+
helper.sorting_table_for(@users) do |table|
|
228
|
+
html = table.headers do
|
229
|
+
table.header 'my name', :sort_as => :username
|
230
|
+
end
|
231
|
+
html.should have_comp_tag("th:nth-child(1)", :text => 'my name')
|
232
|
+
html.should have_comp_tag("th:nth-child(1)[class=cur-sort-not]")
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should works with options sort_as and sort" do
|
237
|
+
helper.sorting_table_for(@users, :sort => false) do |table|
|
238
|
+
html = table.headers do
|
239
|
+
table.header 'my name', :sort_as => :username, :sort => true
|
240
|
+
table.header :price
|
241
|
+
end
|
242
|
+
html.should have_comp_tag("th:nth-child(1)", :text => 'my name')
|
243
|
+
html.should have_comp_tag("th:nth-child(1)[class=cur-sort-not]")
|
244
|
+
html.should_not have_comp_tag("th:nth-child(2)[class=cur-sort-not]")
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
223
248
|
it "should have option colspan" do
|
224
249
|
table_html = helper.sorting_table_for(@users) do |table|
|
225
250
|
html = table.headers do
|
@@ -360,7 +385,7 @@ describe SortingTableFor, :type => :helper do
|
|
360
385
|
it "should edit default actions" do
|
361
386
|
SortingTableFor::TableBuilder.default_actions = [:show, :edit_password, :edit, :delete]
|
362
387
|
helper.sorting_table_for(@users) do |table|
|
363
|
-
table.headers.should have_comp_tag("th", :count =>
|
388
|
+
table.headers.should have_comp_tag("th", :count => SortingTableForUser.column_names.size + 3)
|
364
389
|
end
|
365
390
|
end
|
366
391
|
|
data/spec/helpers/i18n_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
-
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/sorting_table_for_user')
|
5
5
|
|
6
6
|
include SortingTableForSpecHelper
|
7
7
|
|
@@ -9,11 +9,12 @@ describe SortingTableFor do
|
|
9
9
|
describe ' #i18n' do
|
10
10
|
|
11
11
|
before :each do
|
12
|
-
SortingTableFor::
|
12
|
+
SortingTableFor::TableBuilder.i18n_default_scope = [ :namespace, :controller, :action ]
|
13
|
+
SortingTableFor::I18n.set_options({:controller => 'fakes_controller', :action => 'fake_action'}, 'user')
|
13
14
|
end
|
14
15
|
|
15
16
|
it "should works by default" do
|
16
|
-
SortingTableFor::I18n.set_options({}, 'user'
|
17
|
+
SortingTableFor::I18n.set_options({}, 'user')
|
17
18
|
SortingTableFor::I18n.t(:test_name).should == 'i18n name'
|
18
19
|
end
|
19
20
|
|
@@ -28,12 +29,16 @@ describe SortingTableFor do
|
|
28
29
|
it "should works with i18n options" do
|
29
30
|
SortingTableFor::I18n.t(:my_test, :value => :hello).should == 'say hello'
|
30
31
|
end
|
32
|
+
|
33
|
+
it "should works with options add_scope" do
|
34
|
+
SortingTableFor::I18n.t(:name, :add_scope => [:add_scope]).should == 'add to scope'
|
35
|
+
end
|
31
36
|
|
32
37
|
it "should set namespace scope" do
|
33
|
-
SortingTableFor::I18n.set_options({:controller => 'fakes_controller', :action => 'fake_action'}, 'user'
|
38
|
+
SortingTableFor::I18n.set_options({:controller => 'fake_namespace/fakes_controller', :action => 'fake_action'}, 'user')
|
34
39
|
SortingTableFor::I18n.t(:name).should == 'fake namespace'
|
35
40
|
end
|
36
|
-
|
41
|
+
|
37
42
|
it "should set scope with options" do
|
38
43
|
SortingTableFor::TableBuilder.i18n_default_scope = [ :action ]
|
39
44
|
SortingTableFor::I18n.t(:name).should == 'fake action'
|
@@ -41,7 +46,7 @@ describe SortingTableFor do
|
|
41
46
|
|
42
47
|
it "should set scope with all options" do
|
43
48
|
SortingTableFor::TableBuilder.i18n_default_scope = [ :model, :namespace, :controller, :action ]
|
44
|
-
SortingTableFor::I18n.set_options({:controller => 'fakes_controller', :action => 'fake_action'}, 'user'
|
49
|
+
SortingTableFor::I18n.set_options({:controller => 'fake_namespace/fakes_controller', :action => 'fake_action'}, 'user')
|
45
50
|
SortingTableFor::I18n.t(:name).should == 'fake'
|
46
51
|
end
|
47
52
|
|
@@ -51,4 +56,4 @@ describe SortingTableFor do
|
|
51
56
|
end
|
52
57
|
|
53
58
|
end
|
54
|
-
end
|
59
|
+
end
|
data/spec/locales/test.yml
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
test:
|
2
|
+
|
2
3
|
date:
|
3
4
|
formats:
|
4
5
|
default: "%Y-%m-%d"
|
5
6
|
short: "%b %d"
|
6
7
|
long: "%B %d, %Y"
|
7
8
|
|
9
|
+
time:
|
10
|
+
formats:
|
11
|
+
default: "%d %B %Y %H:%M:%S"
|
12
|
+
short: "%d %b %H:%M"
|
13
|
+
long: "%A %d %B %Y %H:%M"
|
14
|
+
|
8
15
|
day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
|
9
16
|
abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
|
10
17
|
|
@@ -42,12 +49,11 @@ test:
|
|
42
49
|
strip_insignificant_zeros: false
|
43
50
|
|
44
51
|
sorting_table_for:
|
45
|
-
total_entries: "Total Entries {{value}}"
|
46
52
|
columns:
|
47
53
|
bool_true: 'True'
|
48
54
|
bool_false: 'False'
|
49
55
|
|
50
|
-
|
56
|
+
sorting_table_for_users:
|
51
57
|
index:
|
52
58
|
table_caption: 'Quick Caption'
|
53
59
|
edit: 'Edit'
|
@@ -68,6 +74,7 @@ test:
|
|
68
74
|
footer:
|
69
75
|
username: 'UserFoot'
|
70
76
|
price: 'PriceFoot'
|
77
|
+
total_entries: "Total Entries %{value}"
|
71
78
|
|
72
79
|
fake_scope:
|
73
80
|
my_test: 'Hello'
|
@@ -79,6 +86,8 @@ test:
|
|
79
86
|
my_test: 'say {{value}}'
|
80
87
|
my_add:
|
81
88
|
name: 'fake add'
|
89
|
+
add_scope:
|
90
|
+
name: "add to scope"
|
82
91
|
|
83
92
|
user:
|
84
93
|
fake_namespace:
|
@@ -1,4 +1,5 @@
|
|
1
1
|
test:
|
2
|
+
|
2
3
|
date:
|
3
4
|
formats:
|
4
5
|
default: "%Y-%m-%d"
|
@@ -42,12 +43,11 @@ test:
|
|
42
43
|
strip_insignificant_zeros: false
|
43
44
|
|
44
45
|
sorting_table_for:
|
45
|
-
total_entries: "Total Entries %{value}"
|
46
46
|
columns:
|
47
47
|
bool_true: 'True'
|
48
|
-
bool_false: 'False'
|
48
|
+
bool_false: 'False'
|
49
49
|
|
50
|
-
|
50
|
+
sorting_table_for_users:
|
51
51
|
index:
|
52
52
|
table_caption: 'Quick Caption'
|
53
53
|
edit: 'Edit'
|
@@ -68,7 +68,7 @@ test:
|
|
68
68
|
footer:
|
69
69
|
username: 'UserFoot'
|
70
70
|
price: 'PriceFoot'
|
71
|
-
|
71
|
+
total_entries: "Total Entries %{value}"
|
72
72
|
|
73
73
|
fake_scope:
|
74
74
|
my_test: 'Hello'
|
@@ -80,6 +80,8 @@ test:
|
|
80
80
|
my_test: 'say %{value}'
|
81
81
|
my_add:
|
82
82
|
name: 'fake add'
|
83
|
+
add_scope:
|
84
|
+
name: "add to scope"
|
83
85
|
|
84
86
|
user:
|
85
87
|
fake_namespace:
|
@@ -1,34 +1,40 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/sorting_table_for_user')
|
3
3
|
|
4
4
|
describe SortingTableModelScope do
|
5
5
|
|
6
6
|
describe "# default usage" do
|
7
7
|
|
8
8
|
it "should do nothing with no option" do
|
9
|
-
|
9
|
+
SortingTableForUser.sorting_table.all.should == SortingTableForUser.all
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should do nothing with option nil" do
|
13
|
-
|
13
|
+
SortingTableForUser.sorting_table(nil).all.should == SortingTableForUser.all
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should do nothing with all options nil" do
|
17
|
-
|
17
|
+
SortingTableForUser.sorting_table(nil, nil, nil).all.should == SortingTableForUser.all
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should raise an error with 4 arguments" do
|
21
21
|
expect {
|
22
|
-
|
22
|
+
SortingTableForUser.sorting_table(nil, nil, nil, nil).all
|
23
23
|
}.to raise_error { ArgumentError }
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should works with other scope" do
|
27
|
-
|
27
|
+
SortingTableForUser.good_position.sorting_table.set_limit(2).all.should == SortingTableForUser.find(:all, :conditions => 'position > 3', :limit => 2)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should not erase other order" do
|
31
|
-
|
31
|
+
# Change order with scope in rails 3.0.3
|
32
|
+
if !defined? ActionPack or (ActionPack::VERSION::MAJOR <= 3 and ActionPack::VERSION::MINOR == 0 and ActionPack::VERSION::TINY <= 1)
|
33
|
+
current_order = 'lastname asc, firstname desc'
|
34
|
+
else
|
35
|
+
current_order = 'firstname desc, lastname asc'
|
36
|
+
end
|
37
|
+
SortingTableForUser.sorting_table(nil, :firstname, :desc).find(:all, :order => 'lastname asc').should == SortingTableForUser.find(:all, :order => current_order)
|
32
38
|
end
|
33
39
|
|
34
40
|
end
|
@@ -36,32 +42,32 @@ describe SortingTableModelScope do
|
|
36
42
|
describe "# params usage" do
|
37
43
|
|
38
44
|
it "should works with correct params" do
|
39
|
-
|
45
|
+
SortingTableForUser.sorting_table({ "table_sort" => { "username" => "asc" } }).all.should == SortingTableForUser.find(:all, :order => 'username asc')
|
40
46
|
end
|
41
47
|
|
42
48
|
it "should do nothing with wrong column" do
|
43
|
-
|
49
|
+
SortingTableForUser.sorting_table({ "table_sort" => { "test" => "asc" } }).all.should == SortingTableForUser.all
|
44
50
|
end
|
45
51
|
|
46
52
|
it "should do nothing with wrong direction" do
|
47
|
-
|
53
|
+
SortingTableForUser.sorting_table({ "table_sort" => { "username" => "test" } }).all.should == SortingTableForUser.all
|
48
54
|
end
|
49
55
|
|
50
56
|
it "should do nothing with wrong arguments" do
|
51
|
-
|
57
|
+
SortingTableForUser.sorting_table({ "table_sort" => { "price" => nil } }).all.should == SortingTableForUser.all
|
52
58
|
end
|
53
59
|
|
54
60
|
it "should do nothing with wrong arguments (2)" do
|
55
|
-
|
61
|
+
SortingTableForUser.sorting_table({ "table_sort" => nil }).all.should == SortingTableForUser.all
|
56
62
|
end
|
57
63
|
|
58
64
|
it "should order by params not option" do
|
59
|
-
|
65
|
+
SortingTableForUser.sorting_table({ "table_sort" => { "username" => "asc" } }, :firstname, :desc).all.should == SortingTableForUser.find(:all, :order => 'username asc')
|
60
66
|
end
|
61
67
|
|
62
68
|
it "should works with custom param name" do
|
63
69
|
SortingTableFor::TableBuilder.params_sort_table = :sort_my_test
|
64
|
-
|
70
|
+
SortingTableForUser.sorting_table({ "sort_my_test" => { "username" => "asc" } }).all.should == SortingTableForUser.find(:all, :order => 'username asc')
|
65
71
|
end
|
66
72
|
|
67
73
|
end
|
@@ -69,19 +75,19 @@ describe SortingTableModelScope do
|
|
69
75
|
describe "# options usage" do
|
70
76
|
|
71
77
|
it "should works with option" do
|
72
|
-
|
78
|
+
SortingTableForUser.sorting_table(nil, :username, :desc).all.should == SortingTableForUser.find(:all, :order => 'username desc')
|
73
79
|
end
|
74
80
|
|
75
81
|
it "should set option asc if not given" do
|
76
|
-
|
82
|
+
SortingTableForUser.sorting_table(nil, :username).all.should == SortingTableForUser.find(:all, :order => 'username asc')
|
77
83
|
end
|
78
84
|
|
79
85
|
it "should do nothing with wrong column" do
|
80
|
-
|
86
|
+
SortingTableForUser.sorting_table(nil, :test).all.should == SortingTableForUser.all
|
81
87
|
end
|
82
88
|
|
83
89
|
it "should do nothing with wring direction" do
|
84
|
-
|
90
|
+
SortingTableForUser.sorting_table(nil, :username, :test).all.should == SortingTableForUser.all
|
85
91
|
end
|
86
92
|
|
87
93
|
end
|