tabletastic 0.2.0.pre6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -2
- data/lib/tabletastic/table_builder.rb +7 -4
- data/lib/tabletastic/version.rb +1 -1
- data/spec/spec_helper.rb +111 -115
- data/spec/tabletastic/table_builder_spec.rb +56 -23
- metadata +3 -4
data/CHANGELOG.rdoc
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
|
1
|
+
v0.2.0 (Oct 24, 2010)
|
2
2
|
|
3
|
-
*
|
3
|
+
* This gem is now Rails 3 only
|
4
4
|
* Update to Rails 3 API and idioms
|
5
|
+
* [DEPRECATED] use of table.data method without = in erb or haml. See README for more information.
|
5
6
|
* Add default table html options
|
6
7
|
* Add default lambda (table block) so that table_for can be called without passing a block
|
7
8
|
* Add has_one associations
|
8
9
|
* Add heading html hook for <th> elements
|
9
10
|
* Super-basic mongoid support (2.x branch)
|
11
|
+
* Add ability to pass :action_prefix an array (Thanks, brunowernimont)
|
10
12
|
|
11
13
|
v0.1.3 (Dec 28, 2009)
|
12
14
|
|
@@ -104,18 +104,21 @@ module Tabletastic
|
|
104
104
|
# Dynamically builds links for the action
|
105
105
|
def action_link(action, prefix)
|
106
106
|
html_class = "actions #{action.to_s}_link"
|
107
|
-
|
107
|
+
block = lambda do |resource|
|
108
108
|
compound_resource = [prefix, resource].compact
|
109
|
+
compound_resource.flatten! if prefix.kind_of?(Array)
|
109
110
|
case action
|
110
111
|
when :show
|
111
112
|
@template.link_to("Show", compound_resource)
|
112
113
|
when :destroy
|
113
|
-
@template.link_to("Destroy", compound_resource,
|
114
|
+
@template.link_to("Destroy", compound_resource,
|
115
|
+
:method => :delete, :confirm => @@destroy_confirm_message)
|
114
116
|
else # edit, other resource GET actions
|
115
|
-
@template.link_to(action.to_s.titleize,
|
117
|
+
@template.link_to(action.to_s.titleize,
|
118
|
+
@template.polymorphic_path(compound_resource, :action => action))
|
116
119
|
end
|
117
120
|
end
|
118
|
-
self.cell(action, :heading => "", :cell_html => {:class => html_class}, &
|
121
|
+
self.cell(action, :heading => "", :cell_html => {:class => html_class}, &block)
|
119
122
|
end
|
120
123
|
|
121
124
|
protected
|
data/lib/tabletastic/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,134 +1,130 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
RSpec.configure do |config|
|
20
|
-
config.include(RspecTagMatchers)
|
21
|
-
end
|
1
|
+
## Use bundler to exec the specs
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.setup
|
5
|
+
require 'rspec'
|
6
|
+
|
7
|
+
require 'rspec_tag_matchers'
|
8
|
+
require 'active_record'
|
9
|
+
require 'action_controller'
|
10
|
+
|
11
|
+
require 'action_view/base'
|
12
|
+
require 'action_view/template'
|
13
|
+
require 'action_view/helpers'
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.include(RspecTagMatchers)
|
17
|
+
end
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
19
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
20
|
+
|
21
|
+
module TabletasticSpecHelper
|
22
|
+
include ActiveSupport
|
23
|
+
include ActionView
|
24
|
+
include ActionView::Helpers::UrlHelper
|
25
|
+
include ActionView::Helpers::TagHelper
|
26
|
+
include ActionView::Helpers::TextHelper
|
27
|
+
include ActionView::Helpers::ActiveModelHelper
|
28
|
+
include ActionView::Helpers::RecordTagHelper
|
29
|
+
include ActionView::Helpers::CaptureHelper
|
30
|
+
include ActionView::Helpers::RawOutputHelper
|
31
|
+
include ActionDispatch::Routing::PolymorphicRoutes
|
32
|
+
|
33
|
+
def self.included(base)
|
34
|
+
base.class_eval do
|
35
|
+
attr_accessor :output_buffer
|
41
36
|
end
|
37
|
+
end
|
42
38
|
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
def reset_output_buffer!
|
40
|
+
@output_buffer = ActionView::OutputBuffer.new
|
41
|
+
end
|
46
42
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
43
|
+
module ::RspecTagMatchers
|
44
|
+
class HaveTag
|
45
|
+
def description
|
46
|
+
description = "have tag <#@selector>"
|
47
|
+
description << " with inner text '#@inner_text'" if @inner_text
|
48
|
+
description
|
51
49
|
end
|
52
50
|
end
|
51
|
+
def have_table_with_tag(selector, inner_text_or_options = nil, options = {}, &block)
|
52
|
+
HaveTag.new("table", nil, {}) &&
|
53
|
+
HaveTag.new(selector, inner_text_or_options, options, &block)
|
54
|
+
end
|
55
|
+
end
|
53
56
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
class MockARModel
|
58
|
+
def id
|
59
|
+
end
|
60
|
+
def to_key
|
61
|
+
[id]
|
57
62
|
end
|
58
|
-
|
63
|
+
def self.human_attribute_name(col)
|
64
|
+
col.humanize if col
|
59
65
|
end
|
60
|
-
|
66
|
+
def self.model_name
|
67
|
+
ActiveModel::Name.new(self)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
class ::Author < MockARModel; end
|
71
|
+
class ::Post < MockARModel; end
|
72
|
+
class ::Profile < MockARModel; end
|
73
|
+
|
74
|
+
def mock_everything
|
75
|
+
def post_path(post); "/posts/#{post.id}"; end
|
76
|
+
def admin_post_path(post); "/admin/posts/#{post.id}"; end
|
77
|
+
def author_post_path(author, post); "/authors/#{author.id}/posts/#{post.id}"; end
|
78
|
+
def admin_author_post_path(author, post); "/admin/authors/#{author.id}/posts/#{post.id}"; end
|
79
|
+
def edit_post_path(post); "/posts/#{post.id}/edit"; end
|
80
|
+
def edit_admin_post_path(post); "/admin/posts/#{post.id}/edit"; end
|
81
|
+
def edit_admin_author_post_path(author, post)
|
82
|
+
"/admin/authors/#{author.id}/posts/#{post.id}/edit"
|
61
83
|
end
|
62
84
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
# Sometimes we need a mock @post object and some Authors for belongs_to
|
70
|
-
@post = mock('post')
|
71
|
-
@post.stub!(:class).and_return(::Post)
|
72
|
-
@post.stub!(:id).and_return(nil)
|
73
|
-
@post.stub!(:author)
|
74
|
-
@post.stub!(:to_key).and_return([2])
|
75
|
-
::Post.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
76
|
-
::Post.stub!(:model_name).and_return(ActiveModel::Name.new(::Post))
|
77
|
-
|
78
|
-
@fred = mock('author', :to_key => nil)
|
79
|
-
@fred.stub!(:class).and_return(::Author)
|
80
|
-
@fred.stub!(:name).and_return('Fred Smith')
|
81
|
-
@fred.stub!(:id).and_return(37)
|
82
|
-
|
83
|
-
@profile = mock('profile')
|
84
|
-
@profile.stub!(:author).and_return(@fred)
|
85
|
-
@profile.stub!(:bio).and_return("This is my bio")
|
86
|
-
@fred.stub!(:profile).and_return(@profile)
|
87
|
-
|
88
|
-
::Author.stub!(:content_columns).and_return([mock('column', :name => "name")])
|
89
|
-
|
90
|
-
::Author.stub!(:find).and_return([@fred])
|
91
|
-
::Author.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
92
|
-
::Author.stub!(:human_name).and_return('Author')
|
93
|
-
::Author.stub!(:model_name).and_return(ActiveModel::Name.new(::Author))
|
94
|
-
|
95
|
-
@freds_post = mock('post')
|
96
|
-
@freds_post.stub!(:class).and_return(::Post)
|
97
|
-
@freds_post.stub!(:title).and_return('Fred\'s Post')
|
98
|
-
@freds_post.stub!(:body)
|
99
|
-
@freds_post.stub!(:id).and_return(19)
|
100
|
-
@freds_post.stub!(:to_key).and_return([19])
|
101
|
-
@freds_post.stub!(:author).and_return(@fred)
|
102
|
-
@freds_post.stub!(:author_id).and_return(@fred.id)
|
103
|
-
@fred.stub!(:posts).and_return([@freds_post])
|
104
|
-
@fred.stub!(:post_ids).and_return([@freds_post.id])
|
105
|
-
|
106
|
-
@mock_reflection_belongs_to_author = mock('reflection1', :options => {}, :name => :author, :macro => :belongs_to, :collection => false)
|
107
|
-
|
108
|
-
@mock_reflection_has_one_profile = mock('reflection2', :options => {}, :name => :profile, :macro => :has_one, :collection => false)
|
109
|
-
|
110
|
-
::Post.stub!(:reflect_on_association).and_return do |column_name|
|
111
|
-
@mock_reflection_belongs_to_author if column_name == :author
|
112
|
-
end
|
85
|
+
# Sometimes we need a mock @post object and some Authors for belongs_to
|
86
|
+
@post = Post.new
|
87
|
+
@post.stub(:id => nil)
|
88
|
+
@post.stub!(:author)
|
89
|
+
::Post.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
113
90
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
91
|
+
@fred = Author.new
|
92
|
+
@fred.stub(:name => "Fred Smith", :id => 37)
|
93
|
+
|
94
|
+
@profile = Profile.new
|
95
|
+
@profile.stub(:author => @fred, :bio => "This is my bio")
|
96
|
+
@fred.stub(:profile => @profile)
|
97
|
+
|
98
|
+
::Author.stub!(:content_columns).and_return([mock('column', :name => "name")])
|
99
|
+
::Author.stub!(:find).and_return([@fred])
|
118
100
|
|
101
|
+
@freds_post = Post.new
|
102
|
+
@freds_post.stub(:title => "Fred's Post", :id => 19, :author => @fred, :author_id => @fred.id)
|
103
|
+
@freds_post.stub!(:body)
|
104
|
+
@fred.stub(:posts => [@freds_post])
|
119
105
|
|
120
|
-
|
121
|
-
|
106
|
+
@mock_reflection_belongs_to_author = mock('reflection1', :options => {}, :name => :author, :macro => :belongs_to, :collection => false)
|
107
|
+
|
108
|
+
@mock_reflection_has_one_profile = mock('reflection2', :options => {}, :name => :profile, :macro => :has_one, :collection => false)
|
109
|
+
|
110
|
+
::Post.stub!(:reflect_on_association).and_return do |column_name|
|
111
|
+
@mock_reflection_belongs_to_author if column_name == :author
|
122
112
|
end
|
123
|
-
end
|
124
113
|
|
125
|
-
|
114
|
+
::Author.stub!(:reflect_on_association).and_return do |column_name|
|
115
|
+
mock('reflection', :options => {}, :klass => Post, :macro => :has_many) if column_name == :posts
|
116
|
+
@mock_reflection_has_one_profile if column_name == :profile
|
117
|
+
end
|
126
118
|
|
127
|
-
Spork.each_run do
|
128
|
-
# This code will be run each time you run your specs.
|
129
|
-
require 'tabletastic'
|
130
119
|
|
131
|
-
|
132
|
-
|
133
|
-
|
120
|
+
::Post.stub!(:reflect_on_all_associations).and_return([])
|
121
|
+
::Author.stub!(:reflect_on_all_associations).and_return([])
|
122
|
+
end
|
134
123
|
end
|
124
|
+
|
125
|
+
|
126
|
+
require 'tabletastic'
|
127
|
+
|
128
|
+
include TabletasticSpecHelper
|
129
|
+
include Tabletastic
|
130
|
+
include Tabletastic::Helper
|
@@ -65,6 +65,7 @@ describe Tabletastic::TableBuilder do
|
|
65
65
|
reset_output_buffer!
|
66
66
|
::Post.stub!(:respond_to?).with(:content_columns).and_return(false)
|
67
67
|
::Post.stub!(:respond_to?).with(:fields).and_return(true)
|
68
|
+
::Post.stub!(:respond_to?).with(:empty?).and_return(false)
|
68
69
|
::Post.stub!(:fields).and_return({'title' => '', 'created_at' => ''})
|
69
70
|
concat(table_for(@posts) { |t| t.data })
|
70
71
|
end
|
@@ -143,34 +144,66 @@ describe Tabletastic::TableBuilder do
|
|
143
144
|
end
|
144
145
|
|
145
146
|
context "with options[:actions_prefix]" do
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
147
|
+
context "with a single symbol as argument" do
|
148
|
+
it "includes path to admin post for :show" do
|
149
|
+
concat(table_for(@posts) do |t|
|
150
|
+
t.data(:actions => :show, :action_prefix => :admin)
|
151
|
+
end)
|
152
|
+
output_buffer.should have_tag("td:nth-child(3) a[@href=\"/admin/posts/#{@post.id}\"]", "Show")
|
153
|
+
end
|
152
154
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
155
|
+
it "includes path to admin post for :edit" do
|
156
|
+
concat(table_for(@posts) do |t|
|
157
|
+
t.data(:actions => :edit, :action_prefix => :admin)
|
158
|
+
end)
|
159
|
+
output_buffer.should have_tag("td:nth-child(3) a[@href=\"/admin/posts/#{@post.id}/edit\"]", "Edit")
|
160
|
+
end
|
161
|
+
|
162
|
+
it "includes path to admin post for :destroy" do
|
163
|
+
concat(table_for(@posts) do |t|
|
164
|
+
t.data(:actions => :destroy, :action_prefix => :admin)
|
165
|
+
end)
|
166
|
+
output_buffer.should have_tag("td:nth-child(3) a[@href=\"/admin/posts/#{@post.id}\"]", "Destroy")
|
167
|
+
end
|
168
|
+
|
169
|
+
it "includes path to admin for all actions" do
|
170
|
+
concat(table_for(@posts) do |t|
|
171
|
+
concat(t.data(:actions => :all, :action_prefix => :admin))
|
172
|
+
end)
|
173
|
+
output_buffer.should have_tag("td:nth-child(3) a[@href=\"/admin/posts/#{@post.id}\"]", "Show")
|
174
|
+
output_buffer.should have_tag("td:nth-child(4) a[@href=\"/admin/posts/#{@post.id}/edit\"]", "Edit")
|
175
|
+
output_buffer.should have_tag("td:nth-child(5) a[@href=\"/admin/posts/#{@post.id}\"]", "Destroy")
|
176
|
+
end
|
158
177
|
end
|
159
178
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
179
|
+
context "with a resource as an argument" do
|
180
|
+
it "nests the link within the resource correctly for :show" do
|
181
|
+
concat(table_for(@posts) do |t|
|
182
|
+
t.data(:actions => :show, :action_prefix => @fred)
|
183
|
+
end)
|
184
|
+
output_buffer.should have_tag("td:nth-child(3) a[@href=\"/authors/#{@fred.id}/posts/#{@post.id}\"]", "Show")
|
185
|
+
end
|
165
186
|
end
|
166
187
|
|
167
|
-
|
168
|
-
|
169
|
-
concat(
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
188
|
+
context "with an array as an argument" do
|
189
|
+
it "nests correctly for namespace and resource for :show" do
|
190
|
+
concat(table_for(@posts) do |t|
|
191
|
+
t.data(:actions => :show, :action_prefix => [:admin, @fred])
|
192
|
+
end)
|
193
|
+
output_buffer.should have_tag(
|
194
|
+
"td a[@href=\"/admin/authors/#{@fred.id}/posts/#{@post.id}\"]", "Show")
|
195
|
+
end
|
196
|
+
it "includes path to admin for all actions" do
|
197
|
+
concat(table_for(@posts) do |t|
|
198
|
+
concat(t.data(:actions => :all, :action_prefix => [:admin, @fred]))
|
199
|
+
end)
|
200
|
+
output_buffer.should have_tag(
|
201
|
+
"td a[@href=\"/admin/authors/#{@fred.id}/posts/#{@post.id}\"]", "Show")
|
202
|
+
output_buffer.should have_tag(
|
203
|
+
"td a[@href=\"/admin/authors/#{@fred.id}/posts/#{@post.id}/edit\"]", "Edit")
|
204
|
+
output_buffer.should have_tag(
|
205
|
+
"td a[@href=\"/admin/authors/#{@fred.id}/posts/#{@post.id}\"]", "Destroy")
|
206
|
+
end
|
174
207
|
end
|
175
208
|
end
|
176
209
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tabletastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
|
10
|
-
version: 0.2.0.pre6
|
9
|
+
version: 0.2.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Joshua Davey
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-09-11 00:00:00 -
|
17
|
+
date: 2010-09-11 00:00:00 -05:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|