sorting_table_for 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.mdown +6 -0
- data/MIT-LICENSE +1 -1
- data/README.mdown +7 -7
- data/Rakefile +32 -8
- data/lib/sorting_table_for/format_cell.rb +1 -5
- data/lib/sorting_table_for/tools.rb +0 -8
- data/lib/sorting_table_for/version.rb +3 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +59 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/fixtures/sorting_table_for_user.rb +4 -10
- data/spec/helpers/builder_spec.rb +13 -13
- data/spec/helpers/caption_spec.rb +19 -19
- data/spec/helpers/cell_value_spec.rb +23 -23
- data/spec/helpers/column_spec.rb +81 -79
- data/spec/helpers/footer_spec.rb +46 -46
- data/spec/helpers/header_spec.rb +74 -84
- data/spec/locales/{test_rails3.yml → test_rails.yml} +0 -0
- data/spec/spec_helper.rb +10 -45
- metadata +120 -12
- data/spec/locales/test.yml +0 -104
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
</div>
|
24
|
+
</body>
|
25
|
+
</html>
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -1,15 +1,9 @@
|
|
1
1
|
class SortingTableForUser < ActiveRecord::Base
|
2
|
-
|
3
|
-
|
4
|
-
:salary, :price, :active, :created_at, :updated_at
|
5
|
-
|
6
|
-
scope :good_position, :conditions => 'position > 3'
|
7
|
-
scope :set_limit, lambda { |limit| { :limit => limit } }
|
8
|
-
else
|
9
|
-
named_scope :good_position, :conditions => 'position > 3'
|
10
|
-
named_scope :set_limit, lambda { |limit| { :limit => limit } }
|
11
|
-
end
|
2
|
+
attr_accessible :username, :firstname, :lastname, :position,
|
3
|
+
:salary, :price, :active, :created_at, :updated_at
|
12
4
|
|
5
|
+
scope :good_position, :conditions => 'position > 3'
|
6
|
+
scope :set_limit, lambda { |limit| { :limit => limit } }
|
13
7
|
end
|
14
8
|
|
15
9
|
20.times do |n|
|
@@ -8,7 +8,7 @@ include SortingTableForSpecHelper
|
|
8
8
|
describe SortingTableFor, :type => :helper do
|
9
9
|
|
10
10
|
before :all do
|
11
|
-
|
11
|
+
routes_rails
|
12
12
|
end
|
13
13
|
|
14
14
|
before :each do
|
@@ -28,13 +28,13 @@ describe SortingTableFor, :type => :helper do
|
|
28
28
|
it "should have balise table with class" do
|
29
29
|
table_html = helper.sorting_table_for(@users) {}
|
30
30
|
helper.output_buffer.concat(table_html)
|
31
|
-
helper.output_buffer.should
|
31
|
+
helper.output_buffer.should have_selector("table[class=sorting_table_for]")
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should be custom by html" do
|
35
35
|
table_html = helper.sorting_table_for(@users, :html => { :class => 'hello', :id => 'my_test' }) {}
|
36
36
|
helper.output_buffer.concat(table_html)
|
37
|
-
helper.output_buffer.should
|
37
|
+
helper.output_buffer.should have_selector("table[class='hello sorting_table_for'][id='my_test']")
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should take another builder" do
|
@@ -48,14 +48,14 @@ describe SortingTableFor, :type => :helper do
|
|
48
48
|
it "should use i18n by default" do
|
49
49
|
helper.sorting_table_for(@users) do |table|
|
50
50
|
html = table.headers(:username)
|
51
|
-
html.should
|
51
|
+
html.should have_selector("th:nth-child(1)", :content => 'Usernames')
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should not use i18n" do
|
56
56
|
helper.sorting_table_for(@users, :i18n => false) do |table|
|
57
57
|
html = table.headers(:username)
|
58
|
-
html.should
|
58
|
+
html.should have_selector("th:nth-child(1)", :content => 'username')
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -69,10 +69,10 @@ describe SortingTableFor, :type => :helper do
|
|
69
69
|
html += table.headers
|
70
70
|
html += table.columns
|
71
71
|
html += table.footers :username
|
72
|
-
html.should
|
73
|
-
html.should
|
74
|
-
html.should
|
75
|
-
html.should
|
72
|
+
html.should have_selector("caption", :count => 1)
|
73
|
+
html.should have_selector("thead", :count => 1)
|
74
|
+
html.should have_selector("tbody", :count => 1)
|
75
|
+
html.should have_selector("tfoot", :count => 1)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -82,10 +82,10 @@ describe SortingTableFor, :type => :helper do
|
|
82
82
|
html += table.headers :username
|
83
83
|
html += table.columns :username
|
84
84
|
html += table.footers :username
|
85
|
-
html.should
|
86
|
-
html.should
|
87
|
-
html.should
|
88
|
-
html.should
|
85
|
+
html.should have_selector("thead tr th", :count => 1)
|
86
|
+
html.should have_selector("tbody tr td", :count => @users.count + 1)
|
87
|
+
html.should have_selector("tbody tr[class=total-entries] td", :count => 1)
|
88
|
+
html.should have_selector("tfoot tr td", :count => 1)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -8,7 +8,7 @@ include SortingTableForSpecHelper
|
|
8
8
|
describe SortingTableFor, :type => :helper do
|
9
9
|
|
10
10
|
before :all do
|
11
|
-
|
11
|
+
routes_rails
|
12
12
|
end
|
13
13
|
|
14
14
|
before :each do
|
@@ -24,42 +24,42 @@ describe SortingTableFor, :type => :helper do
|
|
24
24
|
it "should set caption tag" do
|
25
25
|
helper.sorting_table_for(@users) do |table|
|
26
26
|
html = table.caption
|
27
|
-
html.should
|
27
|
+
html.should have_selector("caption", :count => 1)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should set caption tag with arguments" do
|
32
32
|
helper.sorting_table_for(@users) do |table|
|
33
33
|
html = table.caption 'hello'
|
34
|
-
html.should
|
34
|
+
html.should have_selector("caption", :content => 'hello')
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should set caption tag with arguments and option position left" do
|
39
39
|
helper.sorting_table_for(@users) do |table|
|
40
40
|
html = table.caption 'hello', :position => :left
|
41
|
-
html.should
|
41
|
+
html.should have_selector("caption[align=left]")
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should set caption tag with arguments and option position bottom" do
|
46
46
|
helper.sorting_table_for(@users) do |table|
|
47
47
|
html = table.caption 'hello', :position => :bottom
|
48
|
-
html.should
|
48
|
+
html.should have_selector("caption[align=bottom]")
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should works with html options" do
|
53
53
|
helper.sorting_table_for(@users) do |table|
|
54
54
|
html = table.caption 'hello', :html => {:class => 'my_class', :id => 'my_id', :title => 'my_title'}
|
55
|
-
html.should
|
55
|
+
html.should have_selector("caption[class=my_class][id=my_id][title=my_title]")
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should works with html options and position option" do
|
60
60
|
helper.sorting_table_for(@users) do |table|
|
61
61
|
html = table.caption 'hello', :position => :right, :html => {:class => 'my_class', :id => 'my_id', :title => 'my_title'}
|
62
|
-
html.should
|
62
|
+
html.should have_selector("caption[class=my_class][id=my_id][title=my_title][align=right]")
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -70,7 +70,7 @@ describe SortingTableFor, :type => :helper do
|
|
70
70
|
it "should set caption tag" do
|
71
71
|
helper.sorting_table_for(@users) do |table|
|
72
72
|
html = table.caption {}
|
73
|
-
html.should
|
73
|
+
html.should have_selector("caption", :count => 1)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -79,7 +79,7 @@ describe SortingTableFor, :type => :helper do
|
|
79
79
|
html = table.caption do
|
80
80
|
'hello'
|
81
81
|
end
|
82
|
-
html.should
|
82
|
+
html.should have_selector("caption", :content => 'hello')
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -88,7 +88,7 @@ describe SortingTableFor, :type => :helper do
|
|
88
88
|
html = table.caption :position => :left do
|
89
89
|
'hello'
|
90
90
|
end
|
91
|
-
html.should
|
91
|
+
html.should have_selector("caption[align=left]")
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -97,7 +97,7 @@ describe SortingTableFor, :type => :helper do
|
|
97
97
|
html = table.caption :position => :bottom do
|
98
98
|
'hello'
|
99
99
|
end
|
100
|
-
html.should
|
100
|
+
html.should have_selector("caption[align=bottom]")
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
@@ -106,7 +106,7 @@ describe SortingTableFor, :type => :helper do
|
|
106
106
|
html = table.caption :html => {:class => 'my_class', :id => 'my_id', :title => 'my_title'} do
|
107
107
|
'hello'
|
108
108
|
end
|
109
|
-
html.should
|
109
|
+
html.should have_selector("caption[class=my_class][id=my_id][title=my_title]")
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
@@ -115,7 +115,7 @@ describe SortingTableFor, :type => :helper do
|
|
115
115
|
html = table.caption :position => :right, :html => {:class => 'my_class', :id => 'my_id', :title => 'my_title'} do
|
116
116
|
'hello'
|
117
117
|
end
|
118
|
-
html.should
|
118
|
+
html.should have_selector("caption[class=my_class][id=my_id][title=my_title][align=right]")
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
@@ -127,36 +127,36 @@ describe SortingTableFor, :type => :helper do
|
|
127
127
|
it "should set caption tag with i18n translation" do
|
128
128
|
helper.sorting_table_for(@users) do |table|
|
129
129
|
html = table.caption
|
130
|
-
html.should
|
131
|
-
html.should
|
130
|
+
html.should have_selector("caption", :count => 1)
|
131
|
+
html.should have_selector("caption", :content => 'Quick Caption')
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should set caption tag with arguments and option position left" do
|
136
136
|
helper.sorting_table_for(@users) do |table|
|
137
137
|
html = table.caption :position => :left
|
138
|
-
html.should
|
138
|
+
html.should have_selector("caption[align=left]")
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
142
|
it "should set caption tag with arguments and option position bottom" do
|
143
143
|
helper.sorting_table_for(@users) do |table|
|
144
144
|
html = table.caption :position => :bottom
|
145
|
-
html.should
|
145
|
+
html.should have_selector("caption[align=bottom]")
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
149
149
|
it "should works with html options" do
|
150
150
|
helper.sorting_table_for(@users) do |table|
|
151
151
|
html = table.caption :html => {:class => 'my_class', :id => 'my_id', :title => 'my_title'}
|
152
|
-
html.should
|
152
|
+
html.should have_selector("caption[class=my_class][id=my_id][title=my_title]")
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
156
|
it "should works with html options and position option" do
|
157
157
|
helper.sorting_table_for(@users) do |table|
|
158
158
|
html = table.caption :position => :right, :html => {:class => 'my_class', :id => 'my_id', :title => 'my_title'}
|
159
|
-
html.should
|
159
|
+
html.should have_selector("caption[class=my_class][id=my_id][title=my_title][align=right]")
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
@@ -8,7 +8,7 @@ include SortingTableForSpecHelper
|
|
8
8
|
describe SortingTableFor, :type => :helper do
|
9
9
|
|
10
10
|
before :all do
|
11
|
-
|
11
|
+
routes_rails
|
12
12
|
end
|
13
13
|
|
14
14
|
before :each do
|
@@ -22,15 +22,15 @@ describe SortingTableFor, :type => :helper do
|
|
22
22
|
it "should format by default values" do
|
23
23
|
helper.sorting_table_for(@users) do |table|
|
24
24
|
html = table.columns
|
25
|
-
html.should
|
26
|
-
html.should
|
27
|
-
html.should
|
28
|
-
html.should
|
29
|
-
html.should
|
30
|
-
html.should
|
31
|
-
html.should
|
32
|
-
html.should
|
33
|
-
html.should
|
25
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(1)", :content => @users.first.username)
|
26
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(2)", :content => @users.first.firstname)
|
27
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(3)", :content => @users.first.lastname)
|
28
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(4)", :content => @users.first.position.to_s)
|
29
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(5)", :content => @users.first.salary.to_s)
|
30
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(6)", :content => number_to_currency(@users.first.price))
|
31
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(7)", :content => "True")
|
32
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(8)", :content => I18n.l(@users.first.created_at, :format => :default))
|
33
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(9)", :content => I18n.l(@users.first.updated_at, :format => :default))
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -47,14 +47,14 @@ describe SortingTableFor, :type => :helper do
|
|
47
47
|
table.column true
|
48
48
|
table.column :active
|
49
49
|
end
|
50
|
-
html.should
|
51
|
-
html.should
|
52
|
-
html.should
|
53
|
-
html.should
|
54
|
-
html.should
|
55
|
-
html.should
|
56
|
-
html.should
|
57
|
-
html.should
|
50
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(1)", :content => number_to_currency(@users.first.price))
|
51
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(2)", :content => number_to_currency(@users.first.price))
|
52
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(3)", :content => I18n.l(current_datetime, :format => :default))
|
53
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(4)", :content => I18n.l(current_datetime.to_date, :format => :default))
|
54
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(5)", :content => I18n.l(current_datetime, :format => :short))
|
55
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(6)", :content => I18n.l(current_datetime.to_date, :format => :short))
|
56
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(7)", :content => "True")
|
57
|
+
html.should have_selector("tr:nth-child(3) td:nth-child(8)", :content => "False")
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -65,8 +65,8 @@ describe SortingTableFor, :type => :helper do
|
|
65
65
|
table.column true
|
66
66
|
table.column :active
|
67
67
|
end
|
68
|
-
html.should
|
69
|
-
html.should
|
68
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(1)", :content => "BoolTrue")
|
69
|
+
html.should have_selector("tr:nth-child(3) td:nth-child(2)", :content => "BoolFalse")
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -79,9 +79,9 @@ describe SortingTableFor, :type => :helper do
|
|
79
79
|
table.column current_datetime, :as => :time
|
80
80
|
table.column current_datetime, :as => :time, :format => :default
|
81
81
|
end
|
82
|
-
html.should
|
83
|
-
html.should
|
84
|
-
html.should
|
82
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(1)", :content => I18n.l(@users.first.created_at, :format => :short))
|
83
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(2)", :content => I18n.l(current_datetime, :format => :short))
|
84
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(3)", :content => I18n.l(current_datetime, :format => :default))
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
data/spec/helpers/column_spec.rb
CHANGED
@@ -8,7 +8,7 @@ include SortingTableForSpecHelper
|
|
8
8
|
describe SortingTableFor, :type => :helper do
|
9
9
|
|
10
10
|
before :all do
|
11
|
-
|
11
|
+
routes_rails
|
12
12
|
end
|
13
13
|
|
14
14
|
before :each do
|
@@ -22,9 +22,9 @@ describe SortingTableFor, :type => :helper do
|
|
22
22
|
it "should works" do
|
23
23
|
helper.sorting_table_for(@users) do |table|
|
24
24
|
html = table.columns
|
25
|
-
html.should
|
26
|
-
html.should
|
27
|
-
html.should
|
25
|
+
html.should have_selector("tbody", :count => 1)
|
26
|
+
html.should have_selector("tr", :count => (@users.size + 1))
|
27
|
+
html.should have_selector("td", :count => (@users.size * (SortingTableForUser.content_columns.size + 2)) + 1)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -54,41 +54,41 @@ describe SortingTableFor, :type => :helper do
|
|
54
54
|
|
55
55
|
it "should add link columns" do
|
56
56
|
helper.sorting_table_for(@users) do |table|
|
57
|
-
table.columns.should
|
57
|
+
table.columns.should have_selector('a', :count => (@users.size * 2))
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should add i18n to link columns" do
|
62
62
|
helper.sorting_table_for(@users) do |table|
|
63
63
|
html = table.columns
|
64
|
-
html.should
|
65
|
-
html.should
|
64
|
+
html.should have_selector('a', :content => 'Edit', :count => @users.size)
|
65
|
+
html.should have_selector('a', :content => 'Delete', :count => @users.size)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should add class odd/even" do
|
70
70
|
helper.sorting_table_for(@users) do |table|
|
71
71
|
html = table.columns
|
72
|
-
html.should
|
73
|
-
html.should
|
72
|
+
html.should have_selector("tr[class=odd]", :count => (@users.size / 2))
|
73
|
+
html.should have_selector("tr[class=even]", :count => (@users.size / 2))
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should customize html" do
|
78
78
|
table_html = helper.sorting_table_for(@users, :html => { :class => 'table_class', :id => 'table_id' }) do |table|
|
79
79
|
html = table.columns :html => { :class => 'hello_class', :id => 'hello_id', :title => 'hello_title' }
|
80
|
-
html.should
|
81
|
-
html.should
|
82
|
-
html.should
|
80
|
+
html.should have_selector("tr:nth-child(2)[class='hello_class odd']")
|
81
|
+
html.should have_selector("tr:nth-child(2)[id=hello_id]")
|
82
|
+
html.should have_selector("tr:nth-child(2)[title=hello_title]")
|
83
83
|
end
|
84
84
|
helper.output_buffer.concat(table_html)
|
85
|
-
helper.output_buffer.should
|
85
|
+
helper.output_buffer.should have_selector("table[class='table_class sorting_table_for'][id=table_id]")
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should have option colspan" do
|
89
89
|
table_html = helper.sorting_table_for(@users) do |table|
|
90
90
|
html = table.columns :colspan => 5
|
91
|
-
html.should
|
91
|
+
html.should have_selector('td[colspan="5"]', :count => (@users.size * SortingTableForUser.content_columns.size))
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -99,81 +99,77 @@ describe SortingTableFor, :type => :helper do
|
|
99
99
|
it "should works with one column" do
|
100
100
|
helper.sorting_table_for(@users) do |table|
|
101
101
|
html = table.columns :username
|
102
|
-
html.should
|
103
|
-
html.should
|
104
|
-
html.should
|
102
|
+
html.should have_selector("tbody", :count => 1)
|
103
|
+
html.should have_selector("tr", :count => (@users.size + 1))
|
104
|
+
html.should have_selector("td", :count => (@users.size + 1))
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
108
|
it "should have multi columns" do
|
109
109
|
helper.sorting_table_for(@users) do |table|
|
110
110
|
html = table.columns :username, :price
|
111
|
-
html.should
|
112
|
-
html.should
|
113
|
-
html.should
|
111
|
+
html.should have_selector("tbody", :count => 1)
|
112
|
+
html.should have_selector("tr", :count => (@users.size + 1))
|
113
|
+
html.should have_selector("td", :count => ((@users.size * 2) + 1))
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should have multi columns and action" do
|
118
118
|
helper.sorting_table_for(@users) do |table|
|
119
|
-
table.columns(:username, :price, :actions => :edit).should
|
119
|
+
table.columns(:username, :price, :actions => :edit).should have_selector("td", :count => ((@users.size * 3) + 1))
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
123
|
it "should have multi columns and multi action" do
|
124
124
|
helper.sorting_table_for(@users) do |table|
|
125
|
-
table.columns(:username, :price, :actions => [:edit, :delete]).should
|
125
|
+
table.columns(:username, :price, :actions => [:edit, :delete]).should have_selector("td", :count => ((@users.size * 4) + 1))
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should do nothing if the key isn't correct" do
|
130
130
|
helper.sorting_table_for(@users) do |table|
|
131
|
-
table.columns(:username, :price, :blabla => :edit).should
|
131
|
+
table.columns(:username, :price, :blabla => :edit).should have_selector("td", :count => ((@users.size * 2) + 1))
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should works symbol and non symbol" do
|
136
136
|
helper.sorting_table_for(@users) do |table|
|
137
137
|
html = table.columns(:username, 'hello', image_tag('rails.png'), :actions => :edit)
|
138
|
-
html.should
|
139
|
-
html.should
|
140
|
-
html.should
|
141
|
-
html.should
|
138
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(1)", :content => @users.first.username)
|
139
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(2)", :content => 'hello')
|
140
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(3) img")
|
141
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(4) a")
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
145
|
it "should works with non key symbol" do
|
146
146
|
helper.sorting_table_for(@users) do |table|
|
147
147
|
html = table.columns(:username, :test)
|
148
|
-
html.should
|
149
|
-
html.should
|
148
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(1)", :content => @users.first.username)
|
149
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(2)", :content => '')
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
153
|
it "should add remote on link" do
|
154
154
|
helper.sorting_table_for(@users, :link_remote => true) do |table|
|
155
155
|
html = table.columns :username, :actions => :edit
|
156
|
-
|
157
|
-
html.should have_comp_tag("tr:nth-child(2) td:nth-child(2) a[data-remote]")
|
158
|
-
else
|
159
|
-
html.should have_comp_tag("tr:nth-child(2) td:nth-child(2) a[onclick]")
|
160
|
-
end
|
156
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(2) a[data-remote]")
|
161
157
|
end
|
162
158
|
end
|
163
159
|
|
164
160
|
it "should customize html" do
|
165
161
|
table_html = helper.sorting_table_for(@users, :html => { :class => 'table_class', :id => 'table_id' }) do |table|
|
166
162
|
html = table.columns :username, :price, :html => { :class => 'hello_class', :id => 'hello_id', :title => 'hello_title' }
|
167
|
-
html.should
|
163
|
+
html.should have_selector("tr:nth-child(2)[class='hello_class odd'][id=hello_id][title=hello_title]")
|
168
164
|
end
|
169
165
|
helper.output_buffer.concat(table_html)
|
170
|
-
helper.output_buffer.should
|
166
|
+
helper.output_buffer.should have_selector("table[class='table_class sorting_table_for'][id=table_id]")
|
171
167
|
end
|
172
168
|
|
173
169
|
it "should have option colspan" do
|
174
170
|
table_html = helper.sorting_table_for(@users) do |table|
|
175
171
|
html = table.columns :username, :colspan => 5
|
176
|
-
html.should
|
172
|
+
html.should have_selector('td[colspan="5"]', :count => @users.size)
|
177
173
|
end
|
178
174
|
end
|
179
175
|
|
@@ -186,9 +182,9 @@ describe SortingTableFor, :type => :helper do
|
|
186
182
|
html = table.columns do
|
187
183
|
table.column :username
|
188
184
|
end
|
189
|
-
html.should
|
190
|
-
html.should
|
191
|
-
html.should
|
185
|
+
html.should have_selector("tbody", :count => 1)
|
186
|
+
html.should have_selector("tr", :count => (@users.size + 1))
|
187
|
+
html.should have_selector("td", :count => (@users.size + 1))
|
192
188
|
end
|
193
189
|
end
|
194
190
|
|
@@ -198,9 +194,9 @@ describe SortingTableFor, :type => :helper do
|
|
198
194
|
table.column :username
|
199
195
|
table.column :price
|
200
196
|
end
|
201
|
-
html.should
|
202
|
-
html.should
|
203
|
-
html.should
|
197
|
+
html.should have_selector("tbody", :count => 1)
|
198
|
+
html.should have_selector("tr", :count => (@users.size + 1))
|
199
|
+
html.should have_selector("td", :count => ((@users.size * 2) + 1))
|
204
200
|
end
|
205
201
|
end
|
206
202
|
|
@@ -213,11 +209,11 @@ describe SortingTableFor, :type => :helper do
|
|
213
209
|
table.column image_tag('rails.png')
|
214
210
|
table.column :action => :edit
|
215
211
|
end
|
216
|
-
html.should
|
217
|
-
html.should
|
218
|
-
html.should
|
219
|
-
html.should
|
220
|
-
html.should
|
212
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(1)", :content => @users.first.username)
|
213
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(2)", :content => '')
|
214
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(3)", :content => 'hello')
|
215
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(4) img")
|
216
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(5) a")
|
221
217
|
end
|
222
218
|
end
|
223
219
|
|
@@ -226,11 +222,11 @@ describe SortingTableFor, :type => :helper do
|
|
226
222
|
html = table.columns :html => { :class => 'hello_class', :id => 'hello_id', :title => 'hello_title' } do
|
227
223
|
table.column :username, :html => { :class => 'hi_class', :id => 'hi_id', :title => 'hi_title' }
|
228
224
|
end
|
229
|
-
html.should
|
230
|
-
html.should
|
225
|
+
html.should have_selector("tr:nth-child(2)[class='hello_class odd'][id=hello_id][title=hello_title]")
|
226
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(1)[class='hi_class'][id=hi_id][title=hi_title]")
|
231
227
|
end
|
232
228
|
helper.output_buffer.concat(table_html)
|
233
|
-
helper.output_buffer.should
|
229
|
+
helper.output_buffer.should have_selector("table[class='table_class sorting_table_for'][id=table_id]")
|
234
230
|
end
|
235
231
|
|
236
232
|
it "should have option colspan" do
|
@@ -239,8 +235,8 @@ describe SortingTableFor, :type => :helper do
|
|
239
235
|
table.column :username, :colspan => 5
|
240
236
|
table.column :price, :colspan => 3
|
241
237
|
end
|
242
|
-
html.should
|
243
|
-
html.should
|
238
|
+
html.should have_selector('td[colspan="5"]', :count => @users.size)
|
239
|
+
html.should have_selector('td[colspan="3"]', :count => @users.size)
|
244
240
|
end
|
245
241
|
end
|
246
242
|
|
@@ -253,10 +249,10 @@ describe SortingTableFor, :type => :helper do
|
|
253
249
|
html = table.columns do |value|
|
254
250
|
table.column value.username
|
255
251
|
end
|
256
|
-
html.should
|
257
|
-
html.should
|
258
|
-
html.should
|
259
|
-
html.should
|
252
|
+
html.should have_selector("tbody", :count => 1)
|
253
|
+
html.should have_selector("tr", :count => (@users.size + 1))
|
254
|
+
html.should have_selector("td", :count => (@users.size + 1))
|
255
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(1)", :content => @users.first.username)
|
260
256
|
end
|
261
257
|
end
|
262
258
|
|
@@ -266,8 +262,8 @@ describe SortingTableFor, :type => :helper do
|
|
266
262
|
table.column :price
|
267
263
|
table.column (value.price - 1)
|
268
264
|
end
|
269
|
-
html.should
|
270
|
-
html.should
|
265
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(1)", :content => number_to_currency(@users.first.price))
|
266
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(2)", :content => (@users.first.price - 1).to_s)
|
271
267
|
end
|
272
268
|
end
|
273
269
|
|
@@ -285,12 +281,8 @@ describe SortingTableFor, :type => :helper do
|
|
285
281
|
'hello'
|
286
282
|
end
|
287
283
|
end
|
288
|
-
|
289
|
-
|
290
|
-
else
|
291
|
-
html.should have_comp_tag('tr:nth-child(2) td:nth-child(1)', :text => 'username')
|
292
|
-
end
|
293
|
-
html.should have_comp_tag('tr:nth-child(2) td:nth-child(2)', :text => 'hello')
|
284
|
+
html.should have_selector('tr:nth-child(2) td:nth-child(1)', :content => '')
|
285
|
+
html.should have_selector('tr:nth-child(2) td:nth-child(2)', :content => 'hello')
|
294
286
|
end
|
295
287
|
end
|
296
288
|
|
@@ -301,7 +293,7 @@ describe SortingTableFor, :type => :helper do
|
|
301
293
|
value.username
|
302
294
|
end
|
303
295
|
end
|
304
|
-
html.should
|
296
|
+
html.should have_selector('tr:nth-child(2) td:nth-child(1)', :content => @users.first.username)
|
305
297
|
end
|
306
298
|
end
|
307
299
|
|
@@ -312,11 +304,11 @@ describe SortingTableFor, :type => :helper do
|
|
312
304
|
'hello'
|
313
305
|
end
|
314
306
|
end
|
315
|
-
html.should
|
316
|
-
html.should
|
307
|
+
html.should have_selector("tr:nth-child(2)[class='hello_class odd'][id=hello_id][title=hello_title]")
|
308
|
+
html.should have_selector("tr:nth-child(2) td:nth-child(1)[class='hi_class'][id=hi_id][title=hi_title]")
|
317
309
|
end
|
318
310
|
helper.output_buffer.concat(table_html)
|
319
|
-
helper.output_buffer.should
|
311
|
+
helper.output_buffer.should have_selector("table[class='table_class sorting_table_for'][id=table_id]")
|
320
312
|
end
|
321
313
|
|
322
314
|
it "should have option colspan" do
|
@@ -329,8 +321,8 @@ describe SortingTableFor, :type => :helper do
|
|
329
321
|
'my_colspan_2'
|
330
322
|
end
|
331
323
|
end
|
332
|
-
html.should
|
333
|
-
html.should
|
324
|
+
html.should have_selector('td[colspan="5"]', :count => @users.size)
|
325
|
+
html.should have_selector('td[colspan="3"]', :count => @users.size)
|
334
326
|
end
|
335
327
|
end
|
336
328
|
|
@@ -367,8 +359,8 @@ describe SortingTableFor, :type => :helper do
|
|
367
359
|
SortingTableFor::TableBuilder.reserved_columns = [:id, :firstname, :lastname, :position, :salary, :price, :active, :created_at, :updated_at]
|
368
360
|
helper.sorting_table_for(@users) do |table|
|
369
361
|
html = table.columns
|
370
|
-
html.should
|
371
|
-
html.should
|
362
|
+
html.should have_selector("tr", :count => (@users.size + 1))
|
363
|
+
html.should have_selector("td", :count => ((@users.size * 3) + 1))
|
372
364
|
end
|
373
365
|
end
|
374
366
|
|
@@ -379,24 +371,34 @@ describe SortingTableFor, :type => :helper do
|
|
379
371
|
table.column :username
|
380
372
|
table.column :price
|
381
373
|
end
|
382
|
-
html.should
|
374
|
+
html.should have_selector("td", :count => ((@users.size * 2) + 1))
|
383
375
|
end
|
384
376
|
end
|
385
377
|
|
386
|
-
it "should edit
|
378
|
+
it "should edit create actions" do
|
387
379
|
SortingTableFor::TableBuilder.default_actions = [:show, :edit_password, :edit, :delete]
|
388
380
|
helper.sorting_table_for(@users) do |table|
|
389
|
-
table.columns.should
|
381
|
+
table.columns.should have_selector("td", :count => (@users.size * (SortingTableForUser.content_columns.size + 4)) + 1)
|
390
382
|
end
|
391
383
|
end
|
392
384
|
|
393
|
-
it "should
|
394
|
-
pending('should check if the links are valids')
|
385
|
+
it "links should be correct by default" do
|
395
386
|
SortingTableFor::TableBuilder.default_actions = [:show, :edit_password, :edit, :delete]
|
396
387
|
helper.sorting_table_for(@users) do |table|
|
388
|
+
html = table.columns
|
389
|
+
html.should match("<a href=\"/sorting_table_for_users/#{@users.first.id}\"")
|
390
|
+
html.should match("<a href=\"/sorting_table_for_users/#{@users.first.id}/edit\"")
|
391
|
+
html.should match("<a href=\"/sorting_table_for_users/#{@users.first.id}\" data-confirm=\"translation missing: test.sorting_table_for_users.index.confirm_delete\" data-method=\"delete\" rel=\"nofollow\">")
|
397
392
|
end
|
398
393
|
end
|
399
394
|
|
395
|
+
it "should work with custom links" do
|
396
|
+
SortingTableFor::TableBuilder.default_actions = [:show, :edit_password, :edit, :delete]
|
397
|
+
helper.sorting_table_for(@users) do |table|
|
398
|
+
html = table.columns
|
399
|
+
html.should match("<a href=\"/sorting_table_for_users/#{@users.first.id}/edit_password\"")
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
400
403
|
end
|
401
|
-
## Add spec for links
|
402
404
|
end
|