tabletastic 0.2.0.pre2 → 0.2.0.pre3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tabletastic/helper.rb +4 -1
- data/lib/tabletastic/version.rb +1 -1
- data/spec/spec_helper.rb +99 -101
- data/spec/tabletastic/table_builder_spec.rb +316 -0
- data/spec/tabletastic/table_field_spec.rb +32 -0
- metadata +37 -7
data/lib/tabletastic/helper.rb
CHANGED
data/lib/tabletastic/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,116 +1,114 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
1
|
require 'rubygems'
|
2
|
+
require 'spork'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
gem gem_name, gem_version
|
11
|
-
require lib_name if lib_name
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
4
|
+
Spork.prefork do
|
5
|
+
## Use bundler to exec the specs
|
6
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
+
require 'bundler'
|
8
|
+
Bundler.setup
|
9
|
+
require 'rspec'
|
15
10
|
|
16
|
-
|
17
|
-
require '
|
18
|
-
|
19
|
-
smart_require 'rspec_tag_matchers', '>= 1.0.0'
|
20
|
-
smart_require 'activesupport', '>= 3.0.0.beta3', 'active_support'
|
21
|
-
smart_require 'actionpack', '>= 3.0.0.beta3', 'action_pack'
|
22
|
-
smart_require 'activerecord', '>= 3.0.0.beta3', 'active_record'
|
23
|
-
require 'action_controller'
|
24
|
-
require 'action_view/base'
|
25
|
-
require 'action_view/template'
|
26
|
-
require 'action_view/helpers'
|
27
|
-
Spec::Runner.configure do |config|
|
28
|
-
config.include(RspecTagMatchers)
|
29
|
-
end
|
11
|
+
require 'rspec_tag_matchers'
|
12
|
+
require 'active_record'
|
13
|
+
require 'action_controller'
|
30
14
|
|
31
|
-
|
32
|
-
require '
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
include ActionView::Helpers::UrlHelper
|
38
|
-
include ActionView::Helpers::TagHelper
|
39
|
-
include ActionView::Helpers::TextHelper
|
40
|
-
include ActionView::Helpers::ActiveModelHelper
|
41
|
-
include ActionView::Helpers::RecordIdentificationHelper
|
42
|
-
include ActionView::Helpers::RecordTagHelper
|
43
|
-
include ActionView::Helpers::CaptureHelper
|
44
|
-
include ActionView::Helpers::RawOutputHelper
|
45
|
-
include ActionController::PolymorphicRoutes
|
46
|
-
|
47
|
-
def self.included(base)
|
48
|
-
base.class_eval do
|
49
|
-
attr_accessor :output_buffer
|
50
|
-
end
|
15
|
+
require 'action_view/base'
|
16
|
+
require 'action_view/template'
|
17
|
+
require 'action_view/helpers'
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.include(RspecTagMatchers)
|
51
21
|
end
|
52
22
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
23
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
24
|
+
require 'tabletastic'
|
25
|
+
|
26
|
+
module TabletasticSpecHelper
|
27
|
+
include ActiveSupport
|
28
|
+
include ActionView
|
29
|
+
include ActionView::Helpers::UrlHelper
|
30
|
+
include ActionView::Helpers::TagHelper
|
31
|
+
include ActionView::Helpers::TextHelper
|
32
|
+
include ActionView::Helpers::ActiveModelHelper
|
33
|
+
include ActionView::Helpers::RecordIdentificationHelper
|
34
|
+
include ActionView::Helpers::RecordTagHelper
|
35
|
+
include ActionView::Helpers::CaptureHelper
|
36
|
+
include ActionView::Helpers::RawOutputHelper
|
37
|
+
include ActionController::PolymorphicRoutes
|
38
|
+
|
39
|
+
def self.included(base)
|
40
|
+
base.class_eval do
|
41
|
+
attr_accessor :output_buffer
|
42
|
+
end
|
57
43
|
end
|
58
|
-
end
|
59
44
|
|
60
|
-
|
61
|
-
|
45
|
+
module ::RspecTagMatchers
|
46
|
+
def have_table_with_tag(selector, inner_text_or_options = nil, options = {}, &block)
|
47
|
+
HaveTag.new("table", nil, {}) &&
|
48
|
+
HaveTag.new(selector, inner_text_or_options, options, &block)
|
49
|
+
end
|
62
50
|
end
|
63
|
-
end
|
64
|
-
class ::Author
|
65
|
-
end
|
66
51
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
# Sometimes we need a mock @post object and some Authors for belongs_to
|
74
|
-
@post = mock('post')
|
75
|
-
@post.stub!(:class).and_return(::Post)
|
76
|
-
@post.stub!(:id).and_return(nil)
|
77
|
-
@post.stub!(:author)
|
78
|
-
@post.stub!(:to_key).and_return([2])
|
79
|
-
::Post.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
80
|
-
::Post.stub!(:model_name).and_return(ActiveModel::Name.new(::Post))
|
81
|
-
|
82
|
-
@fred = mock('user')
|
83
|
-
@fred.stub!(:class).and_return(::Author)
|
84
|
-
@fred.stub!(:name).and_return('Fred Smith')
|
85
|
-
@fred.stub!(:id).and_return(37)
|
86
|
-
|
87
|
-
::Author.stub!(:find).and_return([@fred])
|
88
|
-
::Author.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
89
|
-
::Author.stub!(:human_name).and_return('Author')
|
90
|
-
::Author.stub!(:model_name).and_return(ActiveModel::Name.new(::Author))
|
91
|
-
::Author.stub!(:reflect_on_association).and_return { |column_name| mock('reflection', :options => {}, :klass => Post, :macro => :has_many) if column_name == :posts }
|
92
|
-
|
93
|
-
@freds_post = mock('post')
|
94
|
-
@freds_post.stub!(:class).and_return(::Post)
|
95
|
-
@freds_post.stub!(:title).and_return('Fred\'s Post')
|
96
|
-
@freds_post.stub!(:body)
|
97
|
-
@freds_post.stub!(:id).and_return(19)
|
98
|
-
@freds_post.stub!(:to_key).and_return([19])
|
99
|
-
@freds_post.stub!(:author).and_return(@fred)
|
100
|
-
@freds_post.stub!(:author_id).and_return(@fred.id)
|
101
|
-
@fred.stub!(:posts).and_return([@freds_post])
|
102
|
-
@fred.stub!(:post_ids).and_return([@freds_post.id])
|
103
|
-
|
104
|
-
@mock_reflection_belongs_to_author = mock('reflection', :options => {}, :name => :author, :klass => ::Author, :macro => :belongs_to)
|
105
|
-
|
106
|
-
::Post.stub!(:reflect_on_association).and_return do |column_name|
|
107
|
-
@mock_reflection_belongs_to_author if column_name == :author
|
52
|
+
class ::Post
|
53
|
+
def id
|
54
|
+
end
|
55
|
+
end
|
56
|
+
class ::Author
|
108
57
|
end
|
109
58
|
|
110
|
-
|
59
|
+
def mock_everything
|
60
|
+
def post_path(post); "/posts/#{post.id}"; end
|
61
|
+
def admin_post_path(post); "/admin/posts/#{post.id}"; end
|
62
|
+
def edit_post_path(post); "/posts/#{post.id}/edit"; end
|
63
|
+
def edit_admin_post_path(post); "/admin/posts/#{post.id}/edit"; end
|
64
|
+
|
65
|
+
# Sometimes we need a mock @post object and some Authors for belongs_to
|
66
|
+
@post = mock('post')
|
67
|
+
@post.stub!(:class).and_return(::Post)
|
68
|
+
@post.stub!(:id).and_return(nil)
|
69
|
+
@post.stub!(:author)
|
70
|
+
@post.stub!(:to_key).and_return([2])
|
71
|
+
::Post.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
72
|
+
::Post.stub!(:model_name).and_return(ActiveModel::Name.new(::Post))
|
73
|
+
|
74
|
+
@fred = mock('user')
|
75
|
+
@fred.stub!(:class).and_return(::Author)
|
76
|
+
@fred.stub!(:name).and_return('Fred Smith')
|
77
|
+
@fred.stub!(:id).and_return(37)
|
78
|
+
|
79
|
+
::Author.stub!(:find).and_return([@fred])
|
80
|
+
::Author.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
81
|
+
::Author.stub!(:human_name).and_return('Author')
|
82
|
+
::Author.stub!(:model_name).and_return(ActiveModel::Name.new(::Author))
|
83
|
+
::Author.stub!(:reflect_on_association).and_return { |column_name| mock('reflection', :options => {}, :klass => Post, :macro => :has_many) if column_name == :posts }
|
84
|
+
|
85
|
+
@freds_post = mock('post')
|
86
|
+
@freds_post.stub!(:class).and_return(::Post)
|
87
|
+
@freds_post.stub!(:title).and_return('Fred\'s Post')
|
88
|
+
@freds_post.stub!(:body)
|
89
|
+
@freds_post.stub!(:id).and_return(19)
|
90
|
+
@freds_post.stub!(:to_key).and_return([19])
|
91
|
+
@freds_post.stub!(:author).and_return(@fred)
|
92
|
+
@freds_post.stub!(:author_id).and_return(@fred.id)
|
93
|
+
@fred.stub!(:posts).and_return([@freds_post])
|
94
|
+
@fred.stub!(:post_ids).and_return([@freds_post.id])
|
95
|
+
|
96
|
+
@mock_reflection_belongs_to_author = mock('reflection', :options => {}, :name => :author, :klass => ::Author, :macro => :belongs_to)
|
97
|
+
|
98
|
+
::Post.stub!(:reflect_on_association).and_return do |column_name|
|
99
|
+
@mock_reflection_belongs_to_author if column_name == :author
|
100
|
+
end
|
101
|
+
|
102
|
+
::Post.stub!(:reflect_on_all_associations).with(:belongs_to).and_return([])
|
103
|
+
end
|
111
104
|
end
|
105
|
+
|
106
|
+
include TabletasticSpecHelper
|
107
|
+
include Tabletastic
|
108
|
+
include Tabletastic::Helper
|
112
109
|
end
|
113
110
|
|
114
|
-
|
115
|
-
|
116
|
-
|
111
|
+
Spork.each_run do
|
112
|
+
# This code will be run each time you run your specs.
|
113
|
+
|
114
|
+
end
|
@@ -0,0 +1,316 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tabletastic::TableBuilder do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@output_buffer = ActiveSupport::SafeBuffer.new
|
7
|
+
|
8
|
+
mock_everything
|
9
|
+
::Post.stub!(:content_columns).and_return([mock('column', :name => 'title'), mock('column', :name => 'body'), mock('column', :name => 'created_at')])
|
10
|
+
@post.stub!(:title).and_return("The title of the post")
|
11
|
+
@post.stub!(:body).and_return("Lorem ipsum")
|
12
|
+
@post.stub!(:created_at).and_return(Time.now)
|
13
|
+
@post.stub!(:id).and_return(2)
|
14
|
+
@posts = [@post]
|
15
|
+
end
|
16
|
+
|
17
|
+
context "without a block" do
|
18
|
+
context "with no other arguments" do
|
19
|
+
before do
|
20
|
+
concat table_for(@posts) { |t| t.data }
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should output table with id of the class of the collection" do
|
24
|
+
output_buffer.should have_tag("table#posts")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should output head" do
|
28
|
+
output_buffer.should have_table_with_tag("thead")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have a <th> for each attribute" do
|
32
|
+
# title and body
|
33
|
+
output_buffer.should have_table_with_tag("th", :count => 2)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should include header for Title" do
|
37
|
+
output_buffer.should have_table_with_tag("th", "Title")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should include header for Body" do
|
41
|
+
output_buffer.should have_table_with_tag("th", "Body")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should output body" do
|
45
|
+
output_buffer.should have_table_with_tag("tbody")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should include a row for each record" do
|
49
|
+
output_buffer.should have_table_with_tag("tbody") do |tbody|
|
50
|
+
tbody.should have_tag("tr", :count => 1)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should have data for each field" do
|
55
|
+
output_buffer.should have_table_with_tag("td", "The title of the post")
|
56
|
+
output_buffer.should have_table_with_tag("td", "Lorem ipsum")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should include the id for the <tr> for each record" do
|
60
|
+
output_buffer.should have_table_with_tag("tr#post_#{@post.id}")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should cycle row classes" do
|
64
|
+
@output_buffer = ""
|
65
|
+
@posts = [@post, @post]
|
66
|
+
table_for(@posts) do |t|
|
67
|
+
concat(t.data)
|
68
|
+
end
|
69
|
+
output_buffer.should have_table_with_tag("tr.odd")
|
70
|
+
output_buffer.should have_table_with_tag("tr.even")
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when collection has associations" do
|
74
|
+
it "should handle belongs_to associations" do
|
75
|
+
::Post.stub!(:reflect_on_all_associations).with(:belongs_to).and_return([@mock_reflection_belongs_to_author])
|
76
|
+
@posts = [@freds_post]
|
77
|
+
@output_buffer = ""
|
78
|
+
concat table_for(@posts) { |t| t.data }
|
79
|
+
output_buffer.should have_table_with_tag("th", "Author")
|
80
|
+
output_buffer.should have_table_with_tag("td", "Fred Smith")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "with options[:actions]" do
|
86
|
+
it "includes path to post for :show" do
|
87
|
+
table_for(@posts) do |t|
|
88
|
+
concat(t.data(:actions => :show))
|
89
|
+
end
|
90
|
+
output_buffer.should have_table_with_tag("a[@href=\"/posts/#{@post.id}\"]")
|
91
|
+
output_buffer.should have_table_with_tag("th", "")
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should have a cell with default class 'actions' and the action name" do
|
95
|
+
table_for(@posts) do |t|
|
96
|
+
concat(t.data(:actions => :show))
|
97
|
+
end
|
98
|
+
output_buffer.should have_tag("td.actions.show_link") do |td|
|
99
|
+
td.should have_tag("a")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it "includes path to post for :edit" do
|
104
|
+
table_for(@posts) do |t|
|
105
|
+
concat(t.data(:actions => :edit))
|
106
|
+
end
|
107
|
+
output_buffer.should have_tag("a[@href=\"/posts/#{@post.id}/edit\"]", "Edit")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "includes path to post for :destroy" do
|
111
|
+
table_for(@posts) do |t|
|
112
|
+
concat(t.data(:actions => :destroy))
|
113
|
+
end
|
114
|
+
output_buffer.should have_table_with_tag("a[@href=\"/posts/#{@post.id}\"]")
|
115
|
+
output_buffer.should have_table_with_tag("th", "")
|
116
|
+
end
|
117
|
+
|
118
|
+
it "includes path to post for :show and :edit" do
|
119
|
+
table_for(@posts) do |t|
|
120
|
+
concat(t.data(:actions => [:show, :edit]))
|
121
|
+
end
|
122
|
+
output_buffer.should have_tag("td:nth-child(3) a[@href=\"/posts/#{@post.id}\"]", "Show")
|
123
|
+
output_buffer.should have_tag("td:nth-child(4) a[@href=\"/posts/#{@post.id}/edit\"]", "Edit")
|
124
|
+
end
|
125
|
+
|
126
|
+
it "includes path to post for :all" do
|
127
|
+
table_for(@posts) do |t|
|
128
|
+
concat(t.data(:actions => :all))
|
129
|
+
end
|
130
|
+
output_buffer.should have_tag("td:nth-child(3) a[@href=\"/posts/#{@post.id}\"]", "Show")
|
131
|
+
output_buffer.should have_tag("td:nth-child(4) a[@href=\"/posts/#{@post.id}/edit\"]", "Edit")
|
132
|
+
output_buffer.should have_tag("td:nth-child(5) a[@href=\"/posts/#{@post.id}\"]", "Destroy")
|
133
|
+
end
|
134
|
+
|
135
|
+
context "with options[:actions_prefix]" do
|
136
|
+
it "includes path to admin post for :show" do
|
137
|
+
table_for(@posts) do |t|
|
138
|
+
concat(t.data(:actions => :show, :action_prefix => :admin))
|
139
|
+
end
|
140
|
+
output_buffer.should have_tag("td:nth-child(3) a[@href=\"/admin/posts/#{@post.id}\"]", "Show")
|
141
|
+
end
|
142
|
+
|
143
|
+
it "includes path to admin post for :edit" do
|
144
|
+
table_for(@posts) do |t|
|
145
|
+
concat(t.data(:actions => :edit, :action_prefix => :admin))
|
146
|
+
end
|
147
|
+
output_buffer.should have_tag("td:nth-child(3) a[@href=\"/admin/posts/#{@post.id}/edit\"]", "Edit")
|
148
|
+
end
|
149
|
+
|
150
|
+
it "includes path to admin post for :destroy" do
|
151
|
+
table_for(@posts) do |t|
|
152
|
+
concat(t.data(:actions => :destroy, :action_prefix => :admin))
|
153
|
+
end
|
154
|
+
output_buffer.should have_tag("td:nth-child(3) a[@href=\"/admin/posts/#{@post.id}\"]", "Destroy")
|
155
|
+
end
|
156
|
+
|
157
|
+
it "includes path to admin for all actions" do
|
158
|
+
table_for(@posts) do |t|
|
159
|
+
concat(t.data(:actions => :all, :action_prefix => :admin))
|
160
|
+
end
|
161
|
+
output_buffer.should have_tag("td:nth-child(3) a[@href=\"/admin/posts/#{@post.id}\"]", "Show")
|
162
|
+
output_buffer.should have_tag("td:nth-child(4) a[@href=\"/admin/posts/#{@post.id}/edit\"]", "Edit")
|
163
|
+
output_buffer.should have_tag("td:nth-child(5) a[@href=\"/admin/posts/#{@post.id}\"]", "Destroy")
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context "with a list of attributes" do
|
169
|
+
before do
|
170
|
+
table_for(@posts) do |t|
|
171
|
+
concat(t.data(:title, :created_at))
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should call each method passed in, and only those methods" do
|
176
|
+
output_buffer.should have_table_with_tag("th", "Title")
|
177
|
+
output_buffer.should have_table_with_tag("th", "Created at")
|
178
|
+
output_buffer.should_not have_table_with_tag("th", "Body")
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context "with a list of attributes and options[:actions]" do
|
183
|
+
it "includes path to post for :show" do
|
184
|
+
table_for(@posts) do |t|
|
185
|
+
concat(t.data(:title, :created_at, :actions => :show))
|
186
|
+
end
|
187
|
+
output_buffer.should have_tag("th:nth-child(1)", "Title")
|
188
|
+
output_buffer.should have_tag("th:nth-child(2)", "Created at")
|
189
|
+
output_buffer.should have_tag("th:nth-child(3)", "")
|
190
|
+
output_buffer.should_not have_tag("th", "Body")
|
191
|
+
|
192
|
+
output_buffer.should have_tag("td:nth-child(3) a[@href=\"/posts/#{@post.id}\"]")
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context "with a block" do
|
198
|
+
context "and normal columns" do
|
199
|
+
before do
|
200
|
+
concat(table_for(@posts) do |t|
|
201
|
+
t.data do
|
202
|
+
t.cell(:title)
|
203
|
+
t.cell(:body)
|
204
|
+
end
|
205
|
+
end)
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should include the data for the fields passed in" do
|
209
|
+
output_buffer.should have_table_with_tag("th", "Title")
|
210
|
+
output_buffer.should have_tag("td", "The title of the post")
|
211
|
+
output_buffer.should have_tag("td", "Lorem ipsum")
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context "with custom cell options" do
|
216
|
+
before do
|
217
|
+
concat(table_for(@posts) do |t|
|
218
|
+
t.data do
|
219
|
+
t.cell(:title, :heading => "FooBar")
|
220
|
+
t.cell(:body, :cell_html => {:class => "batquux"})
|
221
|
+
end
|
222
|
+
end)
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should change the heading label for :heading option" do
|
226
|
+
output_buffer.should have_table_with_tag("th", "FooBar")
|
227
|
+
output_buffer.should have_table_with_tag("th", "Body")
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should pass :cell_html to the cell" do
|
231
|
+
output_buffer.should have_table_with_tag("td.batquux")
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context "with custom cell options" do
|
236
|
+
before do
|
237
|
+
concat(table_for(@posts) do |t|
|
238
|
+
t.data do
|
239
|
+
t.cell(:title) {|p| link_to p.title, "/" }
|
240
|
+
t.cell(:body, :heading => "Content") {|p| p.body }
|
241
|
+
end
|
242
|
+
end)
|
243
|
+
end
|
244
|
+
|
245
|
+
it "accepts a block as a lazy attribute" do
|
246
|
+
output_buffer.should have_table_with_tag("th:nth-child(1)", "Title")
|
247
|
+
output_buffer.should have_table_with_tag("td:nth-child(1)") do |td|
|
248
|
+
td.should have_tag("a", "The title of the post")
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
it "accepts a block as a lazy attribute (2)" do
|
253
|
+
output_buffer.should have_table_with_tag("th:nth-child(2)", "Content")
|
254
|
+
output_buffer.should have_table_with_tag("td:nth-child(2)", "Lorem ipsum")
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
context "with options[:actions]" do
|
259
|
+
it "includes path to post for :show" do
|
260
|
+
concat(table_for(@posts) do |t|
|
261
|
+
t.data(:actions => :show) do
|
262
|
+
t.cell(:title)
|
263
|
+
t.cell(:body)
|
264
|
+
end
|
265
|
+
end)
|
266
|
+
output_buffer.should have_table_with_tag("td:nth-child(3) a[@href=\"/posts/#{@post.id}\"]")
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
context "and normal/association columns" do
|
271
|
+
before do
|
272
|
+
::Post.stub!(:reflect_on_all_associations).with(:belongs_to).and_return([@mock_reflection_belongs_to_author])
|
273
|
+
@posts = [@freds_post]
|
274
|
+
concat(table_for(@posts) do |t|
|
275
|
+
t.data do
|
276
|
+
t.cell(:title)
|
277
|
+
t.cell(:author)
|
278
|
+
end
|
279
|
+
end)
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should include normal columns" do
|
283
|
+
output_buffer.should have_table_with_tag("th:nth-child(1)", "Title")
|
284
|
+
output_buffer.should have_table_with_tag("td:nth-child(1)", "Fred's Post")
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should include belongs_to associations" do
|
288
|
+
output_buffer.should have_table_with_tag("th:nth-child(2)", "Author")
|
289
|
+
output_buffer.should have_table_with_tag("td:nth-child(2)", "Fred Smith")
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
context "using human_attribute_names" do
|
295
|
+
it "should work" do
|
296
|
+
::Post.stub!(:human_attribute_name).with('body').and_return("Blah blue")
|
297
|
+
|
298
|
+
concat(table_for(@posts) do |t|
|
299
|
+
t.data do
|
300
|
+
t.cell(:title)
|
301
|
+
t.cell(:body)
|
302
|
+
end
|
303
|
+
end)
|
304
|
+
|
305
|
+
output_buffer.should have_table_with_tag("th", "Blah blue")
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
context "when table_for is not passed a block" do
|
310
|
+
it "the data should use the default option" do
|
311
|
+
Tabletastic.default_table_block = lambda {|table| table.data}
|
312
|
+
concat table_for(@posts)
|
313
|
+
output_buffer.should have_table_with_tag("td", "The title of the post")
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tabletastic::TableField do
|
4
|
+
it "should guess its heading automatically" do
|
5
|
+
tf = TableField.new(:method)
|
6
|
+
tf.method_or_proc.should == :method
|
7
|
+
tf.heading.should == "Method"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should know its heading when provided" do
|
11
|
+
tf = TableField.new(:method, :heading => 'Foo', :klass => ::Post)
|
12
|
+
tf.heading.should == "Foo"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should know what to do with a record" do
|
16
|
+
tf = TableField.new(:downcase)
|
17
|
+
tf.cell_data("HELLO").should == "hello"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should use a human_attribute_name whenever possible" do
|
21
|
+
::Post.stub!(:human_attribute_name).with('method').and_return("Blah blue")
|
22
|
+
tf = TableField.new(:method, :klass => ::Post)
|
23
|
+
tf.heading.should == "Blah blue"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should know what to do with a record (proc)" do
|
27
|
+
tf = TableField.new(:fake) do |record|
|
28
|
+
record.upcase
|
29
|
+
end
|
30
|
+
tf.cell_data("hello").should == "HELLO"
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tabletastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: -1876988178
|
4
5
|
prerelease: true
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 2
|
8
9
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.2.0.
|
10
|
+
- pre3
|
11
|
+
version: 0.2.0.pre3
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Joshua Davey
|
@@ -15,21 +16,40 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-
|
19
|
+
date: 2010-06-28 00:00:00 -05:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
23
|
+
name: activesupport
|
23
24
|
prerelease: false
|
24
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: -1848230022
|
31
|
+
segments:
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
- 0
|
35
|
+
- beta2
|
36
|
+
version: 3.0.0.beta2
|
37
|
+
type: :runtime
|
38
|
+
version_requirements: *id001
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: rspec
|
41
|
+
prerelease: false
|
42
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
25
44
|
requirements:
|
26
45
|
- - ">="
|
27
46
|
- !ruby/object:Gem::Version
|
47
|
+
hash: 3
|
28
48
|
segments:
|
29
49
|
- 0
|
30
50
|
version: "0"
|
31
51
|
type: :development
|
32
|
-
version_requirements: *
|
52
|
+
version_requirements: *id002
|
33
53
|
description: A table builder for active record collections that produces semantically rich and accessible table markup
|
34
54
|
email: josh@joshuadavey.com
|
35
55
|
executables: []
|
@@ -49,6 +69,10 @@ files:
|
|
49
69
|
- README.rdoc
|
50
70
|
- CHANGELOG.rdoc
|
51
71
|
- init.rb
|
72
|
+
- spec/tabletastic/table_builder_spec.rb
|
73
|
+
- spec/tabletastic/table_field_spec.rb
|
74
|
+
- spec/tabletastic_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
52
76
|
has_rdoc: true
|
53
77
|
homepage: http://github.com/jgdavey/tabletastic
|
54
78
|
licenses: []
|
@@ -59,16 +83,20 @@ rdoc_options: []
|
|
59
83
|
require_paths:
|
60
84
|
- lib
|
61
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
62
87
|
requirements:
|
63
88
|
- - ">="
|
64
89
|
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
65
91
|
segments:
|
66
92
|
- 0
|
67
93
|
version: "0"
|
68
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
69
96
|
requirements:
|
70
97
|
- - ">="
|
71
98
|
- !ruby/object:Gem::Version
|
99
|
+
hash: 23
|
72
100
|
segments:
|
73
101
|
- 1
|
74
102
|
- 3
|
@@ -77,10 +105,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
105
|
requirements: []
|
78
106
|
|
79
107
|
rubyforge_project:
|
80
|
-
rubygems_version: 1.3.
|
108
|
+
rubygems_version: 1.3.7
|
81
109
|
signing_key:
|
82
110
|
specification_version: 3
|
83
111
|
summary: A smarter table builder for Rails collections
|
84
112
|
test_files:
|
85
|
-
- spec/
|
113
|
+
- spec/tabletastic/table_builder_spec.rb
|
114
|
+
- spec/tabletastic/table_field_spec.rb
|
86
115
|
- spec/tabletastic_spec.rb
|
116
|
+
- spec/spec_helper.rb
|